From 1f87c6d9e2eb9b9887cecc8d6fa890dacf3b2848 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 23 Nov 2015 20:56:06 +0100 Subject: [PATCH] Dont' try to access driver->video_context_data directly --- gfx/drivers_context/glx_ctx.c | 25 +++++++++------------ gfx/drivers_context/ps3_ctx.c | 12 +++++----- gfx/drivers_context/sdl_gl_ctx.c | 24 +++++++------------- gfx/drivers_context/wayland_ctx.c | 37 ++++++++++--------------------- gfx/video_context_driver.c | 2 +- gfx/video_context_driver.h | 2 +- gfx/video_driver.c | 6 ++--- 7 files changed, 41 insertions(+), 67 deletions(-) diff --git a/gfx/drivers_context/glx_ctx.c b/gfx/drivers_context/glx_ctx.c index e715d3413e..6c09f3a74d 100644 --- a/gfx/drivers_context/glx_ctx.c +++ b/gfx/drivers_context/glx_ctx.c @@ -135,8 +135,8 @@ static void ctx_glx_destroy_resources(gfx_ctx_glx_data_t *glx) static void gfx_ctx_glx_destroy(void *data) { - driver_t *driver = driver_get_ptr(); - gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)driver->video_context_data; + gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) + gfx_ctx_data_get_ptr(); if (!glx) return; @@ -144,16 +144,13 @@ static void gfx_ctx_glx_destroy(void *data) (void)data; ctx_glx_destroy_resources(glx); - - if (driver->video_context_data) - free(driver->video_context_data); - driver->video_context_data = NULL; + gfx_ctx_free_data(); } static void gfx_ctx_glx_swap_interval(void *data, unsigned interval) { - driver_t *driver = driver_get_ptr(); - gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)driver->video_context_data; + gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) + gfx_ctx_data_get_ptr(); glx->g_interval = interval; @@ -178,9 +175,8 @@ static void gfx_ctx_glx_swap_interval(void *data, unsigned interval) static void gfx_ctx_glx_swap_buffers(void *data) { - driver_t *driver = driver_get_ptr(); - gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)driver->video_context_data; - (void)data; + gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) + gfx_ctx_data_get_ptr(); if (glx->g_is_double) glXSwapBuffers(g_x11_dpy, glx->g_glx_win); @@ -289,8 +285,9 @@ static bool gfx_ctx_glx_set_video_mode(void *data, XSetWindowAttributes swa = {0}; int (*old_handler)(Display*, XErrorEvent*) = NULL; driver_t *driver = driver_get_ptr(); - gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)driver->video_context_data; settings_t *settings = config_get_ptr(); + gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) + gfx_ctx_data_get_ptr(); x11_install_sighandlers(); @@ -578,8 +575,8 @@ static void gfx_ctx_glx_show_mouse(void *data, bool state) static void gfx_ctx_glx_bind_hw_render(void *data, bool enable) { - driver_t *driver = driver_get_ptr(); - gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*)driver->video_context_data; + gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) + gfx_ctx_data_get_ptr(); if (!glx) return; diff --git a/gfx/drivers_context/ps3_ctx.c b/gfx/drivers_context/ps3_ctx.c index 040908c3ce..49c41ca397 100644 --- a/gfx/drivers_context/ps3_ctx.c +++ b/gfx/drivers_context/ps3_ctx.c @@ -207,8 +207,8 @@ static void gfx_ctx_ps3_update_window_title(void *data) static void gfx_ctx_ps3_get_video_size(void *data, unsigned *width, unsigned *height) { - driver_t *driver = driver_get_ptr(); - gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*)driver->video_context_data; + gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*) + gfx_ctx_data_get_ptr(); (void)data; @@ -327,8 +327,8 @@ static void gfx_ctx_ps3_destroy_resources(gfx_ctx_ps3_data_t *ps3) static void gfx_ctx_ps3_destroy(void *data) { - driver_t *driver = driver_get_ptr(); - gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*)driver->video_context_data; + gfx_ctx_ps3_data_t *ps3 = (gfx_ctx_ps3_data_t*) + gfx_ctx_data_get_ptr(); (void)data; @@ -337,9 +337,7 @@ static void gfx_ctx_ps3_destroy(void *data) gfx_ctx_ps3_destroy_resources(ps3); - if (driver->video_context_data) - free(driver->video_context_data); - driver->video_context_data = NULL; + gfx_ctx_free_data(); } static void gfx_ctx_ps3_input_driver(void *data, diff --git a/gfx/drivers_context/sdl_gl_ctx.c b/gfx/drivers_context/sdl_gl_ctx.c index c5867abc6c..58eb4a1f2c 100644 --- a/gfx/drivers_context/sdl_gl_ctx.c +++ b/gfx/drivers_context/sdl_gl_ctx.c @@ -111,8 +111,7 @@ error: static void sdl_ctx_destroy(void *data) { - driver_t *driver = driver_get_ptr(); - gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)driver->video_context_data; + gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); if (!sdl) return; @@ -120,10 +119,7 @@ static void sdl_ctx_destroy(void *data) (void)data; sdl_ctx_destroy_resources(sdl); - - if (driver->video_context_data) - free(driver->video_context_data); - driver->video_context_data = NULL; + gfx_ctx_free_data(); } static bool sdl_ctx_bind_api(void *data, enum gfx_ctx_api api, unsigned major, @@ -172,7 +168,7 @@ static bool sdl_ctx_set_video_mode(void *data, unsigned width, unsigned height, unsigned fsflag = 0; driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); - gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)driver->video_context_data; + gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); (void)data; @@ -242,7 +238,7 @@ static void sdl_ctx_get_video_size(void *data, { driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); - gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)driver->video_context_data; + gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); if (!sdl) return; @@ -279,9 +275,8 @@ static void sdl_ctx_update_window_title(void *data) { char buf[128] = {0}; char buf_fps[128] = {0}; - driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); - gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)driver->video_context_data; + gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); if (!sdl) return; @@ -303,8 +298,7 @@ static void sdl_ctx_check_window(void *data, bool *quit, bool *resize,unsigned * unsigned *height, unsigned frame_count) { SDL_Event event; - driver_t *driver = driver_get_ptr(); - gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)driver->video_context_data; + gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); (void)data; @@ -367,8 +361,7 @@ static bool sdl_ctx_has_focus(void *data) unsigned flags; #ifdef HAVE_SDL2 - driver_t *driver = driver_get_ptr(); - gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)driver->video_context_data; + gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); flags = (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS); return (SDL_GetWindowFlags(sdl->g_win) & flags) == flags; #else @@ -395,8 +388,7 @@ static bool sdl_ctx_has_windowed(void *data) static void sdl_ctx_swap_buffers(void *data) { #ifdef HAVE_SDL2 - driver_t *driver = driver_get_ptr(); - gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)driver->video_context_data; + gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)gfx_ctx_data_get_ptr(); SDL_GL_SwapWindow(sdl->g_win); #else SDL_GL_SwapBuffers(); diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index 671dc75860..653bffa65c 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -65,9 +65,8 @@ static void shell_surface_handle_configure(void *data, struct wl_shell_surface *shell_surface, uint32_t edges, int32_t width, int32_t height) { - driver_t *driver = driver_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); (void)data; (void)shell_surface; @@ -97,9 +96,8 @@ static const struct wl_shell_surface_listener shell_surface_listener = { static void registry_handle_global(void *data, struct wl_registry *reg, uint32_t id, const char *interface, uint32_t version) { - driver_t *driver = driver_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); (void)data; (void)version; @@ -169,9 +167,8 @@ static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl) static void flush_wayland_fd(void) { struct pollfd fd = {0}; - driver_t *driver = driver_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); wl_display_dispatch_pending(wl->g_dpy); wl_display_flush(wl->g_dpy); @@ -221,9 +218,8 @@ static void gfx_ctx_wl_check_window(void *data, bool *quit, static void gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height) { - driver_t *driver = driver_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); (void)data; @@ -234,10 +230,9 @@ static void gfx_ctx_wl_update_window_title(void *data) { char buf[128] = {0}; char buf_fps[128] = {0}; - driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); (void)data; @@ -252,9 +247,8 @@ static void gfx_ctx_wl_update_window_title(void *data) static void gfx_ctx_wl_get_video_size(void *data, unsigned *width, unsigned *height) { - driver_t *driver = driver_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); (void)data; @@ -384,9 +378,7 @@ error: if (wl) free(wl); - if (driver->video_context_data) - free(driver->video_context_data); - driver->video_context_data = NULL; + gfx_ctx_free_data(); return false; } @@ -455,9 +447,8 @@ static EGLint *egl_fill_attribs(EGLint *attr) static void gfx_ctx_wl_destroy(void *data) { - driver_t *driver = driver_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); (void)data; @@ -466,9 +457,7 @@ static void gfx_ctx_wl_destroy(void *data) gfx_ctx_wl_destroy_resources(wl); - if (driver->video_context_data) - free(driver->video_context_data); - driver->video_context_data = NULL; + gfx_ctx_free_data(); } static bool gfx_ctx_wl_set_video_mode(void *data, @@ -476,10 +465,9 @@ static bool gfx_ctx_wl_set_video_mode(void *data, bool fullscreen) { EGLint egl_attribs[16]; - driver_t *driver = driver_get_ptr(); - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; EGLint *attr = NULL; + gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) + gfx_ctx_data_get_ptr(); egl_install_sighandlers(); @@ -696,9 +684,8 @@ static const struct wl_pointer_listener pointer_listener = { static void seat_handle_capabilities(void *data, struct wl_seat *seat, unsigned caps) { - driver_t *driver = driver_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !wl->g_wl_keyboard) { diff --git a/gfx/video_context_driver.c b/gfx/video_context_driver.c index 7dd80ce001..ade25243ac 100644 --- a/gfx/video_context_driver.c +++ b/gfx/video_context_driver.c @@ -79,7 +79,7 @@ static const gfx_ctx_driver_t *gfx_ctx_drivers[] = { }; -const void *gfx_ctx_data_get_ptr(void) +void *gfx_ctx_data_get_ptr(void) { driver_t *driver = driver_get_ptr(); if (!driver) diff --git a/gfx/video_context_driver.h b/gfx/video_context_driver.h index 1d859ca801..3e76a902d0 100644 --- a/gfx/video_context_driver.h +++ b/gfx/video_context_driver.h @@ -254,7 +254,7 @@ void gfx_ctx_input_driver(void *data, retro_proc_address_t gfx_ctx_get_proc_address(const char *sym); -const void *gfx_ctx_data_get_ptr(void); +void *gfx_ctx_data_get_ptr(void); void gfx_ctx_free_data(void); diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 7da7d35712..fc186d52a0 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -800,7 +800,7 @@ bool video_driver_set_video_mode(unsigned width, return true; } - return gfx_ctx_set_video_mode(driver->video_context_data, width, height, fullscreen); + return gfx_ctx_set_video_mode(gfx_ctx_data_get_ptr(), width, height, fullscreen); } bool video_driver_get_video_output_size(unsigned *width, unsigned *height) @@ -1467,14 +1467,14 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) poke->get_video_output_next(video_data); return true; } - return gfx_ctx_get_video_output_next(driver->video_context_data); + return gfx_ctx_get_video_output_next(gfx_ctx_data_get_ptr()); case RARCH_DISPLAY_CTL_GET_PREV_VIDEO_OUT: if (poke && poke->get_video_output_prev) { poke->get_video_output_prev(video_data); return true; } - return gfx_ctx_get_video_output_next(driver->video_context_data); + return gfx_ctx_get_video_output_next(gfx_ctx_data_get_ptr()); case RARCH_DISPLAY_CTL_INIT: return init_video(); case RARCH_DISPLAY_CTL_DEINIT: