[cairo-commit] test/Makefile.refs test/Makefile.sources test/record-extend.c test/record-extend-none.ref.png test/record-extend-pad.ref.png test/record-extend-reflect.ref.png test/record-extend-repeat.ref.png

Chris Wilson ickle at kemper.freedesktop.org
Wed Aug 10 06:53:33 PDT 2011


 test/Makefile.refs                 |    4 
 test/Makefile.sources              |    1 
 test/record-extend-none.ref.png    |binary
 test/record-extend-pad.ref.png     |binary
 test/record-extend-reflect.ref.png |binary
 test/record-extend-repeat.ref.png  |binary
 test/record-extend.c               |  220 +++++++++++++++++++++++++++++++++++++
 7 files changed, 225 insertions(+)

New commits:
commit 99c129dd1302faaa1b10dca494d414a5738ddaf3
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Aug 10 14:51:25 2011 +0100

    test: Add record-extend
    
    Exercise the extend modes with a clipped paint, because once upon a time
    we had a bug...
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/test/Makefile.refs b/test/Makefile.refs
index ac5194d..bbf64dd 100644
--- a/test/Makefile.refs
+++ b/test/Makefile.refs
@@ -1010,6 +1010,10 @@ REFERENCE_IMAGES = \
 	random-intersections-nonzero.quartz.ref.png \
 	random-intersections-nonzero.ref.png \
 	random-intersections-nonzero.xlib.ref.png \
+	record-extend-none.ref.png \
+	record-extend-pad.ref.png \
+	record-extend-reflect.ref.png \
+	record-extend-repeat.ref.png \
 	record-fill-alpha.ref.png \
 	record-paint-alpha-clip-mask.ref.png \
 	record-paint-alpha-clip.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 846d67b..21e58e8 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -230,6 +230,7 @@ test_sources = \
 	random-intersections-curves-eo.c		\
 	random-intersections-curves-nz.c		\
 	record.c					\
+	record-extend.c					\
 	recording-surface-pattern.c			\
 	recording-surface-extend.c			\
 	rectangle-rounding-error.c			\
