[cairo-commit] boilerplate/cairo-boilerplate-gl.c src/cairo-glx-context.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Sep 3 01:22:32 PDT 2009


 boilerplate/cairo-boilerplate-gl.c |   11 ++++++-----
 src/cairo-glx-context.c            |   16 ++++++++--------
 2 files changed, 14 insertions(+), 13 deletions(-)

New commits:
commit a1bac73f24069990842fa8f31e776b4d2c72546e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Sep 3 09:20:46 2009 +0100

    [boilerplate] Handle errors whilst creating GL surface

diff --git a/boilerplate/cairo-boilerplate-gl.c b/boilerplate/cairo-boilerplate-gl.c
index 0facc5c..8f3669a 100644
--- a/boilerplate/cairo-boilerplate-gl.c
+++ b/boilerplate/cairo-boilerplate-gl.c
@@ -81,6 +81,7 @@ _cairo_boilerplate_gl_create_surface (const char		 *name,
     XVisualInfo *visinfo;
     GLXContext gl_ctx;
     gl_target_closure_t *gltc;
+    cairo_surface_t *surface;
     Display *dpy;
 
     gltc = malloc (sizeof (gl_target_closure_t));
@@ -120,13 +121,13 @@ _cairo_boilerplate_gl_create_surface (const char		 *name,
     gltc->gl_ctx = gl_ctx;
     gltc->ctx = cairo_glx_context_create (dpy, gl_ctx);
 
-    gltc->surface = cairo_gl_surface_create (gltc->ctx, content,
-					     ceil (width), ceil (height));
-
-    if (gltc->surface == NULL || cairo_surface_status (gltc->surface))
+    gltc->surface = surface = cairo_gl_surface_create (gltc->ctx, content,
+					               ceil (width),
+						       ceil (height));
+    if (cairo_surface_status (surface))
 	_cairo_boilerplate_gl_cleanup (gltc);
 
-    return gltc->surface;
+    return surface;
 }
 
 static void
diff --git a/src/cairo-glx-context.c b/src/cairo-glx-context.c
index d3b7b80..18fe229 100644
--- a/src/cairo-glx-context.c
+++ b/src/cairo-glx-context.c
@@ -108,8 +108,9 @@ _glx_dummy_ctx (Display *dpy, GLXContext gl_ctx, Window *dummy)
 
     cnt = 0;
     config = glXChooseFBConfig (dpy, DefaultScreen (dpy), attr, &cnt);
-    if (cnt == 0)
+    if (unlikely (cnt == 0))
 	return _cairo_error (CAIRO_STATUS_INVALID_FORMAT);
+
     vi = glXGetVisualFromFBConfig (dpy, config[0]);
     XFree (config);
 
@@ -129,10 +130,9 @@ _glx_dummy_ctx (Display *dpy, GLXContext gl_ctx, Window *dummy)
     XFree (vi);
 
     XFlush (dpy);
-    if (! glXMakeCurrent (dpy, win, gl_ctx)) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+    if (unlikely (! glXMakeCurrent (dpy, win, gl_ctx))) {
 	XDestroyWindow (dpy, win);
-	win = None;
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
     }
 
     *dummy = win;
@@ -147,11 +147,11 @@ cairo_glx_context_create (Display *dpy, GLXContext gl_ctx)
     Window dummy = None;
 
     status = _glx_dummy_ctx (dpy, gl_ctx, &dummy);
-    if (status)
+    if (unlikely (status))
 	return _cairo_gl_context_create_in_error (status);
 
     ctx = calloc (1, sizeof (cairo_glx_context_t));
-    if (ctx == NULL)
+    if (unlikely (ctx == NULL))
 	return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
 
     ctx->display = dpy;
@@ -163,7 +163,7 @@ cairo_glx_context_create (Display *dpy, GLXContext gl_ctx)
     ctx->base.destroy = _glx_destroy;
 
     status = _cairo_gl_context_init (&ctx->base);
-    if (status) {
+    if (unlikely (status)) {
 	free (ctx);
 	return _cairo_gl_context_create_in_error (status);
     }
@@ -179,7 +179,7 @@ cairo_gl_surface_create_for_window (cairo_gl_context_t   *ctx,
 {
     cairo_glx_surface_t *surface;
 
-    if (ctx->status)
+    if (unlikely (ctx->status))
 	return _cairo_surface_create_in_error (ctx->status);
 
     surface = calloc (1, sizeof (cairo_glx_surface_t));


More information about the cairo-commit mailing list