summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2010-06-11 10:05:09 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2010-06-11 10:05:09 +0100
commitcf426bce8ebd3aff5d50c6a54bbd731132b3d312 (patch)
tree86b74f4066135473585f79a8aa4a5facdeff79a7 /test
parentbd3d9ef3d1dbc5364e79e6afb47d9e124cb61ca4 (diff)
test: Add a simple coverage test.
This test case should be much clearer than half-coverage over what it purports to actually test. In each pixel, it draws a single geometric primitive that coverages a known percentage of the pixel and then we measure how close the rasterisers are to that ideal.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am2
-rw-r--r--test/Makefile.sources1
-rw-r--r--test/coverage-rectangles.ref.pngbin0 -> 259 bytes
-rw-r--r--test/coverage-triangles.ref.pngbin0 -> 253 bytes
-rw-r--r--test/coverage.c135
5 files changed, 138 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 2063f40a..96cf4e93 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -332,6 +332,8 @@ REFERENCE_IMAGES = \
copy-path.ps2.ref.png \
copy-path.ps3.ref.png \
copy-path.ref.png \
+ coverage-rectangles.ref.png \
+ coverage-triangles.ref.png \
create-from-png-stream.ref.png \
create-from-png.alpha.ref.png \
create-from-png.gray-alpha.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 6d11ade6..6ef34577 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -50,6 +50,7 @@ test_sources = \
composite-integer-translate-over.c \
composite-integer-translate-over-repeat.c \
copy-path.c \
+ coverage.c \
create-for-stream.c \
create-from-png.c \
create-from-png-stream.c \
diff --git a/test/coverage-rectangles.ref.png b/test/coverage-rectangles.ref.png
new file mode 100644
index 00000000..cc1d31cf
--- /dev/null
+++ b/test/coverage-rectangles.ref.png
Binary files differ
diff --git a/test/coverage-triangles.ref.png b/test/coverage-triangles.ref.png
new file mode 100644
index 00000000..f56cb557
--- /dev/null
+++ b/test/coverage-triangles.ref.png
Binary files differ
diff --git a/test/coverage.c b/test/coverage.c
new file mode 100644
index 00000000..ebb13da7
--- /dev/null
+++ b/test/coverage.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2010 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.
+ *
+ * Author: Chris Wilson <chris@chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+/* Test the fidelity of the rasterisation, because Cairo is my favourite
+ * driver test suite.
+ */
+
+#define WIDTH 256
+#define HEIGHT 40
+
+#include "../src/cairo-fixed-type-private.h"
+#define PRECISION (1 << CAIRO_FIXED_FRAC_BITS)
+
+static uint32_t state;
+
+static uint32_t
+hars_petruska_f54_1_random (void)
+{
+#define rol(x,k) ((x << k) | (x >> (32-k)))
+ return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
+#undef rol
+}
+
+static double
+random_offset (int range)
+{
+ double x = hars_petruska_f54_1_random() / (double) UINT32_MAX * range / WIDTH;
+ return floor (x * PRECISION) / PRECISION;
+}
+
+static cairo_test_status_t
+rectangles (cairo_t *cr, int width, int height)
+{
+ int x, y, channel;
+
+ state = 0x12345678;
+
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+ cairo_paint (cr);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
+ for (channel = 0; channel < 3; channel++) {
+ switch (channel) {
+ default:
+ case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
+ case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
+ case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
+ }
+
+ for (x = 0; x < WIDTH; x++) {
+ for (y = 0; y < HEIGHT; y++) {
+ double dx = random_offset (WIDTH - x);
+ double dy = random_offset (WIDTH - x);
+ cairo_rectangle (cr, x + dx, y + dy, x / (double) WIDTH, x / (double) WIDTH);
+ }
+ }
+ cairo_fill (cr);
+ }
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+static cairo_test_status_t
+triangles (cairo_t *cr, int width, int height)
+{
+ int x, y, channel;
+
+ state = 0x12345678;
+
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+ cairo_paint (cr);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
+ for (channel = 0; channel < 3; channel++) {
+ switch (channel) {
+ default:
+ case 0: cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); break;
+ case 1: cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); break;
+ case 2: cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); break;
+ }
+
+ for (x = 0; x < WIDTH; x++) {
+ for (y = 0; y < HEIGHT; y++) {
+ double dx = random_offset (WIDTH - x);
+ double dy = random_offset (WIDTH - x);
+ cairo_move_to (cr, x + dx, y + dy);
+ cairo_rel_line_to (cr, x / (double) WIDTH, 0);
+ cairo_rel_line_to (cr, 0, x / (double) WIDTH);
+ cairo_close_path (cr);
+ }
+ }
+ cairo_fill (cr);
+ }
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+CAIRO_TEST (coverage_rectangles,
+ "Check the fidelity of the rasterisation.",
+ NULL, /* keywords */
+ "raster", /* requirements */
+ WIDTH, HEIGHT,
+ NULL, rectangles)
+
+CAIRO_TEST (coverage_triangles,
+ "Check the fidelity of the rasterisation.",
+ NULL, /* keywords */
+ "raster", /* requirements */
+ WIDTH, HEIGHT,
+ NULL, triangles)