| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- /*
- * 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 GENERATE_REFERENCE 0
- #define WIDTH 256
- #define HEIGHT 40
- #include "../src/cairo-fixed-type-private.h"
- #define PRECISION (1 << CAIRO_FIXED_FRAC_BITS)
- /* XXX beware multithreading! */
- 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, int precise)
- {
- double x = hars_petruska_f54_1_random() / (double) UINT32_MAX * range / WIDTH;
- if (precise)
- x = floor (x * PRECISION) / PRECISION;
- return x;
- }
- 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);
- #if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * x * 1.0 / (WIDTH * WIDTH));
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
- cairo_fill (cr);
- }
- #else
- 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, TRUE);
- double dy = random_offset (WIDTH - x, TRUE);
- cairo_rectangle (cr, x + dx, y + dy, x / (double) WIDTH, x / (double) WIDTH);
- }
- }
- cairo_fill (cr);
- }
- #endif
- return CAIRO_TEST_SUCCESS;
- }
- static cairo_test_status_t
- rhombus (cairo_t *cr, int width, int height)
- {
- int x, y;
- cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
- cairo_paint (cr);
- #if GENERATE_REFERENCE
- for (y = 0; y < WIDTH; y++) {
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1,
- x * y / (2. * WIDTH * WIDTH));
- cairo_rectangle (cr, 2*x, 2*y, 2, 2);
- cairo_fill (cr);
- }
- }
- #else
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- cairo_set_source_rgb (cr, 1, 1, 1);
- for (y = 0; y < WIDTH; y++) {
- double yf = y / (double) WIDTH;
- for (x = 0; x < WIDTH; x++) {
- double xf = x / (double) WIDTH;
- cairo_move_to (cr,
- 2*x + 1 - xf,
- 2*y + 1);
- cairo_line_to (cr,
- 2*x + 1,
- 2*y + 1 - yf);
- cairo_line_to (cr,
- 2*x + 1 + xf,
- 2*y + 1);
- cairo_line_to (cr,
- 2*x + 1,
- 2*y + 1 + yf);
- cairo_close_path (cr);
- }
- }
- cairo_fill (cr);
- #endif
- return CAIRO_TEST_SUCCESS;
- }
- static cairo_test_status_t
- intersecting_quads (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);
- #if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (WIDTH * WIDTH));
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
- cairo_fill (cr);
- }
- #else
- 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++) {
- double step = x / (double) WIDTH;
- for (y = 0; y < HEIGHT; y++) {
- double dx = random_offset (WIDTH - x, TRUE);
- double dy = random_offset (WIDTH - x, TRUE);
- cairo_move_to (cr, x + dx, y + dy);
- cairo_rel_line_to (cr, step, step);
- cairo_rel_line_to (cr, 0, -step);
- cairo_rel_line_to (cr, -step, step);
- cairo_close_path (cr);
- }
- }
- cairo_fill (cr);
- }
- #endif
- return CAIRO_TEST_SUCCESS;
- }
- static cairo_test_status_t
- intersecting_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);
- #if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.75 / (WIDTH * WIDTH));
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
- cairo_fill (cr);
- }
- #else
- 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++) {
- double step = x / (double) WIDTH;
- for (y = 0; y < HEIGHT; y++) {
- double dx = random_offset (WIDTH - x, TRUE);
- double dy = random_offset (WIDTH - x, TRUE);
- /* left */
- cairo_move_to (cr, x + dx, y + dy);
- cairo_rel_line_to (cr, 0, step);
- cairo_rel_line_to (cr, step, 0);
- cairo_close_path (cr);
- /* right, mirrored */
- cairo_move_to (cr, x + dx + step, y + dy + step);
- cairo_rel_line_to (cr, 0, -step);
- cairo_rel_line_to (cr, -step, step);
- cairo_close_path (cr);
- }
- }
- cairo_fill (cr);
- }
- #endif
- 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);
- #if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * x * 0.5 / (WIDTH * WIDTH));
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
- cairo_fill (cr);
- }
- #else
- 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, TRUE);
- double dy = random_offset (WIDTH - x, TRUE);
- 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);
- }
- #endif
- return CAIRO_TEST_SUCCESS;
- }
- static cairo_test_status_t
- abutting (cairo_t *cr, int width, int height)
- {
- int x, y;
- cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
- cairo_paint (cr);
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.75);
- #if GENERATE_REFERENCE
- cairo_paint (cr);
- #else
- cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
- for (y = 0; y < 16; y++) {
- for (x = 0; x < 16; x++) {
- double theta = (y * 16 + x) * M_PI / 512;
- double cx = 16 * cos (theta) + x * 16;
- double cy = 16 * sin (theta) + y * 16;
- cairo_move_to (cr, x * 16, y * 16);
- cairo_line_to (cr, cx, cy);
- cairo_line_to (cr, (x + 1) * 16, y * 16);
- cairo_fill (cr);
- cairo_move_to (cr, (x + 1) * 16, y * 16);
- cairo_line_to (cr, cx, cy);
- cairo_line_to (cr, (x + 1) * 16, (y + 1) * 16);
- cairo_fill (cr);
- cairo_move_to (cr, (x + 1) * 16, (y + 1) * 16);
- cairo_line_to (cr, cx, cy);
- cairo_line_to (cr, x * 16, (y + 1) * 16);
- cairo_fill (cr);
- cairo_move_to (cr, x * 16, (y + 1) * 16);
- cairo_line_to (cr, cx, cy);
- cairo_line_to (cr, x * 16, y * 16);
- cairo_fill (cr);
- }
- }
- #endif
- return CAIRO_TEST_SUCCESS;
- }
- static cairo_test_status_t
- column_triangles (cairo_t *cr, int width, int height)
- {
- int x, y, i, channel;
- state = 0x12345678;
- cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
- cairo_paint (cr);
- #if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
- cairo_fill (cr);
- }
- #else
- 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++) {
- double step = x / (double) (2 * WIDTH);
- for (y = 0; y < HEIGHT; y++) {
- for (i = 0; i < PRECISION; i++) {
- double dy = random_offset (WIDTH - x, FALSE);
- /*
- * We want to test some sharing of edges to further
- * stress the rasterisers, so instead of using one
- * tall triangle, it is split into two, with vertical
- * edges on either side that may co-align with their
- * neighbours:
- *
- * s --- . ---
- * t | |\ |
- * e | | \ |
- * p --- .... | 2 * step = x / WIDTH
- * \ | |
- * \| |
- * . ---
- * |---|
- * 1 / PRECISION
- *
- * Each column contains two triangles of width one quantum and
- * total height of (x / WIDTH), thus the total area covered by all
- * columns in each pixel is .5 * (x / WIDTH).
- */
- cairo_move_to (cr, x + i / (double) PRECISION, y + dy);
- cairo_rel_line_to (cr, 0, step);
- cairo_rel_line_to (cr, 1 / (double) PRECISION, step);
- cairo_rel_line_to (cr, 0, -step);
- cairo_close_path (cr);
- }
- cairo_fill (cr); /* do these per-pixel due to the extra volume of edges */
- }
- }
- }
- #endif
- return CAIRO_TEST_SUCCESS;
- }
- static cairo_test_status_t
- row_triangles (cairo_t *cr, int width, int height)
- {
- int x, y, i, channel;
- state = 0x12345678;
- cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
- cairo_paint (cr);
- #if GENERATE_REFERENCE
- for (x = 0; x < WIDTH; x++) {
- cairo_set_source_rgba (cr, 1, 1, 1, x * 0.5 / WIDTH);
- cairo_rectangle (cr, x, 0, 1, HEIGHT);
- cairo_fill (cr);
- }
- #else
- 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++) {
- double step = x / (double) (2 * WIDTH);
- for (y = 0; y < HEIGHT; y++) {
- for (i = 0; i < PRECISION; i++) {
- double dx = random_offset (WIDTH - x, FALSE);
- /* See column_triangles() for a transposed description
- * of this geometry.
- */
- cairo_move_to (cr, x + dx, y + i / (double) PRECISION);
- cairo_rel_line_to (cr, step, 0);
- cairo_rel_line_to (cr, step, 1 / (double) PRECISION);
- cairo_rel_line_to (cr, -step, 0);
- cairo_close_path (cr);
- }
- cairo_fill (cr); /* do these per-pixel due to the extra volume of edges */
- }
- }
- }
- #endif
- return CAIRO_TEST_SUCCESS;
- }
- CAIRO_TEST (coverage_rectangles,
- "Check the fidelity of the rasterisation.",
- NULL, /* keywords */
- "target=raster", /* requirements */
- WIDTH, HEIGHT,
- NULL, rectangles)
- CAIRO_TEST (coverage_rhombus,
- "Check the fidelity of the rasterisation.",
- NULL, /* keywords */
- "target=raster", /* requirements */
- 2*WIDTH, 2*WIDTH,
- NULL, rhombus)
- CAIRO_TEST (coverage_intersecting_quads,
- "Check the fidelity of the rasterisation.",
- NULL, /* keywords */
- "target=raster", /* requirements */
- WIDTH, HEIGHT,
- NULL, intersecting_quads)
- CAIRO_TEST (coverage_intersecting_triangles,
- "Check the fidelity of the rasterisation.",
- NULL, /* keywords */
- "target=raster", /* requirements */
- WIDTH, HEIGHT,
- NULL, intersecting_triangles)
- CAIRO_TEST (coverage_row_triangles,
- "Check the fidelity of the rasterisation.",
- NULL, /* keywords */
- "target=raster", /* requirements */
- WIDTH, HEIGHT,
- NULL, row_triangles)
- CAIRO_TEST (coverage_column_triangles,
- "Check the fidelity of the rasterisation.",
- NULL, /* keywords */
- "target=raster", /* requirements */
- WIDTH, HEIGHT,
- NULL, column_triangles)
- CAIRO_TEST (coverage_triangles,
- "Check the fidelity of the rasterisation.",
- NULL, /* keywords */
- "target=raster", /* requirements */
- WIDTH, HEIGHT,
- NULL, triangles)
- CAIRO_TEST (coverage_abutting,
- "Check the fidelity of the rasterisation.",
- NULL, /* keywords */
- "target=raster", /* requirements */
- 16*16, 16*16,
- NULL, abutting)
|