Permalink
Browse files

Add path to cache GL context on reinit.

If successful, can avoid libretro GL reset context callback being
called.
  • Loading branch information...
1 parent b090f5a commit e18af774124ec3f4315c431d8764e97cec6880c4 @Themaister committed Jun 23, 2013
Showing with 48 additions and 23 deletions.
  1. +1 −1 driver.c
  2. +5 −0 driver.h
  3. +39 −22 gfx/context/glx_ctx.c
  4. +3 −0 retroarch.c
View
@@ -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();
View
@@ -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
View
@@ -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)
+ if (!g_ctx)
{
- 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);
+ 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
- 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;
+ 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;
View
@@ -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)

0 comments on commit e18af77

Please sign in to comment.