2012-09-15 15:17:34 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2015-04-10 05:58:08 +02:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 13:40:32 +01:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2017-12-11 23:55:31 -08:00
|
|
|
*
|
2015-04-10 05:58:08 +02:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2015-11-19 13:16:43 +01:00
|
|
|
/* X/EGL context. Mostly used for testing GLES code paths. */
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2015-09-16 05:53:34 +02:00
|
|
|
#include <stdint.h>
|
2016-09-11 16:24:02 +02:00
|
|
|
#include <stdlib.h>
|
2015-09-16 05:53:34 +02:00
|
|
|
|
2016-09-06 19:39:02 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2016-07-08 12:30:53 -04:00
|
|
|
#include "../../frontend/frontend_driver.h"
|
2018-03-29 15:20:14 -05:00
|
|
|
#include "../../configuration.h"
|
2016-07-08 02:38:33 +02:00
|
|
|
|
2015-11-19 13:16:43 +01:00
|
|
|
#include "../common/egl_common.h"
|
2015-11-17 08:01:33 +01:00
|
|
|
#include "../common/gl_common.h"
|
2015-04-09 05:02:57 +02:00
|
|
|
#include "../common/x11_common.h"
|
2017-04-26 15:29:21 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_XINERAMA
|
2017-03-23 19:59:11 +01:00
|
|
|
#include "../common/xinerama_common.h"
|
2017-04-26 15:29:21 +02:00
|
|
|
#endif
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2014-04-30 10:00:52 +02:00
|
|
|
#ifndef EGL_OPENGL_ES3_BIT_KHR
|
|
|
|
#define EGL_OPENGL_ES3_BIT_KHR 0x0040
|
|
|
|
#endif
|
|
|
|
|
2017-04-19 07:08:05 -06:00
|
|
|
#ifndef EGL_PLATFORM_X11_KHR
|
|
|
|
#define EGL_PLATFORM_X11_KHR 0x31D5
|
|
|
|
#endif
|
|
|
|
|
2016-03-01 06:49:05 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
#ifdef HAVE_EGL
|
2015-12-08 13:54:03 -03:00
|
|
|
egl_ctx_data_t egl;
|
2016-03-01 06:49:05 +01:00
|
|
|
#endif
|
2015-12-08 13:54:03 -03:00
|
|
|
bool should_reset_mode;
|
|
|
|
} xegl_ctx_data_t;
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
static enum gfx_ctx_api xegl_api = GFX_CTX_NONE;
|
2016-02-22 11:54:19 +01:00
|
|
|
|
|
|
|
static int x_nul_handler(Display *dpy, XErrorEvent *event)
|
2013-02-23 15:15:10 +01:00
|
|
|
{
|
|
|
|
(void)dpy;
|
|
|
|
(void)event;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-20 14:31:09 +01:00
|
|
|
static void gfx_ctx_xegl_destroy(void *data)
|
|
|
|
{
|
2015-12-08 13:54:03 -03:00
|
|
|
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
|
|
|
|
|
2015-11-20 14:31:09 +01:00
|
|
|
x11_input_ctx_destroy();
|
2016-03-01 06:49:05 +01:00
|
|
|
#ifdef HAVE_EGL
|
|
|
|
egl_destroy(&xegl->egl);
|
|
|
|
#endif
|
2015-11-20 14:31:09 +01:00
|
|
|
|
|
|
|
if (g_x11_win)
|
|
|
|
{
|
2017-03-23 19:46:06 +01:00
|
|
|
#ifdef HAVE_XINERAMA
|
2015-11-20 14:31:09 +01:00
|
|
|
/* Save last used monitor for later. */
|
2017-03-23 19:46:06 +01:00
|
|
|
xinerama_save_last_used_monitor(RootWindow(
|
2016-02-14 16:39:27 +01:00
|
|
|
g_x11_dpy, DefaultScreen(g_x11_dpy)));
|
2017-03-23 19:46:06 +01:00
|
|
|
#endif
|
2015-11-20 14:31:09 +01:00
|
|
|
x11_window_destroy(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
x11_colormap_destroy();
|
|
|
|
|
2015-12-08 13:54:03 -03:00
|
|
|
if (xegl->should_reset_mode)
|
2015-11-20 14:31:09 +01:00
|
|
|
{
|
2017-03-23 20:07:56 +01:00
|
|
|
x11_exit_fullscreen(g_x11_dpy);
|
2015-12-08 13:54:03 -03:00
|
|
|
xegl->should_reset_mode = false;
|
2015-11-20 14:31:09 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 13:54:03 -03:00
|
|
|
free(data);
|
|
|
|
|
2017-12-11 23:55:31 -08:00
|
|
|
/* Do not close g_x11_dpy. We'll keep one for the entire application
|
2015-11-20 14:31:09 +01:00
|
|
|
* lifecycle to work-around nVidia EGL limitations.
|
|
|
|
*/
|
|
|
|
}
|
2012-09-25 01:26:22 +02:00
|
|
|
|
2016-10-08 14:37:26 +02:00
|
|
|
#define XEGL_ATTRIBS_BASE \
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, \
|
|
|
|
EGL_RED_SIZE, 1, \
|
|
|
|
EGL_GREEN_SIZE, 1, \
|
|
|
|
EGL_BLUE_SIZE, 1, \
|
|
|
|
EGL_ALPHA_SIZE, 0, \
|
|
|
|
EGL_DEPTH_SIZE, 0
|
|
|
|
|
2017-01-22 18:29:22 +01:00
|
|
|
static void *gfx_ctx_xegl_init(video_frame_info_t *video_info, void *video_driver)
|
2014-10-27 14:35:23 +01:00
|
|
|
{
|
2016-03-01 06:49:05 +01:00
|
|
|
#ifdef HAVE_EGL
|
2012-09-25 13:25:03 +02:00
|
|
|
static const EGLint egl_attribs_gl[] = {
|
2014-10-27 14:35:23 +01:00
|
|
|
XEGL_ATTRIBS_BASE,
|
2012-09-24 22:51:26 +02:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
2012-09-16 01:27:32 +02:00
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
|
2012-09-25 13:25:03 +02:00
|
|
|
static const EGLint egl_attribs_gles[] = {
|
2014-10-27 14:35:23 +01:00
|
|
|
XEGL_ATTRIBS_BASE,
|
2012-09-25 13:25:03 +02:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
|
2014-04-30 10:00:52 +02:00
|
|
|
#ifdef EGL_KHR_create_context
|
2013-12-13 14:19:25 +01:00
|
|
|
static const EGLint egl_attribs_gles3[] = {
|
2014-10-27 14:35:23 +01:00
|
|
|
XEGL_ATTRIBS_BASE,
|
2013-12-13 14:19:25 +01:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
|
|
|
#endif
|
2016-03-01 06:56:41 +01:00
|
|
|
#ifdef HAVE_VG
|
2012-09-25 13:25:03 +02:00
|
|
|
static const EGLint egl_attribs_vg[] = {
|
2014-10-27 14:35:23 +01:00
|
|
|
XEGL_ATTRIBS_BASE,
|
2012-09-25 13:25:03 +02:00
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
|
|
|
|
EGL_NONE,
|
|
|
|
};
|
2016-03-01 06:56:41 +01:00
|
|
|
#endif
|
|
|
|
const EGLint *attrib_ptr = NULL;
|
2015-11-19 18:01:37 +01:00
|
|
|
EGLint major, minor;
|
|
|
|
EGLint n;
|
2016-03-01 06:49:05 +01:00
|
|
|
#endif
|
2015-12-08 13:54:03 -03:00
|
|
|
xegl_ctx_data_t *xegl;
|
|
|
|
|
2015-11-20 13:27:31 +01:00
|
|
|
if (g_egl_inited)
|
2015-12-08 12:18:57 -03:00
|
|
|
return NULL;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
|
|
|
XInitThreads();
|
|
|
|
|
2015-12-08 13:54:03 -03:00
|
|
|
xegl = (xegl_ctx_data_t*)calloc(1, sizeof(xegl_ctx_data_t));
|
|
|
|
if (!xegl)
|
|
|
|
return NULL;
|
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
switch (xegl_api)
|
2012-09-25 13:25:03 +02:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
attrib_ptr = egl_attribs_gl;
|
|
|
|
break;
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
2014-04-30 10:00:52 +02:00
|
|
|
#ifdef EGL_KHR_create_context
|
2015-12-08 13:54:03 -03:00
|
|
|
if (xegl->egl.major >= 3)
|
2013-12-13 14:19:25 +01:00
|
|
|
attrib_ptr = egl_attribs_gles3;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
attrib_ptr = egl_attribs_gles;
|
2012-09-25 13:25:03 +02:00
|
|
|
break;
|
|
|
|
case GFX_CTX_OPENVG_API:
|
2016-03-01 06:56:41 +01:00
|
|
|
#ifdef HAVE_VG
|
2012-09-25 13:25:03 +02:00
|
|
|
attrib_ptr = egl_attribs_vg;
|
2016-03-01 06:56:41 +01:00
|
|
|
#endif
|
2012-09-25 13:25:03 +02:00
|
|
|
break;
|
|
|
|
default:
|
2016-03-01 06:56:41 +01:00
|
|
|
break;
|
2012-09-25 13:25:03 +02:00
|
|
|
}
|
|
|
|
|
2015-11-19 11:07:52 +01:00
|
|
|
if (!x11_connect())
|
|
|
|
goto error;
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2016-03-01 06:49:05 +01:00
|
|
|
#ifdef HAVE_EGL
|
2017-04-16 11:12:05 -06:00
|
|
|
if (!egl_init_context(&xegl->egl, EGL_PLATFORM_X11_KHR,
|
|
|
|
(EGLNativeDisplayType)g_x11_dpy, &major, &minor, &n, attrib_ptr))
|
2012-12-11 02:43:29 +02:00
|
|
|
{
|
2014-03-09 16:50:18 +01:00
|
|
|
egl_report_error();
|
2012-09-15 15:17:34 +02:00
|
|
|
goto error;
|
2012-12-11 02:43:29 +02:00
|
|
|
}
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2016-03-01 06:49:05 +01:00
|
|
|
if (n == 0 || !egl_has_config(&xegl->egl))
|
2012-12-11 02:43:29 +02:00
|
|
|
goto error;
|
2016-03-01 06:49:05 +01:00
|
|
|
#endif
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2015-12-08 13:54:03 -03:00
|
|
|
return xegl;
|
2012-09-15 15:17:34 +02:00
|
|
|
|
|
|
|
error:
|
2015-12-08 13:54:03 -03:00
|
|
|
gfx_ctx_xegl_destroy(xegl);
|
2015-12-08 12:18:57 -03:00
|
|
|
return NULL;
|
2012-09-15 15:17:34 +02:00
|
|
|
}
|
|
|
|
|
2015-12-08 13:54:03 -03:00
|
|
|
static EGLint *xegl_fill_attribs(xegl_ctx_data_t *xegl, EGLint *attr)
|
2014-04-20 13:54:29 +02:00
|
|
|
{
|
2018-03-01 21:16:54 +01:00
|
|
|
switch (xegl_api)
|
2014-04-20 13:54:29 +02:00
|
|
|
{
|
|
|
|
#ifdef EGL_KHR_create_context
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2015-04-10 05:58:08 +02:00
|
|
|
{
|
2015-12-08 13:54:03 -03:00
|
|
|
unsigned version = xegl->egl.major * 1000 + xegl->egl.minor;
|
2015-05-20 19:56:12 +02:00
|
|
|
bool core = version >= 3001;
|
2015-01-10 17:51:00 +01:00
|
|
|
#ifdef GL_DEBUG
|
2016-05-12 02:58:09 +02:00
|
|
|
bool debug = true;
|
2015-09-29 17:35:28 +02:00
|
|
|
#else
|
2016-05-12 02:58:09 +02:00
|
|
|
struct retro_hw_render_callback *hwr = video_driver_get_hw_context();
|
|
|
|
bool debug = hwr->debug_context;
|
2014-04-20 13:54:29 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-10 05:58:08 +02:00
|
|
|
if (core)
|
|
|
|
{
|
|
|
|
*attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR;
|
2015-12-08 13:54:03 -03:00
|
|
|
*attr++ = xegl->egl.major;
|
2015-04-10 05:58:08 +02:00
|
|
|
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
|
2015-12-08 13:54:03 -03:00
|
|
|
*attr++ = xegl->egl.minor;
|
2015-04-10 05:58:08 +02:00
|
|
|
|
|
|
|
/* Technically, we don't have core/compat until 3.2.
|
2017-12-11 23:55:31 -08:00
|
|
|
* Version 3.1 is either compat or not depending
|
2015-04-10 05:58:08 +02:00
|
|
|
* on GL_ARB_compatibility.
|
|
|
|
*/
|
|
|
|
if (version >= 3002)
|
|
|
|
{
|
|
|
|
*attr++ = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
|
|
|
|
*attr++ = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
|
|
|
|
}
|
|
|
|
}
|
2014-10-27 14:35:23 +01:00
|
|
|
|
2015-04-10 05:58:08 +02:00
|
|
|
if (debug)
|
2014-04-20 13:54:29 +02:00
|
|
|
{
|
2015-04-10 05:58:08 +02:00
|
|
|
*attr++ = EGL_CONTEXT_FLAGS_KHR;
|
|
|
|
*attr++ = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
|
2014-04-20 13:54:29 +02:00
|
|
|
}
|
|
|
|
|
2015-04-10 05:58:08 +02:00
|
|
|
break;
|
2014-04-20 13:54:29 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
2015-04-10 05:58:08 +02:00
|
|
|
/* Same as EGL_CONTEXT_MAJOR_VERSION. */
|
2014-10-27 14:35:23 +01:00
|
|
|
*attr++ = EGL_CONTEXT_CLIENT_VERSION;
|
2015-12-08 13:54:03 -03:00
|
|
|
*attr++ = xegl->egl.major ? (EGLint)xegl->egl.major : 2;
|
2014-05-03 15:21:14 +02:00
|
|
|
#ifdef EGL_KHR_create_context
|
2015-12-08 13:54:03 -03:00
|
|
|
if (xegl->egl.minor > 0)
|
2014-05-03 15:21:14 +02:00
|
|
|
{
|
|
|
|
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
|
2015-12-08 13:54:03 -03:00
|
|
|
*attr++ = xegl->egl.minor;
|
2014-05-03 15:21:14 +02:00
|
|
|
}
|
|
|
|
#endif
|
2014-04-20 13:54:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*attr = EGL_NONE;
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
2016-03-01 06:49:05 +01:00
|
|
|
/* forward declaration */
|
|
|
|
static void gfx_ctx_xegl_set_swap_interval(void *data, unsigned swap_interval);
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static bool gfx_ctx_xegl_set_video_mode(void *data,
|
2017-01-18 17:41:27 +01:00
|
|
|
video_frame_info_t *video_info,
|
2017-01-11 06:35:50 +01:00
|
|
|
unsigned width, unsigned height,
|
|
|
|
bool fullscreen)
|
2012-09-15 15:17:34 +02:00
|
|
|
{
|
2015-11-19 11:04:17 +01:00
|
|
|
XEvent event;
|
2015-01-10 17:51:00 +01:00
|
|
|
EGLint egl_attribs[16];
|
|
|
|
EGLint vid, num_visuals;
|
2016-11-06 18:41:59 +01:00
|
|
|
EGLint *attr = NULL;
|
|
|
|
bool true_full = false;
|
|
|
|
int x_off = 0;
|
|
|
|
int y_off = 0;
|
|
|
|
XVisualInfo temp = {0};
|
2015-01-10 17:51:00 +01:00
|
|
|
XSetWindowAttributes swa = {0};
|
2016-11-06 18:41:59 +01:00
|
|
|
XVisualInfo *vi = NULL;
|
2018-04-02 20:01:14 -05:00
|
|
|
char *wm_name = NULL;
|
2016-11-06 18:41:59 +01:00
|
|
|
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
|
2018-03-30 15:50:11 +02:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2015-06-26 17:46:13 +02:00
|
|
|
int (*old_handler)(Display*, XErrorEvent*) = NULL;
|
|
|
|
|
2016-07-08 02:38:33 +02:00
|
|
|
frontend_driver_install_signal_handler();
|
2012-09-16 01:27:32 +02:00
|
|
|
|
2015-01-10 17:51:00 +01:00
|
|
|
attr = egl_attribs;
|
2015-12-08 13:54:03 -03:00
|
|
|
attr = xegl_fill_attribs(xegl, attr);
|
2014-02-06 22:49:14 +01:00
|
|
|
|
2016-03-01 06:49:05 +01:00
|
|
|
#ifdef HAVE_EGL
|
|
|
|
if (!egl_get_native_visual_id(&xegl->egl, &vid))
|
2012-09-15 15:17:34 +02:00
|
|
|
goto error;
|
2016-03-01 06:49:05 +01:00
|
|
|
#endif
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2012-09-16 01:27:32 +02:00
|
|
|
temp.visualid = vid;
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2015-11-19 10:00:25 +01:00
|
|
|
vi = XGetVisualInfo(g_x11_dpy, VisualIDMask, &temp, &num_visuals);
|
2012-09-15 15:17:34 +02:00
|
|
|
if (!vi)
|
|
|
|
goto error;
|
|
|
|
|
2016-02-14 16:39:27 +01:00
|
|
|
swa.colormap = g_x11_cmap = XCreateColormap(
|
|
|
|
g_x11_dpy, RootWindow(g_x11_dpy, vi->screen),
|
2012-09-15 15:17:34 +02:00
|
|
|
vi->visual, AllocNone);
|
2017-12-11 23:55:31 -08:00
|
|
|
swa.event_mask = StructureNotifyMask | KeyPressMask |
|
2016-02-14 16:39:27 +01:00
|
|
|
ButtonPressMask | ButtonReleaseMask | KeyReleaseMask;
|
2018-04-02 20:01:14 -05:00
|
|
|
swa.override_redirect = False;
|
2012-09-29 10:47:55 +02:00
|
|
|
|
2017-01-18 17:41:27 +01:00
|
|
|
if (fullscreen && !video_info->windowed_fullscreen)
|
2012-09-29 10:47:55 +02:00
|
|
|
{
|
2017-03-23 20:07:56 +01:00
|
|
|
if (x11_enter_fullscreen(video_info, g_x11_dpy, width, height))
|
2012-10-05 14:15:54 +02:00
|
|
|
{
|
2015-12-08 13:54:03 -03:00
|
|
|
xegl->should_reset_mode = true;
|
2012-10-05 14:15:54 +02:00
|
|
|
true_full = true;
|
|
|
|
}
|
2012-10-23 23:17:56 +02:00
|
|
|
else
|
|
|
|
RARCH_ERR("[X/EGL]: Entering true fullscreen failed. Will attempt windowed mode.\n");
|
2012-09-29 10:47:55 +02:00
|
|
|
}
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2018-04-02 20:01:14 -05:00
|
|
|
wm_name = x11_get_wm_name(g_x11_dpy);
|
|
|
|
if (wm_name)
|
|
|
|
{
|
|
|
|
RARCH_LOG("[X/EGL]: Window manager is %s.\n", wm_name);
|
|
|
|
|
|
|
|
if (true_full && strcasestr(wm_name, "xfwm"))
|
|
|
|
{
|
|
|
|
RARCH_LOG("[X/EGL]: Using override-redirect workaround.\n");
|
|
|
|
swa.override_redirect = True;
|
|
|
|
}
|
|
|
|
free(wm_name);
|
|
|
|
}
|
2018-04-02 20:21:32 -05:00
|
|
|
if (!x11_has_net_wm_fullscreen(g_x11_dpy) && true_full)
|
|
|
|
swa.override_redirect = True;
|
2018-03-29 17:11:32 -05:00
|
|
|
|
2017-01-18 17:41:27 +01:00
|
|
|
if (video_info->monitor_index)
|
|
|
|
g_x11_screen = video_info->monitor_index - 1;
|
2012-10-12 21:15:58 +02:00
|
|
|
|
2012-10-12 19:05:29 +02:00
|
|
|
#ifdef HAVE_XINERAMA
|
2015-12-01 08:42:33 +01:00
|
|
|
if (fullscreen || g_x11_screen != 0)
|
2012-10-12 19:05:29 +02:00
|
|
|
{
|
|
|
|
unsigned new_width = width;
|
|
|
|
unsigned new_height = height;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2017-03-23 19:46:06 +01:00
|
|
|
if (xinerama_get_coord(g_x11_dpy, g_x11_screen,
|
2016-02-14 16:39:27 +01:00
|
|
|
&x_off, &y_off, &new_width, &new_height))
|
2015-12-01 08:42:33 +01:00
|
|
|
RARCH_LOG("[X/EGL]: Using Xinerama on screen #%u.\n", g_x11_screen);
|
2012-10-12 19:05:29 +02:00
|
|
|
else
|
|
|
|
RARCH_LOG("[X/EGL]: Xinerama is not active on screen.\n");
|
|
|
|
|
|
|
|
if (fullscreen)
|
|
|
|
{
|
|
|
|
width = new_width;
|
|
|
|
height = new_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RARCH_LOG("[X/EGL]: X = %d, Y = %d, W = %u, H = %u.\n",
|
|
|
|
x_off, y_off, width, height);
|
|
|
|
|
2015-11-19 10:00:25 +01:00
|
|
|
g_x11_win = XCreateWindow(g_x11_dpy, RootWindow(g_x11_dpy, vi->screen),
|
2012-10-12 19:05:29 +02:00
|
|
|
x_off, y_off, width, height, 0,
|
2017-12-11 23:55:31 -08:00
|
|
|
vi->depth, InputOutput, vi->visual,
|
2018-04-02 20:01:14 -05:00
|
|
|
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect,
|
2018-04-01 17:44:04 -05:00
|
|
|
&swa);
|
2015-11-19 10:00:25 +01:00
|
|
|
XSetWindowBackground(g_x11_dpy, g_x11_win, 0);
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2018-03-30 15:50:11 +02:00
|
|
|
if (fullscreen && settings && settings->bools.video_disable_composition)
|
2018-03-29 15:20:14 -05:00
|
|
|
{
|
2018-03-30 15:50:11 +02:00
|
|
|
uint32_t value = 1;
|
|
|
|
Atom cardinal = XInternAtom(g_x11_dpy, "CARDINAL", False);
|
2018-03-29 15:20:14 -05:00
|
|
|
Atom net_wm_bypass_compositor = XInternAtom(g_x11_dpy, "_NET_WM_BYPASS_COMPOSITOR", False);
|
|
|
|
|
|
|
|
RARCH_LOG("[X/EGL]: Requesting compositor bypass.\n");
|
|
|
|
XChangeProperty(g_x11_dpy, g_x11_win, net_wm_bypass_compositor, cardinal, 32, PropModeReplace, (const unsigned char*)&value, 1);
|
|
|
|
}
|
|
|
|
|
2016-03-01 06:49:05 +01:00
|
|
|
if (!egl_create_context(&xegl->egl, (attr != egl_attribs) ? egl_attribs : NULL))
|
2014-04-19 16:06:12 +02:00
|
|
|
{
|
2015-11-19 18:29:15 +01:00
|
|
|
egl_report_error();
|
|
|
|
goto error;
|
2014-04-19 16:06:12 +02:00
|
|
|
}
|
|
|
|
|
2016-09-08 06:11:02 +02:00
|
|
|
if (!egl_create_surface(&xegl->egl, (void*)g_x11_win))
|
2012-09-15 15:17:34 +02:00
|
|
|
goto error;
|
|
|
|
|
2015-11-19 10:00:25 +01:00
|
|
|
x11_set_window_attr(g_x11_dpy, g_x11_win);
|
2017-01-18 17:41:27 +01:00
|
|
|
x11_update_title(NULL, video_info);
|
2012-10-12 19:05:29 +02:00
|
|
|
|
|
|
|
if (fullscreen)
|
2015-11-19 10:00:25 +01:00
|
|
|
x11_show_mouse(g_x11_dpy, g_x11_win, false);
|
2012-09-29 11:59:08 +02:00
|
|
|
|
2012-10-05 14:15:54 +02:00
|
|
|
if (true_full)
|
2012-09-29 11:59:08 +02:00
|
|
|
{
|
2013-02-23 14:49:49 +01:00
|
|
|
RARCH_LOG("[X/EGL]: Using true fullscreen.\n");
|
2015-11-19 10:00:25 +01:00
|
|
|
XMapRaised(g_x11_dpy, g_x11_win);
|
2018-04-01 17:44:04 -05:00
|
|
|
x11_set_net_wm_fullscreen(g_x11_dpy, g_x11_win);
|
2012-09-29 11:59:08 +02:00
|
|
|
}
|
2017-12-11 23:55:31 -08:00
|
|
|
else if (fullscreen)
|
2012-10-05 13:55:24 +02:00
|
|
|
{
|
2014-10-27 14:35:23 +01:00
|
|
|
/* We attempted true fullscreen, but failed.
|
|
|
|
* Attempt using windowed fullscreen. */
|
2015-11-19 10:00:25 +01:00
|
|
|
XMapRaised(g_x11_dpy, g_x11_win);
|
2012-10-12 19:05:29 +02:00
|
|
|
RARCH_LOG("[X/EGL]: Using windowed fullscreen.\n");
|
2014-10-27 14:35:23 +01:00
|
|
|
|
2017-12-11 23:55:31 -08:00
|
|
|
/* We have to move the window to the screen we
|
2014-10-27 14:35:23 +01:00
|
|
|
* want to go fullscreen on first.
|
|
|
|
* x_off and y_off usually get ignored in XCreateWindow().
|
|
|
|
*/
|
2015-11-19 10:00:25 +01:00
|
|
|
x11_move_window(g_x11_dpy, g_x11_win, x_off, y_off, width, height);
|
2018-03-29 17:11:32 -05:00
|
|
|
x11_set_net_wm_fullscreen(g_x11_dpy, g_x11_win);
|
2012-10-05 13:55:24 +02:00
|
|
|
}
|
2012-09-29 11:59:08 +02:00
|
|
|
else
|
2012-10-12 19:05:29 +02:00
|
|
|
{
|
2015-11-19 10:00:25 +01:00
|
|
|
XMapWindow(g_x11_dpy, g_x11_win);
|
2014-10-27 14:35:23 +01:00
|
|
|
|
2017-12-11 23:55:31 -08:00
|
|
|
/* If we want to map the window on a different screen,
|
2014-10-27 14:35:23 +01:00
|
|
|
* we'll have to do it by force.
|
|
|
|
*
|
|
|
|
* Otherwise, we should try to let the window manager sort it out.
|
|
|
|
* x_off and y_off usually get ignored in XCreateWindow().
|
|
|
|
*/
|
2015-12-01 08:42:33 +01:00
|
|
|
if (g_x11_screen)
|
2015-11-19 10:00:25 +01:00
|
|
|
x11_move_window(g_x11_dpy, g_x11_win, x_off, y_off, width, height);
|
2012-10-12 19:05:29 +02:00
|
|
|
}
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2015-11-19 15:05:17 +01:00
|
|
|
x11_event_queue_check(&event);
|
2015-11-19 12:18:35 +01:00
|
|
|
x11_install_quit_atom();
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2016-03-01 06:49:05 +01:00
|
|
|
#ifdef HAVE_EGL
|
|
|
|
gfx_ctx_xegl_set_swap_interval(&xegl->egl, xegl->egl.interval);
|
|
|
|
#endif
|
2012-09-16 22:36:43 +02:00
|
|
|
|
2017-12-11 23:55:31 -08:00
|
|
|
/* This can blow up on some drivers. It's not fatal,
|
2014-10-27 14:35:23 +01:00
|
|
|
* so override errors for this call.
|
|
|
|
*/
|
2016-02-22 11:54:19 +01:00
|
|
|
old_handler = XSetErrorHandler(x_nul_handler);
|
2015-11-19 10:00:25 +01:00
|
|
|
XSetInputFocus(g_x11_dpy, g_x11_win, RevertToNone, CurrentTime);
|
|
|
|
XSync(g_x11_dpy, False);
|
2013-02-23 15:15:10 +01:00
|
|
|
XSetErrorHandler(old_handler);
|
|
|
|
|
2012-09-15 15:17:34 +02:00
|
|
|
XFree(vi);
|
2015-12-08 13:54:03 -03:00
|
|
|
g_egl_inited = true;
|
2012-09-15 15:17:34 +02:00
|
|
|
|
2015-11-19 12:05:32 +01:00
|
|
|
if (!x11_input_ctx_new(true_full))
|
2013-12-08 14:42:03 +01:00
|
|
|
goto error;
|
|
|
|
|
2012-09-15 15:17:34 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (vi)
|
|
|
|
XFree(vi);
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_xegl_destroy(data);
|
2012-09-15 15:17:34 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void gfx_ctx_xegl_input_driver(void *data,
|
2017-01-16 00:13:57 +01:00
|
|
|
const char *joypad_name,
|
|
|
|
const input_driver_t **input, void **input_data)
|
2012-09-15 15:17:34 +02:00
|
|
|
{
|
2017-01-16 00:13:57 +01:00
|
|
|
void *xinput = input_x.init(joypad_name);
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2012-09-15 15:17:34 +02:00
|
|
|
*input = xinput ? &input_x : NULL;
|
|
|
|
*input_data = xinput;
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:32:14 +01:00
|
|
|
static bool gfx_ctx_xegl_suppress_screensaver(void *data, bool enable)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
2015-11-29 01:12:49 +01:00
|
|
|
if (video_driver_display_type_get() != RARCH_DISPLAY_X11)
|
2015-01-18 22:32:14 +01:00
|
|
|
return false;
|
|
|
|
|
2016-05-08 19:19:31 +02:00
|
|
|
x11_suspend_screensaver(video_driver_window_get(), enable);
|
2015-01-18 22:32:14 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static bool gfx_ctx_xegl_has_windowed(void *data)
|
2014-10-08 17:23:02 +02:00
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
/* TODO - verify if this has windowed mode or not. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
static enum gfx_ctx_api gfx_ctx_xegl_get_api(void *data)
|
|
|
|
{
|
|
|
|
return xegl_api;
|
|
|
|
}
|
|
|
|
|
2015-12-08 13:54:03 -03:00
|
|
|
static bool gfx_ctx_xegl_bind_api(void *video_driver,
|
2015-04-10 05:58:08 +02:00
|
|
|
enum gfx_ctx_api api, unsigned major, unsigned minor)
|
2012-09-25 01:26:22 +02:00
|
|
|
{
|
2015-12-08 13:54:03 -03:00
|
|
|
g_egl_major = major;
|
|
|
|
g_egl_minor = minor;
|
2018-03-01 21:16:54 +01:00
|
|
|
xegl_api = api;
|
2015-01-10 17:51:00 +01:00
|
|
|
|
2012-09-25 01:26:22 +02:00
|
|
|
switch (api)
|
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
2014-04-20 13:54:29 +02:00
|
|
|
#ifndef EGL_KHR_create_context
|
|
|
|
if ((major * 1000 + minor) >= 3001)
|
2016-02-14 16:39:27 +01:00
|
|
|
break;
|
2014-04-20 13:54:29 +02:00
|
|
|
#endif
|
2012-09-25 01:26:22 +02:00
|
|
|
return eglBindAPI(EGL_OPENGL_API);
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
2014-04-20 13:54:29 +02:00
|
|
|
#ifndef EGL_KHR_create_context
|
2013-12-13 14:19:25 +01:00
|
|
|
if (major >= 3)
|
2016-02-14 16:39:27 +01:00
|
|
|
break;
|
2013-12-13 14:19:25 +01:00
|
|
|
#endif
|
2012-09-25 01:26:22 +02:00
|
|
|
return eglBindAPI(EGL_OPENGL_ES_API);
|
|
|
|
case GFX_CTX_OPENVG_API:
|
2016-03-01 06:56:41 +01:00
|
|
|
#ifdef HAVE_VG
|
2012-09-25 01:26:22 +02:00
|
|
|
return eglBindAPI(EGL_OPENVG_API);
|
2016-03-01 06:56:41 +01:00
|
|
|
#endif
|
2012-09-25 01:26:22 +02:00
|
|
|
default:
|
2015-04-16 23:03:55 +02:00
|
|
|
break;
|
2012-09-25 01:26:22 +02:00
|
|
|
}
|
2015-04-16 23:03:55 +02:00
|
|
|
|
|
|
|
return false;
|
2012-09-25 01:26:22 +02:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:09:01 +02:00
|
|
|
static void gfx_ctx_xegl_show_mouse(void *data, bool state)
|
2013-03-29 13:46:11 +01:00
|
|
|
{
|
2014-03-09 16:50:18 +01:00
|
|
|
(void)data;
|
2015-11-19 10:00:25 +01:00
|
|
|
x11_show_mouse(g_x11_dpy, g_x11_win, state);
|
2013-03-29 13:46:11 +01:00
|
|
|
}
|
|
|
|
|
2017-05-19 03:34:53 +02:00
|
|
|
static void gfx_ctx_xegl_swap_buffers(void *data, void *data2)
|
2016-03-01 06:49:05 +01:00
|
|
|
{
|
|
|
|
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
|
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
switch (xegl_api)
|
2016-03-01 06:49:05 +01:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
egl_swap_buffers(&xegl->egl);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_xegl_bind_hw_render(void *data, bool enable)
|
|
|
|
{
|
|
|
|
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
|
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
switch (xegl_api)
|
2016-03-01 06:49:05 +01:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
|
|
|
case GFX_CTX_OPENVG_API:
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
egl_bind_hw_render(&xegl->egl, enable);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_ctx_xegl_set_swap_interval(void *data, unsigned swap_interval)
|
|
|
|
{
|
|
|
|
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
|
|
|
|
|
2018-03-01 21:16:54 +01:00
|
|
|
switch (xegl_api)
|
2016-03-01 06:49:05 +01:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
egl_set_swap_interval(&xegl->egl, swap_interval);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gfx_ctx_proc_t gfx_ctx_xegl_get_proc_address(const char *symbol)
|
|
|
|
{
|
2018-03-01 21:16:54 +01:00
|
|
|
switch (xegl_api)
|
2016-03-01 06:49:05 +01:00
|
|
|
{
|
|
|
|
case GFX_CTX_OPENGL_ES_API:
|
|
|
|
case GFX_CTX_OPENVG_API:
|
|
|
|
#ifdef HAVE_EGL
|
|
|
|
return egl_get_proc_address(symbol);
|
|
|
|
#else
|
|
|
|
break;
|
|
|
|
#endif
|
2016-10-08 14:37:26 +02:00
|
|
|
case GFX_CTX_OPENGL_API:
|
|
|
|
break;
|
2016-03-01 06:49:05 +01:00
|
|
|
case GFX_CTX_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-05 05:35:35 +02:00
|
|
|
static uint32_t gfx_ctx_xegl_get_flags(void *data)
|
|
|
|
{
|
2016-05-05 17:35:28 +02:00
|
|
|
uint32_t flags = 0;
|
|
|
|
BIT32_SET(flags, GFX_CTX_FLAGS_NONE);
|
|
|
|
return flags;
|
|
|
|
}
|
2016-05-05 05:46:00 +02:00
|
|
|
|
2016-05-05 17:35:28 +02:00
|
|
|
static void gfx_ctx_xegl_set_flags(void *data, uint32_t flags)
|
|
|
|
{
|
|
|
|
(void)data;
|
2016-05-05 05:35:35 +02:00
|
|
|
}
|
|
|
|
|
2015-04-10 05:58:08 +02:00
|
|
|
const gfx_ctx_driver_t gfx_ctx_x_egl =
|
|
|
|
{
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_xegl_init,
|
|
|
|
gfx_ctx_xegl_destroy,
|
2018-03-01 21:16:54 +01:00
|
|
|
gfx_ctx_xegl_get_api,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_xegl_bind_api,
|
2017-12-11 23:55:31 -08:00
|
|
|
gfx_ctx_xegl_set_swap_interval,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_xegl_set_video_mode,
|
2015-11-19 10:29:26 +01:00
|
|
|
x11_get_video_size,
|
2018-04-15 17:38:00 -05:00
|
|
|
x11_get_refresh_rate,
|
2015-02-24 21:36:23 +01:00
|
|
|
NULL, /* get_video_output_size */
|
|
|
|
NULL, /* get_video_output_prev */
|
|
|
|
NULL, /* get_video_output_next */
|
2015-11-19 10:25:07 +01:00
|
|
|
x11_get_metrics,
|
2015-02-24 19:58:14 +01:00
|
|
|
NULL,
|
2017-01-18 17:41:27 +01:00
|
|
|
x11_update_title,
|
2015-11-19 10:35:15 +01:00
|
|
|
x11_check_window,
|
2017-01-19 14:31:57 +01:00
|
|
|
NULL, /* set_resize */
|
2016-10-08 14:37:26 +02:00
|
|
|
x11_has_focus,
|
2015-01-18 22:32:14 +01:00
|
|
|
gfx_ctx_xegl_suppress_screensaver,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_xegl_has_windowed,
|
2016-03-01 06:49:05 +01:00
|
|
|
gfx_ctx_xegl_swap_buffers,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_xegl_input_driver,
|
2016-03-01 06:49:05 +01:00
|
|
|
gfx_ctx_xegl_get_proc_address,
|
2014-03-09 16:50:18 +01:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-10-08 18:09:01 +02:00
|
|
|
gfx_ctx_xegl_show_mouse,
|
2012-09-25 01:26:22 +02:00
|
|
|
"x-egl",
|
2016-05-05 05:35:35 +02:00
|
|
|
gfx_ctx_xegl_get_flags,
|
2016-05-05 17:35:28 +02:00
|
|
|
gfx_ctx_xegl_set_flags,
|
2016-08-31 15:02:07 +02:00
|
|
|
gfx_ctx_xegl_bind_hw_render,
|
|
|
|
NULL,
|
|
|
|
NULL
|
2012-09-25 01:26:22 +02:00
|
|
|
};
|