diff --git a/test/record-extend-none.ref.png b/test/record-extend-none.ref.png
new file mode 100644
index 0000000..d63c31c
Binary files /dev/null and b/test/record-extend-none.ref.png differ
diff --git a/test/record-extend-pad.ref.png b/test/record-extend-pad.ref.png
new file mode 100644
index 0000000..1291525
Binary files /dev/null and b/test/record-extend-pad.ref.png differ
diff --git a/test/record-extend-reflect.ref.png b/test/record-extend-reflect.ref.png
new file mode 100644
index 0000000..aec5c94
Binary files /dev/null and b/test/record-extend-reflect.ref.png differ
diff --git a/test/record-extend-repeat.ref.png b/test/record-extend-repeat.ref.png
new file mode 100644
index 0000000..d4db9bf
Binary files /dev/null and b/test/record-extend-repeat.ref.png differ
diff --git a/test/record-extend.c b/test/record-extend.c
new file mode 100644
index 0000000..a71c801
--- /dev/null
+++ b/test/record-extend.c
@@ -0,0 +1,220 @@
+/*
+ * Copyright © 2007 Red Hat, Inc.
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors:
+ *	Behdad Esfahbod <behdad at behdad.org>
+ *	Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include <math.h>
+#include "cairo-test.h"
+#include <stdio.h>
+
+#define SIZE 90
+
+/* This is written using clip+paint to exercise a bug that once was in the
+ * recording surface.
+ */
+
+static cairo_surface_t *
+source (void)
+{
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    /* Create a 4-pixel image surface with my favorite four colors in each
+     * quadrant. */
+    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 2, 2);
+    cr = cairo_create (surface);
+    cairo_surface_destroy (surface);
+
+    /* upper-left = white */
+    cairo_set_source_rgb (cr, 1, 1, 1);
+    cairo_rectangle (cr, 0, 0, 1, 1);
+    cairo_fill (cr);
+
+    /* upper-right = red */
+    cairo_set_source_rgb (cr, 1, 0, 0);
+    cairo_rectangle (cr, 1, 0, 1, 1);
+    cairo_fill (cr);
+
+    /* lower-left = green */
+    cairo_set_source_rgb (cr, 0, 1, 0);
+    cairo_rectangle (cr, 0, 1, 1, 1);
+    cairo_fill (cr);
+
+    /* lower-right = blue */
+    cairo_set_source_rgb (cr, 0, 0, 1);
+    cairo_rectangle (cr, 1, 1, 1, 1);
+    cairo_fill (cr);
+
+    surface = cairo_surface_reference (cairo_get_target (cr));
+    cairo_destroy (cr);
+
+    return surface;
+}
+
+static cairo_t *
+extend (cairo_t *cr, cairo_extend_t mode)
+{
+    cairo_surface_t *surface;
+
+    cairo_set_source_rgb (cr, 0, 1, 1);
+    cairo_paint (cr);
+
+    /* Now use extend modes to cover most of the surface with those 4 colors */
+    surface = source ();
+    cairo_set_source_surface (cr, surface, SIZE/2 - 1, SIZE/2 - 1);
+    cairo_surface_destroy (surface);
+
+    cairo_pattern_set_extend (cairo_get_source (cr), mode);
+
+    cairo_rectangle (cr, 10, 10, SIZE-20, SIZE-20);
+    cairo_clip (cr);
+    cairo_paint (cr);
+
+    return cr;
+}
+
+static cairo_t *
+extend_none (cairo_t *cr)
+{
+    return extend (cr, CAIRO_EXTEND_NONE);
+}
+
+static cairo_t *
+extend_pad (cairo_t *cr)
+{
+    return extend (cr, CAIRO_EXTEND_PAD);
+}
+
+static cairo_t *
+extend_repeat (cairo_t *cr)
+{
+    return extend (cr, CAIRO_EXTEND_REPEAT);
+}
+
+static cairo_t *
+extend_reflect (cairo_t *cr)
+{
+    return extend (cr, CAIRO_EXTEND_REFLECT);
+}
+
+static cairo_t *
+record_create (cairo_t *target)
+{
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    surface = cairo_recording_surface_create (cairo_surface_get_content (cairo_get_target (target)), NULL);
+    cr = cairo_create (surface);
+    cairo_surface_destroy (surface);
+
+    return cr;
+}
+
+static cairo_surface_t *
+record_get (cairo_t *target)
+{
+    cairo_surface_t *surface;
+
+    surface = cairo_surface_reference (cairo_get_target (target));
+    cairo_destroy (target);
+
+    return surface;
+}
+
+static cairo_test_status_t
+record_replay (cairo_t *cr, cairo_t *(*func)(cairo_t *), int width, int height)
+{
+    cairo_surface_t *surface;
+    int x, y;
+
+    surface = record_get (func (record_create (cr)));
+
+    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+    cairo_set_source_surface (cr, surface, 0, 0);
+    cairo_surface_destroy (surface);
+    cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_NONE);
+
+    for (y = 0; y < height; y += 2) {
+	for (x = 0; x < width; x += 2) {
+	    cairo_rectangle (cr, x, y, 2, 2);
+	    cairo_clip (cr);
+	    cairo_paint (cr);
+	    cairo_reset_clip (cr);
+	}
+    }
+
+    return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+record_extend_none (cairo_t *cr, int width, int height)
+{
+    return record_replay (cr, extend_none, width, height);
+}
+
+static cairo_test_status_t
+record_extend_pad (cairo_t *cr, int width, int height)
+{
+    return record_replay (cr, extend_pad, width, height);
+}
+
+static cairo_test_status_t
+record_extend_repeat (cairo_t *cr, int width, int height)
+{
+    return record_replay (cr, extend_repeat, width, height);
+}
+
+static cairo_test_status_t
+record_extend_reflect (cairo_t *cr, int width, int height)
+{
+    return record_replay (cr, extend_reflect, width, height);
+}
+
+CAIRO_TEST (record_extend_none,
+	    "Test CAIRO_EXTEND_NONE for recorded surface patterns",
+	    "record, extend", /* keywords */
+	    NULL, /* requirements */
+	    SIZE, SIZE,
+	    NULL, record_extend_none)
+CAIRO_TEST (record_extend_pad,
+	    "Test CAIRO_EXTEND_PAD for recorded surface patterns",
+	    "record, extend", /* keywords */
+	    NULL, /* requirements */
+	    SIZE, SIZE,
+	    NULL, record_extend_pad)
+CAIRO_TEST (record_extend_repeat,
+	    "Test CAIRO_EXTEND_REPEAT for recorded surface patterns",
+	    "record, extend", /* keywords */
+	    NULL, /* requirements */
+	    SIZE, SIZE,
+	    NULL, record_extend_repeat)
+CAIRO_TEST (record_extend_reflect,
+	    "Test CAIRO_EXTEND_REFLECT for recorded surface patterns",
+	    "record, extend", /* keywords */
+	    NULL, /* requirements */
+	    SIZE, SIZE,
+	    NULL, record_extend_reflect)


More information about the cairo-commit mailing list