From 41b46975f92c69a52be2eea576bbc3c17b70aa0e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 23 Nov 2015 20:45:09 +0100 Subject: [PATCH] Cleanups - go through standard functions --- gfx/drivers_context/drm_egl_ctx.c | 27 ++++++++++----------------- gfx/video_context_driver.c | 16 ++++++++++++++++ gfx/video_context_driver.h | 4 ++++ 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/gfx/drivers_context/drm_egl_ctx.c b/gfx/drivers_context/drm_egl_ctx.c index 523d0f8ecc..f69feff90e 100644 --- a/gfx/drivers_context/drm_egl_ctx.c +++ b/gfx/drivers_context/drm_egl_ctx.c @@ -83,9 +83,9 @@ struct drm_fb static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) { - driver_t *driver = driver_get_ptr(); struct drm_fb *fb = (struct drm_fb*)data; - gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)driver->video_context_data; + gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*) + gfx_ctx_data_get_ptr(); if (drm && fb->fb_id) drmModeRmFB(drm->g_drm_fd, fb->fb_id); @@ -236,9 +236,8 @@ static bool queue_flip(gfx_ctx_drm_egl_data_t *drm) static void gfx_ctx_drm_egl_swap_buffers(void *data) { - driver_t *driver = driver_get_ptr(); gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); egl_swap_buffers(data); @@ -281,10 +280,11 @@ static void gfx_ctx_drm_egl_update_window_title(void *data) rarch_main_msg_queue_push( buf_fps, 1, 1, false); } -static void gfx_ctx_drm_egl_get_video_size(void *data, unsigned *width, unsigned *height) +static void gfx_ctx_drm_egl_get_video_size(void *data, + unsigned *width, unsigned *height) { - driver_t *driver = driver_get_ptr(); - gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*)driver->video_context_data; + gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*) + gfx_ctx_data_get_ptr(); if (!drm) return; @@ -631,10 +631,9 @@ static bool gfx_ctx_drm_egl_set_video_mode(void *data, float refresh_mod; int i, ret = 0; struct drm_fb *fb = NULL; - driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); if (!drm) return false; @@ -765,20 +764,14 @@ error: static void gfx_ctx_drm_egl_destroy(void *data) { - driver_t *driver = driver_get_ptr(); gfx_ctx_drm_egl_data_t *drm = (gfx_ctx_drm_egl_data_t*) - driver->video_context_data; + gfx_ctx_data_get_ptr(); if (!drm) return; - (void)data; - gfx_ctx_drm_egl_destroy_resources(drm); - - if (driver->video_context_data) - free(driver->video_context_data); - driver->video_context_data = NULL; + gfx_ctx_free_data(); } static void gfx_ctx_drm_egl_input_driver(void *data, diff --git a/gfx/video_context_driver.c b/gfx/video_context_driver.c index 6c47d772ef..7dd80ce001 100644 --- a/gfx/video_context_driver.c +++ b/gfx/video_context_driver.c @@ -79,6 +79,22 @@ static const gfx_ctx_driver_t *gfx_ctx_drivers[] = { }; +const void *gfx_ctx_data_get_ptr(void) +{ + driver_t *driver = driver_get_ptr(); + if (!driver) + return NULL; + return driver->video_context_data; +} + +void gfx_ctx_free_data(void) +{ + driver_t *driver = driver_get_ptr(); + if (driver->video_context_data) + free(driver->video_context_data); + driver->video_context_data = NULL; +} + static const gfx_ctx_driver_t *gfx_ctx_get_ptr(void) { driver_t *driver = driver_get_ptr(); diff --git a/gfx/video_context_driver.h b/gfx/video_context_driver.h index 2d72074023..1d859ca801 100644 --- a/gfx/video_context_driver.h +++ b/gfx/video_context_driver.h @@ -254,6 +254,10 @@ 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_free_data(void); + #ifdef __cplusplus } #endif