Merge pull request #2542 from heuripedes/master

Context driver improvements
This commit is contained in:
Twinaphex 2015-12-08 19:51:16 +01:00
commit 8144fd0d92
23 changed files with 531 additions and 537 deletions

View File

@ -23,16 +23,11 @@
#endif #endif
volatile sig_atomic_t g_egl_quit; volatile sig_atomic_t g_egl_quit;
EGLContext g_egl_ctx;
EGLContext g_egl_hw_ctx;
EGLSurface g_egl_surf;
EGLDisplay g_egl_dpy;
EGLConfig g_egl_config;
enum gfx_ctx_api g_egl_api;
bool g_egl_inited; bool g_egl_inited;
static bool g_egl_use_hw_ctx;
unsigned g_interval; enum gfx_ctx_api g_egl_api;
unsigned g_egl_major = 0;
unsigned g_egl_minor = 0;
void egl_report_error(void) void egl_report_error(void)
{ {
@ -79,11 +74,12 @@ gfx_ctx_proc_t egl_get_proc_address(const char *symbol)
void egl_destroy(void *data) void egl_destroy(void *data)
{ {
if (g_egl_dpy) egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (egl->dpy)
{ {
#if defined HAVE_OPENGL #if defined HAVE_OPENGL
#if !defined(RARCH_MOBILE) #if !defined(RARCH_MOBILE)
if (g_egl_ctx != EGL_NO_CONTEXT) if (egl->ctx != EGL_NO_CONTEXT)
{ {
glFlush(); glFlush();
glFinish(); glFinish();
@ -91,71 +87,74 @@ void egl_destroy(void *data)
#endif #endif
#endif #endif
eglMakeCurrent(g_egl_dpy, eglMakeCurrent(egl->dpy,
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (g_egl_ctx != EGL_NO_CONTEXT) if (egl->ctx != EGL_NO_CONTEXT)
eglDestroyContext(g_egl_dpy, g_egl_ctx); eglDestroyContext(egl->dpy, egl->ctx);
if (g_egl_hw_ctx != EGL_NO_CONTEXT) if (egl->hw_ctx != EGL_NO_CONTEXT)
eglDestroyContext(g_egl_dpy, g_egl_hw_ctx); eglDestroyContext(egl->dpy, egl->hw_ctx);
if (g_egl_surf != EGL_NO_SURFACE) if (egl->surf != EGL_NO_SURFACE)
eglDestroySurface(g_egl_dpy, g_egl_surf); eglDestroySurface(egl->dpy, egl->surf);
eglTerminate(g_egl_dpy); eglTerminate(egl->dpy);
} }
/* Be as careful as possible in deinit. /* Be as careful as possible in deinit.
* If we screw up, any TTY will not restore. * If we screw up, any TTY will not restore.
*/ */
g_egl_ctx = EGL_NO_CONTEXT; egl->ctx = EGL_NO_CONTEXT;
g_egl_hw_ctx = EGL_NO_CONTEXT; egl->hw_ctx = EGL_NO_CONTEXT;
g_egl_surf = EGL_NO_SURFACE; egl->surf = EGL_NO_SURFACE;
g_egl_dpy = EGL_NO_DISPLAY; egl->dpy = EGL_NO_DISPLAY;
g_egl_config = 0; egl->config = 0;
g_egl_quit = 0; g_egl_quit = 0;
g_egl_api = GFX_CTX_NONE; egl->api = GFX_CTX_NONE;
g_egl_inited = false; g_egl_inited = false;
} }
void egl_bind_hw_render(void *data, bool enable) void egl_bind_hw_render(void *data, bool enable)
{ {
g_egl_use_hw_ctx = enable; egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
egl->use_hw_ctx = enable;
if (g_egl_dpy == EGL_NO_DISPLAY) if (egl->dpy == EGL_NO_DISPLAY)
return; return;
if (g_egl_surf == EGL_NO_SURFACE) if (egl->surf == EGL_NO_SURFACE)
return; return;
eglMakeCurrent(g_egl_dpy, g_egl_surf, eglMakeCurrent(egl->dpy, egl->surf,
g_egl_surf, egl->surf,
enable ? g_egl_hw_ctx : g_egl_ctx); enable ? egl->hw_ctx : egl->ctx);
} }
void egl_swap_buffers(void *data) void egl_swap_buffers(void *data)
{ {
if (g_egl_dpy == EGL_NO_DISPLAY) egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (egl->dpy == EGL_NO_DISPLAY)
return; return;
if (g_egl_surf == EGL_NO_SURFACE) if (egl->surf == EGL_NO_SURFACE)
return; return;
eglSwapBuffers(g_egl_dpy, g_egl_surf); eglSwapBuffers(egl->dpy, egl->surf);
} }
void egl_set_swap_interval(void *data, unsigned interval) void egl_set_swap_interval(void *data, unsigned interval)
{ {
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
/* Can be called before initialization. /* Can be called before initialization.
* Some contexts require that swap interval * Some contexts require that swap interval
* is known at startup time. * is known at startup time.
*/ */
g_interval = interval; egl->interval = interval;
if (g_egl_dpy == EGL_NO_DISPLAY) if (egl->dpy == EGL_NO_DISPLAY)
return; return;
if (!(eglGetCurrentContext())) if (!(eglGetCurrentContext()))
return; return;
RARCH_LOG("[EGL]: eglSwapInterval(%u)\n", interval); RARCH_LOG("[EGL]: eglSwapInterval(%u)\n", interval);
if (!eglSwapInterval(g_egl_dpy, interval)) if (!eglSwapInterval(egl->dpy, interval))
{ {
RARCH_ERR("[EGL]: eglSwapInterval() failed.\n"); RARCH_ERR("[EGL]: eglSwapInterval() failed.\n");
egl_report_error(); egl_report_error();
@ -164,15 +163,17 @@ void egl_set_swap_interval(void *data, unsigned interval)
void egl_get_video_size(void *data, unsigned *width, unsigned *height) void egl_get_video_size(void *data, unsigned *width, unsigned *height)
{ {
egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
*width = 0; *width = 0;
*height = 0; *height = 0;
if (g_egl_dpy != EGL_NO_DISPLAY && g_egl_surf != EGL_NO_SURFACE) if (egl->dpy != EGL_NO_DISPLAY && egl->surf != EGL_NO_SURFACE)
{ {
EGLint gl_width, gl_height; EGLint gl_width, gl_height;
eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_WIDTH, &gl_width); eglQuerySurface(egl->dpy, egl->surf, EGL_WIDTH, &gl_width);
eglQuerySurface(g_egl_dpy, g_egl_surf, EGL_HEIGHT, &gl_height); eglQuerySurface(egl->dpy, egl->surf, EGL_HEIGHT, &gl_height);
*width = gl_width; *width = gl_width;
*height = gl_height; *height = gl_height;
} }
@ -196,59 +197,66 @@ void egl_install_sighandlers(void)
sigaction(SIGTERM, &sa, NULL); sigaction(SIGTERM, &sa, NULL);
} }
bool egl_init_context(NativeDisplayType display, bool egl_init_context(void *data, NativeDisplayType display,
EGLint *major, EGLint *minor, EGLint *major, EGLint *minor,
EGLint *n, const EGLint *attrib_ptr) EGLint *n, const EGLint *attrib_ptr)
{ {
g_egl_dpy = eglGetDisplay(display); egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (!g_egl_dpy) egl->dpy = eglGetDisplay(display);
if (!egl->dpy)
{ {
RARCH_ERR("[EGL]: Couldn't get EGL display.\n"); RARCH_ERR("[EGL]: Couldn't get EGL display.\n");
return false; return false;
} }
if (!eglInitialize(g_egl_dpy, major, minor)) if (!eglInitialize(egl->dpy, major, minor))
return false; return false;
RARCH_LOG("[EGL]: EGL version: %d.%d\n", *major, *minor); RARCH_LOG("[EGL]: EGL version: %d.%d\n", *major, *minor);
if (!eglChooseConfig(g_egl_dpy, attrib_ptr, &g_egl_config, 1, n) || *n != 1) if (!eglChooseConfig(egl->dpy, attrib_ptr, &egl->config, 1, n) || *n != 1)
return false; return false;
egl->api = g_egl_api;
egl->major = g_egl_major;
egl->minor = g_egl_minor;
return true; return true;
} }
bool egl_create_context(EGLint *egl_attribs) bool egl_create_context(void *data, EGLint *egl_attribs)
{ {
g_egl_ctx = eglCreateContext(g_egl_dpy, g_egl_config, EGL_NO_CONTEXT, egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
egl->ctx = eglCreateContext(egl->dpy, egl->config, EGL_NO_CONTEXT,
egl_attribs); egl_attribs);
g_egl_hw_ctx = NULL; egl->hw_ctx = NULL;
if (g_egl_ctx == EGL_NO_CONTEXT) if (egl->ctx == EGL_NO_CONTEXT)
return false; return false;
if (g_egl_use_hw_ctx) if (egl->use_hw_ctx)
{ {
g_egl_hw_ctx = eglCreateContext(g_egl_dpy, g_egl_config, g_egl_ctx, egl->hw_ctx = eglCreateContext(egl->dpy, egl->config, egl->ctx,
egl_attribs); egl_attribs);
RARCH_LOG("[EGL]: Created shared context: %p.\n", (void*)g_egl_hw_ctx); RARCH_LOG("[EGL]: Created shared context: %p.\n", (void*)egl->hw_ctx);
if (g_egl_hw_ctx == EGL_NO_CONTEXT) if (egl->hw_ctx == EGL_NO_CONTEXT)
return false;; return false;;
} }
return true; return true;
} }
bool egl_create_surface(NativeWindowType native_window) bool egl_create_surface(void *data, NativeWindowType native_window)
{ {
g_egl_surf = eglCreateWindowSurface(g_egl_dpy, g_egl_config, native_window, NULL); egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
egl->surf = eglCreateWindowSurface(egl->dpy, egl->config, native_window, NULL);
if (g_egl_surf == EGL_NO_SURFACE) if (egl->surf == EGL_NO_SURFACE)
return false; return false;
/* Connect the context to the surface. */ /* Connect the context to the surface. */
if (!eglMakeCurrent(g_egl_dpy, g_egl_surf, g_egl_surf, g_egl_ctx)) if (!eglMakeCurrent(egl->dpy, egl->surf, egl->surf, egl->ctx))
return false; return false;
RARCH_LOG("[EGL]: Current context: %p.\n", (void*)eglGetCurrentContext()); RARCH_LOG("[EGL]: Current context: %p.\n", (void*)eglGetCurrentContext());
@ -256,9 +264,10 @@ bool egl_create_surface(NativeWindowType native_window)
return true; return true;
} }
bool egl_get_native_visual_id(EGLint *value) bool egl_get_native_visual_id(void *data, EGLint *value)
{ {
if (!eglGetConfigAttrib(g_egl_dpy, g_egl_config, egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (!eglGetConfigAttrib(egl->dpy, egl->config,
EGL_NATIVE_VISUAL_ID, value)) EGL_NATIVE_VISUAL_ID, value))
{ {
RARCH_ERR("[EGL]: egl_get_native_visual_id failed.\n"); RARCH_ERR("[EGL]: egl_get_native_visual_id failed.\n");
@ -268,9 +277,10 @@ bool egl_get_native_visual_id(EGLint *value)
return true; return true;
} }
bool egl_has_config(void) bool egl_has_config(void *data)
{ {
if (!g_egl_config) egl_ctx_data_t *egl = (egl_ctx_data_t*)data;
if (!egl->config)
{ {
RARCH_ERR("[EGL]: No EGL configurations available.\n"); RARCH_ERR("[EGL]: No EGL configurations available.\n");
return false; return false;

View File

@ -29,16 +29,44 @@
extern "C" { extern "C" {
#endif #endif
extern volatile sig_atomic_t g_egl_quit; /* Put this structure as the first member of egl-based contexts
* like this:
* typedef struct
* {
* egl_ctx_data_t egl;
* int member0;
* char member1;
* ....
* } my_ctx_data_t;
*
* You can call egl functions passing the data pointer you receive
* or using &ctx_data->egl. It's up to you.
*/
typedef struct
{
EGLContext ctx;
EGLContext hw_ctx;
EGLSurface surf;
EGLDisplay dpy;
EGLConfig config;
unsigned interval;
extern EGLContext g_egl_ctx; unsigned major;
extern EGLContext g_egl_hw_ctx; unsigned minor;
extern EGLSurface g_egl_surf; enum gfx_ctx_api api;
extern EGLDisplay g_egl_dpy;
extern EGLConfig g_egl_config; /* egl "private" */
extern enum gfx_ctx_api g_egl_api; bool use_hw_ctx;
} egl_ctx_data_t;
extern volatile sig_atomic_t g_egl_quit;
extern bool g_egl_inited; extern bool g_egl_inited;
extern unsigned g_interval;
/* bind_api is called before init so we need these, please
* try no to use them outside of bind_api() and init() */
extern enum gfx_ctx_api g_egl_api;
extern unsigned g_egl_major;
extern unsigned g_egl_minor;
void egl_report_error(void); void egl_report_error(void);
@ -56,17 +84,17 @@ void egl_get_video_size(void *data, unsigned *width, unsigned *height);
void egl_install_sighandlers(void); void egl_install_sighandlers(void);
bool egl_init_context(NativeDisplayType display, bool egl_init_context(void *data, NativeDisplayType display,
EGLint *major, EGLint *minor, EGLint *major, EGLint *minor,
EGLint *n, const EGLint *attrib_ptr); EGLint *n, const EGLint *attrib_ptr);
bool egl_create_context(EGLint *egl_attribs); bool egl_create_context(void *data, EGLint *egl_attribs);
bool egl_create_surface(NativeWindowType native_window); bool egl_create_surface(void *data, NativeWindowType native_window);
bool egl_get_native_visual_id(EGLint *value); bool egl_get_native_visual_id(void *data, EGLint *value);
bool egl_has_config(void); bool egl_has_config(void *data);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -108,7 +108,7 @@ static const GLfloat white_color[] = {
static INLINE void context_bind_hw_render(gl_t *gl, bool enable) static INLINE void context_bind_hw_render(gl_t *gl, bool enable)
{ {
if (gl && gl->shared_context_use) if (gl && gl->shared_context_use)
gfx_ctx_bind_hw_render(gl, enable); gfx_ctx_bind_hw_render(enable);
} }
static INLINE bool gl_query_extension(gl_t *gl, const char *ext) static INLINE bool gl_query_extension(gl_t *gl, const char *ext)
@ -851,7 +851,7 @@ static void gl_set_viewport(void *data, unsigned viewport_width,
video_driver_get_size(&width, &height); video_driver_get_size(&width, &height);
gfx_ctx_translate_aspect(gl, &device_aspect, gfx_ctx_translate_aspect(&device_aspect,
viewport_width, viewport_height); viewport_width, viewport_height);
if (settings->video.scale_integer && !force_full) if (settings->video.scale_integer && !force_full)
@ -951,7 +951,7 @@ static void gl_set_rotation(void *data, unsigned rotation)
static void gl_set_video_mode(void *data, unsigned width, unsigned height, static void gl_set_video_mode(void *data, unsigned width, unsigned height,
bool fullscreen) bool fullscreen)
{ {
gfx_ctx_set_video_mode(data, width, height, fullscreen); gfx_ctx_set_video_mode(width, height, fullscreen);
} }
#ifdef HAVE_FBO #ifdef HAVE_FBO
@ -1680,7 +1680,7 @@ static bool gl_frame(void *data, const void *frame,
{ {
gl->should_resize = false; gl->should_resize = false;
gfx_ctx_set_resize(gl, width, height); gfx_ctx_set_resize(width, height);
#ifdef HAVE_FBO #ifdef HAVE_FBO
if (gl->fbo_inited) if (gl->fbo_inited)
@ -1809,7 +1809,7 @@ static bool gl_frame(void *data, const void *frame,
gl_render_overlay(gl); gl_render_overlay(gl);
#endif #endif
gfx_ctx_update_window_title(gl); gfx_ctx_update_window_title();
retro_perf_stop(&frame_run); retro_perf_stop(&frame_run);
@ -1856,11 +1856,11 @@ static bool gl_frame(void *data, const void *frame,
&& !input_driver_ctl(RARCH_INPUT_CTL_IS_NONBLOCK_STATE, NULL) && !input_driver_ctl(RARCH_INPUT_CTL_IS_NONBLOCK_STATE, NULL)
&& !is_slowmotion && !is_paused) && !is_slowmotion && !is_paused)
{ {
gfx_ctx_swap_buffers(gl); gfx_ctx_swap_buffers();
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
} }
gfx_ctx_swap_buffers(gl); gfx_ctx_swap_buffers();
#ifdef HAVE_GL_SYNC #ifdef HAVE_GL_SYNC
if (settings->video.hard_sync && gl->have_sync) if (settings->video.hard_sync && gl->have_sync)
@ -1987,7 +1987,7 @@ static void gl_free(void *data)
} }
#endif #endif
gfx_ctx_free(gl); gfx_ctx_free();
free(gl->empty_buf); free(gl->empty_buf);
free(gl->conv_buffer); free(gl->conv_buffer);
@ -2005,7 +2005,7 @@ static void gl_set_nonblock_state(void *data, bool state)
RARCH_LOG("[GL]: VSync => %s\n", state ? "off" : "on"); RARCH_LOG("[GL]: VSync => %s\n", state ? "off" : "on");
context_bind_hw_render(gl, false); context_bind_hw_render(gl, false);
gfx_ctx_swap_interval(gl, gfx_ctx_swap_interval(
state ? 0 : settings->video.swap_interval); state ? 0 : settings->video.swap_interval);
context_bind_hw_render(gl, true); context_bind_hw_render(gl, true);
} }
@ -2467,10 +2467,10 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
RARCH_LOG("Found GL context: %s\n", ctx_driver->ident); RARCH_LOG("Found GL context: %s\n", ctx_driver->ident);
gfx_ctx_get_video_size(gl, &gl->full_x, &gl->full_y); gfx_ctx_get_video_size(&gl->full_x, &gl->full_y);
RARCH_LOG("Detecting screen resolution %ux%u.\n", gl->full_x, gl->full_y); RARCH_LOG("Detecting screen resolution %ux%u.\n", gl->full_x, gl->full_y);
gfx_ctx_swap_interval(gl, gfx_ctx_swap_interval(
video->vsync ? settings->video.swap_interval : 0); video->vsync ? settings->video.swap_interval : 0);
win_width = video->width; win_width = video->width;
@ -2482,7 +2482,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
win_height = gl->full_y; win_height = gl->full_y;
} }
if (!gfx_ctx_set_video_mode(gl, win_width, win_height, video->fullscreen)) if (!gfx_ctx_set_video_mode(win_width, win_height, video->fullscreen))
goto error; goto error;
/* Clear out potential error flags in case we use cached context. */ /* Clear out potential error flags in case we use cached context. */
@ -2513,7 +2513,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
gl->fullscreen = video->fullscreen; gl->fullscreen = video->fullscreen;
/* Get real known video size, which might have been altered by context. */ /* Get real known video size, which might have been altered by context. */
gfx_ctx_get_video_size(gl, &temp_width, &temp_height); gfx_ctx_get_video_size(&temp_width, &temp_height);
if (temp_width != 0 && temp_height != 0) if (temp_width != 0 && temp_height != 0)
video_driver_set_size(&temp_width, &temp_height); video_driver_set_size(&temp_width, &temp_height);
@ -2641,7 +2641,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
goto error; goto error;
#endif #endif
gfx_ctx_input_driver(gl, input, input_data); gfx_ctx_input_driver(input, input_data);
if (settings->video.font_enable) if (settings->video.font_enable)
{ {
@ -2677,7 +2677,7 @@ static bool gl_alive(void *data)
/* Needed because some context drivers don't track their sizes */ /* Needed because some context drivers don't track their sizes */
video_driver_get_size(&temp_width, &temp_height); video_driver_get_size(&temp_width, &temp_height);
if (gfx_ctx_check_window(data, &quit, if (gfx_ctx_check_window(&quit,
&resize, &temp_width, &temp_height)) &resize, &temp_width, &temp_height))
{ {
if (quit) if (quit)
@ -2696,17 +2696,17 @@ static bool gl_alive(void *data)
static bool gl_focus(void *data) static bool gl_focus(void *data)
{ {
return gfx_ctx_focus(data); return gfx_ctx_focus();
} }
static bool gl_suppress_screensaver(void *data, bool enable) static bool gl_suppress_screensaver(void *data, bool enable)
{ {
return gfx_ctx_suppress_screensaver(data, enable); return gfx_ctx_suppress_screensaver(enable);
} }
static bool gl_has_windowed(void *data) static bool gl_has_windowed(void *data)
{ {
return gfx_ctx_has_windowed(data); return gfx_ctx_has_windowed();
} }
static void gl_update_tex_filter_frame(gl_t *gl) static void gl_update_tex_filter_frame(gl_t *gl)
@ -3189,7 +3189,7 @@ static void gl_overlay_enable(void *data, bool state)
gl->overlay_enable = state; gl->overlay_enable = state;
if (gl->fullscreen) if (gl->fullscreen)
gfx_ctx_show_mouse(gl, state); gfx_ctx_show_mouse(state);
} }
static void gl_overlay_full_screen(void *data, bool enable) static void gl_overlay_full_screen(void *data, bool enable)
@ -3381,7 +3381,7 @@ static void gl_set_osd_msg(void *data, const char *msg,
static void gl_show_mouse(void *data, bool state) static void gl_show_mouse(void *data, bool state)
{ {
gfx_ctx_show_mouse(data, state); gfx_ctx_show_mouse(state);
} }
static struct video_shader *gl_get_current_shader(void *data) static struct video_shader *gl_get_current_shader(void *data)
@ -3393,17 +3393,17 @@ static struct video_shader *gl_get_current_shader(void *data)
static void gl_get_video_output_size(void *data, static void gl_get_video_output_size(void *data,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
gfx_ctx_get_video_output_size(data, width, height); gfx_ctx_get_video_output_size(width, height);
} }
static void gl_get_video_output_prev(void *data) static void gl_get_video_output_prev(void *data)
{ {
gfx_ctx_get_video_output_prev(data); gfx_ctx_get_video_output_prev();
} }
static void gl_get_video_output_next(void *data) static void gl_get_video_output_next(void *data)
{ {
gfx_ctx_get_video_output_next(data); gfx_ctx_get_video_output_next();
} }
static const video_poke_interface_t gl_poke_interface = { static const video_poke_interface_t gl_poke_interface = {

View File

@ -32,7 +32,7 @@ int system_property_get(const char *cmd, const char *args, char *value);
static bool g_es3; static bool g_es3;
static bool android_gfx_ctx_init(void *data) static void *android_gfx_ctx_init(void *video_driver)
{ {
EGLint n, major, minor; EGLint n, major, minor;
EGLint format; EGLint format;
@ -50,39 +50,55 @@ static bool android_gfx_ctx_init(void *data)
EGL_NONE EGL_NONE
}; };
struct android_app *android_app = (struct android_app*)g_android; struct android_app *android_app = (struct android_app*)g_android;
egl_ctx_data_t *egl;
if (!android_app) if (!android_app)
return false; return false;
egl = (egl_ctx_data_t*)calloc(1, sizeof(*egl));
RARCH_LOG("Android EGL: GLES version = %d.\n", g_es3 ? 3 : 2); RARCH_LOG("Android EGL: GLES version = %d.\n", g_es3 ? 3 : 2);
if (!egl_init_context(EGL_DEFAULT_DISPLAY, if (!egl_init_context(egl, EGL_DEFAULT_DISPLAY,
&major, &minor, &n, attribs)) &major, &minor, &n, attribs))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if (!egl_get_native_visual_id(&format)) if (!egl_get_native_visual_id(egl, &format))
goto error; goto error;
ANativeWindow_setBuffersGeometry(android_app->window, 0, 0, format); ANativeWindow_setBuffersGeometry(android_app->window, 0, 0, format);
if (!egl_create_context(context_attributes)) if (!egl_create_context(egl, context_attributes))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if (!egl_create_surface(android_app->window)) if (!egl_create_surface(egl, android_app->window))
goto error; goto error;
return true; return egl;
error: error:
egl_destroy(NULL); if (egl)
{
egl_destroy(egl);
free(egl);
}
return false; return NULL;
}
static void android_gfx_ctx_destroy(void *data)
{
if (data)
{
egl_destroy(data);
free(data);
}
} }
static void android_gfx_ctx_check_window(void *data, bool *quit, static void android_gfx_ctx_check_window(void *data, bool *quit,
@ -229,7 +245,7 @@ static bool android_gfx_ctx_get_metrics(void *data,
const gfx_ctx_driver_t gfx_ctx_android = { const gfx_ctx_driver_t gfx_ctx_android = {
android_gfx_ctx_init, android_gfx_ctx_init,
egl_destroy, android_gfx_ctx_destroy,
android_gfx_ctx_bind_api, android_gfx_ctx_bind_api,
egl_set_swap_interval, egl_set_swap_interval,
android_gfx_ctx_set_video_mode, android_gfx_ctx_set_video_mode,

View File

@ -34,20 +34,24 @@
#define WINDOW_BUFFERS 2 #define WINDOW_BUFFERS 2
static bool g_resize;
screen_context_t screen_ctx; screen_context_t screen_ctx;
screen_window_t screen_win;
static screen_display_t screen_disp; typedef struct {
screen_window_t screen_win;
screen_display_t screen_disp;
bool resize;
} qnx_ctx_data_t;
static void gfx_ctx_qnx_destroy(void *data) static void gfx_ctx_qnx_destroy(void *data)
{ {
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)data;
egl_destroy(data); egl_destroy(data);
g_resize = false; qnx->resize = false;
free(data);
} }
static bool gfx_ctx_qnx_init(void *data) static void *gfx_ctx_qnx_init(void *video_driver)
{ {
EGLint n; EGLint n;
EGLint major, minor; EGLint major, minor;
@ -65,6 +69,10 @@ static bool gfx_ctx_qnx_init(void *data)
}; };
int angle, size[2]; int angle, size[2];
int usage, format = SCREEN_FORMAT_RGBX8888; int usage, format = SCREEN_FORMAT_RGBX8888;
qnx_ctx_data_t *qnx = (qnx_ctx_data_t*)calloc(1, sizeof(*qnx));
if (!qnx)
goto screen_error;
/* Create a screen context that will be used to /* Create a screen context that will be used to
* create an EGL surface to receive libscreen events */ * create an EGL surface to receive libscreen events */
@ -101,41 +109,41 @@ static bool gfx_ctx_qnx_init(void *data)
goto error; goto error;
} }
if (!egl_init_context(EGL_DEFAULT_DISPLAY, &major, &minor, if (!egl_init_context(qnx, EGL_DEFAULT_DISPLAY, &major, &minor,
&n, attribs)) &n, attribs))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if (!egl_create_context(context_attributes)) if (!egl_create_context(qnx, context_attributes))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if(!screen_win) if(!qnx->screen_win)
{ {
if (screen_create_window(&screen_win, screen_ctx)) if (screen_create_window(&qnx->screen_win, screen_ctx))
{ {
RARCH_ERR("screen_create_window failed:.\n"); RARCH_ERR("screen_create_window failed:.\n");
goto error; goto error;
} }
} }
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_FORMAT, &format)) if (screen_set_window_property_iv(qnx->screen_win, SCREEN_PROPERTY_FORMAT, &format))
{ {
RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n"); RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_FORMAT] failed.\n");
goto error; goto error;
} }
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage)) if (screen_set_window_property_iv(qnx->screen_win, SCREEN_PROPERTY_USAGE, &usage))
{ {
RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n"); RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_USAGE] failed.\n");
goto error; goto error;
} }
if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&screen_disp)) if (screen_get_window_property_pv(qnx->screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&qnx->screen_disp))
{ {
RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n"); RARCH_ERR("screen_get_window_property_pv [SCREEN_PROPERTY_DISPLAY] failed.\n");
goto error; goto error;
@ -143,7 +151,7 @@ static bool gfx_ctx_qnx_init(void *data)
int screen_resolution[2]; int screen_resolution[2];
if (screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution)) if (screen_get_display_property_iv(qnx->screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution))
{ {
RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n"); RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_SIZE] failed.\n");
goto error; goto error;
@ -153,13 +161,13 @@ static bool gfx_ctx_qnx_init(void *data)
angle = atoi(getenv("ORIENTATION")); angle = atoi(getenv("ORIENTATION"));
screen_display_mode_t screen_mode; screen_display_mode_t screen_mode;
if (screen_get_display_property_pv(screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode)) if (screen_get_display_property_pv(qnx->screen_disp, SCREEN_PROPERTY_MODE, (void**)&screen_mode))
{ {
RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n"); RARCH_ERR("screen_get_display_property_pv [SCREEN_PROPERTY_MODE] failed.\n");
goto error; goto error;
} }
if (screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size)) if (screen_get_window_property_iv(qnx->screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size))
{ {
RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n"); RARCH_ERR("screen_get_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
goto error; goto error;
@ -192,36 +200,36 @@ static bool gfx_ctx_qnx_init(void *data)
} }
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size)) if (screen_set_window_property_iv(qnx->screen_win, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size))
{ {
RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n"); RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_BUFFER_SIZE] failed.\n");
goto error; goto error;
} }
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle)) if (screen_set_window_property_iv(qnx->screen_win, SCREEN_PROPERTY_ROTATION, &angle))
{ {
RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n"); RARCH_ERR("screen_set_window_property_iv [SCREEN_PROPERTY_ROTATION] failed.\n");
goto error; goto error;
} }
#endif #endif
if (screen_create_window_buffers(screen_win, WINDOW_BUFFERS)) if (screen_create_window_buffers(qnx->screen_win, WINDOW_BUFFERS))
{ {
RARCH_ERR("screen_create_window_buffers failed.\n"); RARCH_ERR("screen_create_window_buffers failed.\n");
goto error; goto error;
} }
if (!egl_create_surface(screen_win)) if (!egl_create_surface(qnx->screen_win))
goto error; goto error;
return true; return "egl";
error: error:
RARCH_ERR("EGL error: %d.\n", eglGetError()); RARCH_ERR("EGL error: %d.\n", eglGetError());
gfx_ctx_qnx_destroy(data); gfx_ctx_qnx_destroy(video_driver);
screen_error: screen_error:
screen_stop_events(screen_ctx); screen_stop_events(screen_ctx);
return false; return NULL;
} }
static void gfx_ctx_qnx_check_window(void *data, bool *quit, static void gfx_ctx_qnx_check_window(void *data, bool *quit,

View File

@ -304,7 +304,7 @@ static CGSSurfaceID attach_gl_context_to_window(CGLContextObj glCtx,
return sid; return sid;
} }
static bool gfx_ctx_cgl_init(void *data) static void *gfx_ctx_cgl_init(void *video_driver)
{ {
CGError err; CGError err;
gfx_ctx_cgl_data_t *cgl = (gfx_ctx_cgl_data_t*)calloc(1, sizeof(gfx_ctx_cgl_data_t)); gfx_ctx_cgl_data_t *cgl = (gfx_ctx_cgl_data_t*)calloc(1, sizeof(gfx_ctx_cgl_data_t));
@ -333,12 +333,12 @@ static bool gfx_ctx_cgl_init(void *data)
gfx_ctx_data_set(cgl); gfx_ctx_data_set(cgl);
return true; return cgl;
error: error:
gfx_ctx_cgl_destroy(cgl); gfx_ctx_cgl_destroy(cgl);
return false; return NULL;
} }
const gfx_ctx_driver_t gfx_ctx_cgl = { const gfx_ctx_driver_t gfx_ctx_cgl = {

View File

@ -148,9 +148,9 @@ void cocoagl_gfx_ctx_update(void)
#endif #endif
} }
static bool cocoagl_gfx_ctx_init(void *data) static void *cocoagl_gfx_ctx_init(void *video_driver)
{ {
(void)data; (void)video_driver;
#if defined(HAVE_COCOA) #if defined(HAVE_COCOA)
CocoaView *g_view = (CocoaView*)nsview_get_ptr(); CocoaView *g_view = (CocoaView*)nsview_get_ptr();
@ -196,7 +196,7 @@ static bool cocoagl_gfx_ctx_init(void *data)
[g_context makeCurrentContext]; [g_context makeCurrentContext];
// Make sure the view was created // Make sure the view was created
[CocoaView get]; [CocoaView get];
return true; return "cocoa";
} }
static void cocoagl_gfx_ctx_destroy(void *data) static void cocoagl_gfx_ctx_destroy(void *data)

View File

@ -159,13 +159,13 @@ static bool gfx_ctx_d3d_bind_api(void *data,
#endif #endif
} }
static bool gfx_ctx_d3d_init(void *data) static void *gfx_ctx_d3d_init(void *video_driver)
{ {
(void)data; (void)video_driver;
win32_monitor_init(); win32_monitor_init();
return true; return "d3d";
} }
static void gfx_ctx_d3d_destroy(void *data) static void gfx_ctx_d3d_destroy(void *data)

View File

@ -59,15 +59,12 @@ static bool waiting_for_flip;
typedef struct gfx_ctx_drm_egl_data typedef struct gfx_ctx_drm_egl_data
{ {
egl_ctx_data_t egl;
RFILE *g_drm; RFILE *g_drm;
unsigned g_fb_width; unsigned g_fb_width;
unsigned g_fb_height; unsigned g_fb_height;
} gfx_ctx_drm_egl_data_t; } gfx_ctx_drm_egl_data_t;
static unsigned g_major;
static unsigned g_minor;
struct drm_fb struct drm_fb
{ {
struct gbm_bo *bo; struct gbm_bo *bo;
@ -117,7 +114,8 @@ error:
static void gfx_ctx_drm_egl_swap_interval(void *data, unsigned interval) static void gfx_ctx_drm_egl_swap_interval(void *data, unsigned interval)
{ {
g_interval = interval; gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)data;
drm->egl.interval = interval;
if (interval > 1) if (interval > 1)
RARCH_WARN("[KMS/EGL]: Swap intervals > 1 currently not supported. Will use swap interval of 1.\n"); RARCH_WARN("[KMS/EGL]: Swap intervals > 1 currently not supported. Will use swap interval of 1.\n");
} }
@ -206,6 +204,7 @@ static bool queue_flip(void)
static void gfx_ctx_drm_egl_swap_buffers(void *data) static void gfx_ctx_drm_egl_swap_buffers(void *data)
{ {
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)data;
egl_swap_buffers(data); egl_swap_buffers(data);
/* I guess we have to wait for flip to have taken /* I guess we have to wait for flip to have taken
@ -213,7 +212,7 @@ static void gfx_ctx_drm_egl_swap_buffers(void *data)
* *
* If true, we are still waiting for a flip * If true, we are still waiting for a flip
* (nonblocking mode, so just drop the frame). */ * (nonblocking mode, so just drop the frame). */
if (wait_flip(g_interval)) if (wait_flip(drm->egl.interval))
return; return;
waiting_for_flip = queue_flip(); waiting_for_flip = queue_flip();
@ -250,8 +249,7 @@ static void gfx_ctx_drm_egl_update_window_title(void *data)
static void gfx_ctx_drm_egl_get_video_size(void *data, static void gfx_ctx_drm_egl_get_video_size(void *data,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*) gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)data;
gfx_ctx_data_get_ptr();
if (!drm) if (!drm)
return; return;
@ -290,7 +288,7 @@ static void gfx_ctx_drm_egl_destroy_resources(gfx_ctx_drm_egl_data_t *drm)
/* Make sure we acknowledge all page-flips. */ /* Make sure we acknowledge all page-flips. */
wait_flip(true); wait_flip(true);
egl_destroy(NULL); egl_destroy(drm);
/* Restore original CRTC. */ /* Restore original CRTC. */
drm_restore_crtc(); drm_restore_crtc();
@ -307,7 +305,7 @@ static void gfx_ctx_drm_egl_destroy_resources(gfx_ctx_drm_egl_data_t *drm)
g_next_bo = NULL; g_next_bo = NULL;
} }
static bool gfx_ctx_drm_egl_init(void *data) static void *gfx_ctx_drm_egl_init(void *video_driver)
{ {
int fd, i; int fd, i;
unsigned monitor_index; unsigned monitor_index;
@ -317,7 +315,7 @@ static bool gfx_ctx_drm_egl_init(void *data)
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)calloc(1, sizeof(gfx_ctx_drm_egl_data_t)); gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)calloc(1, sizeof(gfx_ctx_drm_egl_data_t));
if (!drm) if (!drm)
return false; return NULL;
fd = -1; fd = -1;
gpu_descriptors = dir_list_new("/dev/dri", NULL, false, false); gpu_descriptors = dir_list_new("/dev/dri", NULL, false, false);
@ -368,8 +366,6 @@ nextgpu:
dir_list_free(gpu_descriptors); dir_list_free(gpu_descriptors);
gfx_ctx_data_set(drm);
/* Setup the flip handler. */ /* Setup the flip handler. */
g_drm_fds.fd = fd; g_drm_fds.fd = fd;
g_drm_fds.events = POLLIN; g_drm_fds.events = POLLIN;
@ -378,7 +374,7 @@ nextgpu:
g_drm_fd = fd; g_drm_fd = fd;
return true; return drm;
error: error:
dir_list_free(gpu_descriptors); dir_list_free(gpu_descriptors);
@ -388,17 +384,17 @@ error:
if (drm) if (drm)
free(drm); free(drm);
return false; return NULL;
} }
static EGLint *egl_fill_attribs(EGLint *attr) static EGLint *egl_fill_attribs(gfx_ctx_drm_egl_data_t *drm, EGLint *attr)
{ {
switch (g_egl_api) switch (drm->egl.api)
{ {
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_API:
{ {
unsigned version = g_major * 1000 + g_minor; unsigned version = drm->egl.major * 1000 + drm->egl.minor;
bool core = version >= 3001; bool core = version >= 3001;
#ifdef GL_DEBUG #ifdef GL_DEBUG
bool debug = true; bool debug = true;
@ -411,9 +407,9 @@ static EGLint *egl_fill_attribs(EGLint *attr)
if (core) if (core)
{ {
*attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR;
*attr++ = g_major; *attr++ = drm->egl.major;
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = g_minor; *attr++ = drm->egl.minor;
/* Technically, we don't have core/compat until 3.2. /* Technically, we don't have core/compat until 3.2.
* Version 3.1 is either compat or not depending * Version 3.1 is either compat or not depending
@ -437,12 +433,12 @@ static EGLint *egl_fill_attribs(EGLint *attr)
case GFX_CTX_OPENGL_ES_API: case GFX_CTX_OPENGL_ES_API:
*attr++ = EGL_CONTEXT_CLIENT_VERSION; *attr++ = EGL_CONTEXT_CLIENT_VERSION;
*attr++ = g_major ? (EGLint)g_major : 2; *attr++ = drm->egl.major ? (EGLint)drm->egl.major : 2;
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
if (g_minor > 0) if (drm->egl.minor > 0)
{ {
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = g_minor; *attr++ = drm->egl.minor;
} }
#endif #endif
break; break;
@ -499,8 +495,7 @@ static bool gfx_ctx_drm_egl_set_video_mode(void *data,
int i, ret = 0; int i, ret = 0;
struct drm_fb *fb = NULL; struct drm_fb *fb = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*) gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)data;
gfx_ctx_data_get_ptr();
if (!drm) if (!drm)
return false; return false;
@ -514,7 +509,7 @@ static bool gfx_ctx_drm_egl_set_video_mode(void *data,
break; break;
case GFX_CTX_OPENGL_ES_API: case GFX_CTX_OPENGL_ES_API:
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
if (g_major >= 3) if (drm->egl.major >= 3)
attrib_ptr = egl_attribs_gles3; attrib_ptr = egl_attribs_gles3;
else else
#endif #endif
@ -587,27 +582,27 @@ static bool gfx_ctx_drm_egl_set_video_mode(void *data,
} }
if (!egl_init_context((EGLNativeDisplayType)g_gbm_dev, &major, if (!egl_init_context(drm, (EGLNativeDisplayType)g_gbm_dev, &major,
&minor, &n, attrib_ptr)) &minor, &n, attrib_ptr))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
attr = egl_fill_attribs(egl_attribs); attr = egl_fill_attribs(drm, egl_attribs);
egl_attribs_ptr = &egl_attribs[0]; egl_attribs_ptr = &egl_attribs[0];
if (!egl_create_context((attr != egl_attribs_ptr) ? egl_attribs_ptr : NULL)) if (!egl_create_context(drm, (attr != egl_attribs_ptr) ? egl_attribs_ptr : NULL))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if (!egl_create_surface((EGLNativeWindowType)g_gbm_surface)) if (!egl_create_surface(drm, (EGLNativeWindowType)g_gbm_surface))
goto error; goto error;
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
egl_swap_buffers(NULL); egl_swap_buffers(drm);
g_bo = gbm_surface_lock_front_buffer(g_gbm_surface); g_bo = gbm_surface_lock_front_buffer(g_gbm_surface);
fb = drm_fb_get_from_bo(g_bo); fb = drm_fb_get_from_bo(g_bo);
@ -631,14 +626,13 @@ error:
static void gfx_ctx_drm_egl_destroy(void *data) static void gfx_ctx_drm_egl_destroy(void *data)
{ {
gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*) gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)data;
gfx_ctx_data_get_ptr();
if (!drm) if (!drm)
return; return;
gfx_ctx_drm_egl_destroy_resources(drm); gfx_ctx_drm_egl_destroy_resources(drm);
gfx_ctx_free_data(); free(drm);
} }
static void gfx_ctx_drm_egl_input_driver(void *data, static void gfx_ctx_drm_egl_input_driver(void *data,
@ -667,14 +661,14 @@ static bool gfx_ctx_drm_egl_has_windowed(void *data)
return false; return false;
} }
static bool gfx_ctx_drm_egl_bind_api(void *data, static bool gfx_ctx_drm_egl_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor) enum gfx_ctx_api api, unsigned major, unsigned minor)
{ {
(void)data; (void)video_driver;
g_major = major; g_egl_major = major;
g_minor = minor; g_egl_minor = minor;
g_egl_api = api; g_egl_api = api;
switch (api) switch (api)
{ {

View File

@ -101,7 +101,7 @@ static void gfx_ctx_emscripten_get_video_size(void *data,
static void gfx_ctx_emscripten_destroy(void *data); static void gfx_ctx_emscripten_destroy(void *data);
static bool gfx_ctx_emscripten_init(void *data) static void *gfx_ctx_emscripten_init(void *video_driver)
{ {
EGLint width, height, n, major, minor; EGLint width, height, n, major, minor;
static const EGLint attribute_list[] = static const EGLint attribute_list[] =
@ -119,12 +119,12 @@ static bool gfx_ctx_emscripten_init(void *data)
EGL_NONE EGL_NONE
}; };
(void)data; (void)video_driver;
if (g_egl_inited) if (g_egl_inited)
{ {
RARCH_LOG("[EMSCRIPTEN/EGL]: Attempted to re-initialize driver.\n"); RARCH_LOG("[EMSCRIPTEN/EGL]: Attempted to re-initialize driver.\n");
return true; return (void*)"emscripten";
} }
if (!egl_init_context(EGL_DEFAULT_DISPLAY, &major, &minor, if (!egl_init_context(EGL_DEFAULT_DISPLAY, &major, &minor,
@ -149,11 +149,11 @@ static bool gfx_ctx_emscripten_init(void *data)
g_fb_height = height; g_fb_height = height;
RARCH_LOG("[EMSCRIPTEN/EGL]: Dimensions: %ux%u\n", width, height); RARCH_LOG("[EMSCRIPTEN/EGL]: Dimensions: %ux%u\n", width, height);
return true; return (void*)"emscripten";
error: error:
gfx_ctx_emscripten_destroy(data); gfx_ctx_emscripten_destroy(video_driver);
return false; return NULL;
} }
static bool gfx_ctx_emscripten_set_video_mode(void *data, static bool gfx_ctx_emscripten_set_video_mode(void *data,

View File

@ -125,11 +125,11 @@ static void gfx_ctx_null_bind_hw_render(void *data, bool enable)
(void)enable; (void)enable;
} }
static bool gfx_ctx_null_init(void *data) static void *gfx_ctx_null_init(void *video_driver)
{ {
(void)data; (void)video_driver;
return true; return (void*)"null";
} }
const gfx_ctx_driver_t gfx_ctx_null = { const gfx_ctx_driver_t gfx_ctx_null = {

View File

@ -116,8 +116,7 @@ static void ctx_glx_destroy_resources(gfx_ctx_glx_data_t *glx)
static void gfx_ctx_glx_destroy(void *data) static void gfx_ctx_glx_destroy(void *data)
{ {
gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)data;
gfx_ctx_data_get_ptr();
if (!glx) if (!glx)
return; return;
@ -125,13 +124,12 @@ static void gfx_ctx_glx_destroy(void *data)
(void)data; (void)data;
ctx_glx_destroy_resources(glx); ctx_glx_destroy_resources(glx);
gfx_ctx_free_data(); free(data);
} }
static void gfx_ctx_glx_swap_interval(void *data, unsigned interval) static void gfx_ctx_glx_swap_interval(void *data, unsigned interval)
{ {
gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)data;
gfx_ctx_data_get_ptr();
glx->g_interval = interval; glx->g_interval = interval;
@ -156,8 +154,7 @@ static void gfx_ctx_glx_swap_interval(void *data, unsigned interval)
static void gfx_ctx_glx_swap_buffers(void *data) static void gfx_ctx_glx_swap_buffers(void *data)
{ {
gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)data;
gfx_ctx_data_get_ptr();
if (glx->g_is_double) if (glx->g_is_double)
glXSwapBuffers(g_x11_dpy, glx->g_glx_win); glXSwapBuffers(g_x11_dpy, glx->g_glx_win);
@ -171,7 +168,7 @@ static void gfx_ctx_glx_set_resize(void *data,
(void)height; (void)height;
} }
static bool gfx_ctx_glx_init(void *data) static void *gfx_ctx_glx_init(void *data)
{ {
static const int visual_attribs[] = { static const int visual_attribs[] = {
GLX_X_RENDERABLE , True, GLX_X_RENDERABLE , True,
@ -241,9 +238,7 @@ static bool gfx_ctx_glx_init(void *data)
glx->g_fbc = fbcs[0]; glx->g_fbc = fbcs[0];
XFree(fbcs); XFree(fbcs);
gfx_ctx_data_set(glx); return glx;
return true;
error: error:
ctx_glx_destroy_resources(glx); ctx_glx_destroy_resources(glx);
@ -252,7 +247,7 @@ error:
free(glx); free(glx);
g_x11_screen = 0; g_x11_screen = 0;
return false; return NULL;
} }
static bool gfx_ctx_glx_set_video_mode(void *data, static bool gfx_ctx_glx_set_video_mode(void *data,
@ -266,8 +261,7 @@ static bool gfx_ctx_glx_set_video_mode(void *data,
XSetWindowAttributes swa = {0}; XSetWindowAttributes swa = {0};
int (*old_handler)(Display*, XErrorEvent*) = NULL; int (*old_handler)(Display*, XErrorEvent*) = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)data;
gfx_ctx_data_get_ptr();
x11_install_sighandlers(); x11_install_sighandlers();
@ -555,8 +549,7 @@ static void gfx_ctx_glx_show_mouse(void *data, bool state)
static void gfx_ctx_glx_bind_hw_render(void *data, bool enable) static void gfx_ctx_glx_bind_hw_render(void *data, bool enable)
{ {
gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)data;
gfx_ctx_data_get_ptr();
if (!glx) if (!glx)
return; return;

View File

@ -61,7 +61,7 @@ static void gfx_ctx_mali_fbdev_get_video_size(void *data,
*height = g_height; *height = g_height;
} }
static bool gfx_ctx_mali_fbdev_init(void *data) static void *gfx_ctx_mali_fbdev_init(void *video_driver)
{ {
EGLint n; EGLint n;
EGLint major, minor; EGLint major, minor;
@ -88,12 +88,12 @@ static bool gfx_ctx_mali_fbdev_init(void *data)
goto error; goto error;
} }
return true; return (void*)"mali";
error: error:
RARCH_ERR("[Mali fbdev]: EGL error: %d.\n", eglGetError()); RARCH_ERR("[Mali fbdev]: EGL error: %d.\n", eglGetError());
gfx_ctx_mali_fbdev_destroy(data); gfx_ctx_mali_fbdev_destroy(video_driver);
return false; return NULL;
} }
static void gfx_ctx_mali_fbdev_check_window(void *data, bool *quit, static void gfx_ctx_mali_fbdev_check_window(void *data, bool *quit,

View File

@ -207,10 +207,7 @@ static void gfx_ctx_ps3_update_window_title(void *data)
static void gfx_ctx_ps3_get_video_size(void *data, static void gfx_ctx_ps3_get_video_size(void *data,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*) gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*)data;
gfx_ctx_data_get_ptr();
(void)data;
#if defined(HAVE_PSGL) #if defined(HAVE_PSGL)
if (ps3) if (ps3)
@ -218,7 +215,7 @@ static void gfx_ctx_ps3_get_video_size(void *data,
#endif #endif
} }
static bool gfx_ctx_ps3_init(void *data) static void *gfx_ctx_ps3_init(void *video_driver)
{ {
#ifdef HAVE_PSGL #ifdef HAVE_PSGL
PSGLdeviceParameters params; PSGLdeviceParameters params;
@ -228,11 +225,11 @@ static bool gfx_ctx_ps3_init(void *data)
gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*) gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*)
calloc(1, sizeof(gfx_ctx_ps3_data_t)); calloc(1, sizeof(gfx_ctx_ps3_data_t));
(void)data; (void)video_driver;
(void)global; (void)global;
if (!ps3) if (!ps3)
return false; return NULL;
#if defined(HAVE_PSGL) #if defined(HAVE_PSGL)
options.enable = PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS; options.enable = PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS;
@ -291,9 +288,7 @@ static bool gfx_ctx_ps3_init(void *data)
gfx_ctx_ps3_get_available_resolutions(); gfx_ctx_ps3_get_available_resolutions();
gfx_ctx_data_set(ps3); return ps3;
return true;
} }
static bool gfx_ctx_ps3_set_video_mode(void *data, static bool gfx_ctx_ps3_set_video_mode(void *data,
@ -326,10 +321,7 @@ static void gfx_ctx_ps3_destroy_resources(gfx_ctx_ps3_data_t *ps3)
static void gfx_ctx_ps3_destroy(void *data) static void gfx_ctx_ps3_destroy(void *data)
{ {
gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*) gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*)data;
gfx_ctx_data_get_ptr();
(void)data;
if (!ps3) if (!ps3)
return; return;

View File

@ -65,13 +65,13 @@ static void sdl_ctx_destroy_resources(gfx_ctx_sdl_data_t *sdl)
SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_QuitSubSystem(SDL_INIT_VIDEO);
} }
static bool sdl_ctx_init(void *data) static void *sdl_ctx_init(void *video_driver)
{ {
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*) gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)
calloc(1, sizeof(gfx_ctx_sdl_data_t)); calloc(1, sizeof(gfx_ctx_sdl_data_t));
if (!sdl) if (!sdl)
return false; return NULL;
#ifdef HAVE_X11 #ifdef HAVE_X11
XInitThreads(); XInitThreads();
@ -88,9 +88,7 @@ static bool sdl_ctx_init(void *data)
RARCH_LOG("[SDL_GL] SDL %i.%i.%i gfx context driver initialized.\n", RARCH_LOG("[SDL_GL] SDL %i.%i.%i gfx context driver initialized.\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL); SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
gfx_ctx_data_set(sdl); return sdl;
return true;
error: error:
RARCH_WARN("[SDL_GL]: Failed to initialize SDL gfx context driver: %s\n", RARCH_WARN("[SDL_GL]: Failed to initialize SDL gfx context driver: %s\n",
@ -101,20 +99,18 @@ error:
if (sdl) if (sdl)
free(sdl); free(sdl);
return false; return NULL;
} }
static void sdl_ctx_destroy(void *data) static void sdl_ctx_destroy(void *data)
{ {
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
if (!sdl) if (!sdl)
return; return;
(void)data;
sdl_ctx_destroy_resources(sdl); sdl_ctx_destroy_resources(sdl);
gfx_ctx_free_data(); free(sdl);
} }
static bool sdl_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major, static bool sdl_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major,
@ -162,9 +158,7 @@ static bool sdl_ctx_set_video_mode(void *data, unsigned width, unsigned height,
{ {
unsigned fsflag = 0; unsigned fsflag = 0;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
(void)data;
sdl->g_new_width = width; sdl->g_new_width = width;
sdl->g_new_height = height; sdl->g_new_height = height;
@ -231,7 +225,7 @@ static void sdl_ctx_get_video_size(void *data,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
if (!sdl) if (!sdl)
return; return;
@ -269,7 +263,7 @@ static void sdl_ctx_update_window_title(void *data)
char buf[128] = {0}; char buf[128] = {0};
char buf_fps[128] = {0}; char buf_fps[128] = {0};
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
if (!sdl) if (!sdl)
return; return;
@ -291,9 +285,7 @@ static void sdl_ctx_check_window(void *data, bool *quit, bool *resize,unsigned *
unsigned *height, unsigned frame_count) unsigned *height, unsigned frame_count)
{ {
SDL_Event event; SDL_Event event;
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
(void)data;
SDL_PumpEvents(); SDL_PumpEvents();
@ -354,7 +346,7 @@ static bool sdl_ctx_has_focus(void *data)
unsigned flags; unsigned flags;
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
flags = (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS); flags = (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS);
return (SDL_GetWindowFlags(sdl->g_win) & flags) == flags; return (SDL_GetWindowFlags(sdl->g_win) & flags) == flags;
#else #else
@ -381,7 +373,7 @@ static bool sdl_ctx_has_windowed(void *data)
static void sdl_ctx_swap_buffers(void *data) static void sdl_ctx_swap_buffers(void *data)
{ {
#ifdef HAVE_SDL2 #ifdef HAVE_SDL2
gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;
SDL_GL_SwapWindow(sdl->g_win); SDL_GL_SwapWindow(sdl->g_win);
#else #else
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();

View File

@ -131,7 +131,7 @@ static void gfx_ctx_vc_get_video_size(void *data,
static void gfx_ctx_vc_destroy(void *data); static void gfx_ctx_vc_destroy(void *data);
static bool gfx_ctx_vc_init(void *data) static void *gfx_ctx_vc_init(void *video_driver)
{ {
VC_DISPMANX_ALPHA_T alpha; VC_DISPMANX_ALPHA_T alpha;
EGLint n, major, minor; EGLint n, major, minor;
@ -164,7 +164,7 @@ static bool gfx_ctx_vc_init(void *data)
if (g_egl_inited) if (g_egl_inited)
{ {
RARCH_ERR("[VC/EGL]: Attempted to re-initialize driver.\n"); RARCH_ERR("[VC/EGL]: Attempted to re-initialize driver.\n");
return false; return (void*)"vc";
} }
bcm_host_init(); bcm_host_init();
@ -262,11 +262,11 @@ static bool gfx_ctx_vc_init(void *data)
if (!egl_create_surface(&nativewindow)) if (!egl_create_surface(&nativewindow))
goto error; goto error;
return true; return (void*)"vc";
error: error:
gfx_ctx_vc_destroy(data); gfx_ctx_vc_destroy(video_driver);
return false; return NULL;
} }
static bool gfx_ctx_vc_set_video_mode(void *data, static bool gfx_ctx_vc_set_video_mode(void *data,

View File

@ -32,7 +32,7 @@ static void gfx_ctx_vivante_destroy(void *data)
g_resize = false; g_resize = false;
} }
static bool gfx_ctx_vivante_init(void *data) static void *gfx_ctx_vivante_init(void *video_driver)
{ {
EGLint n; EGLint n;
EGLint major, minor; EGLint major, minor;
@ -50,7 +50,7 @@ static bool gfx_ctx_vivante_init(void *data)
EGL_NONE EGL_NONE
}; };
(void)data; (void)video_driver;
egl_install_sighandlers(); egl_install_sighandlers();
@ -61,12 +61,12 @@ static bool gfx_ctx_vivante_init(void *data)
goto error; goto error;
} }
return true; return (void*)"vivante";
error: error:
RARCH_ERR("[Vivante fbdev]: EGL error: %d.\n", eglGetError()); RARCH_ERR("[Vivante fbdev]: EGL error: %d.\n", eglGetError());
gfx_ctx_vivante_destroy(data); gfx_ctx_vivante_destroy(video_driver);
return false; return NULL;
} }
static void gfx_ctx_vivante_check_window(void *data, bool *quit, static void gfx_ctx_vivante_check_window(void *data, bool *quit,

View File

@ -28,26 +28,22 @@
typedef struct gfx_ctx_wayland_data typedef struct gfx_ctx_wayland_data
{ {
bool g_resize; egl_ctx_data_t egl;
int g_fd; bool resize;
unsigned g_width; int fd;
unsigned g_height; unsigned width;
struct wl_display *g_dpy; unsigned height;
struct wl_registry *g_registry; struct wl_display *dpy;
struct wl_compositor *g_compositor; struct wl_registry *registry;
struct wl_surface *g_surface; struct wl_compositor *compositor;
struct wl_shell_surface *g_shell_surf; struct wl_surface *surface;
struct wl_shell *g_shell; struct wl_shell_surface *shell_surf;
struct wl_egl_window *g_win; struct wl_shell *shell;
struct wl_keyboard *g_wl_keyboard; struct wl_egl_window *win;
struct wl_pointer *g_wl_pointer; struct wl_keyboard *wl_keyboard;
struct wl_pointer *wl_pointer;
} gfx_ctx_wayland_data_t; } gfx_ctx_wayland_data_t;
static unsigned g_major;
static unsigned g_minor;
#ifndef EGL_OPENGL_ES3_BIT_KHR #ifndef EGL_OPENGL_ES3_BIT_KHR
#define EGL_OPENGL_ES3_BIT_KHR 0x0040 #define EGL_OPENGL_ES3_BIT_KHR 0x0040
#endif #endif
@ -65,18 +61,16 @@ static void shell_surface_handle_configure(void *data,
struct wl_shell_surface *shell_surface, struct wl_shell_surface *shell_surface,
uint32_t edges, int32_t width, int32_t height) uint32_t edges, int32_t width, int32_t height)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_data_get_ptr();
(void)data;
(void)shell_surface; (void)shell_surface;
(void)edges; (void)edges;
wl->g_width = width; wl->width = width;
wl->g_height = height; wl->height = height;
RARCH_LOG("[Wayland/EGL]: Surface configure: %u x %u.\n", RARCH_LOG("[Wayland/EGL]: Surface configure: %u x %u.\n",
wl->g_width, wl->g_height); wl->width, wl->height);
} }
static void shell_surface_handle_popup_done(void *data, static void shell_surface_handle_popup_done(void *data,
@ -96,16 +90,14 @@ static const struct wl_shell_surface_listener shell_surface_listener = {
static void registry_handle_global(void *data, struct wl_registry *reg, static void registry_handle_global(void *data, struct wl_registry *reg,
uint32_t id, const char *interface, uint32_t version) uint32_t id, const char *interface, uint32_t version)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_data_get_ptr();
(void)data;
(void)version; (void)version;
if (!strcmp(interface, "wl_compositor")) if (!strcmp(interface, "wl_compositor"))
wl->g_compositor = (struct wl_compositor*)wl_registry_bind(reg, id, &wl_compositor_interface, 1); wl->compositor = (struct wl_compositor*)wl_registry_bind(reg, id, &wl_compositor_interface, 1);
else if (!strcmp(interface, "wl_shell")) else if (!strcmp(interface, "wl_shell"))
wl->g_shell = (struct wl_shell*)wl_registry_bind(reg, id, &wl_shell_interface, 1); wl->shell = (struct wl_shell*)wl_registry_bind(reg, id, &wl_shell_interface, 1);
} }
static void registry_handle_global_remove(void *data, static void registry_handle_global_remove(void *data,
@ -131,37 +123,37 @@ static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl)
if (!wl) if (!wl)
return; return;
egl_destroy(NULL); egl_destroy(wl);
if (wl->g_win) if (wl->win)
wl_egl_window_destroy(wl->g_win); wl_egl_window_destroy(wl->win);
if (wl->g_shell) if (wl->shell)
wl_shell_destroy(wl->g_shell); wl_shell_destroy(wl->shell);
if (wl->g_compositor) if (wl->compositor)
wl_compositor_destroy(wl->g_compositor); wl_compositor_destroy(wl->compositor);
if (wl->g_registry) if (wl->registry)
wl_registry_destroy(wl->g_registry); wl_registry_destroy(wl->registry);
if (wl->g_shell_surf) if (wl->shell_surf)
wl_shell_surface_destroy(wl->g_shell_surf); wl_shell_surface_destroy(wl->shell_surf);
if (wl->g_surface) if (wl->surface)
wl_surface_destroy(wl->g_surface); wl_surface_destroy(wl->surface);
if (wl->g_dpy) if (wl->dpy)
{ {
wl_display_flush(wl->g_dpy); wl_display_flush(wl->dpy);
wl_display_disconnect(wl->g_dpy); wl_display_disconnect(wl->dpy);
} }
wl->g_win = NULL; wl->win = NULL;
wl->g_shell = NULL; wl->shell = NULL;
wl->g_compositor = NULL; wl->compositor = NULL;
wl->g_registry = NULL; wl->registry = NULL;
wl->g_dpy = NULL; wl->dpy = NULL;
wl->g_shell_surf = NULL; wl->shell_surf = NULL;
wl->g_surface = NULL; wl->surface = NULL;
wl->g_width = 0; wl->width = 0;
wl->g_height = 0; wl->height = 0;
} }
static void flush_wayland_fd(void) static void flush_wayland_fd(void)
@ -170,24 +162,24 @@ static void flush_wayland_fd(void)
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)
gfx_ctx_data_get_ptr(); gfx_ctx_data_get_ptr();
wl_display_dispatch_pending(wl->g_dpy); wl_display_dispatch_pending(wl->dpy);
wl_display_flush(wl->g_dpy); wl_display_flush(wl->dpy);
fd.fd = wl->g_fd; fd.fd = wl->fd;
fd.events = POLLIN | POLLOUT | POLLERR | POLLHUP; fd.events = POLLIN | POLLOUT | POLLERR | POLLHUP;
if (poll(&fd, 1, 0) > 0) if (poll(&fd, 1, 0) > 0)
{ {
if (fd.revents & (POLLERR | POLLHUP)) if (fd.revents & (POLLERR | POLLHUP))
{ {
close(wl->g_fd); close(wl->fd);
g_egl_quit = true; g_egl_quit = true;
} }
if (fd.revents & POLLIN) if (fd.revents & POLLIN)
wl_display_dispatch(wl->g_dpy); wl_display_dispatch(wl->dpy);
if (fd.revents & POLLOUT) if (fd.revents & POLLOUT)
wl_display_flush(wl->g_dpy); wl_display_flush(wl->dpy);
} }
} }
@ -218,12 +210,9 @@ static void gfx_ctx_wl_check_window(void *data, bool *quit,
static void gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height) static void gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_data_get_ptr();
(void)data; wl_egl_window_resize(wl->win, width, height, 0, 0);
wl_egl_window_resize(wl->g_win, width, height, 0, 0);
} }
static void gfx_ctx_wl_update_window_title(void *data) static void gfx_ctx_wl_update_window_title(void *data)
@ -231,14 +220,11 @@ static void gfx_ctx_wl_update_window_title(void *data)
char buf[128] = {0}; char buf[128] = {0};
char buf_fps[128] = {0}; char buf_fps[128] = {0};
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_data_get_ptr();
(void)data;
if (video_monitor_get_fps(buf, sizeof(buf), if (video_monitor_get_fps(buf, sizeof(buf),
buf_fps, sizeof(buf_fps))) buf_fps, sizeof(buf_fps)))
wl_shell_surface_set_title(wl->g_shell_surf, buf); wl_shell_surface_set_title(wl->shell_surf, buf);
if (settings->fps_show) if (settings->fps_show)
runloop_msg_queue_push(buf_fps, 1, 1, false); runloop_msg_queue_push(buf_fps, 1, 1, false);
@ -247,13 +233,10 @@ static void gfx_ctx_wl_update_window_title(void *data)
static void gfx_ctx_wl_get_video_size(void *data, static void gfx_ctx_wl_get_video_size(void *data,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_data_get_ptr();
(void)data; *width = wl->width;
*height = wl->height;
*width = wl->g_width;
*height = wl->g_height;
} }
#define DEFAULT_WINDOWED_WIDTH 640 #define DEFAULT_WINDOWED_WIDTH 640
@ -267,7 +250,7 @@ static void gfx_ctx_wl_get_video_size(void *data,
EGL_ALPHA_SIZE, 0, \ EGL_ALPHA_SIZE, 0, \
EGL_DEPTH_SIZE, 0 EGL_DEPTH_SIZE, 0
static bool gfx_ctx_wl_init(void *data) static void *gfx_ctx_wl_init(void *video_driver)
{ {
static const EGLint egl_attribs_gl[] = { static const EGLint egl_attribs_gl[] = {
WL_EGL_ATTRIBS_BASE, WL_EGL_ATTRIBS_BASE,
@ -301,19 +284,19 @@ static bool gfx_ctx_wl_init(void *data)
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)
calloc(1, sizeof(gfx_ctx_wayland_data_t)); calloc(1, sizeof(gfx_ctx_wayland_data_t));
(void)data; (void)video_driver;
if (!wl) if (!wl)
return false; return NULL;
switch (g_egl_api) switch (wl->egl.api)
{ {
case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_API:
attrib_ptr = egl_attribs_gl; attrib_ptr = egl_attribs_gl;
break; break;
case GFX_CTX_OPENGL_ES_API: case GFX_CTX_OPENGL_ES_API:
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
if (g_major >= 3) if (g_egl_major >= 3)
attrib_ptr = egl_attribs_gles3; attrib_ptr = egl_attribs_gles3;
else else
#endif #endif
@ -328,44 +311,43 @@ static bool gfx_ctx_wl_init(void *data)
g_egl_quit = 0; g_egl_quit = 0;
wl->g_dpy = wl_display_connect(NULL); wl->dpy = wl_display_connect(NULL);
if (!wl->g_dpy) if (!wl->dpy)
{ {
RARCH_ERR("Failed to connect to Wayland server.\n"); RARCH_ERR("Failed to connect to Wayland server.\n");
goto error; goto error;
} }
gfx_ctx_data_set(wl); wl->registry = wl_display_get_registry(wl->dpy);
wl_registry_add_listener(wl->registry, &registry_listener, wl);
wl_display_dispatch(wl->dpy);
wl_display_roundtrip(wl->dpy);
wl->g_registry = wl_display_get_registry(wl->g_dpy); if (!wl->compositor)
wl_registry_add_listener(wl->g_registry, &registry_listener, NULL);
wl_display_dispatch(wl->g_dpy);
if (!wl->g_compositor)
{ {
RARCH_ERR("Failed to create compositor.\n"); RARCH_ERR("Failed to create compositor.\n");
goto error; goto error;
} }
if (!wl->g_shell) if (!wl->shell)
{ {
RARCH_ERR("Failed to create shell.\n"); RARCH_ERR("Failed to create shell.\n");
goto error; goto error;
} }
wl->g_fd = wl_display_get_fd(wl->g_dpy); wl->fd = wl_display_get_fd(wl->dpy);
if (!egl_init_context((EGLNativeDisplayType)wl->g_dpy, if (!egl_init_context(wl, (EGLNativeDisplayType)wl->dpy,
&major, &minor, &n, attrib_ptr)) &major, &minor, &n, attrib_ptr))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if (n == 0 || !egl_has_config()) if (n == 0 || !egl_has_config(wl))
goto error; goto error;
return true; return wl;
error: error:
gfx_ctx_wl_destroy_resources(wl); gfx_ctx_wl_destroy_resources(wl);
@ -373,19 +355,17 @@ error:
if (wl) if (wl)
free(wl); free(wl);
gfx_ctx_free_data(); return NULL;
return false;
} }
static EGLint *egl_fill_attribs(EGLint *attr) static EGLint *egl_fill_attribs(gfx_ctx_wayland_data_t *wl, EGLint *attr)
{ {
switch (g_egl_api) switch (wl->egl.api)
{ {
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_API:
{ {
unsigned version = g_major * 1000 + g_minor; unsigned version = wl->egl.major * 1000 + wl->egl.minor;
bool core = version >= 3001; bool core = version >= 3001;
#ifdef GL_DEBUG #ifdef GL_DEBUG
bool debug = true; bool debug = true;
@ -398,9 +378,9 @@ static EGLint *egl_fill_attribs(EGLint *attr)
if (core) if (core)
{ {
*attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR;
*attr++ = g_major; *attr++ = wl->egl.major;
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = g_minor; *attr++ = wl->egl.minor;
/* Technically, we don't have core/compat until 3.2. /* Technically, we don't have core/compat until 3.2.
* Version 3.1 is either compat or not depending on GL_ARB_compatibility. */ * Version 3.1 is either compat or not depending on GL_ARB_compatibility. */
if (version >= 3002) if (version >= 3002)
@ -422,12 +402,12 @@ static EGLint *egl_fill_attribs(EGLint *attr)
case GFX_CTX_OPENGL_ES_API: case GFX_CTX_OPENGL_ES_API:
*attr++ = EGL_CONTEXT_CLIENT_VERSION; /* Same as EGL_CONTEXT_MAJOR_VERSION */ *attr++ = EGL_CONTEXT_CLIENT_VERSION; /* Same as EGL_CONTEXT_MAJOR_VERSION */
*attr++ = g_major ? (EGLint)g_major : 2; *attr++ = wl->egl.major ? (EGLint)wl->egl.major : 2;
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
if (g_minor > 0) if (wl->egl.minor > 0)
{ {
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = g_minor; *attr++ = wl->egl.minor;
} }
#endif #endif
break; break;
@ -442,17 +422,14 @@ static EGLint *egl_fill_attribs(EGLint *attr)
static void gfx_ctx_wl_destroy(void *data) static void gfx_ctx_wl_destroy(void *data)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_data_get_ptr();
(void)data;
if (!wl) if (!wl)
return; return;
gfx_ctx_wl_destroy_resources(wl); gfx_ctx_wl_destroy_resources(wl);
gfx_ctx_free_data(); free(wl);
} }
static bool gfx_ctx_wl_set_video_mode(void *data, static bool gfx_ctx_wl_set_video_mode(void *data,
@ -461,38 +438,37 @@ static bool gfx_ctx_wl_set_video_mode(void *data,
{ {
EGLint egl_attribs[16]; EGLint egl_attribs[16];
EGLint *attr = NULL; EGLint *attr = NULL;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_data_get_ptr();
egl_install_sighandlers(); egl_install_sighandlers();
attr = egl_fill_attribs(egl_attribs); attr = egl_fill_attribs(wl, egl_attribs);
wl->g_width = width ? width : DEFAULT_WINDOWED_WIDTH; wl->width = width ? width : DEFAULT_WINDOWED_WIDTH;
wl->g_height = height ? height : DEFAULT_WINDOWED_HEIGHT; wl->height = height ? height : DEFAULT_WINDOWED_HEIGHT;
wl->g_surface = wl_compositor_create_surface(wl->g_compositor); wl->surface = wl_compositor_create_surface(wl->compositor);
wl->g_win = wl_egl_window_create(wl->g_surface, wl->g_width, wl->g_height); wl->win = wl_egl_window_create(wl->surface, wl->width, wl->height);
wl->g_shell_surf = wl_shell_get_shell_surface(wl->g_shell, wl->g_surface); wl->shell_surf = wl_shell_get_shell_surface(wl->shell, wl->surface);
wl_shell_surface_add_listener(wl->g_shell_surf, &shell_surface_listener, NULL); wl_shell_surface_add_listener(wl->shell_surf, &shell_surface_listener, NULL);
wl_shell_surface_set_toplevel(wl->g_shell_surf); wl_shell_surface_set_toplevel(wl->shell_surf);
wl_shell_surface_set_class(wl->g_shell_surf, "RetroArch"); wl_shell_surface_set_class(wl->shell_surf, "RetroArch");
wl_shell_surface_set_title(wl->g_shell_surf, "RetroArch"); wl_shell_surface_set_title(wl->shell_surf, "RetroArch");
if (!egl_create_context((attr != egl_attribs) ? egl_attribs : NULL)) if (!egl_create_context(wl, (attr != egl_attribs) ? egl_attribs : NULL))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if (!egl_create_surface((EGLNativeWindowType)wl->g_win)) if (!egl_create_surface(wl, (EGLNativeWindowType)wl->win))
goto error; goto error;
egl_set_swap_interval(data, g_interval); egl_set_swap_interval(wl, wl->egl.interval);
if (fullscreen) if (fullscreen)
wl_shell_surface_set_fullscreen(wl->g_shell_surf, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, NULL); wl_shell_surface_set_fullscreen(wl->shell_surf, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, NULL);
flush_wayland_fd(); flush_wayland_fd();
return true; return true;
@ -534,14 +510,12 @@ static bool gfx_ctx_wl_has_windowed(void *data)
return true; return true;
} }
static bool gfx_ctx_wl_bind_api(void *data, static bool gfx_ctx_wl_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor) enum gfx_ctx_api api, unsigned major, unsigned minor)
{ {
(void)data; g_egl_major = major;
g_egl_minor = minor;
g_major = major; g_egl_api = api;
g_minor = minor;
g_egl_api = api;
switch (api) switch (api)
{ {
@ -679,28 +653,27 @@ static const struct wl_pointer_listener pointer_listener = {
static void seat_handle_capabilities(void *data, static void seat_handle_capabilities(void *data,
struct wl_seat *seat, unsigned caps) struct wl_seat *seat, unsigned caps)
{ {
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
gfx_ctx_data_get_ptr();
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wl->g_wl_keyboard) if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wl->wl_keyboard)
{ {
wl->g_wl_keyboard = wl_seat_get_keyboard(seat); wl->wl_keyboard = wl_seat_get_keyboard(seat);
wl_keyboard_add_listener(wl->g_wl_keyboard, &keyboard_listener, NULL); wl_keyboard_add_listener(wl->wl_keyboard, &keyboard_listener, NULL);
} }
else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && wl->g_wl_keyboard) else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && wl->wl_keyboard)
{ {
wl_keyboard_destroy(wl->g_wl_keyboard); wl_keyboard_destroy(wl->wl_keyboard);
wl->g_wl_keyboard = NULL; wl->wl_keyboard = NULL;
} }
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wl->g_wl_pointer) if ((caps & WL_SEAT_CAPABILITY_POINTER) && !wl->wl_pointer)
{ {
wl->g_wl_pointer = wl_seat_get_pointer(seat); wl->wl_pointer = wl_seat_get_pointer(seat);
wl_pointer_add_listener(wl->g_wl_pointer, &pointer_listener, NULL); wl_pointer_add_listener(wl->wl_pointer, &pointer_listener, NULL);
} }
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wl->g_wl_pointer) else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && wl->wl_pointer)
{ {
wl_pointer_destroy(wl->g_wl_pointer); wl_pointer_destroy(wl->wl_pointer);
wl->g_wl_pointer = NULL; wl->wl_pointer = NULL;
} }
} }

View File

@ -295,23 +295,23 @@ static void gfx_ctx_wgl_get_video_size(void *data, unsigned *width, unsigned *he
} }
} }
static bool gfx_ctx_wgl_init(void *data) static void *gfx_ctx_wgl_init(void *video_driver)
{ {
WNDCLASSEX wndclass = {0}; WNDCLASSEX wndclass = {0};
(void)data; (void)video_driver;
if (g_inited) if (g_inited)
return false; return NULL;
win32_window_reset(); win32_window_reset();
win32_monitor_init(); win32_monitor_init();
wndclass.lpfnWndProc = WndProcGL; wndclass.lpfnWndProc = WndProcGL;
if (!win32_window_init(&wndclass, true, NULL)) if (!win32_window_init(&wndclass, true, NULL))
return false; return NULL;
return true; return (void*)"wgl";
} }
static void gfx_ctx_wgl_destroy(void *data) static void gfx_ctx_wgl_destroy(void *data)

View File

@ -27,11 +27,11 @@
#define EGL_OPENGL_ES3_BIT_KHR 0x0040 #define EGL_OPENGL_ES3_BIT_KHR 0x0040
#endif #endif
static XF86VidModeModeInfo g_desktop_mode; typedef struct {
static bool g_should_reset_mode; egl_ctx_data_t egl;
XF86VidModeModeInfo desktop_mode;
static unsigned g_major; bool should_reset_mode;
static unsigned g_minor; } xegl_ctx_data_t;
static int egl_nul_handler(Display *dpy, XErrorEvent *event) static int egl_nul_handler(Display *dpy, XErrorEvent *event)
{ {
@ -42,6 +42,8 @@ static int egl_nul_handler(Display *dpy, XErrorEvent *event)
static void gfx_ctx_xegl_destroy(void *data) static void gfx_ctx_xegl_destroy(void *data)
{ {
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
x11_input_ctx_destroy(); x11_input_ctx_destroy();
egl_destroy(data); egl_destroy(data);
@ -54,12 +56,14 @@ static void gfx_ctx_xegl_destroy(void *data)
x11_colormap_destroy(); x11_colormap_destroy();
if (g_should_reset_mode) if (xegl->should_reset_mode)
{ {
x11_exit_fullscreen(g_x11_dpy, &g_desktop_mode); x11_exit_fullscreen(g_x11_dpy, &xegl->desktop_mode);
g_should_reset_mode = false; xegl->should_reset_mode = false;
} }
free(data);
/* Do not close g_x11_dpy. We'll keep one for the entire application /* Do not close g_x11_dpy. We'll keep one for the entire application
* lifecycle to work-around nVidia EGL limitations. * lifecycle to work-around nVidia EGL limitations.
*/ */
@ -81,7 +85,7 @@ EGL_BLUE_SIZE, 1, \
EGL_ALPHA_SIZE, 0, \ EGL_ALPHA_SIZE, 0, \
EGL_DEPTH_SIZE, 0 EGL_DEPTH_SIZE, 0
static bool gfx_ctx_xegl_init(void *data) static void *gfx_ctx_xegl_init(void *video_driver)
{ {
static const EGLint egl_attribs_gl[] = { static const EGLint egl_attribs_gl[] = {
XEGL_ATTRIBS_BASE, XEGL_ATTRIBS_BASE,
@ -112,20 +116,26 @@ static bool gfx_ctx_xegl_init(void *data)
const EGLint *attrib_ptr; const EGLint *attrib_ptr;
EGLint major, minor; EGLint major, minor;
EGLint n; EGLint n;
xegl_ctx_data_t *xegl;
if (g_egl_inited) if (g_egl_inited)
return false; return NULL;
XInitThreads(); XInitThreads();
switch (g_egl_api) xegl = (xegl_ctx_data_t*)calloc(1, sizeof(xegl_ctx_data_t));
if (!xegl)
return NULL;
switch (xegl->egl.api)
{ {
case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_API:
attrib_ptr = egl_attribs_gl; attrib_ptr = egl_attribs_gl;
break; break;
case GFX_CTX_OPENGL_ES_API: case GFX_CTX_OPENGL_ES_API:
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
if (g_major >= 3) if (xegl->egl.major >= 3)
attrib_ptr = egl_attribs_gles3; attrib_ptr = egl_attribs_gles3;
else else
#endif #endif
@ -141,33 +151,33 @@ static bool gfx_ctx_xegl_init(void *data)
if (!x11_connect()) if (!x11_connect())
goto error; goto error;
if (!egl_init_context((EGLNativeDisplayType)g_x11_dpy, if (!egl_init_context(xegl, (EGLNativeDisplayType)g_x11_dpy,
&major, &minor, &n, attrib_ptr)) &major, &minor, &n, attrib_ptr))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if (n == 0 || !egl_has_config()) if (n == 0 || !egl_has_config(xegl))
goto error; goto error;
return true; return xegl;
error: error:
gfx_ctx_xegl_destroy(data); gfx_ctx_xegl_destroy(xegl);
return false; return NULL;
} }
static EGLint *xegl_fill_attribs(EGLint *attr) static EGLint *xegl_fill_attribs(xegl_ctx_data_t *xegl, EGLint *attr)
{ {
switch (g_egl_api) switch (xegl->egl.api)
{ {
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
case GFX_CTX_OPENGL_API: case GFX_CTX_OPENGL_API:
{ {
const struct retro_hw_render_callback *hw_render = const struct retro_hw_render_callback *hw_render =
(const struct retro_hw_render_callback*)video_driver_callback(); (const struct retro_hw_render_callback*)video_driver_callback();
unsigned version = g_major * 1000 + g_minor; unsigned version = xegl->egl.major * 1000 + xegl->egl.minor;
bool core = version >= 3001; bool core = version >= 3001;
#ifdef GL_DEBUG #ifdef GL_DEBUG
bool debug = true; bool debug = true;
@ -178,9 +188,9 @@ static EGLint *xegl_fill_attribs(EGLint *attr)
if (core) if (core)
{ {
*attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MAJOR_VERSION_KHR;
*attr++ = g_major; *attr++ = xegl->egl.major;
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = g_minor; *attr++ = xegl->egl.minor;
/* Technically, we don't have core/compat until 3.2. /* Technically, we don't have core/compat until 3.2.
* Version 3.1 is either compat or not depending * Version 3.1 is either compat or not depending
@ -206,12 +216,12 @@ static EGLint *xegl_fill_attribs(EGLint *attr)
case GFX_CTX_OPENGL_ES_API: case GFX_CTX_OPENGL_ES_API:
/* Same as EGL_CONTEXT_MAJOR_VERSION. */ /* Same as EGL_CONTEXT_MAJOR_VERSION. */
*attr++ = EGL_CONTEXT_CLIENT_VERSION; *attr++ = EGL_CONTEXT_CLIENT_VERSION;
*attr++ = g_major ? (EGLint)g_major : 2; *attr++ = xegl->egl.major ? (EGLint)xegl->egl.major : 2;
#ifdef EGL_KHR_create_context #ifdef EGL_KHR_create_context
if (g_minor > 0) if (xegl->egl.minor > 0)
{ {
*attr++ = EGL_CONTEXT_MINOR_VERSION_KHR; *attr++ = EGL_CONTEXT_MINOR_VERSION_KHR;
*attr++ = g_minor; *attr++ = xegl->egl.minor;
} }
#endif #endif
break; break;
@ -240,6 +250,7 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
XSetWindowAttributes swa = {0}; XSetWindowAttributes swa = {0};
XVisualInfo *vi = NULL; XVisualInfo *vi = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
xegl_ctx_data_t *xegl = (xegl_ctx_data_t*)data;
int (*old_handler)(Display*, XErrorEvent*) = NULL; int (*old_handler)(Display*, XErrorEvent*) = NULL;
@ -248,9 +259,9 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
windowed_full = settings->video.windowed_fullscreen; windowed_full = settings->video.windowed_fullscreen;
attr = egl_attribs; attr = egl_attribs;
attr = xegl_fill_attribs(attr); attr = xegl_fill_attribs(xegl, attr);
if (!egl_get_native_visual_id(&vid)) if (!egl_get_native_visual_id(xegl, &vid))
goto error; goto error;
temp.visualid = vid; temp.visualid = vid;
@ -266,9 +277,9 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
if (fullscreen && !windowed_full) if (fullscreen && !windowed_full)
{ {
if (x11_enter_fullscreen(g_x11_dpy, width, height, &g_desktop_mode)) if (x11_enter_fullscreen(g_x11_dpy, width, height, &xegl->desktop_mode))
{ {
g_should_reset_mode = true; xegl->should_reset_mode = true;
true_full = true; true_full = true;
} }
else else
@ -306,13 +317,13 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
CWBorderPixel | CWColormap | CWEventMask | (true_full ? CWOverrideRedirect : 0), &swa); CWBorderPixel | CWColormap | CWEventMask | (true_full ? CWOverrideRedirect : 0), &swa);
XSetWindowBackground(g_x11_dpy, g_x11_win, 0); XSetWindowBackground(g_x11_dpy, g_x11_win, 0);
if (!egl_create_context((attr != egl_attribs) ? egl_attribs : NULL)) if (!egl_create_context(xegl, (attr != egl_attribs) ? egl_attribs : NULL))
{ {
egl_report_error(); egl_report_error();
goto error; goto error;
} }
if (!egl_create_surface((EGLNativeWindowType)g_x11_win)) if (!egl_create_surface(xegl, (EGLNativeWindowType)g_x11_win))
goto error; goto error;
x11_set_window_attr(g_x11_dpy, g_x11_win); x11_set_window_attr(g_x11_dpy, g_x11_win);
@ -356,7 +367,7 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
x11_event_queue_check(&event); x11_event_queue_check(&event);
x11_install_quit_atom(); x11_install_quit_atom();
egl_set_swap_interval(data, g_interval); egl_set_swap_interval(xegl, xegl->egl.interval);
/* This can blow up on some drivers. It's not fatal, /* This can blow up on some drivers. It's not fatal,
* so override errors for this call. * so override errors for this call.
@ -367,7 +378,7 @@ static bool gfx_ctx_xegl_set_video_mode(void *data,
XSetErrorHandler(old_handler); XSetErrorHandler(old_handler);
XFree(vi); XFree(vi);
g_egl_inited = true; g_egl_inited = true;
if (!x11_input_ctx_new(true_full)) if (!x11_input_ctx_new(true_full))
goto error; goto error;
@ -423,13 +434,11 @@ static bool gfx_ctx_xegl_has_windowed(void *data)
return true; return true;
} }
static bool gfx_ctx_xegl_bind_api(void *data, static bool gfx_ctx_xegl_bind_api(void *video_driver,
enum gfx_ctx_api api, unsigned major, unsigned minor) enum gfx_ctx_api api, unsigned major, unsigned minor)
{ {
(void)data; g_egl_major = major;
g_egl_minor = minor;
g_major = major;
g_minor = minor;
g_egl_api = api; g_egl_api = api;
switch (api) switch (api)

View File

@ -98,25 +98,12 @@ void gfx_ctx_destroy(const gfx_ctx_driver_t *ctx_driver)
current_video_context = NULL; current_video_context = NULL;
} }
void gfx_ctx_data_set(void *ptr) void gfx_ctx_free(void)
{
if (!ptr)
return;
video_context_data = ptr;
}
void gfx_ctx_free_data(void)
{
if (video_context_data)
free(video_context_data);
video_context_data = NULL;
}
void gfx_ctx_free(void *data)
{ {
if (current_video_context->destroy) if (current_video_context->destroy)
current_video_context->destroy(data); current_video_context->destroy(video_context_data);
current_video_context = NULL; current_video_context = NULL;
video_context_data = NULL;
} }
const char *gfx_ctx_get_ident(void) const char *gfx_ctx_get_ident(void)
@ -128,78 +115,78 @@ const char *gfx_ctx_get_ident(void)
return ctx->ident; return ctx->ident;
} }
void gfx_ctx_update_window_title(void *data) void gfx_ctx_update_window_title(void)
{ {
if (current_video_context->update_window_title) if (current_video_context->update_window_title)
current_video_context->update_window_title(data); current_video_context->update_window_title(video_context_data);
} }
void gfx_ctx_get_video_output_size(void *data, void gfx_ctx_get_video_output_size(
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
const gfx_ctx_driver_t *ctx = current_video_context; const gfx_ctx_driver_t *ctx = current_video_context;
if (ctx->get_video_output_size) if (ctx->get_video_output_size)
ctx->get_video_output_size(data, width, height); ctx->get_video_output_size(video_context_data, width, height);
} }
bool gfx_ctx_get_video_output_prev(void *data) bool gfx_ctx_get_video_output_prev(void)
{ {
if (current_video_context->get_video_output_prev) if (current_video_context->get_video_output_prev)
{ {
current_video_context->get_video_output_prev(data); current_video_context->get_video_output_prev(video_context_data);
return true; return true;
} }
return false; return false;
} }
bool gfx_ctx_get_video_output_next(void *data) bool gfx_ctx_get_video_output_next(void)
{ {
if (current_video_context->get_video_output_next) if (current_video_context->get_video_output_next)
{ {
current_video_context->get_video_output_next(data); current_video_context->get_video_output_next(video_context_data);
return true; return true;
} }
return false; return false;
} }
void gfx_ctx_swap_buffers(void *data) void gfx_ctx_swap_buffers(void)
{ {
if (!current_video_context) if (!current_video_context)
return; return;
if (current_video_context->swap_buffers) if (current_video_context->swap_buffers)
current_video_context->swap_buffers(data); current_video_context->swap_buffers(video_context_data);
} }
void gfx_ctx_bind_hw_render(void *data, bool enable) void gfx_ctx_bind_hw_render(bool enable)
{ {
if (current_video_context->bind_hw_render) if (current_video_context->bind_hw_render)
current_video_context->bind_hw_render(data, enable); current_video_context->bind_hw_render(video_context_data, enable);
} }
bool gfx_ctx_focus(void *data) bool gfx_ctx_focus(void)
{ {
if (data && current_video_context->has_focus) if (video_context_data && current_video_context->has_focus)
return current_video_context->has_focus(data); return current_video_context->has_focus(video_context_data);
return false; return false;
} }
bool gfx_ctx_set_video_mode(void *data, bool gfx_ctx_set_video_mode(
unsigned width, unsigned height, unsigned width, unsigned height,
bool fullscreen) bool fullscreen)
{ {
if (current_video_context->set_video_mode) if (current_video_context->set_video_mode)
return current_video_context->set_video_mode(data, width, height, fullscreen); return current_video_context->set_video_mode(video_context_data, width, height, fullscreen);
return false; return false;
} }
void gfx_ctx_translate_aspect(void *data, float *aspect, void gfx_ctx_translate_aspect(float *aspect,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
if (current_video_context->translate_aspect) if (current_video_context->translate_aspect)
*aspect = current_video_context->translate_aspect(data, width, height); *aspect = current_video_context->translate_aspect(video_context_data, width, height);
} }
bool gfx_ctx_get_metrics(enum display_metric_types type, float *value) bool gfx_ctx_get_metrics(enum display_metric_types type, float *value)
@ -234,64 +221,64 @@ retro_proc_address_t gfx_ctx_get_proc_address(const char *sym)
return current_video_context->get_proc_address(sym); return current_video_context->get_proc_address(sym);
} }
void gfx_ctx_show_mouse(void *data, bool state) void gfx_ctx_show_mouse(bool state)
{ {
if (data && current_video_context->show_mouse) if (video_context_data && current_video_context->show_mouse)
current_video_context->show_mouse(data, state); current_video_context->show_mouse(video_context_data, state);
} }
bool gfx_ctx_has_windowed(void *data) bool gfx_ctx_has_windowed(void)
{ {
if (data) if (video_context_data)
return current_video_context->has_windowed(data); return current_video_context->has_windowed(video_context_data);
return true; return true;
} }
bool gfx_ctx_check_window(void *data, bool *quit, bool *resize, bool gfx_ctx_check_window(bool *quit, bool *resize,
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
uint64_t *frame_count; uint64_t *frame_count;
video_driver_ctl(RARCH_DISPLAY_CTL_GET_FRAME_COUNT, &frame_count); video_driver_ctl(RARCH_DISPLAY_CTL_GET_FRAME_COUNT, &frame_count);
if (!data) if (!video_context_data)
return false; return false;
current_video_context->check_window(data, quit, resize, width, height, (unsigned int)*frame_count); current_video_context->check_window(video_context_data, quit, resize, width, height, (unsigned int)*frame_count);
return true; return true;
} }
bool gfx_ctx_suppress_screensaver(void *data, bool enable) bool gfx_ctx_suppress_screensaver(bool enable)
{ {
if (data && current_video_context) if (video_context_data && current_video_context)
return current_video_context->suppress_screensaver(data, enable); return current_video_context->suppress_screensaver(video_context_data, enable);
return false; return false;
} }
void gfx_ctx_get_video_size(void *data, void gfx_ctx_get_video_size(
unsigned *width, unsigned *height) unsigned *width, unsigned *height)
{ {
current_video_context->get_video_size(data, width, height); current_video_context->get_video_size(video_context_data, width, height);
} }
void gfx_ctx_swap_interval(void *data, unsigned interval) void gfx_ctx_swap_interval(unsigned interval)
{ {
if (current_video_context) if (current_video_context)
current_video_context->swap_interval(data, interval); current_video_context->swap_interval(video_context_data, interval);
} }
void gfx_ctx_set_resize(void *data, unsigned width, unsigned height) void gfx_ctx_set_resize(unsigned width, unsigned height)
{ {
if (current_video_context) if (current_video_context)
current_video_context->set_resize(data, width, height); current_video_context->set_resize(video_context_data, width, height);
} }
void gfx_ctx_input_driver(void *data, void gfx_ctx_input_driver(
const input_driver_t **input, void **input_data) const input_driver_t **input, void **input_data)
{ {
if (current_video_context) if (current_video_context)
current_video_context->input_driver(data, input, input_data); current_video_context->input_driver(video_context_data, input, input_data);
} }
/** /**
@ -375,15 +362,16 @@ static const gfx_ctx_driver_t *gfx_ctx_init(void *data,
if (ctx->bind_api(data, api, major, minor)) if (ctx->bind_api(data, api, major, minor))
{ {
bool initialized = ctx->init(data); void *ctx_data = ctx->init(data);
if (!initialized) if (!ctx_data)
return NULL; return NULL;
if (ctx->bind_hw_render) if (ctx->bind_hw_render)
ctx->bind_hw_render(data, ctx->bind_hw_render(ctx_data,
settings->video.shared_context && hw_render_ctx); settings->video.shared_context && hw_render_ctx);
video_context_data = ctx_data;
return ctx; return ctx;
} }

View File

@ -53,21 +53,18 @@ enum display_metric_types
typedef void (*gfx_ctx_proc_t)(void); typedef void (*gfx_ctx_proc_t)(void);
/* The opaque void* argument should be the overlying driver data
* (e.g. gl_t for OpenGL contexts).
*
* This will allow us in the future to have separate contexts
* to separate gl_t structs (if needed).
*
* For now, this is only relevant for D3D. */
typedef struct gfx_ctx_driver typedef struct gfx_ctx_driver
{ {
bool (*init)(void *data); /* The opaque pointer is the underlying video driver data (e.g. gl_t for
* OpenGL contexts). Although not advised, the context driver is allowed
* to hold a pointer to it as the context never outlives the video driver.
*
* The context driver is responsible for it's own data.*/
void* (*init)(void *video_driver);
void (*destroy)(void *data); void (*destroy)(void *data);
/* Which API to bind to. */ /* Which API to bind to. */
bool (*bind_api)(void *data, enum gfx_ctx_api, bool (*bind_api)(void *video_driver, enum gfx_ctx_api,
unsigned major, unsigned minor); unsigned major, unsigned minor);
/* Sets the swap interval. */ /* Sets the swap interval. */
@ -203,16 +200,15 @@ void find_prev_gfx_context_driver(void);
bool gfx_ctx_get_metrics(enum display_metric_types type, float *value); bool gfx_ctx_get_metrics(enum display_metric_types type, float *value);
void gfx_ctx_translate_aspect(void *data, float *aspect, void gfx_ctx_translate_aspect(float *aspect,
unsigned width, unsigned height); unsigned width, unsigned height);
bool gfx_ctx_set_video_mode(void *data, bool gfx_ctx_set_video_mode(unsigned width, unsigned height,
unsigned width, unsigned height,
bool fullscreen); bool fullscreen);
void gfx_ctx_swap_buffers(void *data); void gfx_ctx_swap_buffers(void);
bool gfx_ctx_focus(void *data); bool gfx_ctx_focus(void);
bool gfx_ctx_image_buffer_init(void *data, const video_info_t *info); bool gfx_ctx_image_buffer_init(void *data, const video_info_t *info);
@ -220,47 +216,42 @@ bool gfx_ctx_image_buffer_write(void *data, const void *frame,
unsigned width, unsigned height, unsigned pitch, bool rgb32, unsigned width, unsigned height, unsigned pitch, bool rgb32,
unsigned index, void **image_handle); unsigned index, void **image_handle);
void gfx_ctx_show_mouse(void *data, bool state); void gfx_ctx_show_mouse(bool state);
bool gfx_ctx_has_windowed(void *data); bool gfx_ctx_has_windowed(void);
bool gfx_ctx_check_window(void *data, bool *quit, bool *resize, bool gfx_ctx_check_window(bool *quit, bool *resize,
unsigned *width, unsigned *height); unsigned *width, unsigned *height);
bool gfx_ctx_suppress_screensaver(void *data, bool enable); bool gfx_ctx_suppress_screensaver(bool enable);
void gfx_ctx_update_window_title(void *data); void gfx_ctx_update_window_title(void);
void gfx_ctx_get_video_size(void *data, unsigned *width, unsigned *height); void gfx_ctx_get_video_size(unsigned *width, unsigned *height);
void gfx_ctx_set_resize(void *data, unsigned width, unsigned height); void gfx_ctx_set_resize(unsigned width, unsigned height);
void gfx_ctx_swap_interval(void *data, unsigned interval); void gfx_ctx_swap_interval(unsigned interval);
void gfx_ctx_bind_hw_render(void *data, bool enable); void gfx_ctx_bind_hw_render(bool enable);
void gfx_ctx_get_video_output_size(void *data, void gfx_ctx_get_video_output_size(unsigned *width, unsigned *height);
unsigned *width, unsigned *height);
bool gfx_ctx_get_video_output_prev(void *data); bool gfx_ctx_get_video_output_prev(void);
bool gfx_ctx_get_video_output_next(void *data); bool gfx_ctx_get_video_output_next(void);
const char *gfx_ctx_get_ident(void); const char *gfx_ctx_get_ident(void);
void gfx_ctx_free(void *data); void gfx_ctx_free(void);
void gfx_ctx_input_driver(void *data, void gfx_ctx_input_driver(
const input_driver_t **input, void **input_data); const input_driver_t **input, void **input_data);
retro_proc_address_t gfx_ctx_get_proc_address(const char *sym); retro_proc_address_t gfx_ctx_get_proc_address(const char *sym);
void *gfx_ctx_data_get_ptr(void); void *gfx_ctx_data_get_ptr(void);
void gfx_ctx_data_set(void *ptr);
void gfx_ctx_free_data(void);
void gfx_ctx_set(const gfx_ctx_driver_t *ctx_driver); void gfx_ctx_set(const gfx_ctx_driver_t *ctx_driver);
void gfx_ctx_destroy(const gfx_ctx_driver_t *ctx_driver); void gfx_ctx_destroy(const gfx_ctx_driver_t *ctx_driver);

View File

@ -797,7 +797,7 @@ bool video_driver_set_video_mode(unsigned width,
return true; return true;
} }
return gfx_ctx_set_video_mode(gfx_ctx_data_get_ptr(), width, height, fullscreen); return gfx_ctx_set_video_mode(width, height, fullscreen);
} }
bool video_driver_get_video_output_size(unsigned *width, unsigned *height) bool video_driver_get_video_output_size(unsigned *width, unsigned *height)
@ -1485,7 +1485,7 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data)
video_driver_poke->get_video_output_next(video_driver_data); video_driver_poke->get_video_output_next(video_driver_data);
return true; return true;
} }
return gfx_ctx_get_video_output_next(gfx_ctx_data_get_ptr()); return gfx_ctx_get_video_output_next();
case RARCH_DISPLAY_CTL_GET_PREV_VIDEO_OUT: case RARCH_DISPLAY_CTL_GET_PREV_VIDEO_OUT:
if (!video_driver_poke) if (!video_driver_poke)
return false; return false;
@ -1495,7 +1495,7 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data)
video_driver_poke->get_video_output_prev(video_driver_data); video_driver_poke->get_video_output_prev(video_driver_data);
return true; return true;
} }
return gfx_ctx_get_video_output_next(gfx_ctx_data_get_ptr()); return gfx_ctx_get_video_output_next();
case RARCH_DISPLAY_CTL_INIT: case RARCH_DISPLAY_CTL_INIT:
return init_video(); return init_video();
case RARCH_DISPLAY_CTL_DESTROY_DATA: case RARCH_DISPLAY_CTL_DESTROY_DATA: