diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2009-09-30 17:50:09 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2009-09-30 17:50:35 +0100 |
commit | 8e4e0aa7ee5b4e0963409cda825705a09aae61e1 (patch) | |
tree | 345272105cf8b5827026238c39ec552d7d10f1bb /boilerplate/cairo-boilerplate-xcb.c | |
parent | 395555b116a497c99b9e8365a202377c344c0c45 (diff) | |
download | cairo-8e4e0aa7ee5b4e0963409cda825705a09aae61e1.tar.gz |
[boilerplate/xcb] Check for connection errors during test
Diffstat (limited to 'boilerplate/cairo-boilerplate-xcb.c')
-rw-r--r-- | boilerplate/cairo-boilerplate-xcb.c | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/boilerplate/cairo-boilerplate-xcb.c b/boilerplate/cairo-boilerplate-xcb.c index e8996fae4..de71fa6fd 100644 --- a/boilerplate/cairo-boilerplate-xcb.c +++ b/boilerplate/cairo-boilerplate-xcb.c @@ -30,12 +30,24 @@ #include <xcb/xcb_renderutil.h> +static const cairo_user_data_key_t xcb_closure_key; + typedef struct _xcb_target_closure { xcb_connection_t *c; xcb_pixmap_t pixmap; } xcb_target_closure_t; static void +_cairo_boilerplate_xcb_cleanup (void *closure) +{ + xcb_target_closure_t *xtc = closure; + + xcb_free_pixmap (xtc->c, xtc->pixmap); + xcb_disconnect (xtc->c); + free (xtc); +} + +static void _cairo_boilerplate_xcb_synchronize (void *closure) { xcb_target_closure_t *xtc = closure; @@ -61,6 +73,8 @@ _cairo_boilerplate_xcb_create_surface (const char *name, xcb_connection_t *c; xcb_render_pictforminfo_t *render_format; xcb_pict_standard_t format; + cairo_surface_t *surface; + cairo_status_t status; *closure = xtc = xmalloc (sizeof (xcb_target_closure_t)); @@ -98,19 +112,32 @@ _cairo_boilerplate_xcb_create_surface (const char *name, if (render_format->id == 0) return NULL; - return cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root, - render_format, - width, height); + surface = cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root, + render_format, + width, height); + + status = cairo_surface_set_user_data (surface, &xcb_closure_key, xtc, NULL); + if (status == CAIRO_STATUS_SUCCESS) + return surface; + + cairo_surface_destroy (surface); + surface = cairo_boilerplate_surface_create_in_error (status); + + _cairo_boilerplate_xcb_cleanup (xtc); + + return surface; } -static void -_cairo_boilerplate_xcb_cleanup (void *closure) +static cairo_status_t +_cairo_boilerplate_xcb_finish_surface (cairo_surface_t *surface) { - xcb_target_closure_t *xtc = closure; + xcb_target_closure_t *xtc = cairo_surface_get_user_data (surface, + &xcb_closure_key); - xcb_free_pixmap (xtc->c, xtc->pixmap); - xcb_disconnect (xtc->c); - free (xtc); + if (xcb_connection_has_error (xtc->c)) + return CAIRO_STATUS_WRITE_ERROR; + + return CAIRO_STATUS_SUCCESS; } static const cairo_boilerplate_target_t targets[] = { @@ -121,7 +148,8 @@ static const cairo_boilerplate_target_t targets[] = { CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, 1, "cairo_xcb_surface_create_with_xrender_format", _cairo_boilerplate_xcb_create_surface, - NULL, NULL, + NULL, + _cairo_boilerplate_xcb_finish_surface, _cairo_boilerplate_get_image_surface, cairo_surface_write_to_png, _cairo_boilerplate_xcb_cleanup, @@ -132,7 +160,8 @@ static const cairo_boilerplate_target_t targets[] = { CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR, 1, "cairo_xcb_surface_create_with_xrender_format", _cairo_boilerplate_xcb_create_surface, - NULL, NULL, + NULL, + _cairo_boilerplate_xcb_finish_surface, _cairo_boilerplate_get_image_surface, cairo_surface_write_to_png, _cairo_boilerplate_xcb_cleanup, |