summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2011-08-10 14:51:25 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-08-10 14:53:07 +0100
commit99c129dd1302faaa1b10dca494d414a5738ddaf3 (patch)
tree6ea8b86466d7e3691b87b1c46d05a700e0fd5959
parentdeb88cca133b4f6ae89061662c06bca0c0573d0e (diff)
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@chris-wilson.co.uk>
-rw-r--r--test/Makefile.refs4
-rw-r--r--test/Makefile.sources1
-rw-r--r--test/record-extend-none.ref.pngbin0 -> 293 bytes
-rw-r--r--test/record-extend-pad.ref.pngbin0 -> 298 bytes
-rw-r--r--test/record-extend-reflect.ref.pngbin0 -> 335 bytes
-rw-r--r--test/record-extend-repeat.ref.pngbin0 -> 286 bytes
-rw-r--r--test/record-extend.c220
7 files changed, 225 insertions, 0 deletions
diff --git a/test/Makefile.refs b/test/Makefile.refs
index ac5194dd5..bbf64dd18 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 846d67b4e..21e58e8bd 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 000000000..d63c31c1f
--- /dev/null
+++ b/test/record-extend-none.ref.png
Binary files differ
diff --git a/test/record-extend-pad.ref.png b/test/record-extend-pad.ref.png
new file mode 100644
index 000000000..12915255c
--- /dev/null
+++ b/test/record-extend-pad.ref.png
Binary files differ
diff --git a/test/record-extend-reflect.ref.png b/test/record-extend-reflect.ref.png
new file mode 100644
index 000000000..aec5c9454
--- /dev/null
+++ b/test/record-extend-reflect.ref.png
Binary files differ
diff --git a/test/record-extend-repeat.ref.png b/test/record-extend-repeat.ref.png
new file mode 100644
index 000000000..d4db9bf58
--- /dev/null
+++ b/test/record-extend-repeat.ref.png
Binary files differ
diff --git a/test/record-extend.c b/test/record-extend.c
new file mode 100644
index 000000000..a71c80169
--- /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@behdad.org>
+ * Chris Wilson <chris@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)