(video_context_driver) Make better use of the data argument in context calls

This commit is contained in:
Higor Eurípedes 2015-12-08 12:18:57 -03:00
parent e6360627ab
commit c257374dcd
20 changed files with 191 additions and 263 deletions

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

@ -47,7 +47,7 @@ static void gfx_ctx_qnx_destroy(void *data)
g_resize = false; g_resize = false;
} }
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;
@ -214,14 +214,14 @@ static bool gfx_ctx_qnx_init(void *data)
if (!egl_create_surface(screen_win)) if (!egl_create_surface(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

@ -250,8 +250,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;
@ -307,7 +306,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 +316,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 +367,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 +375,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,7 +385,7 @@ 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(EGLint *attr)
@ -499,8 +496,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;
@ -631,14 +627,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,

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

@ -65,10 +65,8 @@ 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;
@ -96,10 +94,8 @@ 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"))
@ -218,10 +214,7 @@ 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->g_win, width, height, 0, 0); wl_egl_window_resize(wl->g_win, width, height, 0, 0);
} }
@ -231,10 +224,7 @@ 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)))
@ -247,10 +237,7 @@ 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->g_width; *width = wl->g_width;
*height = wl->g_height; *height = wl->g_height;
@ -267,7 +254,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,10 +288,10 @@ 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 (g_egl_api)
{ {
@ -335,8 +322,6 @@ static bool gfx_ctx_wl_init(void *data)
goto error; goto error;
} }
gfx_ctx_data_set(wl);
wl->g_registry = wl_display_get_registry(wl->g_dpy); wl->g_registry = wl_display_get_registry(wl->g_dpy);
wl_registry_add_listener(wl->g_registry, &registry_listener, NULL); wl_registry_add_listener(wl->g_registry, &registry_listener, NULL);
wl_display_dispatch(wl->g_dpy); wl_display_dispatch(wl->g_dpy);
@ -365,7 +350,7 @@ static bool gfx_ctx_wl_init(void *data)
if (n == 0 || !egl_has_config()) if (n == 0 || !egl_has_config())
goto error; goto error;
return true; return wl;
error: error:
gfx_ctx_wl_destroy_resources(wl); gfx_ctx_wl_destroy_resources(wl);
@ -373,9 +358,7 @@ 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(EGLint *attr)
@ -442,17 +425,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,8 +441,7 @@ 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();
@ -679,8 +658,7 @@ 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->g_wl_keyboard)
{ {

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

@ -81,7 +81,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,
@ -114,7 +114,7 @@ static bool gfx_ctx_xegl_init(void *data)
EGLint n; EGLint n;
if (g_egl_inited) if (g_egl_inited)
return false; return NULL;
XInitThreads(); XInitThreads();
@ -151,11 +151,11 @@ static bool gfx_ctx_xegl_init(void *data)
if (n == 0 || !egl_has_config()) if (n == 0 || !egl_has_config())
goto error; goto error;
return true; return (void*)"xegl";
error: error:
gfx_ctx_xegl_destroy(data); gfx_ctx_xegl_destroy(video_driver);
return false; return NULL;
} }
static EGLint *xegl_fill_attribs(EGLint *attr) static EGLint *xegl_fill_attribs(EGLint *attr)

View File

@ -98,24 +98,10 @@ 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;
} }
@ -128,78 +114,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 +220,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 +361,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,17 +53,14 @@ 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. */
@ -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: