diff --git a/command_event.c b/command_event.c index 2689dd8cac..5d84305bd9 100644 --- a/command_event.c +++ b/command_event.c @@ -1226,10 +1226,14 @@ bool event_command(enum event_command cmd) const struct retro_hw_render_callback *hw_render = (const struct retro_hw_render_callback*)video_driver_callback(); - driver->video_cache_context = hw_render->cache_context; - driver->video_cache_context_ack = false; + if (hw_render->cache_context) + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT, NULL); + else + video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT, NULL); + + video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT_ACK, NULL); event_command(EVENT_CMD_RESET_CONTEXT); - driver->video_cache_context = false; + video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT, NULL); /* Poll input to avoid possibly stale data to corrupt things. */ input_driver_ctl(RARCH_INPUT_CTL_POLL, NULL); diff --git a/driver.c b/driver.c index 48d04831f5..015ee92c14 100644 --- a/driver.c +++ b/driver.c @@ -385,10 +385,10 @@ void init_drivers(int flags) video_driver_ctl(RARCH_DISPLAY_CTL_MONITOR_RESET, NULL); video_driver_ctl(RARCH_DISPLAY_CTL_INIT, NULL); - if (!driver->video_cache_context_ack + if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT_ACK, NULL) && hw_render->context_reset) hw_render->context_reset(); - driver->video_cache_context_ack = false; + video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT_ACK, NULL); system->frame_time_last = 0; } diff --git a/driver.h b/driver.h index 2c8c57d84c..72050f441c 100644 --- a/driver.h +++ b/driver.h @@ -229,14 +229,6 @@ typedef struct driver const menu_ctx_driver_t *menu_ctx; #endif - /* If set during context deinit, the driver should keep - * graphics context alive to avoid having to reset all - * context state. */ - bool video_cache_context; - - /* Set to true by driver if context caching succeeded. */ - bool video_cache_context_ack; - /* Set this to true if the platform in question needs to 'own' * the respective handle and therefore skip regular RetroArch * driver teardown/reiniting procedure. diff --git a/gfx/drivers_context/glx_ctx.c b/gfx/drivers_context/glx_ctx.c index 39e24a38f6..d96b691b0e 100644 --- a/gfx/drivers_context/glx_ctx.c +++ b/gfx/drivers_context/glx_ctx.c @@ -63,8 +63,6 @@ static int glx_nul_handler(Display *dpy, XErrorEvent *event) static void ctx_glx_destroy_resources(gfx_ctx_glx_data_t *glx) { - driver_t *driver = driver_get_ptr(); - if (!glx) return; @@ -76,7 +74,7 @@ static void ctx_glx_destroy_resources(gfx_ctx_glx_data_t *glx) glFinish(); glXMakeContextCurrent(g_x11_dpy, None, None, NULL); - if (!driver->video_cache_context) + if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL)) { if (glx->g_hw_ctx) glXDestroyContext(g_x11_dpy, glx->g_hw_ctx); @@ -120,7 +118,7 @@ static void ctx_glx_destroy_resources(gfx_ctx_glx_data_t *glx) glx->g_should_reset_mode = false; } - if (!driver->video_cache_context && g_x11_dpy) + if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL) && g_x11_dpy) { XCloseDisplay(g_x11_dpy); g_x11_dpy = NULL; @@ -283,7 +281,6 @@ static bool gfx_ctx_glx_set_video_mode(void *data, XVisualInfo *vi = NULL; XSetWindowAttributes swa = {0}; int (*old_handler)(Display*, XErrorEvent*) = NULL; - driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); gfx_ctx_glx_data_t *glx = (gfx_ctx_glx_data_t*) gfx_ctx_data_get_ptr(); @@ -446,7 +443,7 @@ static bool gfx_ctx_glx_set_video_mode(void *data, } else { - driver->video_cache_context_ack = true; + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT_ACK, NULL); RARCH_LOG("[GLX]: Using cached GL context.\n"); } diff --git a/gfx/drivers_context/sdl_gl_ctx.c b/gfx/drivers_context/sdl_gl_ctx.c index 533f5b147d..489c1ac6ab 100644 --- a/gfx/drivers_context/sdl_gl_ctx.c +++ b/gfx/drivers_context/sdl_gl_ctx.c @@ -158,10 +158,9 @@ static void sdl_ctx_swap_interval(void *data, unsigned interval) } static bool sdl_ctx_set_video_mode(void *data, unsigned width, unsigned height, - bool fullscreen) + bool fullscreen) { 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*)gfx_ctx_data_get_ptr(); @@ -207,7 +206,7 @@ static bool sdl_ctx_set_video_mode(void *data, unsigned width, unsigned height, #ifdef HAVE_SDL2 if (sdl->g_ctx) - driver->video_cache_context_ack = true; + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT_ACK, NULL); else { sdl->g_ctx = SDL_GL_CreateContext(sdl->g_win); diff --git a/gfx/drivers_context/wgl_ctx.cpp b/gfx/drivers_context/wgl_ctx.cpp index e6ee1383ce..9c738bfe0d 100644 --- a/gfx/drivers_context/wgl_ctx.cpp +++ b/gfx/drivers_context/wgl_ctx.cpp @@ -100,7 +100,6 @@ void create_gl_context(HWND hwnd, bool *quit) bool core_context; const struct retro_hw_render_callback *hw_render = (const struct retro_hw_render_callback*)video_driver_callback(); - driver_t *driver = driver_get_ptr(); bool debug = hw_render->debug_context; #ifdef _WIN32 @@ -118,7 +117,7 @@ void create_gl_context(HWND hwnd, bool *quit) if (g_hrc) { RARCH_LOG("[WGL]: Using cached GL context.\n"); - driver->video_cache_context_ack = true; + video_driver_ctl(RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT_ACK, NULL); } else { @@ -317,7 +316,6 @@ static bool gfx_ctx_wgl_init(void *data) static void gfx_ctx_wgl_destroy(void *data) { - driver_t *driver = driver_get_ptr(); HWND window = win32_get_window(); (void)data; @@ -327,7 +325,7 @@ static void gfx_ctx_wgl_destroy(void *data) glFinish(); wglMakeCurrent(NULL, NULL); - if (!driver->video_cache_context) + if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL)) { if (g_hw_hrc) wglDeleteContext(g_hw_hrc); diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 0e833b19d6..b6915eb275 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -75,6 +75,14 @@ typedef struct video_pixel_scaler void *scaler_out; } video_pixel_scaler_t; +/* If set during context deinit, the driver should keep + * graphics context alive to avoid having to reset all + * context state. */ +static bool video_cache_context; + +/* Set to true by driver if context caching succeeded. */ +static bool video_cache_context_ack; + /* Opaque handles to currently running window. * Used by e.g. input drivers which bind to a window. * Drivers are responsible for setting these if an input driver @@ -548,7 +556,7 @@ static bool uninit_video_input(void) event_command(EVENT_CMD_SHADER_DIR_DEINIT); video_monitor_compute_fps_statistics(); - if (hw_render->context_destroy && !driver->video_cache_context) + if (hw_render->context_destroy && !video_cache_context) hw_render->context_destroy(); video_driver_ctl(RARCH_DISPLAY_CTL_UNSET_RGBA, NULL); @@ -1627,6 +1635,22 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) break; case RARCH_DISPLAY_CTL_OWNS_DRIVER: return video_data_own; + case RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT: + video_cache_context = true; + break; + case RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT: + video_cache_context = false; + break; + case RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT: + return video_cache_context; + case RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT_ACK: + video_cache_context_ack = true; + break; + case RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT_ACK: + video_cache_context_ack = false; + break; + case RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT_ACK: + return video_cache_context_ack; case RARCH_DISPLAY_CTL_NONE: default: break; diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 25cd7e1639..51219337c8 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -316,7 +316,13 @@ enum rarch_display_ctl_state RARCH_DISPLAY_CTL_GET_FRAME_COUNT, RARCH_DISPLAY_CTL_SET_OWN_DRIVER, RARCH_DISPLAY_CTL_UNSET_OWN_DRIVER, - RARCH_DISPLAY_CTL_OWNS_DRIVER + RARCH_DISPLAY_CTL_OWNS_DRIVER, + RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT, + RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT, + RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, + RARCH_DISPLAY_CTL_SET_VIDEO_CACHE_CONTEXT_ACK, + RARCH_DISPLAY_CTL_UNSET_VIDEO_CACHE_CONTEXT_ACK, + RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT_ACK }; bool video_driver_ctl(enum rarch_display_ctl_state state, void *data);