[cairo-commit] 10 commits - src/cairo-xlib-surface.c test/cairo-test.c test/get-xrender-format.c test/.gitignore test/glitz-surface-source.c test/large-source.c test/large-source-ref.c test/Makefile.am test/stroke-image.c test/surface-source.c test/xlib-surface.c

Chris Wilson ickle at kemper.freedesktop.org
Mon Apr 7 23:59:49 PDT 2008


 src/cairo-xlib-surface.c    |   29 ++--------
 test/.gitignore             |    1 
 test/Makefile.am            |    3 +
 test/cairo-test.c           |  119 ++++++++++++++++++++++++++++++++++++++------
 test/get-xrender-format.c   |    3 +
 test/glitz-surface-source.c |   15 +++--
 test/large-source-ref.c     |binary
 test/large-source.c         |  109 ++++++++++++++++++++++++++++++++++++++++
 test/stroke-image.c         |    3 -
 test/surface-source.c       |    8 ++
 test/xlib-surface.c         |   87 ++++++++++++++++++++++++++++++--
 11 files changed, 329 insertions(+), 48 deletions(-)

New commits:
commit 33c54ed240b319acb28ef370eef5188ad42a5737
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 22:14:04 2008 +0100

    [test] Add large-source to exercise handling of massive images.
    
    This test exercises https://bugzilla.mozilla.org/show_bug.cgi?id=424333.
    
    The test is expected to fail due to issues with pixman, but cairo
    should fail gracefully and neither crash nor cause XErrors.

diff --git a/test/.gitignore b/test/.gitignore
index 564a8ed..9d2587b 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -90,6 +90,7 @@ infinite-join
 in-fill-empty-trapezoid
 in-fill-trapezoid
 invalid-matrix
+large-source
 leaky-dash
 leaky-polygon
 line-width
diff --git a/test/Makefile.am b/test/Makefile.am
index 8a38df0..faf82f0 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -69,6 +69,7 @@ infinite-join$(EXEEXT)					\
 in-fill-empty-trapezoid$(EXEEXT)			\
 in-fill-trapezoid$(EXEEXT)				\
 invalid-matrix$(EXEEXT)					\
+large-source$(EXEEXT)					\
 leaky-dash$(EXEEXT)					\
 leaky-polygon$(EXEEXT)					\
 line-width$(EXEEXT)					\
@@ -427,6 +428,7 @@ REFERENCE_IMAGES = \
 	image-surface-source-ref.png \
 	infinite-join-ref.png	\
 	infinite-join-ps-ref.png	\
+	large-source-ref.png	\
 	leaky-dash-ps-argb32-ref.png	\
 	leaky-dash-ps-rgb24-ref.png	\
 	leaky-dash-quartz-ref.png	\
@@ -708,6 +710,7 @@ big-trap$(EXEEXT)				\
 extend-pad$(EXEEXT)				\
 filter-nearest-offset$(EXEEXT)			\
 filter-bilinear-extents$(EXEEXT)		\
+large-source$(EXEEXT)				\
 long-lines$(EXEEXT)				\
 self-intersecting$(EXEEXT)			\
 surface-pattern$(EXEEXT)			\
