summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2009-09-03 09:20:46 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2009-09-03 09:22:23 +0100
commita1bac73f24069990842fa8f31e776b4d2c72546e (patch)
treec62f415f6a0d6ff3635d2c0c48910eb722aa9e53
parentf1d284f9976d38f636c6791f11479ae75d7bd199 (diff)
[boilerplate] Handle errors whilst creating GL surface
-rw-r--r--boilerplate/cairo-boilerplate-gl.c11
-rw-r--r--src/cairo-glx-context.c16
2 files changed, 14 insertions, 13 deletions
diff --git a/boilerplate/cairo-boilerplate-gl.c b/boilerplate/cairo-boilerplate-gl.c
index 0facc5cb..8f3669a0 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 d3b7b80a..18fe2297 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));