From cf426bce8ebd3aff5d50c6a54bbd731132b3d312 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 11 Jun 2010 10:05:09 +0100 Subject: [PATCH] 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. --- test/Makefile.am | 2 + test/Makefile.sources | 1 + test/coverage-rectangles.ref.png | Bin 0 -> 259 bytes test/coverage-triangles.ref.png | Bin 0 -> 253 bytes test/coverage.c | 135 +++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 test/coverage-rectangles.ref.png create mode 100644 test/coverage-triangles.ref.png create mode 100644 test/coverage.c diff --git a/test/Makefile.am b/test/Makefile.am index 2063f40a0..96cf4e93b 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 6d11ade66..6ef345773 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 0000000000000000000000000000000000000000..cc1d31cf8825b3a67906d045e7588af5dee63336 GIT binary patch literal 259 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5G&q=mcByV>YhW{YAVDIwDK#?7u zE{-7;bKYJy~Q@@@H!9?P-ty?cBqEyr%xIt$g_JzrX*?>6tF~_wR>v7Kd339>NTnObWgXOE?=$ i7$>MPT%xYv7X5$!n7x)RVmu7=1B0ilpUXO@geCwps9qWX literal 0 HcmV?d00001 diff --git a/test/coverage-triangles.ref.png b/test/coverage-triangles.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..f56cb55700817b10a2c0e59f29fb8566450d4441 GIT binary patch literal 253 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5G&q=mcByV>YhW{YAVDIwDK#@(J zE{-7;bKYJyM~?EC^|8!B!7MfR;<_wM-1PbPWy^lJ4ugc&lK6nq($a5k7QPEcdG#NsfE!Gp?z Z`{Wlhp54h?)C_bzgQu&X%Q~loCIEscRU7~S literal 0 HcmV?d00001 diff --git a/test/coverage.c b/test/coverage.c new file mode 100644 index 000000000..ebb13da74 --- /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 + */ + +#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)