[cairo-commit] src/cairo-egl-context.c

Kristian Høgsberg krh at kemper.freedesktop.org
Wed Jul 28 20:52:59 PDT 2010


 src/cairo-egl-context.c |   58 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 38 insertions(+), 20 deletions(-)

New commits:
commit 14639e6b8525ada2cb93abb1d70dde827b7bf9e0
Author: Kristian Høgsberg <krh at bitplanet.net>
Date:   Thu Jun 17 18:29:48 2010 -0400

    egl: Use EGL_KHR_surfaceless_opengl extension when available
    
    This lets us avoid creating a throwaway pbuffer just to make the
    context current.

diff --git a/src/cairo-egl-context.c b/src/cairo-egl-context.c
index 607e3bf..a4ec281 100644
--- a/src/cairo-egl-context.c
+++ b/src/cairo-egl-context.c
@@ -115,6 +115,21 @@ _egl_destroy (void *abstract_ctx)
     eglDestroySurface (ctx->display, ctx->dummy_surface);
 }
 
+static cairo_bool_t
+_egl_make_current_surfaceless(cairo_egl_context_t *ctx)
+{
+    const char *extensions;
+
+    extensions = eglQueryString(ctx->display, EGL_EXTENSIONS);
+    if (!strstr(extensions, "EGL_KHR_surfaceless_opengl"))
+	return FALSE;
+    if (!eglMakeCurrent(ctx->display,
+			EGL_NO_SURFACE, EGL_NO_SURFACE, ctx->context))
+	return FALSE;
+
+    return TRUE;
+}
+
 cairo_device_t *
 cairo_egl_device_create (EGLDisplay dpy, EGLContext egl)
 {
@@ -141,30 +156,33 @@ cairo_egl_device_create (EGLDisplay dpy, EGLContext egl)
     ctx->base.swap_buffers = _egl_swap_buffers;
     ctx->base.destroy = _egl_destroy;
 
-    /* dummy surface, meh. */
-    eglGetConfigs (dpy, NULL, 0, &numConfigs);
-    configs = malloc (sizeof(*configs) *numConfigs);
-    if (configs == NULL) {
-	free (ctx);
-	return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
-    }
-    eglGetConfigs (dpy, configs, numConfigs, &numConfigs);
-    ctx->dummy_surface = eglCreatePbufferSurface (dpy, configs[0], attribs);
-    free (configs);
-
-    if (ctx->dummy_surface == NULL) {
-	free (ctx);
-	return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
-    }
-
-    if (!eglMakeCurrent (dpy, ctx->dummy_surface, ctx->dummy_surface, egl)) {
-	free (ctx);
-	return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
+    if (!_egl_make_current_surfaceless (ctx)) {
+	/* Fall back to dummy surface, meh. */
+	eglGetConfigs (dpy, NULL, 0, &numConfigs);
+	configs = malloc (sizeof(*configs) *numConfigs);
+	if (configs == NULL) {
+	    free (ctx);
+	    return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
+	}
+	eglGetConfigs (dpy, configs, numConfigs, &numConfigs);
+	ctx->dummy_surface = eglCreatePbufferSurface (dpy, configs[0], attribs);
+	free (configs);
+
+	if (ctx->dummy_surface == NULL) {
+	    free (ctx);
+	    return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
+	}
+
+	if (!eglMakeCurrent (dpy, ctx->dummy_surface, ctx->dummy_surface, egl)) {
+	    free (ctx);
+	    return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
+	}
     }
 
     status = _cairo_gl_context_init (&ctx->base);
     if (unlikely (status)) {
-	eglDestroySurface (dpy, ctx->dummy_surface);
+	if (ctx->dummy_surface != EGL_NO_SURFACE)
+	    eglDestroySurface (dpy, ctx->dummy_surface);
 	free (ctx);
 	return _cairo_gl_context_create_in_error (status);
     }


More information about the cairo-commit mailing list