[cairo-commit] test/xcomposite-projection.c

Chris Wilson ickle at kemper.freedesktop.org
Thu Nov 5 02:05:31 PST 2009


 test/xcomposite-projection.c |   69 +++++++++++++++++++++++++++++--------------
 1 file changed, 48 insertions(+), 21 deletions(-)

New commits:
commit 8a10c25c3f4036d17e24852e7dc970fa06fcb4af
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Thu Nov 5 10:02:54 2009 +0000

    test: Tweak Benjamin's xcomposite-projection
    
    Include Benjamin's advice on how to make the bug more visible inline
    with the code.

diff --git a/test/xcomposite-projection.c b/test/xcomposite-projection.c
index f36697a..cca60f5 100644
--- a/test/xcomposite-projection.c
+++ b/test/xcomposite-projection.c
@@ -6,9 +6,9 @@
  * 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
- * Kai-Uwe Behrmann not be used in advertising or publicity pertaining to
+ * Benjamin Otte not be used in advertising or publicity pertaining to
  * distribution of the software without specific, written prior
- * permission. Kai-Uwe Behrmann makes no representations about the
+ * permission. Benjamin Otte makes no representations about the
  * suitability of this software for any purpose.  It is provided "as
  * is" without express or implied warranty.
  *
@@ -25,33 +25,60 @@
 
 #include "cairo-test.h"
 
+/*
+ * Exercise a bug in the projection of a rotated trapezoid mask.
+ * I used CAIRO_ANTIALIAS_NONE and a single-color source in the test to get
+ * rid of aliasing issues in the output images. This makes some issues
+ * slightly less visible, but still fails for all of them. If you want to
+ * get a clearer view:
+ * #define ANTIALIAS CAIRO_ANTIALIAS_DEFAULT
+ */
+
+#define ANTIALIAS CAIRO_ANTIALIAS_NONE
+
 static const char png_filename[] = "romedalen.png";
 
-static cairo_surface_t *
-get_red_surface (void)
+static cairo_pattern_t *
+get_source (const cairo_test_context_t *ctx,
+	    int *width, int *height)
 {
-  cairo_surface_t *surface;
-  cairo_t *cr;
-  
-  surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 256, 192);
-  
-  cr = cairo_create (surface);
-  cairo_set_source_rgb (cr, 0.75, 0.25, 0.25);
-  cairo_paint (cr);
-  cairo_destroy (cr);
-
-  return surface;
+    cairo_surface_t *surface;
+    cairo_pattern_t *pattern;
+
+    if (ANTIALIAS == CAIRO_ANTIALIAS_NONE) {
+	cairo_t *cr;
+
+	surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 256, 192);
+	cr = cairo_create (surface);
+
+	cairo_set_source_rgb (cr, 0.75, 0.25, 0.25);
+	cairo_paint (cr);
+
+	pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
+	cairo_destroy (cr);
+    } else {
+	surface = cairo_test_create_surface_from_png (ctx, png_filename);
+	pattern = cairo_pattern_create_for_surface (surface);
+    }
+
+    *width = cairo_image_surface_get_width (surface);
+    *height = cairo_image_surface_get_height (surface);
+    cairo_surface_destroy (surface);
+
+    return pattern;
 }
 
 static cairo_test_status_t
 draw (cairo_t *cr, int width, int height)
 {
-    cairo_surface_t *image;
+    cairo_pattern_t *image;
+    int img_width, img_height;
 
-    image = get_red_surface ();
+    image = get_source (cairo_test_get_context (cr),
+			&img_width, &img_height);
 
     /* we don't want to debug antialiasing artifacts */
-    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+    cairo_set_antialias (cr, ANTIALIAS);
 
     /* dark grey background */
     cairo_set_source_rgb (cr, 0.25, 0.25, 0.25);
@@ -62,13 +89,13 @@ draw (cairo_t *cr, int width, int height)
     cairo_rotate (cr, -0.05);
 
     /* place the image on our surface */
-    cairo_set_source_surface (cr, image, 0, 0);
+    cairo_set_source (cr, image);
 
     /* paint the image */
-    cairo_rectangle (cr, 0, 0, cairo_image_surface_get_width (image), cairo_image_surface_get_height (image));
+    cairo_rectangle (cr, 0, 0, img_width, img_height);
     cairo_fill (cr);
 
-    cairo_surface_destroy (image);
+    cairo_pattern_destroy (image);
 
     return CAIRO_TEST_SUCCESS;
 }


More information about the cairo-commit mailing list