[cairo-commit] boilerplate/cairo-boilerplate.c boilerplate/cairo-boilerplate.h test/cairo-test.c

Carl Worth cworth at kemper.freedesktop.org
Tue Sep 5 22:25:26 PDT 2006


 boilerplate/cairo-boilerplate.c |   68 ++++++++++++++++++++++------------------
 boilerplate/cairo-boilerplate.h |    1 
 test/cairo-test.c               |   40 -----------------------
 3 files changed, 40 insertions(+), 69 deletions(-)

New commits:
diff-tree bcb7863f00b4cfdf0985993067fc32d07b81540b (from 4620b929ae84dfa08c1c9a4072e114f6b38e1bd9)
Author: Carl Worth <cworth at cworth.org>
Date:   Tue Sep 5 22:25:21 2006 -0700

    Move target tolerance to cairo_test_target structure (should let single-pixel SVG errors pass)
    
    Previously we were setting the target tolerance based on the surface
    type. But that doesn't work as multiple backends will provide a surface
    of type meta. So instead we put the tolerance as a value in the
    cairo_test_target data structure.
    
    With this change, some single-pixel errors of 1 in the SVG backend
    should now be ignored.

diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index 3026e63..8f2df72 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -1342,82 +1342,85 @@ cleanup_svg (void *closure)
 
 cairo_test_target_t targets[] =
 {
-    { "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR_ALPHA,
+    /* I'm uncompromising about leaving the image backend as 0
+     * for tolerance. There shouldn't ever be anything that is out of
+     * our control here. */
+    { "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_image_surface, cairo_surface_write_to_png, NULL},
-    { "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR,
+    { "image", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
       create_image_surface, cairo_surface_write_to_png, NULL},
 #ifdef CAIRO_HAS_TEST_SURFACES
     { "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
-      CAIRO_CONTENT_COLOR_ALPHA,
+      CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_test_fallback_surface, cairo_surface_write_to_png, NULL },
     { "test-fallback", CAIRO_INTERNAL_SURFACE_TYPE_TEST_FALLBACK,
-      CAIRO_CONTENT_COLOR,
+      CAIRO_CONTENT_COLOR, 0,
       create_test_fallback_surface, cairo_surface_write_to_png, NULL },
     { "test-meta", CAIRO_INTERNAL_SURFACE_TYPE_TEST_META,
-      CAIRO_CONTENT_COLOR_ALPHA,
+      CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_test_meta_surface, cairo_surface_write_to_png, NULL },
     { "test-meta", CAIRO_INTERNAL_SURFACE_TYPE_TEST_META,
-      CAIRO_CONTENT_COLOR,
+      CAIRO_CONTENT_COLOR, 0,
       create_test_meta_surface, cairo_surface_write_to_png, NULL },
     { "test-paginated", CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
-      CAIRO_CONTENT_COLOR_ALPHA,
+      CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_test_paginated_surface,
       test_paginated_write_to_png,
       cleanup_test_paginated },
     { "test-paginated", CAIRO_INTERNAL_SURFACE_TYPE_TEST_PAGINATED,
-      CAIRO_CONTENT_COLOR,
+      CAIRO_CONTENT_COLOR, 0,
       create_test_paginated_surface,
       test_paginated_write_to_png,
       cleanup_test_paginated },
 #endif
 #ifdef CAIRO_HAS_GLITZ_SURFACE
 #if CAIRO_CAN_TEST_GLITZ_GLX_SURFACE
-    { "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ,CAIRO_CONTENT_COLOR_ALPHA,
+    { "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ,CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_cairo_glitz_glx_surface, cairo_surface_write_to_png,
       cleanup_cairo_glitz_glx },
-    { "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR,
+    { "glitz-glx", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
       create_cairo_glitz_glx_surface, cairo_surface_write_to_png,
       cleanup_cairo_glitz_glx },
 #endif
 #if CAIRO_CAN_TEST_GLITZ_AGL_SURFACE
-    { "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA,
+    { "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_cairo_glitz_agl_surface, cairo_surface_write_to_png,
       cleanup_cairo_glitz_agl },
-    { "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR,
+    { "glitz-agl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
       create_cairo_glitz_agl_surface, cairo_surface_write_to_png,
       cleanup_cairo_glitz_agl },
 #endif
 #if CAIRO_CAN_TEST_GLITZ_WGL_SURFACE
-    { "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA,
+    { "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_cairo_glitz_wgl_surface, cairo_surface_write_to_png,
       cleanup_cairo_glitz_wgl },
-    { "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR,
+    { "glitz-wgl", CAIRO_SURFACE_TYPE_GLITZ, CAIRO_CONTENT_COLOR, 0,
       create_cairo_glitz_wgl_surface, cairo_surface_write_to_png,
       cleanup_cairo_glitz_wgl },
 #endif
 #endif /* CAIRO_HAS_GLITZ_SURFACE */
 #if 0 && CAIRO_HAS_QUARTZ_SURFACE
-    { "quartz", CAIRO_SURFACE_TYPE_QUARTZ, CAIRO_CONTENT_COLOR,
+    { "quartz", CAIRO_SURFACE_TYPE_QUARTZ, CAIRO_CONTENT_COLOR, 0,
       create_quartz_surface, cairo_surface_write_to_png,
       cleanup_quartz },
 #endif
 #if CAIRO_HAS_WIN32_SURFACE
-    { "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR,
+    { "win32", CAIRO_SURFACE_TYPE_WIN32, CAIRO_CONTENT_COLOR, 0,
       create_win32_surface, cairo_surface_write_to_png, cleanup_win32 },
 #endif
 #if CAIRO_HAS_XCB_SURFACE
-    { "xcb", CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA,
+    { "xcb", CAIRO_SURFACE_TYPE_XCB, CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_xcb_surface, cairo_surface_write_to_png, cleanup_xcb},
 #endif
 #if CAIRO_HAS_XLIB_SURFACE
-    { "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR_ALPHA,
+    { "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_xlib_surface, cairo_surface_write_to_png, cleanup_xlib},
-    { "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR,
+    { "xlib", CAIRO_SURFACE_TYPE_XLIB, CAIRO_CONTENT_COLOR, 0,
       create_xlib_surface, cairo_surface_write_to_png, cleanup_xlib},
 #endif
 #if CAIRO_HAS_PS_SURFACE
     { "ps", CAIRO_SURFACE_TYPE_PS,
-      CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED,
+      CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
       create_ps_surface, ps_surface_write_to_png, cleanup_ps },
 
     /* XXX: We expect type image here only due to a limitation in
@@ -1428,12 +1431,12 @@ cairo_test_target_t targets[] =
      * have source support for PS/meta-surfaces, so the
      * create_similar path for all paginated surfaces currently
      * returns an image surface.*/
-    { "ps", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR,
+    { "ps", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
       create_ps_surface, ps_surface_write_to_png, cleanup_ps },
 #endif
 #if CAIRO_HAS_PDF_SURFACE && CAIRO_CAN_TEST_PDF_SURFACE
     { "pdf", CAIRO_SURFACE_TYPE_PDF,
-      CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED,
+      CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED, 0,
       create_pdf_surface, pdf_surface_write_to_png, cleanup_pdf },
 
     /* XXX: We expect type image here only due to a limitation in
@@ -1444,28 +1447,33 @@ cairo_test_target_t targets[] =
      * have source support for PDF/meta-surfaces, so the
      * create_similar path for all paginated surfaces currently
      * returns an image surface.*/
-    { "pdf", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR,
+    { "pdf", CAIRO_SURFACE_TYPE_IMAGE, CAIRO_CONTENT_COLOR, 0,
       create_pdf_surface, pdf_surface_write_to_png, cleanup_pdf },
 #endif
 #if CAIRO_HAS_SVG_SURFACE && CAIRO_CAN_TEST_SVG_SURFACE
-    { "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR_ALPHA,
+    /* It seems we should be able to round-trip SVG content perfrectly
+     * through librsvg and cairo, but for some mysterious reason, some
+     * systems get an error of 1 for some pixels on some of the text
+     * tests. XXX: I'd still like to chase these down at some point.
+     * For now just set teh svg error tolerance to 1. */
+    { "svg", CAIRO_SURFACE_TYPE_SVG, CAIRO_CONTENT_COLOR_ALPHA, 1,
       create_svg_surface, svg_surface_write_to_png, cleanup_svg },
-    { "svg", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR,
+    { "svg", CAIRO_INTERNAL_SURFACE_TYPE_META, CAIRO_CONTENT_COLOR, 1,
       create_svg_surface, svg_surface_write_to_png, cleanup_svg },
 #endif
 #if CAIRO_HAS_BEOS_SURFACE
-    { "beos", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR,
+    { "beos", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, 0,
       create_beos_surface, cairo_surface_write_to_png, cleanup_beos},
-    { "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR,
+    { "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR, 0,
       create_beos_bitmap_surface, cairo_surface_write_to_png, cleanup_beos_bitmap},
-    { "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR_ALPHA,
+    { "beos-bitmap", CAIRO_SURFACE_TYPE_BEOS, CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_beos_bitmap_surface, cairo_surface_write_to_png, cleanup_beos_bitmap},
 #endif
 
 #if CAIRO_HAS_DIRECTFB_SURFACE
-    { "directfb", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR,
+    { "directfb", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR, 0,
       create_directfb_surface, cairo_surface_write_to_png, cleanup_directfb},
-    { "directfb-bitmap", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR_ALPHA,
+    { "directfb-bitmap", CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR_ALPHA, 0,
       create_directfb_bitmap_surface, cairo_surface_write_to_png,cleanup_directfb},
 #endif
 
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index 4810353..ea9ccf3 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -75,6 +75,7 @@ typedef struct _cairo_test_target
     const char		       	       *name;
     cairo_surface_type_t		expected_type;
     cairo_content_t			content;
+    int					error_tolerance;
     cairo_test_create_target_surface_t	create_target_surface;
     cairo_test_write_to_png_t		write_to_png;
     cairo_test_cleanup_target_t		cleanup_target;
diff --git a/test/cairo-test.c b/test/cairo-test.c
index cceed29..a43551f 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -85,44 +85,6 @@ const char *srcdir;
  * an nonrecoverable fashion. */
 jmp_buf jmpbuf;
 
-/* What's the maximum single-channel difference we will tolerate and
- * still allow a test to pass? */
-static unsigned int
-target_tolerance (cairo_test_target_t *target)
-{
-    switch (target->expected_type) {
-    /* I'm uncompromising about leaving the image backend as no
-     * tolerance. There's shouldn't ever be anything that is out of
-     * our control here. */
-    case CAIRO_SURFACE_TYPE_IMAGE:
-	return 0;
-
-    /* It seems we should be able to round-trip SVG content perfrectly
-     * through librsvg and cairo, but for some mysterious reason, some
-     * systems get an error of 1 for some pixels on some of the text
-     * tests. XXX: I'd still like to chase these down at some point. */
-    case CAIRO_SURFACE_TYPE_SVG:
-	return 1;
-
-    /* Everything else gets the no-tolerance policy. It would actually
-     * be nice to go through some of the backends and see * if it
-     * wouldn't make sense to increase this. For example, * could we
-     * use a small value here for the PS backend and * eliminate some
-     * of the ps-specific reference images? */
-    case CAIRO_SURFACE_TYPE_PDF:
-    case CAIRO_SURFACE_TYPE_PS:
-    case CAIRO_SURFACE_TYPE_XLIB:
-    case CAIRO_SURFACE_TYPE_XCB:
-    case CAIRO_SURFACE_TYPE_GLITZ:
-    case CAIRO_SURFACE_TYPE_QUARTZ:
-    case CAIRO_SURFACE_TYPE_WIN32:
-    case CAIRO_SURFACE_TYPE_BEOS:
-    case CAIRO_SURFACE_TYPE_DIRECTFB:
-    default:
-	return 0;
-    }
-}
-
 void
 cairo_test_init (const char *test_name)
 {
@@ -365,7 +327,7 @@ cairo_test_for_target (cairo_test_t		 *t
 	if (result.pixels_changed) {
 	    cairo_test_log ("%d pixels differ (with maximum difference of %d) from reference image %s\n",
 			    result.pixels_changed, result.max_diff, ref_name);
-	    if (result.max_diff > target_tolerance (target)) {
+	    if (result.max_diff > target->error_tolerance) {
 		ret = CAIRO_TEST_FAILURE;
 		goto UNWIND_CAIRO;
 	    }


More information about the cairo-commit mailing list