From e18af774124ec3f4315c431d8764e97cec6880c4 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 23 Jun 2013 23:01:34 +0200 Subject: [PATCH] Add path to cache GL context on reinit. If successful, can avoid libretro GL reset context callback being called. --- driver.c | 2 +- driver.h | 5 ++++ gfx/context/glx_ctx.c | 65 +++++++++++++++++++++++++++---------------- retroarch.c | 3 ++ 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/driver.c b/driver.c index 05ad5689a1..da6eb582a5 100644 --- a/driver.c +++ b/driver.c @@ -373,7 +373,7 @@ void init_drivers(void) g_extern.frame_count = 0; init_video_input(); - if (g_extern.system.hw_render_callback.context_reset) + if (!driver.video_cache_context_ack && g_extern.system.hw_render_callback.context_reset) g_extern.system.hw_render_callback.context_reset(); init_audio(); diff --git a/driver.h b/driver.h index d51e37bc0d..bc4cdd7d1a 100644 --- a/driver.h +++ b/driver.h @@ -419,6 +419,11 @@ typedef struct driver bool threaded_video; + // If set during context deinit, the driver should keep + // graphics context alive to avoid having to reset all context state. + bool video_cache_context; + bool video_cache_context_ack; // Set to true by driver if context caching succeeded. + // Set if the respective handles are owned by RetroArch driver core. // Consoles upper logic will generally intialize the drivers before // the driver core initializes. It will then be up to upper logic diff --git a/gfx/context/glx_ctx.c b/gfx/context/glx_ctx.c index fef98c4401..fae58f4674 100644 --- a/gfx/context/glx_ctx.c +++ b/gfx/context/glx_ctx.c @@ -113,20 +113,24 @@ static void gfx_ctx_check_window(bool *quit, switch (event.type) { case ClientMessage: - if ((Atom)event.xclient.data.l[0] == g_quit_atom) + if (event.xclient.window == g_win && + (Atom)event.xclient.data.l[0] == g_quit_atom) g_quit = true; break; case DestroyNotify: - g_quit = true; + if (event.xdestroywindow.window == g_win) + g_quit = true; break; case MapNotify: - g_has_focus = true; + if (event.xmap.window == g_win) + g_has_focus = true; break; case UnmapNotify: - g_has_focus = false; + if (event.xunmap.window == g_win) + g_has_focus = false; break; case KeyPress: @@ -210,7 +214,9 @@ static bool gfx_ctx_init(void) GLXFBConfig *fbcs = NULL; g_quit = 0; - g_dpy = XOpenDisplay(NULL); + if (!g_dpy) + g_dpy = XOpenDisplay(NULL); + if (!g_dpy) goto error; @@ -361,24 +367,32 @@ static bool gfx_ctx_set_video_mode( XEvent event; XIfEvent(g_dpy, &event, glx_wait_notify, NULL); - if (g_core) - { - const int attribs[] = { - GLX_CONTEXT_MAJOR_VERSION_ARB, g_major, - GLX_CONTEXT_MINOR_VERSION_ARB, g_minor, - GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, - None, - }; - - g_ctx = glx_create_context_attribs(g_dpy, g_fbc, NULL, True, attribs); - } - else - g_ctx = glXCreateNewContext(g_dpy, g_fbc, GLX_RGBA_TYPE, 0, True); - if (!g_ctx) { - RARCH_ERR("[GLX]: Failed to create new context.\n"); - goto error; + if (g_core) + { + const int attribs[] = { + GLX_CONTEXT_MAJOR_VERSION_ARB, g_major, + GLX_CONTEXT_MINOR_VERSION_ARB, g_minor, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + None, + }; + + g_ctx = glx_create_context_attribs(g_dpy, g_fbc, NULL, True, attribs); + } + else + g_ctx = glXCreateNewContext(g_dpy, g_fbc, GLX_RGBA_TYPE, 0, True); + + if (!g_ctx) + { + RARCH_ERR("[GLX]: Failed to create new context.\n"); + goto error; + } + } + else + { + driver.video_cache_context_ack = true; + RARCH_LOG("[GLX]: Using cached GL context.\n"); } glXMakeContextCurrent(g_dpy, g_glx_win, g_glx_win, g_ctx); @@ -445,8 +459,11 @@ static void gfx_ctx_destroy(void) if (g_dpy && g_ctx) { glXMakeContextCurrent(g_dpy, None, None, NULL); - glXDestroyContext(g_dpy, g_ctx); - g_ctx = NULL; + if (!driver.video_cache_context) + { + glXDestroyContext(g_dpy, g_ctx); + g_ctx = NULL; + } } if (g_win) @@ -487,7 +504,7 @@ static void gfx_ctx_destroy(void) g_should_reset_mode = false; } - if (g_dpy) + if (!driver.video_cache_context && g_dpy) { XCloseDisplay(g_dpy); g_dpy = NULL; diff --git a/retroarch.c b/retroarch.c index ecd6bf9d6d..11c674c084 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1934,8 +1934,11 @@ void rarch_set_fullscreen(bool fullscreen) { g_settings.video.fullscreen = fullscreen; + driver.video_cache_context = true; + driver.video_cache_context_ack = false; uninit_drivers(); init_drivers(); + driver.video_cache_context = false; // Poll input to avoid possibly stale data to corrupt things. if (driver.input)