diff --git a/test/large-source-ref.c b/test/large-source-ref.c
new file mode 100644
index 0000000..5d96dd3
Binary files /dev/null and b/test/large-source-ref.c differ
diff --git a/test/large-source.c b/test/large-source.c
new file mode 100644
index 0000000..c4781d0
--- /dev/null
+++ b/test/large-source.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright © Chris Wilson, 2008
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Chris Wilson not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Chris Wilson makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+/* This is a test case for the following bug:
+ *
+ *	crafted gif file will crash firefox
+ *	[XError: 'BadAlloc (insufficient resources for operation)']
+ *	https://bugzilla.mozilla.org/show_bug.cgi?id=424333
+ *
+ * The output is currently marked as XFAIL as pixman is still limited
+ * to 16.16.
+ */
+
+static cairo_test_draw_function_t draw;
+
+cairo_test_t test = {
+    "large-source",
+    "Exercises mozilla bug 424333 - handling of massive images",
+    20, 20,
+    draw
+};
+
+#ifdef WORDS_BIGENDIAN
+#define RED_MASK 0xA0
+#define GREEN_MASK 0xA
+#else
+#define RED_MASK 0x5
+#define GREEN_MASK 0x50
+#endif
+
+static cairo_test_status_t
+draw (cairo_t *cr, int width, int height)
+{
+    cairo_surface_t *surface;
+    unsigned char *data;
+
+    cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
+    cairo_paint (cr);
+
+    surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 64000, 20);
+    data = cairo_image_surface_get_data (surface);
+    if (data != NULL) {
+	int stride = cairo_image_surface_get_stride (surface);
+	int width  = cairo_image_surface_get_width  (surface);
+	int height = cairo_image_surface_get_height (surface);
+	int x, y;
+
+	for (y = 0; y < height; y++) {
+	    for (x = 0; x < (width + 7) / 8; x++)
+		data[x] = RED_MASK;
+	    data += stride;
+	}
+    }
+
+    cairo_set_source_rgb (cr, 1, 0, 0); /* red */
+    cairo_mask_surface (cr, surface, 0, 0);
+    cairo_surface_destroy (surface);
+
+    surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 20, 64000);
+    data = cairo_image_surface_get_data (surface);
+    if (data != NULL) {
+	int stride = cairo_image_surface_get_stride (surface);
+	int width  = cairo_image_surface_get_width  (surface);
+	int height = cairo_image_surface_get_height (surface);
+	int x, y;
+
+	for (y = 0; y < height; y++) {
+	    for (x = 0; x < (width + 7) / 8; x++)
+		data[x] = GREEN_MASK;
+	    data += stride;
+	}
+    }
+
+    cairo_set_source_rgb (cr, 0, 1, 0); /* green */
+    cairo_mask_surface (cr, surface, 0, 0);
+    cairo_surface_destroy (surface);
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+    return cairo_test (&test);
+}
commit 4924d4d928666981f3e64bec685e8f90e524e62e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 23:48:36 2008 +0100

    [cairo-xlib] Do not create surface with mismatching Visual and PictFormat.
    
    As identified by Vladimir Vukicevic,
    _cairo_xlib_surface_create_similar_with_format() was erroneously passing
    down the source Visual when creating a surface with a different
    XRenderPictFormat.

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index bc5aa1a..acb51c5 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -162,7 +162,7 @@ _cairo_xlib_surface_create_similar_with_format (void	       *abstract_src,
 
     surface = (cairo_xlib_surface_t *)
 	      _cairo_xlib_surface_create_internal (dpy, pix,
-		                                   src->screen, src->visual,
+		                                   src->screen, NULL,
 						   xrender_format,
 						   width, height,
 						   xrender_format->depth);
commit 9aac5916bcb4a3e62194315b12961d97f193a585
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 23:42:47 2008 +0100

    [test/xlib-surface] Check for mismatching Visuals and XRenderPictFormats
    
    Vladimir Vukicevic reported that surfaces were being created with
    mismatching Visuals and XRenderPictFormats - and demonstated here.

diff --git a/test/xlib-surface.c b/test/xlib-surface.c
index deb2889..eda085f 100644
--- a/test/xlib-surface.c
+++ b/test/xlib-surface.c
@@ -39,6 +39,63 @@
 
 cairo_bool_t result = 0;
 
+#if CAIRO_HAS_XLIB_XRENDER_SURFACE
+
+#include "cairo-xlib-xrender.h"
+
+/* Vladimir Vukicevic reported that surfaces were being created with
+ * mismatching Visuals and XRenderPictFormats.
+ */
+static cairo_bool_t
+surface_compare_visual_and_format (cairo_surface_t *surface)
+{
+    Display *dpy;
+    Visual *visual;
+    XRenderPictFormat *format;
+
+    dpy = cairo_xlib_surface_get_display (surface);
+
+    visual = cairo_xlib_surface_get_visual (surface);
+    if (visual == NULL)
+	return TRUE;
+
+    format = cairo_xlib_surface_get_xrender_format (surface);
+    if (format == NULL)
+	return TRUE;
+
+    return format == XRenderFindVisualFormat (dpy, visual);
+
+}
+#else
+
+static cairo_bool_t
+surface_compare_visual_and_format (cairo_surface_t *surface)
+{
+    return TRUE;
+}
+
+#endif
+
+static cairo_bool_t
+check_similar_visual_and_format (cairo_surface_t *surface)
+{
+    cairo_surface_t *similar;
+    cairo_bool_t ret;
+
+    similar = cairo_surface_create_similar (surface,
+	                                    CAIRO_CONTENT_COLOR_ALPHA,
+					    1, 1);
+    if (cairo_surface_status (similar))
+	return FALSE;
+
+    ret = surface_compare_visual_and_format (similar);
+
+    cairo_surface_destroy (similar);
+
+    return ret;
+}
+
+
 static void
 draw_pattern (cairo_surface_t *surface)
 {
@@ -123,6 +180,9 @@ do_test (Display        *dpy,
 					 DefaultVisual (dpy, screen),
 					 SIZE, SIZE);
 
+    if (! surface_compare_visual_and_format (surface))
+	return CAIRO_TEST_FAILURE;
+
     if (!use_render)
 	cairo_boilerplate_xlib_surface_disable_render (surface);
 
@@ -134,6 +194,9 @@ do_test (Display        *dpy,
 	    return CAIRO_TEST_FAILURE;
     }
 
+    if (! check_similar_visual_and_format (surface))
+	return CAIRO_TEST_FAILURE;
+
     draw_pattern (surface);
 
     test_surface = cairo_image_surface_create_for_data (test_data,
commit f6afba8f5453b8e3af9101fa2cde4c05a67f6d4b
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 23:25:57 2008 +0100

    [cairo-xlib] Create Pixmap using depth from xrender_format.
    
    Use the depth as specified by the xrender_format when creating the
    pixmap (as opposed to a guess based on the cairo_format_t).

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 90cfc8a..bc5aa1a 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -117,22 +117,6 @@ static const XTransform identity = { {
 #define CAIRO_SURFACE_RENDER_HAS_PICTURE_TRANSFORM(surface)	CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 6)
 #define CAIRO_SURFACE_RENDER_HAS_FILTERS(surface)	CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 6)
 
-static int
-_CAIRO_FORMAT_DEPTH (cairo_format_t format)
-{
-    switch (format) {
-    case CAIRO_FORMAT_A1:
-	return 1;
-    case CAIRO_FORMAT_A8:
-	return 8;
-    case CAIRO_FORMAT_RGB24:
-	return 24;
-    case CAIRO_FORMAT_ARGB32:
-    default:
-	return 32;
-    }
-}
-
 static XRenderPictFormat *
 _CAIRO_FORMAT_TO_XRENDER_FORMAT(Display *dpy, cairo_format_t format)
 {
@@ -161,7 +145,6 @@ _cairo_xlib_surface_create_similar_with_format (void	       *abstract_src,
     Display *dpy = src->dpy;
     Pixmap pix;
     cairo_xlib_surface_t *surface;
-    int depth = _CAIRO_FORMAT_DEPTH (format);
     XRenderPictFormat *xrender_format = _CAIRO_FORMAT_TO_XRENDER_FORMAT (dpy,
 									 format);
 
@@ -175,14 +158,14 @@ _cairo_xlib_surface_create_similar_with_format (void	       *abstract_src,
 
     pix = XCreatePixmap (dpy, src->drawable,
 			 width <= 0 ? 1 : width, height <= 0 ? 1 : height,
-			 depth);
+			 xrender_format->depth);
 
     surface = (cairo_xlib_surface_t *)
 	      _cairo_xlib_surface_create_internal (dpy, pix,
 		                                   src->screen, src->visual,
 						   xrender_format,
 						   width, height,
-						   depth);
+						   xrender_format->depth);
     if (surface->base.status) {
 	XFreePixmap (dpy, pix);
 	return &surface->base;
commit 922fefdde4af28f9fc1e42fcba1b315980b01dc7
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 23:06:18 2008 +0100

    [cairo-xlib] Handle missing RENDER during similar surface creation
    
    If the xserver doesn't support the RENDER extension or simply doesn't
    have the matching PictFormat then xrender_format might be NULL. Check
    and fallback in this case.

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 48b7550..90cfc8a 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -170,9 +170,8 @@ _cairo_xlib_surface_create_similar_with_format (void	       *abstract_src,
      * using image surfaces for all temporary operations, so return NULL
      * and let the fallback code happen.
      */
-    if (!CAIRO_SURFACE_RENDER_HAS_COMPOSITE(src)) {
+    if (xrender_format == NULL || ! CAIRO_SURFACE_RENDER_HAS_COMPOSITE (src))
 	return NULL;
-    }
 
     pix = XCreatePixmap (dpy, src->drawable,
 			 width <= 0 ? 1 : width, height <= 0 ? 1 : height,
@@ -1080,6 +1079,9 @@ _cairo_xlib_surface_clone_similar (void			*abstract_surface,
 	clone = (cairo_xlib_surface_t *)
 	    _cairo_xlib_surface_create_similar_with_format (surface, image_src->format,
 						image_src->width, image_src->height);
+	if (clone == NULL)
+	    return CAIRO_INT_STATUS_UNSUPPORTED;
+
 	if (clone->base.status)
 	    return clone->base.status;
 
commit 07122e64fa9529e7ba9323988a5af1d1e7c2c55f
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 22:00:51 2008 +0100

    [test] Repeat tests using cairo_push_group().
    
    Test surfaces using similar surfaces with both CONTENT_COLOR and
    CONTENT_COLOR_ALPHA, if applicable. This seems justified by the apparent
    bugs in the pdf backend when going from an ARGB32 similar surface to
    a destination RGB24 surface as well as isolated bugs in the image
    backend.
    
    The original goal was to try and trick the test suite into producing
    a xlib surface with mismatching Visual/XRenderPictFormat. This succeeds,
    although with a little bit of brute force in the xlib backend, but the
    search to reproduce a BadMatch error fruitless.

diff --git a/test/cairo-test.c b/test/cairo-test.c
index 61cbb31..c4a8aba 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -226,8 +226,40 @@ cairo_test_target_has_similar (const cairo_test_t *test, cairo_boilerplate_targe
     cairo_surface_t *surface;
     cairo_bool_t has_similar = FALSE;
 
-    /* ignore image intermediate targets */
-    if (target->expected_type == CAIRO_SURFACE_TYPE_IMAGE)
+    if (getenv ("CAIRO_TEST_IGNORE_SIMILAR"))
+	return FALSE;
+
+    surface = (target->create_surface) (test->name,
+					target->content,
+					test->width,
+					test->height,
+					CAIRO_BOILERPLATE_MODE_TEST,
+					&target->closure);
+    if (surface != NULL) {
+	cairo_t * cr = cairo_create (surface);
+	cairo_surface_t *similar;
+
+	cairo_push_group_with_content (cr, target->content);
+	similar = cairo_get_group_target (cr);
+	has_similar = cairo_surface_get_type (similar) == cairo_surface_get_type (surface);
+
+	cairo_destroy (cr);
+	cairo_surface_destroy (surface);
+
+	if (target->cleanup)
+	    target->cleanup (target->closure);
+    }
+
+    return has_similar;
+}
+
+static cairo_bool_t
+cairo_test_target_has_similar_alpha (const cairo_test_t *test, cairo_boilerplate_target_t *target)
+{
+    cairo_surface_t *surface;
+    cairo_bool_t has_similar = FALSE;
+
+    if (target->content == CAIRO_CONTENT_COLOR_ALPHA) /* already handled */
 	return FALSE;
 
     if (getenv ("CAIRO_TEST_IGNORE_SIMILAR"))
@@ -242,7 +274,8 @@ cairo_test_target_has_similar (const cairo_test_t *test, cairo_boilerplate_targe
     if (surface != NULL) {
 	cairo_t * cr = cairo_create (surface);
 	cairo_surface_t *similar;
-	cairo_push_group_with_content (cr, target->content);
+
+	cairo_push_group (cr);
 	similar = cairo_get_group_target (cr);
 	has_similar = cairo_surface_get_type (similar) == cairo_surface_get_type (surface);
 
@@ -260,7 +293,7 @@ static cairo_test_status_t
 cairo_test_for_target (cairo_test_t			 *test,
 		       cairo_boilerplate_target_t	 *target,
 		       int				  dev_offset,
-		       cairo_bool_t                       similar)
+		       int				  similar)
 {
     cairo_test_status_t status;
     cairo_surface_t *surface = NULL;
@@ -270,6 +303,7 @@ cairo_test_for_target (cairo_test_t			 *test,
     cairo_content_t expected_content;
     cairo_font_options_t *font_options;
     const char *format;
+    const char *similar_str;
 
     /* Get the strings ready that we'll need. */
     format = cairo_boilerplate_content_name (target->content);
@@ -278,18 +312,25 @@ cairo_test_for_target (cairo_test_t			 *test,
     else
 	offset_str = strdup("");
 
+    switch (similar) {
+    default:
+    case 0: similar_str = ""; break;
+    case 1: similar_str = "-similar"; break;
+    case 2: similar_str = "-similar+"; break;
+    }
+
     xasprintf (&png_name, "%s-%s-%s%s%s%s",
 	       test->name,
 	       target->name,
 	       format,
-	       similar ? "-similar" : "",
+	       similar_str,
 	       offset_str, CAIRO_TEST_PNG_SUFFIX);
     ref_name = cairo_ref_name_for_test_target_format (test->name, target->name, format);
     xasprintf (&diff_name, "%s-%s-%s%s%s%s",
 	       test->name,
 	       target->name,
 	       format,
-	       similar ? "-similar" : "",
+	       similar_str,
 	       offset_str, CAIRO_TEST_DIFF_SUFFIX);
 
     if (target->is_vector) {
@@ -356,8 +397,19 @@ cairo_test_for_target (cairo_test_t			 *test,
     cairo_surface_set_device_offset (surface, dev_offset, dev_offset);
 
     cr = cairo_create (surface);
-    if (similar)
+    switch (similar) {
+    default:
+    case 0:
+	break;
+
+    case 1:
 	cairo_push_group_with_content (cr, target->content);
+	break;
+
+    case 2:
+	cairo_push_group (cr);
+	break;
+    }
 
     /* Clear to transparent (or black) depending on whether the target
      * surface supports alpha. */
@@ -476,7 +528,7 @@ cairo_test_expecting (cairo_test_t *test,
 {
     /* we use volatile here to make sure values are not clobbered
      * by longjmp */
-    volatile size_t i, j, num_targets, similar, has_similar;
+    volatile size_t i, j, num_targets, similar;
     volatile cairo_bool_t limited_targets = FALSE, print_fail_on_stdout = TRUE;
 #ifdef HAVE_SIGNAL_H
     void (*old_segfault_handler)(int);
@@ -531,16 +583,47 @@ cairo_test_expecting (cairo_test_t *test,
      */
     status = ret = CAIRO_TEST_UNTESTED;
     for (i = 0; i < num_targets; i++) {
+	cairo_boilerplate_target_t * volatile target = targets_to_test[i];
+	volatile cairo_bool_t has_similar = cairo_test_target_has_similar (test, target);
+	volatile cairo_bool_t has_similar_alpha = cairo_test_target_has_similar_alpha (test, target);
+
 	for (j = 0; j < NUM_DEVICE_OFFSETS; j++) {
-	    cairo_boilerplate_target_t * volatile target = targets_to_test[i];
 	    volatile int dev_offset = j * 25;
-	    has_similar = cairo_test_target_has_similar (test, target);
-	    for (similar = 0; similar <= has_similar ; similar++) {
-		cairo_test_log ("Testing %s with %s%s target (dev offset %d)\n", test->name, similar ? " (similar)" : "", target->name, dev_offset);
-		printf ("%s-%s-%s [%d]%s:\t", test->name, target->name,
+
+	    for (similar = 0; similar <= 2; similar++) {
+		const char * volatile similar_str;
+		cairo_bool_t skip;
+
+		switch (similar) {
+		default:
+		case 0:
+		    similar_str = "";
+		    skip = FALSE;
+		    break;
+
+		case 1:
+		    similar_str = "-similar";
+		    skip = ! has_similar;
+		    break;
+
+		case 2:
+		    similar_str = "-similar+";
+		    skip = ! has_similar_alpha;
+		    break;
+		}
+		if (skip)
+		    continue;
+
+		cairo_test_log ("Testing %s with %s%s target (dev offset %d)\n",
+			        test->name,
+				similar_str,
+				target->name,
+				dev_offset);
+		printf ("%s-%s-%s [%d]%s:\t",
+			test->name, target->name,
 			cairo_boilerplate_content_name (target->content),
 			dev_offset,
-			similar ? " (similar)": "");
+			similar_str);
 
 #ifdef HAVE_SIGNAL_H
 		/* Set up a checkpoint to get back to in case of segfaults. */
@@ -581,7 +664,9 @@ cairo_test_expecting (cairo_test_t *test,
 		    cairo_test_log ("CRASHED\n");
 		    fprintf (stderr, "%s-%s-%s [%d]%s:\t%s!!!CRASHED!!!%s\n",
 			     test->name, target->name,
-			     cairo_boilerplate_content_name (target->content), dev_offset, similar ? " (similar)" : "",
+			     cairo_boilerplate_content_name (target->content),
+			     dev_offset,
+			     similar_str,
 			     fail_face, normal_face);
 		    ret = CAIRO_TEST_FAILURE;
 		    break;
@@ -600,7 +685,9 @@ cairo_test_expecting (cairo_test_t *test,
 			}
 			fprintf (stderr, "%s-%s-%s [%d]%s:\t%sFAIL%s\n",
 				 test->name, target->name,
-				 cairo_boilerplate_content_name (target->content), dev_offset, similar ? " (similar)" : "",
+				 cairo_boilerplate_content_name (target->content),
+				 dev_offset,
+				 similar_str,
 				 fail_face, normal_face);
 			cairo_test_log ("FAIL\n");
 		    }
commit e04e4262386b8735d2ceabbc187405cace89dc80
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 10:56:38 2008 +0100

    [test/get-xrender-format] Free static data on exit.
    
    Free the internal caches so that valgrind reports zero leaks.

diff --git a/test/get-xrender-format.c b/test/get-xrender-format.c
index 0c9ce9a..6678249 100644
--- a/test/get-xrender-format.c
+++ b/test/get-xrender-format.c
@@ -106,9 +106,12 @@ main (void)
 	return CAIRO_TEST_FAILURE;
     }
 
+    cairo_surface_destroy (surface);
 
     XCloseDisplay (dpy);
 
+    cairo_debug_reset_static_data ();
+
     cairo_test_fini ();
 
     return CAIRO_TEST_SUCCESS;
commit e57ef66fab7cb05b84175b3cfb5c032150cfa682
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 10:51:27 2008 +0100

    [test/xlib-surface] Zero pixel buffers before use.
    
    As we only use RGB24 surface data the alpha channel is undefined, so
    zero it to prevent valgrind warnings.

diff --git a/test/xlib-surface.c b/test/xlib-surface.c
index d958349..deb2889 100644
--- a/test/xlib-surface.c
+++ b/test/xlib-surface.c
@@ -210,6 +210,19 @@ check_visual (Display *dpy)
 	return 0;
 }
 
+#undef xcalloc
+static void *
+xcalloc (size_t a, size_t b)
+{
+    void *ptr = calloc (a, b);
+    if (ptr == NULL) {
+	cairo_test_log ("xlib-surface: unable to allocate memory, skipping\n");
+	cairo_test_fini ();
+	exit (0);
+    }
+    return ptr;
+}
+
 int
 main (void)
 {
@@ -222,6 +235,7 @@ main (void)
     cairo_bool_t set_size;
     cairo_bool_t offscreen;
     cairo_test_status_t status, result = CAIRO_TEST_SUCCESS;
+    int stride;
 
     cairo_test_init ("xlib-surface");
 
@@ -238,14 +252,16 @@ main (void)
 	return 0;
     }
 
-    reference_data = malloc (SIZE * SIZE * 4);
-    test_data = malloc (SIZE * SIZE * 4);
-    diff_data = malloc (SIZE * SIZE * 4);
+    stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, SIZE);
+
+    reference_data = xcalloc (SIZE, stride);
+    test_data = xcalloc (SIZE, stride);
+    diff_data = xcalloc (SIZE, stride);
 
     reference_surface = cairo_image_surface_create_for_data (reference_data,
 							     CAIRO_FORMAT_RGB24,
 							     SIZE, SIZE,
-							     SIZE * 4);
+							     stride);
 
     draw_pattern (reference_surface);
     cairo_surface_destroy (reference_surface);
commit d0672e85ef120a4e3cd0dfcbdb717afbf9526f17
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 10:42:57 2008 +0100

    [test/surface-source] Skip tests if we cannot create the source surface.
    
    Check that the test environment supports the desired source and avoid
    triggering asserts in the test routines.

diff --git a/test/glitz-surface-source.c b/test/glitz-surface-source.c
index d70940a..2dfa735 100644
--- a/test/glitz-surface-source.c
+++ b/test/glitz-surface-source.c
@@ -28,8 +28,6 @@
 #include <cairo-xlib.h>
 #include <cairo-xlib-xrender.h>
 
-#include <assert.h>
-
 #define NAME "glitz"
 #include "surface-source.c"
 
@@ -174,18 +172,25 @@ static cairo_surface_t *
 create_source_surface (int size)
 {
     struct closure *closure;
-    glitz_surface_t  * glitz_surface;
+    glitz_surface_t  *glitz_surface;
     cairo_surface_t *surface;
 
     closure = xcalloc (1, sizeof (struct closure));
 
     closure->dpy = XOpenDisplay (getenv("CAIRO_TEST_GLITZ_DISPLAY"));
-    assert (closure->dpy);
+    if (closure->dpy == NULL) {
+	free (closure);
+	return NULL;
+    }
 
     glitz_surface = _glitz_glx_create_surface (GLITZ_STANDARD_ARGB32,
 					       size, size,
 					       closure);
-    assert (glitz_surface != NULL);
+    if (glitz_surface == NULL) {
+	XCloseDisplay (closure->dpy);
+	free (closure);
+	return NULL;
+    }
 
     surface = cairo_glitz_surface_create (glitz_surface);
 
diff --git a/test/surface-source.c b/test/surface-source.c
index c7f3334..5a034ad 100644
--- a/test/surface-source.c
+++ b/test/surface-source.c
@@ -89,5 +89,13 @@ draw (cairo_t *cr, int width, int height)
 int
 main (void)
 {
+    cairo_surface_t *surface;
+
+    surface = create_source_surface (SIZE);
+    if (surface == NULL) /* can't create the source so skip the test */
+	return CAIRO_TEST_SUCCESS;
+
+    cairo_surface_destroy (surface);
+
     return cairo_test (&test);
 }
commit 056d3c853e6660db31ee4a50d0e990a6013aa703
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 7 10:35:04 2008 +0100

    [test/stroke-image] Fix memleak.
    
    Release the temporary image surface after setting it as the source.

diff --git a/test/stroke-image.c b/test/stroke-image.c
index 464d7af..20b868c 100644
--- a/test/stroke-image.c
+++ b/test/stroke-image.c
@@ -61,12 +61,13 @@ draw (cairo_t *cr, int width, int height)
     cairo_translate (cr, PAD, PAD);
 
     cairo_set_source_surface (cr, isurf, 0, 0);
+    cairo_surface_destroy (isurf);
 
     cairo_new_path (cr);
     cairo_set_line_width (cr, LINE_WIDTH);
     cairo_arc (cr, IMAGE_SIZE/2, IMAGE_SIZE/2, IMAGE_SIZE/2 - LINE_WIDTH/2, 0, M_PI * 2.0);
     cairo_stroke (cr);
-    
+
     return CAIRO_TEST_SUCCESS;
 }
 


More information about the cairo-commit mailing list