diff --git a/driver.c b/driver.c index ee0c76b3c7..5cf18e48af 100644 --- a/driver.c +++ b/driver.c @@ -1544,3 +1544,19 @@ void uninit_video_input(void) deinit_shader_dir(); compute_monitor_fps_statistics(); } + + +void *driver_video_resolve(const video_driver_t **drv) +{ +#ifdef HAVE_THREADS + if (g_settings.video.threaded && !g_extern.system.hw_render_callback.context_type) + return rarch_threaded_video_resolve(drv); + else +#endif + { + if (drv) + *drv = driver.video; + + return driver.video_data; + } +} diff --git a/driver.h b/driver.h index 7ca66b58c8..78c18a76e9 100644 --- a/driver.h +++ b/driver.h @@ -554,6 +554,9 @@ bool driver_set_sensor_state(unsigned port, float driver_sensor_get_input(unsigned port, unsigned action); +/* Use this if you need the real video driver and driver data pointers */ +void *driver_video_resolve(const video_driver_t **drv); + #ifdef HAVE_DYLIB void rarch_deinit_filter(void); void rarch_init_filter(enum retro_pixel_format); diff --git a/frontend/menu/disp/glui.c b/frontend/menu/disp/glui.c index dd10d95f1f..1b71a25b40 100644 --- a/frontend/menu/disp/glui.c +++ b/frontend/menu/disp/glui.c @@ -49,7 +49,8 @@ const gl_font_renderer_t *font_driver; static void blit_line(float x, float y, const char *message, bool green) { - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); + if (!driver.menu || !gl) return; @@ -77,7 +78,8 @@ static void glui_render_background(void) 0.0f, 0.0f, 0.0f, 0.9f, }; - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); + if (!gl) return; @@ -103,7 +105,7 @@ static void glui_render_messagebox(const char *message) static void glui_frame(void) { - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); if (!driver.menu || !gl) return; @@ -258,10 +260,19 @@ static void glui_init_core_info(void *data) static void *glui_init(void) { - menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu)); - gl_t *gl = (gl_t*)driver.video_data; + menu_handle_t *menu; + const video_driver_t *video_driver = NULL; + gl_t *gl = (gl_t*)driver_video_resolve(&video_driver); - if (!menu || !gl) + if (video_driver != &video_gl || !gl) + { + RARCH_ERR("Cannot initialize GLUI menu driver: gl video driver is not active.\n"); + return NULL; + } + + menu = (menu_handle_t*)calloc(1, sizeof(*menu)); + + if (!menu) return NULL; glui_init_core_info(menu); @@ -300,7 +311,7 @@ static void glui_context_reset(void *data) { char mediapath[256], themepath[256], iconpath[256]; menu_handle_t *menu = (menu_handle_t*)data; - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); driver.gfx_use_rgba = true; diff --git a/frontend/menu/disp/lakka.c b/frontend/menu/disp/lakka.c index 10db78c0e9..783ae11424 100644 --- a/frontend/menu/disp/lakka.c +++ b/frontend/menu/disp/lakka.c @@ -120,7 +120,8 @@ static int numtweens = 0; static void lakka_responsive(void) { - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); + if (!gl) return; @@ -352,7 +353,8 @@ static void lakka_draw_text(const char *str, float x, if (alpha == 0) return; - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); + if (!gl) return; @@ -383,7 +385,8 @@ void lakka_draw_background(void) 1.0f, 1.0f, 1.0f, global_alpha, }; - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); + if (!gl) return; @@ -416,7 +419,7 @@ void lakka_draw_icon(GLuint texture, float x, float y, if (alpha == 0) return; - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); if (!gl) return; @@ -623,7 +626,7 @@ static void lakka_draw_categories(void) static void lakka_frame(void) { - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); menu_category_t *active_category = (menu_category_t*) &categories[menu_active_category]; menu_item_t *active_item; @@ -680,9 +683,7 @@ static GLuint png_texture_load(const char * file_name) static void lakka_context_destroy(void *data) { int i, j, k; - gl_t *gl = (gl_t*)driver.video_data; - - (void)gl; + (void)data; for (i = 0; i < TEXTURE_LAST; i++) glDeleteTextures(1, &textures[i].id); @@ -841,7 +842,7 @@ static void lakka_context_reset(void *data) int i, j, k; char mediapath[256], themepath[256], iconpath[256]; menu_handle_t *menu = (menu_handle_t*)data; - gl_t *gl = (gl_t*)driver.video_data; + gl_t *gl = (gl_t*)driver_video_resolve(NULL); driver.gfx_use_rgba = true; @@ -1105,18 +1106,18 @@ static void *lakka_init(void) { int i; menu_handle_t *menu; - gl_t *gl; + const video_driver_t *video_driver = NULL; + gl_t *gl = (gl_t*)driver_video_resolve(&video_driver); - if (driver.video != &video_gl) + if (video_driver != &video_gl || !gl) { RARCH_ERR("Cannot initialize Lakka menu driver: gl video driver is not active.\n"); return NULL; } menu = (menu_handle_t*)calloc(1, sizeof(*menu)); - gl = (gl_t*)driver.video_data; - if (!menu || !gl) + if (!menu) return NULL; lakka_responsive(); diff --git a/gfx/thread_wrapper.h b/gfx/thread_wrapper.h index 835773415b..244ac2c4f2 100644 --- a/gfx/thread_wrapper.h +++ b/gfx/thread_wrapper.h @@ -26,5 +26,7 @@ bool rarch_threaded_video_init( const input_driver_t **input, void **input_data, const video_driver_t *driver, const video_info_t *info); +void *rarch_threaded_video_resolve(const video_driver_t **drv); + #endif diff --git a/gfx/video_thread_wrapper.c b/gfx/video_thread_wrapper.c index 5f312838ed..e1ad10d7ac 100644 --- a/gfx/video_thread_wrapper.c +++ b/gfx/video_thread_wrapper.c @@ -926,4 +926,13 @@ bool rarch_threaded_video_init(const video_driver_t **out_driver, return thread_init(thr, info, input, input_data); } +void *rarch_threaded_video_resolve(const video_driver_t **drv) +{ + const thread_video_t *thr = (const thread_video_t*)driver.video_data; + + if (drv) + *drv = thr->driver; + + return thr->driver_data; +}