[cairo-commit] 2 commits - boilerplate/cairo-boilerplate-xcb.c src/cairo-xlib-surface.c test/cairo-test.c

Chris Wilson ickle at kemper.freedesktop.org
Wed Sep 30 09:51:59 PDT 2009


 boilerplate/cairo-boilerplate-xcb.c |   51 ++++++++++++++++-----
 src/cairo-xlib-surface.c            |    2 
 test/cairo-test.c                   |   86 ++++++++++++++++++------------------
 3 files changed, 84 insertions(+), 55 deletions(-)

New commits:
commit 8e4e0aa7ee5b4e0963409cda825705a09aae61e1
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Sep 30 17:50:09 2009 +0100

    [boilerplate/xcb] Check for connection errors during test

diff --git a/boilerplate/cairo-boilerplate-xcb.c b/boilerplate/cairo-boilerplate-xcb.c
index e8996fa..de71fa6 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,
diff --git a/test/cairo-test.c b/test/cairo-test.c
index 1f495af..7228865 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -1014,61 +1014,61 @@ REPEAT:
     }
 #endif
 
-    /* Skip image check for tests with no image (width,height == 0,0) */
-    if (ctx->test->width != 0 && ctx->test->height != 0) {
-	cairo_surface_t *ref_image;
-	cairo_surface_t *test_image;
-	cairo_surface_t *diff_image;
-	buffer_diff_result_t result;
-	cairo_status_t diff_status;
-
-	if (target->finish_surface != NULL) {
+    if (target->finish_surface != NULL) {
 #if HAVE_MEMFAULT
-	    /* We need to re-enable faults as most meta-surface processing
-	     * is done during cairo_surface_finish().
-	     */
-	    MEMFAULT_CLEAR_FAULTS ();
-	    last_fault_count = MEMFAULT_COUNT_FAULTS ();
-	    MEMFAULT_ENABLE_FAULTS ();
+	/* We need to re-enable faults as most meta-surface processing
+	 * is done during cairo_surface_finish().
+	 */
+	MEMFAULT_CLEAR_FAULTS ();
+	last_fault_count = MEMFAULT_COUNT_FAULTS ();
+	MEMFAULT_ENABLE_FAULTS ();
 #endif
 
-	    /* also check for infinite loops whilst replaying */
-	    alarm (ctx->timeout);
-	    diff_status = target->finish_surface (surface);
-	    alarm (0);
+	/* also check for infinite loops whilst replaying */
+	alarm (ctx->timeout);
+	status = target->finish_surface (surface);
+	alarm (0);
 
 #if HAVE_MEMFAULT
-	    MEMFAULT_DISABLE_FAULTS ();
+	MEMFAULT_DISABLE_FAULTS ();
 
-	    if (ctx->malloc_failure &&
-		MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
-		diff_status == CAIRO_STATUS_NO_MEMORY)
-	    {
-		cairo_destroy (cr);
-		cairo_surface_destroy (surface);
-		if (target->cleanup)
-		    target->cleanup (closure);
-		if (ctx->thread == 0) {
-		    cairo_debug_reset_static_data ();
+	if (ctx->malloc_failure &&
+	    MEMFAULT_COUNT_FAULTS () - last_fault_count > 0 &&
+	    status == CAIRO_STATUS_NO_MEMORY)
+	{
+	    cairo_destroy (cr);
+	    cairo_surface_destroy (surface);
+	    if (target->cleanup)
+		target->cleanup (closure);
+	    if (ctx->thread == 0) {
+		cairo_debug_reset_static_data ();
 #if HAVE_FCFINI
-		    FcFini ();
+		FcFini ();
 #endif
-		    if (MEMFAULT_COUNT_LEAKS () > 0) {
-			MEMFAULT_PRINT_FAULTS ();
-			MEMFAULT_PRINT_LEAKS ();
-		    }
+		if (MEMFAULT_COUNT_LEAKS () > 0) {
+		    MEMFAULT_PRINT_FAULTS ();
+		    MEMFAULT_PRINT_LEAKS ();
 		}
-
-		goto REPEAT;
 	    }
+
+	    goto REPEAT;
+	}
 #endif
-	    if (diff_status) {
-		cairo_test_log (ctx, "Error: Failed to finish surface: %s\n",
-				cairo_status_to_string (diff_status));
-		ret = CAIRO_TEST_FAILURE;
-		goto UNWIND_CAIRO;
-	    }
+	if (status) {
+	    cairo_test_log (ctx, "Error: Failed to finish surface: %s\n",
+			    cairo_status_to_string (status));
+	    ret = CAIRO_TEST_FAILURE;
+	    goto UNWIND_CAIRO;
 	}
+    }
+
+    /* Skip image check for tests with no image (width,height == 0,0) */
+    if (ctx->test->width != 0 && ctx->test->height != 0) {
+	cairo_surface_t *ref_image;
+	cairo_surface_t *test_image;
+	cairo_surface_t *diff_image;
+	buffer_diff_result_t result;
+	cairo_status_t diff_status;
 
 	if (ref_png_path == NULL) {
 	    cairo_test_log (ctx, "Error: Cannot find reference image for %s\n",
commit 395555b116a497c99b9e8365a202377c344c0c45
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Sep 30 00:37:36 2009 +0100

    [xlib] Suppress warning that should never have been.

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 66311ea..81f2ec3 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -101,7 +101,7 @@ _x_bread_crumb (Display *dpy,
 }
 #define X_DEBUG(x) _x_bread_crumb x
 #else
-#define X_DEBUG
+#define X_DEBUG(x)
 #endif
 
 /* Xlib doesn't define a typedef, so define one ourselves */


More information about the cairo-commit mailing list