gl: Don't query the display when checking if the context changed

If display has changed, the associated context must change. A
context is tied a display so we can avoid this check, eliminating
unnecessary work during context acquisition and release.
This commit is contained in:
Henry Song 2013-01-16 15:32:32 +01:00 committed by Martin Robinson
parent fa4f48cccb
commit 7054c9969c
2 changed files with 8 additions and 18 deletions

View file

@ -50,7 +50,6 @@ typedef struct _cairo_egl_context {
EGLSurface dummy_surface;
EGLDisplay previous_display;
EGLContext previous_context;
EGLSurface previous_surface;
} cairo_egl_context_t;
@ -66,9 +65,8 @@ static cairo_bool_t
_context_acquisition_changed_egl_state (cairo_egl_context_t *ctx,
EGLSurface current_surface)
{
return !(ctx->previous_display == ctx->display &&
ctx->previous_surface == current_surface &&
ctx->previous_context == ctx->context);
return ctx->previous_context != ctx->context ||
ctx->previous_surface != current_surface;
}
static EGLSurface
@ -85,18 +83,15 @@ _egl_get_current_surface (cairo_egl_context_t *ctx)
static void
_egl_query_current_state (cairo_egl_context_t *ctx)
{
ctx->previous_display = eglGetCurrentDisplay ();
ctx->previous_surface = eglGetCurrentSurface (EGL_DRAW);
ctx->previous_context = eglGetCurrentContext ();
/* If any of the values were none, assume they are all none. Not all
drivers seem well behaved when it comes to using these values across
multiple threads. */
if (ctx->previous_surface == EGL_NO_SURFACE
|| ctx->previous_display == EGL_NO_DISPLAY
|| ctx->previous_context == EGL_NO_CONTEXT) {
if (ctx->previous_surface == EGL_NO_SURFACE ||
ctx->previous_context == EGL_NO_CONTEXT) {
ctx->previous_surface = EGL_NO_SURFACE;
ctx->previous_display = EGL_NO_DISPLAY;
ctx->previous_context = EGL_NO_CONTEXT;
}
}

View file

@ -53,7 +53,6 @@ typedef struct _cairo_glx_context {
Window dummy_window;
GLXContext context;
Display *previous_display;
GLXDrawable previous_drawable;
GLXContext previous_context;
@ -70,9 +69,8 @@ static cairo_bool_t
_context_acquisition_changed_glx_state (cairo_glx_context_t *ctx,
GLXDrawable current_drawable)
{
return !(ctx->previous_display == ctx->display &&
ctx->previous_drawable == current_drawable &&
ctx->previous_context == ctx->context);
return ctx->previous_drawable != current_drawable ||
ctx->previous_context != ctx->context;
}
static GLXDrawable
@ -90,17 +88,14 @@ static void
_glx_query_current_state (cairo_glx_context_t * ctx)
{
ctx->previous_drawable = glXGetCurrentDrawable ();
ctx->previous_display = glXGetCurrentDisplay ();
ctx->previous_context = glXGetCurrentContext ();
/* If any of the values were none, assume they are all none. Not all
drivers seem well behaved when it comes to using these values across
multiple threads. */
if (ctx->previous_drawable == None
|| ctx->previous_display == None
|| ctx->previous_context == None) {
if (ctx->previous_drawable == None ||
ctx->previous_context == None) {
ctx->previous_drawable = None;
ctx->previous_display = None;
ctx->previous_context = None;
}
}