[cairo-commit] src/cairo-egl-context.c src/cairo-gl-device.c src/cairo-gl.h src/cairo-gl-private.h src/cairo-glx-context.c

Martin Robinson mrobinson at kemper.freedesktop.org
Wed Aug 22 13:50:51 PDT 2012


 src/cairo-egl-context.c |    2 ++
 src/cairo-gl-device.c   |   13 +++++++++++++
 src/cairo-gl-private.h  |    2 ++
 src/cairo-gl.h          |    4 ++++
 src/cairo-glx-context.c |    7 ++++---
 5 files changed, 25 insertions(+), 3 deletions(-)

New commits:
commit 5c4087af810763ee98682b3bcc1c759ad8b4c27b
Author: Martin Robinson <mrobinson at igalia.com>
Date:   Tue Feb 28 10:50:16 2012 -0800

    gl: Add a non-thread-aware mode for GL devices
    
    GLX and EGL devices are thread-aware currently. This
    is safe, but on certain GPUs can be very expensive. In
    this patch, we expose a new API which turns off the
    safety feature in cases where performance is a priority.

diff --git a/src/cairo-egl-context.c b/src/cairo-egl-context.c
index b24bc80..0e9fd71 100644
--- a/src/cairo-egl-context.c
+++ b/src/cairo-egl-context.c
@@ -80,6 +80,8 @@ static void
 _egl_release (void *abstract_ctx)
 {
     cairo_egl_context_t *ctx = abstract_ctx;
+    if (!ctx->base.thread_aware)
+	return;
 
     eglMakeCurrent (ctx->display,
 		    EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c
index 6abee1c..9cb0c21 100644
--- a/src/cairo-gl-device.c
+++ b/src/cairo-gl-device.c
@@ -185,6 +185,8 @@ _cairo_gl_context_init (cairo_gl_context_t *ctx)
 	ctx->compositor = _cairo_gl_span_compositor_get ();
 
 
+    ctx->thread_aware = TRUE;
+
     memset (ctx->glyph_cache, 0, sizeof (ctx->glyph_cache));
     cairo_list_init (&ctx->fonts);
 
@@ -703,3 +705,14 @@ _cairo_gl_context_set_destination (cairo_gl_context_t *ctx,
 	_gl_identity_ortho (ctx->modelviewprojection_matrix,
 			    0, surface->width, surface->height, 0);
 }
+
+void
+cairo_gl_device_set_thread_aware (cairo_device_t	*device,
+				  cairo_bool_t		 thread_aware)
+{
+    if (device->backend->type != CAIRO_DEVICE_TYPE_GL) {
+	_cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH);
+	return;
+    }
+    ((cairo_gl_context_t *) device)->thread_aware = thread_aware;
+}
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 48087ec..d6b0554 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -349,6 +349,8 @@ struct _cairo_gl_context {
     cairo_bool_t has_packed_depth_stencil;
     cairo_bool_t has_npot_repeat;
 
+    cairo_bool_t thread_aware;
+
     void (*acquire) (void *ctx);
     void (*release) (void *ctx);
 
diff --git a/src/cairo-gl.h b/src/cairo-gl.h
index dd17be6..cec3173 100644
--- a/src/cairo-gl.h
+++ b/src/cairo-gl.h
@@ -88,6 +88,10 @@ cairo_gl_surface_get_height (cairo_surface_t *abstract_surface);
 cairo_public void
 cairo_gl_surface_swapbuffers (cairo_surface_t *surface);
 
+cairo_public void
+cairo_gl_device_set_thread_aware (cairo_device_t	*device,
+				  cairo_bool_t		 thread_aware);
+
 #if CAIRO_HAS_GLX_FUNCTIONS
 #include <GL/glx.h>
 
diff --git a/src/cairo-glx-context.c b/src/cairo-glx-context.c
index 512bee8..47634f1 100644
--- a/src/cairo-glx-context.c
+++ b/src/cairo-glx-context.c
@@ -94,9 +94,10 @@ _glx_release (void *abstract_ctx)
 {
     cairo_glx_context_t *ctx = abstract_ctx;
 
-    if (!ctx->has_multithread_makecurrent) {
-	glXMakeCurrent (ctx->display, None, None);
-    }
+    if (ctx->has_multithread_makecurrent || !ctx->base.thread_aware)
+	return;
+
+    glXMakeCurrent (ctx->display, None, None);
 }
 
 static void


More information about the cairo-commit mailing list