RetroArch/gfx/drivers_context/xegl_ctx.c

848 lines
20 KiB
C
Raw Normal View History

2012-09-15 13:17:34 +00:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2015 - Daniel De Matteis
*
* 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 13:17:34 +00:00
2014-10-27 13:35:23 +00:00
/* X/EGL context. Mostly used for testing GLES code paths.
* Should be its own file as it has lots of X11 stuff baked into it as well.
*/
2012-09-15 13:17:34 +00:00
2015-09-16 03:53:34 +00:00
#include <stdint.h>
#include <signal.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
2012-09-15 13:17:34 +00:00
#include "../../driver.h"
#include "../../runloop.h"
2015-04-09 02:57:17 +00:00
#include "../drivers/gl_common.h"
#include "../video_monitor.h"
2015-04-09 03:02:57 +00:00
#include "../common/x11_common.h"
2012-09-15 13:17:34 +00:00
#ifndef EGL_OPENGL_ES3_BIT_KHR
#define EGL_OPENGL_ES3_BIT_KHR 0x0040
#endif
2012-09-15 13:17:34 +00:00
static Display *g_dpy;
static Window g_win;
static Colormap g_cmap;
static Atom g_quit_atom;
static bool g_has_focus;
static bool g_true_full;
2012-10-12 17:05:29 +00:00
static unsigned g_screen;
2012-09-15 13:17:34 +00:00
2013-12-08 13:42:03 +00:00
static XIM g_xim;
static XIC g_xic;
static bool g_use_hw_ctx;
static EGLContext g_egl_hw_ctx;
2012-09-15 13:17:34 +00:00
static EGLContext g_egl_ctx;
static EGLSurface g_egl_surf;
static EGLDisplay g_egl_dpy;
static EGLConfig g_egl_config;
2012-09-15 13:17:34 +00:00
2012-09-29 08:47:55 +00:00
static XF86VidModeModeInfo g_desktop_mode;
static bool g_should_reset_mode;
2012-09-15 13:17:34 +00:00
static volatile sig_atomic_t g_quit;
static bool g_inited;
static unsigned g_interval;
2012-09-24 23:26:22 +00:00
static enum gfx_ctx_api g_api;
static unsigned g_major;
static unsigned g_minor;
2012-09-15 13:17:34 +00:00
static void egl_sighandler(int sig)
2012-09-15 13:17:34 +00:00
{
(void)sig;
g_quit = 1;
}
2012-09-29 08:47:55 +00:00
static Bool egl_wait_notify(Display *d, XEvent *e, char *arg)
{
(void)d;
(void)e;
return e->type == MapNotify && e->xmap.window == g_win;
}
static int egl_nul_handler(Display *dpy, XErrorEvent *event)
{
(void)dpy;
(void)event;
return 0;
}
static void gfx_ctx_xegl_get_video_size(void *data,
unsigned *width, unsigned *height);
static void gfx_ctx_xegl_destroy(void *data);
2012-09-24 23:26:22 +00:00
static void egl_report_error(void)
{
EGLint error = eglGetError();
const char *str = NULL;
switch (error)
{
case EGL_SUCCESS:
str = "EGL_SUCCESS";
break;
case EGL_BAD_DISPLAY:
str = "EGL_BAD_DISPLAY";
break;
case EGL_BAD_SURFACE:
str = "EGL_BAD_SURFACE";
break;
case EGL_BAD_CONTEXT:
str = "EGL_BAD_CONTEXT";
break;
default:
str = "Unknown";
break;
}
RARCH_ERR("[X/EGL]: #0x%x, %s\n", (unsigned)error, str);
}
static void gfx_ctx_xegl_swap_interval(void *data, unsigned interval)
2012-09-15 13:17:34 +00:00
{
(void)data;
2012-09-15 13:17:34 +00:00
g_interval = interval;
if (!g_egl_dpy)
return;
if (!(eglGetCurrentContext()))
return;
RARCH_LOG("[X/EGL]: eglSwapInterval(%u)\n", g_interval);
if (!eglSwapInterval(g_egl_dpy, g_interval))
{
RARCH_ERR("[X/EGL]: eglSwapInterval() failed.\n");
egl_report_error();
}
2012-09-15 13:17:34 +00:00
}
void x_input_poll_wheel(void *data, XButtonEvent *event, bool latch);
static void gfx_ctx_xegl_check_window(void *data, bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
2012-09-15 13:17:34 +00:00
{
XEvent event;
unsigned new_width = *width;
unsigned new_height = *height;
driver_t *driver = driver_get_ptr();
2012-09-15 13:17:34 +00:00
(void)frame_count;
gfx_ctx_xegl_get_video_size(data, &new_width, &new_height);
2012-09-15 13:17:34 +00:00
if (new_width != *width || new_height != *height)
{
*resize = true;
*width = new_width;
*height = new_height;
}
while (XPending(g_dpy))
{
bool filter;
2014-10-27 13:35:23 +00:00
/* Can get events from older windows. Check this. */
2012-09-15 13:17:34 +00:00
XNextEvent(g_dpy, &event);
filter = XFilterEvent(&event, g_win);
2013-12-08 13:42:03 +00:00
2012-09-15 13:17:34 +00:00
switch (event.type)
{
case ClientMessage:
if (event.xclient.window == g_win && (Atom)event.xclient.data.l[0] == g_quit_atom)
2012-09-15 13:17:34 +00:00
g_quit = true;
break;
case DestroyNotify:
if (event.xdestroywindow.window == g_win)
g_quit = true;
2012-09-15 13:17:34 +00:00
break;
case MapNotify:
if (event.xmap.window == g_win)
g_has_focus = true;
2012-09-15 13:17:34 +00:00
break;
case UnmapNotify:
if (event.xunmap.window == g_win)
g_has_focus = false;
2012-09-15 13:17:34 +00:00
break;
2012-12-15 11:00:57 +00:00
case ButtonPress:
x_input_poll_wheel(driver->input_data, &event.xbutton, true);
break;
case ButtonRelease:
break;
2012-12-15 11:00:57 +00:00
case KeyPress:
case KeyRelease:
if (event.xkey.window == g_win)
x11_handle_key_event(&event, g_xic, filter);
2012-12-15 11:00:57 +00:00
break;
2012-09-15 13:17:34 +00:00
}
}
*quit = g_quit;
}
static void gfx_ctx_xegl_swap_buffers(void *data)
2012-09-15 13:17:34 +00:00
{
(void)data;
2012-09-15 13:17:34 +00:00
eglSwapBuffers(g_egl_dpy, g_egl_surf);
}
static void gfx_ctx_xegl_set_resize(void *data,
unsigned width, unsigned height)
2012-09-15 13:17:34 +00:00
{
(void)data;
2012-09-15 13:17:34 +00:00
(void)width;
(void)height;
}
static void gfx_ctx_xegl_update_window_title(void *data)
2012-09-15 13:17:34 +00:00
{
2015-06-13 00:10:06 +00:00
char buf[128] = {0};
char buf_fps[128] = {0};
2015-03-20 21:08:36 +00:00
settings_t *settings = config_get_ptr();
(void)data;
if (video_monitor_get_fps(buf, sizeof(buf),
2015-03-07 22:03:56 +00:00
buf_fps, sizeof(buf_fps)))
2012-09-15 13:17:34 +00:00
XStoreName(g_dpy, g_win, buf);
2015-03-20 21:08:36 +00:00
if (settings->fps_show)
rarch_main_msg_queue_push(buf_fps, 1, 1, false);
2012-09-15 13:17:34 +00:00
}
static void gfx_ctx_xegl_get_video_size(void *data,
unsigned *width, unsigned *height)
2012-09-15 13:17:34 +00:00
{
(void)data;
2012-09-15 13:17:34 +00:00
if (!g_dpy || g_win == None)
{
2012-09-15 22:57:39 +00:00
Display *dpy = XOpenDisplay(NULL);
if (dpy)
{
int screen = DefaultScreen(dpy);
*width = DisplayWidth(dpy, screen);
*height = DisplayHeight(dpy, screen);
XCloseDisplay(dpy);
}
else
{
*width = 0;
*height = 0;
}
2012-09-15 13:17:34 +00:00
}
else
{
XWindowAttributes target;
XGetWindowAttributes(g_dpy, g_win, &target);
*width = target.width;
*height = target.height;
}
}
2014-10-27 13:35:23 +00: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
2014-10-27 13:35:23 +00:00
static bool gfx_ctx_xegl_init(void *data)
{
static const EGLint egl_attribs_gl[] = {
2014-10-27 13:35:23 +00:00
XEGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE,
};
static const EGLint egl_attribs_gles[] = {
2014-10-27 13:35:23 +00:00
XEGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE,
};
#ifdef EGL_KHR_create_context
static const EGLint egl_attribs_gles3[] = {
2014-10-27 13:35:23 +00:00
XEGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR,
EGL_NONE,
};
#endif
static const EGLint egl_attribs_vg[] = {
2014-10-27 13:35:23 +00:00
XEGL_ATTRIBS_BASE,
EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
EGL_NONE,
};
const EGLint *attrib_ptr;
2015-06-26 15:46:13 +00:00
EGLint egl_major, egl_minor;
EGLint num_configs;
if (g_inited)
return false;
XInitThreads();
switch (g_api)
{
case GFX_CTX_OPENGL_API:
attrib_ptr = egl_attribs_gl;
break;
case GFX_CTX_OPENGL_ES_API:
#ifdef EGL_KHR_create_context
if (g_major >= 3)
attrib_ptr = egl_attribs_gles3;
else
#endif
attrib_ptr = egl_attribs_gles;
break;
case GFX_CTX_OPENVG_API:
attrib_ptr = egl_attribs_vg;
break;
default:
attrib_ptr = NULL;
}
2012-09-15 13:17:34 +00:00
g_quit = 0;
2014-10-27 13:35:23 +00:00
/* Keep one g_dpy alive the entire process lifetime.
* This is necessary for nVidia's EGL implementation for now. */
2012-09-15 13:17:34 +00:00
if (!g_dpy)
{
g_dpy = XOpenDisplay(NULL);
if (!g_dpy)
goto error;
}
2012-09-15 13:17:34 +00:00
g_egl_dpy = eglGetDisplay((EGLNativeDisplayType)g_dpy);
2014-03-03 22:00:37 +00:00
if (g_egl_dpy == EGL_NO_DISPLAY)
{
RARCH_ERR("[X/EGL]: EGL display not available.\n");
egl_report_error();
2012-09-15 13:17:34 +00:00
goto error;
}
2012-09-15 13:17:34 +00:00
if (!eglInitialize(g_egl_dpy, &egl_major, &egl_minor))
{
RARCH_ERR("[X/EGL]: Unable to initialize EGL.\n");
egl_report_error();
2012-09-15 13:17:34 +00:00
goto error;
}
2012-09-15 13:17:34 +00:00
RARCH_LOG("[X/EGL]: EGL version: %d.%d\n", egl_major, egl_minor);
if (!eglChooseConfig(g_egl_dpy, attrib_ptr, &g_egl_config, 1, &num_configs))
{
2014-03-03 22:00:37 +00:00
RARCH_ERR("[X/EGL]: eglChooseConfig failed with 0x%x.\n", eglGetError());
2012-09-15 13:17:34 +00:00
goto error;
}
if (num_configs == 0 || !g_egl_config)
{
RARCH_ERR("[X/EGL]: No EGL configurations available.\n");
goto error;
}
2012-09-15 13:17:34 +00:00
return true;
error:
gfx_ctx_xegl_destroy(data);
2012-09-15 13:17:34 +00:00
return false;
}
static EGLint *xegl_fill_attribs(EGLint *attr)
{
switch (g_api)
{
#ifdef EGL_KHR_create_context
case GFX_CTX_OPENGL_API:
{
const struct retro_hw_render_callback *hw_render =
(const struct retro_hw_render_callback*)video_driver_callback();
unsigned version = g_major * 1000 + g_minor;
bool core = version >= 3001;
#ifdef GL_DEBUG
2015-09-29 15:35:28 +00:00
bool debug = true;
#else
bool debug = hw_render->debug_context;
#endif
if (core)
{
*attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR;
*attr++ = g_major;
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = g_minor;
/* Technically, we don't have core/compat until 3.2.
* Version 3.1 is either compat or not depending
* 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 13:35:23 +00:00
if (debug)
{
*attr++ = EGL_CONTEXT_FLAGS_KHR;
*attr++ = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
}
break;
}
#endif
case GFX_CTX_OPENGL_ES_API:
/* Same as EGL_CONTEXT_MAJOR_VERSION. */
2014-10-27 13:35:23 +00:00
*attr++ = EGL_CONTEXT_CLIENT_VERSION;
*attr++ = g_major ? (EGLint)g_major : 2;
2014-05-03 13:21:14 +00:00
#ifdef EGL_KHR_create_context
if (g_minor > 0)
{
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = g_minor;
}
#endif
break;
default:
break;
}
*attr = EGL_NONE;
return attr;
}
static bool gfx_ctx_xegl_set_video_mode(void *data,
unsigned width, unsigned height,
bool fullscreen)
2012-09-15 13:17:34 +00:00
{
EGLint egl_attribs[16];
EGLint *attr;
EGLint vid, num_visuals;
bool windowed_full;
bool true_full = false;
int x_off = 0;
int y_off = 0;
struct sigaction sa = {{0}};
XVisualInfo temp = {0};
XSetWindowAttributes swa = {0};
XVisualInfo *vi = NULL;
2015-03-20 21:08:36 +00:00
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
2015-06-26 15:46:13 +00:00
int (*old_handler)(Display*, XErrorEvent*) = NULL;
XEvent event;
sa.sa_handler = egl_sighandler;
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
2015-03-20 21:08:36 +00:00
windowed_full = settings->video.windowed_fullscreen;
attr = egl_attribs;
attr = xegl_fill_attribs(attr);
2014-02-06 21:49:14 +00:00
if (!eglGetConfigAttrib(g_egl_dpy, g_egl_config, EGL_NATIVE_VISUAL_ID, &vid))
2012-09-15 13:17:34 +00:00
goto error;
temp.visualid = vid;
2012-09-15 13:17:34 +00:00
vi = XGetVisualInfo(g_dpy, VisualIDMask, &temp, &num_visuals);
2012-09-15 13:17:34 +00:00
if (!vi)
goto error;
swa.colormap = g_cmap = XCreateColormap(g_dpy, RootWindow(g_dpy, vi->screen),
vi->visual, AllocNone);
swa.event_mask = StructureNotifyMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | KeyReleaseMask;
2012-09-29 08:47:55 +00:00
swa.override_redirect = fullscreen ? True : False;
2012-10-05 12:15:54 +00:00
if (fullscreen && !windowed_full)
2012-09-29 08:47:55 +00:00
{
if (x11_enter_fullscreen(g_dpy, width, height, &g_desktop_mode))
2012-10-05 12:15:54 +00:00
{
2012-09-29 08:47:55 +00:00
g_should_reset_mode = true;
2012-10-05 12:15:54 +00:00
true_full = true;
}
else
RARCH_ERR("[X/EGL]: Entering true fullscreen failed. Will attempt windowed mode.\n");
2012-09-29 08:47:55 +00:00
}
2012-09-15 13:17:34 +00:00
2015-03-20 21:08:36 +00:00
if (settings->video.monitor_index)
g_screen = settings->video.monitor_index - 1;
2012-10-12 19:15:58 +00:00
2012-10-12 17:05:29 +00:00
#ifdef HAVE_XINERAMA
if (fullscreen || g_screen != 0)
{
unsigned new_width = width;
unsigned new_height = height;
2012-10-12 17:05:29 +00:00
if (x11_get_xinerama_coord(g_dpy, g_screen, &x_off, &y_off, &new_width, &new_height))
RARCH_LOG("[X/EGL]: Using Xinerama on screen #%u.\n", g_screen);
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);
2012-09-15 13:17:34 +00:00
g_win = XCreateWindow(g_dpy, RootWindow(g_dpy, vi->screen),
2012-10-12 17:05:29 +00:00
x_off, y_off, width, height, 0,
2012-09-15 13:17:34 +00:00
vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap | CWEventMask | (true_full ? CWOverrideRedirect : 0), &swa);
2012-09-15 13:17:34 +00:00
XSetWindowBackground(g_dpy, g_win, 0);
g_egl_ctx = eglCreateContext(g_egl_dpy, g_egl_config, EGL_NO_CONTEXT,
attr != egl_attribs ? egl_attribs : NULL);
RARCH_LOG("[X/EGL]: Created context: %p.\n", (void*)g_egl_ctx);
if (g_egl_ctx == EGL_NO_CONTEXT)
2012-09-15 13:17:34 +00:00
goto error;
if (g_use_hw_ctx)
{
g_egl_hw_ctx = eglCreateContext(g_egl_dpy, g_egl_config, g_egl_ctx,
attr != egl_attribs ? egl_attribs : NULL);
RARCH_LOG("[X/EGL]: Created shared context: %p.\n", (void*)g_egl_hw_ctx);
if (g_egl_hw_ctx == EGL_NO_CONTEXT)
goto error;
}
g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_egl_config, (EGLNativeWindowType)g_win, NULL);
2012-09-15 13:17:34 +00:00
if (!g_egl_surf)
goto error;
if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx))
goto error;
RARCH_LOG("[X/EGL]: Current context: %p.\n", (void*)eglGetCurrentContext());
2012-10-26 21:01:32 +00:00
x11_set_window_attr(g_dpy, g_win);
2012-10-12 17:05:29 +00:00
if (fullscreen)
2013-03-29 12:46:11 +00:00
x11_show_mouse(g_dpy, g_win, false);
2012-09-29 09:59:08 +00:00
2012-10-05 12:15:54 +00:00
if (true_full)
2012-09-29 09:59:08 +00:00
{
2013-02-23 13:49:49 +00:00
RARCH_LOG("[X/EGL]: Using true fullscreen.\n");
2012-09-29 09:59:08 +00:00
XMapRaised(g_dpy, g_win);
}
2014-10-27 13:35:23 +00:00
else if (fullscreen)
{
2014-10-27 13:35:23 +00:00
/* We attempted true fullscreen, but failed.
* Attempt using windowed fullscreen. */
XMapRaised(g_dpy, g_win);
2012-10-12 17:05:29 +00:00
RARCH_LOG("[X/EGL]: Using windowed fullscreen.\n");
2014-10-27 13:35:23 +00:00
/* We have to move the window to the screen we
* want to go fullscreen on first.
* x_off and y_off usually get ignored in XCreateWindow().
*/
2012-10-12 17:05:29 +00:00
x11_move_window(g_dpy, g_win, x_off, y_off, width, height);
x11_windowed_fullscreen(g_dpy, g_win);
}
2012-09-29 09:59:08 +00:00
else
2012-10-12 17:05:29 +00:00
{
2012-09-29 09:59:08 +00:00
XMapWindow(g_dpy, g_win);
2014-10-27 13:35:23 +00:00
/* If we want to map the window on a different screen,
* 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().
*/
2012-10-12 17:05:29 +00:00
if (g_screen)
x11_move_window(g_dpy, g_win, x_off, y_off, width, height);
}
2012-09-15 13:17:34 +00:00
2012-09-29 08:47:55 +00:00
XIfEvent(g_dpy, &event, egl_wait_notify, NULL);
2012-09-15 13:17:34 +00:00
g_quit_atom = XInternAtom(g_dpy, "WM_DELETE_WINDOW", False);
if (g_quit_atom)
XSetWMProtocols(g_dpy, g_win, &g_quit_atom, 1);
gfx_ctx_xegl_swap_interval(data, g_interval);
2014-10-27 13:35:23 +00:00
/* This can blow up on some drivers. It's not fatal,
* so override errors for this call.
*/
old_handler = XSetErrorHandler(egl_nul_handler);
XSetInputFocus(g_dpy, g_win, RevertToNone, CurrentTime);
XSync(g_dpy, False);
XSetErrorHandler(old_handler);
2012-09-15 13:17:34 +00:00
XFree(vi);
g_has_focus = true;
g_inited = true;
2013-12-08 13:42:03 +00:00
if (!x11_create_input_context(g_dpy, g_win, &g_xim, &g_xic))
goto error;
driver->display_type = RARCH_DISPLAY_X11;
driver->video_display = (uintptr_t)g_dpy;
driver->video_window = (uintptr_t)g_win;
g_true_full = true_full;
2012-09-28 20:38:42 +00:00
2012-09-15 13:17:34 +00:00
return true;
error:
if (vi)
XFree(vi);
gfx_ctx_xegl_destroy(data);
2012-09-15 13:17:34 +00:00
return false;
}
static void gfx_ctx_xegl_destroy(void *data)
2012-09-15 13:17:34 +00:00
{
(void)data;
2013-12-08 13:42:03 +00:00
x11_destroy_input_context(&g_xim, &g_xic);
2012-09-15 13:17:34 +00:00
if (g_egl_dpy)
{
if (g_egl_ctx)
2012-09-15 13:41:12 +00:00
{
2014-10-27 13:35:23 +00:00
eglMakeCurrent(g_egl_dpy, EGL_NO_SURFACE,
EGL_NO_SURFACE, EGL_NO_CONTEXT);
2012-09-15 13:17:34 +00:00
eglDestroyContext(g_egl_dpy, g_egl_ctx);
2012-09-15 13:41:12 +00:00
}
if (g_egl_hw_ctx)
eglDestroyContext(g_egl_dpy, g_egl_hw_ctx);
2012-09-15 13:17:34 +00:00
if (g_egl_surf)
eglDestroySurface(g_egl_dpy, g_egl_surf);
eglTerminate(g_egl_dpy);
}
g_egl_ctx = NULL;
g_egl_hw_ctx = NULL;
g_egl_surf = NULL;
g_egl_dpy = NULL;
g_egl_config = 0;
2012-09-15 13:17:34 +00:00
if (g_win)
{
2014-10-27 13:35:23 +00:00
/* Save last used monitor for later. */
2012-10-12 17:05:29 +00:00
#ifdef HAVE_XINERAMA
XWindowAttributes target;
Window child;
int x = 0, y = 0;
XGetWindowAttributes(g_dpy, g_win, &target);
XTranslateCoordinates(g_dpy, g_win, RootWindow(g_dpy, DefaultScreen(g_dpy)),
target.x, target.y, &x, &y, &child);
g_screen = x11_get_xinerama_monitor(g_dpy, x, y,
target.width, target.height);
2013-02-23 13:49:49 +00:00
RARCH_LOG("[X/EGL]: Saved monitor #%u.\n", g_screen);
2012-10-12 17:05:29 +00:00
#endif
2012-09-15 13:41:12 +00:00
XUnmapWindow(g_dpy, g_win);
2012-09-15 13:17:34 +00:00
XDestroyWindow(g_dpy, g_win);
g_win = None;
}
if (g_cmap)
{
XFreeColormap(g_dpy, g_cmap);
g_cmap = None;
}
2012-09-29 08:47:55 +00:00
if (g_should_reset_mode)
{
x11_exit_fullscreen(g_dpy, &g_desktop_mode);
g_should_reset_mode = false;
}
2014-10-27 13:35:23 +00:00
/* Do not close g_dpy. We'll keep one for the entire application
* lifecycle to work-around nVidia EGL limitations.
*/
2012-09-15 13:17:34 +00:00
g_inited = false;
}
static void gfx_ctx_xegl_input_driver(void *data,
const input_driver_t **input, void **input_data)
2012-09-15 13:17:34 +00:00
{
void *xinput = input_x.init();
(void)data;
2012-09-15 13:17:34 +00:00
*input = xinput ? &input_x : NULL;
*input_data = xinput;
}
static bool gfx_ctx_xegl_has_focus(void *data)
2012-09-15 13:17:34 +00:00
{
Window win;
int rev;
(void)data;
2012-09-15 13:17:34 +00:00
if (!g_inited)
return false;
XGetInputFocus(g_dpy, &win, &rev);
return (win == g_win && g_has_focus) || g_true_full;
2012-09-15 13:17:34 +00:00
}
2015-01-18 21:32:14 +00:00
static bool gfx_ctx_xegl_suppress_screensaver(void *data, bool enable)
{
driver_t *driver = driver_get_ptr();
2015-01-18 21:32:14 +00:00
(void)data;
(void)enable;
if (driver->display_type != RARCH_DISPLAY_X11)
2015-01-18 21:32:14 +00:00
return false;
x11_suspend_screensaver(driver->video_window);
2015-01-18 21:32:14 +00:00
return true;
}
static bool gfx_ctx_xegl_has_windowed(void *data)
{
(void)data;
/* TODO - verify if this has windowed mode or not. */
return true;
}
static gfx_ctx_proc_t gfx_ctx_xegl_get_proc_address(const char *symbol)
2012-09-15 13:17:34 +00:00
{
return eglGetProcAddress(symbol);
}
static bool gfx_ctx_xegl_bind_api(void *data,
enum gfx_ctx_api api, unsigned major, unsigned minor)
2012-09-24 23:26:22 +00:00
{
(void)data;
g_major = major;
g_minor = minor;
2012-09-24 23:26:22 +00:00
g_api = api;
2012-09-24 23:26:22 +00:00
switch (api)
{
case GFX_CTX_OPENGL_API:
#ifndef EGL_KHR_create_context
if ((major * 1000 + minor) >= 3001)
return false;
#endif
2012-09-24 23:26:22 +00:00
return eglBindAPI(EGL_OPENGL_API);
case GFX_CTX_OPENGL_ES_API:
#ifndef EGL_KHR_create_context
if (major >= 3)
return false;
#endif
2012-09-24 23:26:22 +00:00
return eglBindAPI(EGL_OPENGL_ES_API);
case GFX_CTX_OPENVG_API:
return eglBindAPI(EGL_OPENVG_API);
default:
2015-04-16 21:03:55 +00:00
break;
2012-09-24 23:26:22 +00:00
}
2015-04-16 21:03:55 +00:00
return false;
2012-09-24 23:26:22 +00:00
}
static void gfx_ctx_xegl_show_mouse(void *data, bool state)
2013-03-29 12:46:11 +00:00
{
(void)data;
2013-03-29 12:46:11 +00:00
x11_show_mouse(g_dpy, g_win, state);
}
static void gfx_ctx_xegl_bind_hw_render(void *data, bool enable)
{
(void)data;
g_use_hw_ctx = enable;
if (!g_egl_dpy)
return;
if (!g_egl_surf)
return;
eglMakeCurrent(g_egl_dpy, g_egl_surf,
g_egl_surf, enable ? g_egl_hw_ctx : g_egl_ctx);
}
2015-04-09 01:59:16 +00:00
static bool gfx_ctx_xegl_get_metrics(void *data,
enum display_metric_types type, float *value)
2015-04-09 01:59:16 +00:00
{
2015-04-09 03:05:29 +00:00
return x11_get_metrics(data, type, value);
2015-04-09 01:59:16 +00:00
}
const gfx_ctx_driver_t gfx_ctx_x_egl =
{
gfx_ctx_xegl_init,
gfx_ctx_xegl_destroy,
gfx_ctx_xegl_bind_api,
gfx_ctx_xegl_swap_interval,
gfx_ctx_xegl_set_video_mode,
gfx_ctx_xegl_get_video_size,
NULL, /* get_video_output_size */
NULL, /* get_video_output_prev */
NULL, /* get_video_output_next */
2015-04-09 01:59:16 +00:00
gfx_ctx_xegl_get_metrics,
NULL,
gfx_ctx_xegl_update_window_title,
gfx_ctx_xegl_check_window,
gfx_ctx_xegl_set_resize,
gfx_ctx_xegl_has_focus,
2015-01-18 21:32:14 +00:00
gfx_ctx_xegl_suppress_screensaver,
gfx_ctx_xegl_has_windowed,
gfx_ctx_xegl_swap_buffers,
gfx_ctx_xegl_input_driver,
gfx_ctx_xegl_get_proc_address,
NULL,
NULL,
gfx_ctx_xegl_show_mouse,
2012-09-24 23:26:22 +00:00
"x-egl",
gfx_ctx_xegl_bind_hw_render,
2012-09-24 23:26:22 +00:00
};