diff options
author | Bryce W. Harrington <b.harrington@samsung.com> | 2013-09-12 22:55:02 +0000 |
---|---|---|
committer | Uli Schlachter <psychon@znc.in> | 2013-09-13 12:57:17 +0200 |
commit | a6ace0cf6b96930c08397c64bffabc4b201ab4e8 (patch) | |
tree | 0d36927d859aeb70fef01e09058b5b0785730053 /test | |
parent | aacc5e76ed39b69595194a23e94bbd6483dd88a6 (diff) |
test: Comma separate keywords
The parser accepts spaces as separtors between keywords, so this is nit
picky. But only a minority of tests don't follow the comma convention,
so change them to be consistent.
Signed-off-by: Bryce Harrington <b.harrington@samsung.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
Diffstat (limited to 'test')
-rw-r--r-- | test/a1-bug.c | 61 | ||||
-rw-r--r-- | test/arc-direction.c | 2 | ||||
-rw-r--r-- | test/caps-joins-curve.c | 111 | ||||
-rw-r--r-- | test/caps-tails-curve.c | 127 | ||||
-rw-r--r-- | test/caps.c | 8 | ||||
-rw-r--r-- | test/clip-empty-group.c | 65 | ||||
-rw-r--r-- | test/drunkard-tails.c | 135 | ||||
-rw-r--r-- | test/joins.c | 109 | ||||
-rw-r--r-- | test/partial-coverage.c | 680 | ||||
-rw-r--r-- | test/rectilinear-dash-scale.c | 4 | ||||
-rw-r--r-- | test/rectilinear-dash.c | 176 | ||||
-rw-r--r-- | test/scale-offset-image.c | 142 | ||||
-rw-r--r-- | test/scale-offset-similar.c | 143 | ||||
-rw-r--r-- | test/unclosed-strokes.c | 83 |
14 files changed, 1839 insertions, 7 deletions
diff --git a/test/a1-bug.c b/test/a1-bug.c index 9166ff5..8e00d40 100644 --- a/test/a1-bug.c +++ b/test/a1-bug.c @@ -0,0 +1,61 @@ +/* + * 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. + */ + +#include "cairo-test.h" + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + static const struct point { + double x; + double y; + } xy[] = { + { 627.016212, 221.749777 }, + { 756.120787, 221.749777 }, + { 756.120787, 557.602766 }, + { 626.952721, 557.602766 }, + { 626.548456, 493.315729 }, + }; + unsigned int i; + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_paint (cr); + + for (i = 0; i < ARRAY_LENGTH (xy); i++) + cairo_line_to (cr, xy[i].x, xy[i].y); + + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_fill_preserve (cr); + + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + cairo_set_source_rgb (cr, 0, 1, 0); + cairo_fill (cr); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (a1_bug, + "Check the fidelity of the rasterisation.", + "a1, raster", /* keywords */ + "target=raster", /* requirements */ + 1000, 800, + NULL, draw) diff --git a/test/arc-direction.c b/test/arc-direction.c index fddb528..92c1a8d 100644 --- a/test/arc-direction.c +++ b/test/arc-direction.c @@ -98,7 +98,7 @@ draw (cairo_t *cr, int width, int height) CAIRO_TEST (arc_direction, "Test drawing positive/negative arcs", - "arc fill", /* keywords */ + "arc, fill", /* keywords */ NULL, /* requirements */ 2*(3*PAD + 2*SIZE), 2*(3*PAD + 2*SIZE), NULL, draw) diff --git a/test/caps-joins-curve.c b/test/caps-joins-curve.c index 1b2fc7f..cf19754 100644 --- a/test/caps-joins-curve.c +++ b/test/caps-joins-curve.c @@ -0,0 +1,111 @@ +/* + * Copyright © 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson <chris@chris-wilson.co.uk> + */ + +#include "cairo-test.h" + +#define LINE_WIDTH 10. +#define SIZE (5 * LINE_WIDTH) +#define PAD (3 * LINE_WIDTH) + +static void +make_path (cairo_t *cr) +{ + cairo_move_to (cr, 0, 0); + cairo_rel_curve_to (cr, + -SIZE/4, SIZE/3, + -SIZE/4, SIZE/3, + 0, SIZE); + cairo_rel_curve_to (cr, + SIZE/3, -SIZE/4, + SIZE/3, -SIZE/4, + SIZE, 0); + cairo_close_path (cr); + + cairo_move_to (cr, 5 * LINE_WIDTH, 3 * LINE_WIDTH); + cairo_rel_curve_to (cr, + 0, -3 * LINE_WIDTH, + 0, -3 * LINE_WIDTH, + -3 * LINE_WIDTH, -3 * LINE_WIDTH); +} + +static void +draw_caps_joins (cairo_t *cr) +{ + cairo_save (cr); + + cairo_translate (cr, PAD, PAD); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL); + cairo_stroke (cr); + + cairo_translate (cr, SIZE + PAD, 0.); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); + cairo_stroke (cr); + + cairo_translate (cr, SIZE + PAD, 0.); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); + cairo_stroke (cr); + + cairo_restore (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + /* We draw in the default black, so paint white first. */ + cairo_save (cr); + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ + cairo_paint (cr); + cairo_restore (cr); + + cairo_set_line_width (cr, LINE_WIDTH); + + draw_caps_joins (cr); + + /* and reflect to generate the opposite vertex ordering */ + cairo_translate (cr, 0, height); + cairo_scale (cr, 1, -1); + + draw_caps_joins (cr); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (caps_joins_curve, + "Test caps and joins on curves", + "stroke, cap, join", /* keywords */ + NULL, /* requirements */ + 3 * (PAD + SIZE) + PAD, + 2 * (PAD + SIZE) + PAD, + NULL, draw) + diff --git a/test/caps-tails-curve.c b/test/caps-tails-curve.c index 0dc8b31..25e5819 100644 --- a/test/caps-tails-curve.c +++ b/test/caps-tails-curve.c @@ -0,0 +1,127 @@ +/* + * 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. + * + * Author: Chris Wilson <chris@chris-wilson.co.uk> + */ + +#include "cairo-test.h" + +#define LINE_WIDTH 30. +#define SIZE (2 * LINE_WIDTH) +#define PAD (2 * LINE_WIDTH) + +static void +make_path (cairo_t *cr, double theta) +{ + double line_width = cairo_get_line_width (cr) / 4; + + cairo_move_to (cr, 0, 0); + cairo_rel_curve_to (cr, + SIZE/3, -SIZE/4, + SIZE/3, -SIZE/4, + SIZE, 0); + + cairo_rel_line_to (cr, + cos (theta) * line_width, + sin (theta) * line_width); +} + +static void +draw_joins (cairo_t *cr, double theta) +{ + make_path (cr, theta); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL); + cairo_stroke (cr); + + cairo_translate (cr, SIZE + PAD, 0.); + + make_path (cr, theta); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); + cairo_stroke (cr); + + cairo_translate (cr, SIZE + PAD, 0.); + + make_path (cr, theta); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); + cairo_stroke (cr); + + cairo_translate (cr, SIZE + PAD, 0.); +} + +static void +draw_caps_joins (cairo_t *cr, double theta) +{ + cairo_translate (cr, PAD, 0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + draw_joins (cr, theta); + + cairo_translate (cr, PAD, 0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + draw_joins (cr, theta); + + cairo_translate (cr, PAD, 0); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + draw_joins (cr, theta); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + const double theta[] = { + -M_PI/2, -M_PI/4, 0, M_PI/8, M_PI/3, M_PI + }; + unsigned int t; + + /* We draw in the default black, so paint white first. */ + cairo_save (cr); + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ + cairo_paint (cr); + cairo_restore (cr); + + cairo_set_line_width (cr, LINE_WIDTH); + + for (t = 0; t < sizeof(theta)/sizeof (theta[0]); t++) { + cairo_save (cr); + cairo_translate (cr, 0, t * (SIZE + PAD) + PAD); + draw_caps_joins (cr, theta[t]); + cairo_restore (cr); + + cairo_save (cr); + /* and reflect to generate the opposite vertex ordering */ + cairo_translate (cr, 0, height - t * (SIZE + PAD) - PAD); + cairo_scale (cr, 1, -1); + draw_caps_joins (cr, theta[t]); + cairo_restore (cr); + } + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (caps_tails_curve, + "Test caps and joins on short tail segments", + "stroke, cap, join", /* keywords */ + NULL, /* requirements */ + 9 * (PAD + SIZE) + 4*PAD, + 12 * (PAD + SIZE) + PAD, + NULL, draw) + diff --git a/test/caps.c b/test/caps.c index cde2773..87f008a 100644 --- a/test/caps.c +++ b/test/caps.c @@ -106,7 +106,7 @@ draw_05 (cairo_t *cr, int width, int height) CAIRO_TEST (caps, "Test caps", - "stroke caps", /* keywords */ + "stroke, caps", /* keywords */ NULL, /* requirements */ PAD + SIZE + PAD, 3 * (PAD + SIZE) + PAD, @@ -114,7 +114,7 @@ CAIRO_TEST (caps, CAIRO_TEST (caps_2, "Test normal caps", - "stroke caps", /* keywords */ + "stroke, caps", /* keywords */ NULL, /* requirements */ PAD + SIZE + PAD, 3 * (PAD + SIZE) + PAD, @@ -122,7 +122,7 @@ CAIRO_TEST (caps_2, CAIRO_TEST (caps_1, "Test hairline caps", - "stroke caps", /* keywords */ + "stroke, caps", /* keywords */ NULL, /* requirements */ PAD + SIZE + PAD, 3 * (PAD + SIZE) + PAD, @@ -130,7 +130,7 @@ CAIRO_TEST (caps_1, CAIRO_TEST (caps_05, "Test fine caps", - "stroke caps", /* keywords */ + "stroke, caps", /* keywords */ NULL, /* requirements */ PAD + SIZE + PAD, 3 * (PAD + SIZE) + PAD, diff --git a/test/clip-empty-group.c b/test/clip-empty-group.c index 20e95c2..3829c88 100644 --- a/test/clip-empty-group.c +++ b/test/clip-empty-group.c @@ -0,0 +1,65 @@ +/* + * Copyright (c) 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 handling of cairo_push_group() with everything clipped. */ +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_paint (cr); /* opaque background */ + + cairo_rectangle (cr, 20, 20, 0, 0); + cairo_clip (cr); + + cairo_push_group (cr); /* => 0x0 group */ + cairo_reset_clip (cr); + + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_paint (cr); + + cairo_rectangle (cr, 0, 0, width, height); + cairo_set_source_rgba (cr, 0, 1, 0, .5); + cairo_fill (cr); + + cairo_move_to (cr, 0, 20); + cairo_line_to (cr, width, 20); + cairo_set_source_rgb (cr, 0, 0, 1); + cairo_stroke (cr); + + cairo_pop_group_to_source (cr); + cairo_reset_clip (cr); + cairo_paint (cr); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (clip_empty_group, + "Test handling of groups with everything clipped", + "clip, group", /* keywords */ + NULL, /* requirements */ + 40, 40, + NULL, draw) diff --git a/test/drunkard-tails.c b/test/drunkard-tails.c index 3d3e09a..f55c7be 100644 --- a/test/drunkard-tails.c +++ b/test/drunkard-tails.c @@ -0,0 +1,135 @@ +/* + * 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. + * + * Author: Chris Wilson <chris@chris-wilson.co.uk> + */ + +#include "cairo-test.h" + +#define LINE_WIDTH 10. +#define SIZE (5 * LINE_WIDTH) +#define PAD (3 * LINE_WIDTH) + +static uint32_t state; + +static double +uniform_random (double minval, double maxval) +{ + static uint32_t const poly = 0x9a795537U; + uint32_t n = 32; + while (n-->0) + state = 2*state < state ? (2*state ^ poly) : 2*state; + return minval + state * (maxval - minval) / 4294967296.0; +} + +static void +make_path (cairo_t *cr) +{ + int i; + + state = 0xdeadbeef; + + cairo_move_to (cr, SIZE/2, SIZE/2); + for (i = 0; i < 200; i++) { + double theta = uniform_random (-M_PI, M_PI); + cairo_rel_line_to (cr, + cos (theta) * LINE_WIDTH / 4, + sin (theta) * LINE_WIDTH / 4); + } +} + +static void +draw_caps_joins (cairo_t *cr) +{ + cairo_save (cr); + + cairo_translate (cr, PAD, PAD); + + cairo_reset_clip (cr); + cairo_rectangle (cr, 0, 0, SIZE, SIZE); + cairo_clip (cr); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL); + cairo_stroke (cr); + + cairo_translate (cr, SIZE + PAD, 0.); + + cairo_reset_clip (cr); + cairo_rectangle (cr, 0, 0, SIZE, SIZE); + cairo_clip (cr); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); + cairo_stroke (cr); + + cairo_translate (cr, SIZE + PAD, 0.); + + cairo_reset_clip (cr); + cairo_rectangle (cr, 0, 0, SIZE, SIZE); + cairo_clip (cr); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); + cairo_stroke (cr); + + cairo_restore (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + /* We draw in the default black, so paint white first. */ + cairo_save (cr); + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ + cairo_paint (cr); + cairo_restore (cr); + + cairo_set_line_width (cr, LINE_WIDTH); + + draw_caps_joins (cr); + + cairo_save (cr); + /* and reflect to generate the opposite vertex ordering */ + cairo_translate (cr, 0, height); + cairo_scale (cr, 1, -1); + + draw_caps_joins (cr); + cairo_restore (cr); + + cairo_translate (cr, 0, SIZE + PAD); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (drunkard_tails, + "Test caps and joins on short tail segments", + "stroke, cap, join", /* keywords */ + NULL, /* requirements */ + 3 * (PAD + SIZE) + PAD, + 2 * (PAD + SIZE) + PAD, + NULL, draw) + diff --git a/test/joins.c b/test/joins.c index 66847dc..40ef72e 100644 --- a/test/joins.c +++ b/test/joins.c @@ -0,0 +1,109 @@ +/* + * Copyright © 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson <chris@chris-wilson.co.uk> + */ + +#include "cairo-test.h" + +#define LINE_WIDTH 12. +#define SIZE (5 * LINE_WIDTH) +#define PAD (2 * LINE_WIDTH) + +static void +make_path (cairo_t *cr) +{ + const struct { + double x, y; + } scales[] = { + { 1, 1 }, + { -1, 1 }, + { 1, -1 }, + { -1, -1 }, + }; + unsigned int i, j; + + for (j = 0; j < ARRAY_LENGTH (scales); j++) { + cairo_save (cr); + /* include reflections to flip the orientation of the join */ + cairo_scale (cr, scales[j].x, scales[j].y); + for (i = 0; i < 3; i++) { + cairo_new_sub_path (cr); + cairo_move_to (cr, 0, -9*LINE_WIDTH/4 - 2); + cairo_line_to (cr, 0, -2*LINE_WIDTH - 2); + cairo_line_to (cr, LINE_WIDTH/4, -2*LINE_WIDTH - 2); + cairo_rotate (cr, M_PI / 4.); + } + cairo_restore (cr); + } +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_line_join_t join; + + cairo_save (cr); + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ + cairo_paint (cr); + cairo_restore (cr); + + cairo_set_line_width (cr, LINE_WIDTH); + cairo_translate (cr, PAD + SIZE / 2., PAD + SIZE / 2.); + + for (join = CAIRO_LINE_JOIN_MITER; join <= CAIRO_LINE_JOIN_BEVEL; join++) { + cairo_save (cr); + + cairo_set_line_join (cr, join); + + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + make_path (cr); + cairo_stroke (cr); + + cairo_translate (cr, 0, SIZE + PAD); + + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + make_path (cr); + cairo_stroke (cr); + + cairo_translate (cr, 0, SIZE + PAD); + + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + make_path (cr); + cairo_stroke (cr); + + cairo_restore (cr); + + cairo_translate (cr, SIZE + PAD, 0); + } + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (joins, + "Test joins", + "stroke, joins", /* keywords */ + NULL, /* requirements */ + 3 * (PAD + SIZE) + PAD, + 3 * (PAD + SIZE) + PAD, + NULL, draw) + diff --git a/test/partial-coverage.c b/test/partial-coverage.c index 0b5cbdc..7e67a5e 100644 --- a/test/partial-coverage.c +++ b/test/partial-coverage.c @@ -0,0 +1,680 @@ +/* + * 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 sampling stratagems of the rasterisers by creating pixels + * containing minute holes and seeing how close to the expected + * coverage each rasteriser approaches. + */ + +#define SIZE 64 + +#include "../src/cairo-fixed-type-private.h" +#define SAMPLE (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 +uniform_random (void) +{ + return hars_petruska_f54_1_random() / (double) UINT32_MAX; +} + +/* coverage is given in [0,sample] */ +static void +compute_occupancy (uint8_t *occupancy, int coverage, int sample) +{ + int i, c; + + if (coverage < sample/2) { + memset (occupancy, 0, sample); + if (coverage == 0) + return; + + for (i = c = 0; i < sample; i++) { + if ((sample - i) * uniform_random() < coverage - c) { + occupancy[i] = 0xff; + if (++c == coverage) + return; + } + } + } else { + coverage = sample - coverage; + memset (occupancy, 0xff, sample); + if (coverage == 0) + return; + + for (i = c = 0; i < sample; i++) { + if ((sample - i) * uniform_random() < coverage - c) { + occupancy[i] = 0; + if (++c == coverage) + return; + } + } + } +} + +static cairo_test_status_t +reference (cairo_t *cr, int width, int height) +{ + int i; + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_paint (cr); + + for (i = 0; i < SIZE*SIZE; i++) { + cairo_set_source_rgba (cr, 1., 1., 1., + i / (double) (SIZE * SIZE)); + cairo_rectangle (cr, i % SIZE, i / SIZE, 1, 1); + cairo_fill (cr); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_test_status_t +three_quarter_reference (cairo_t *cr, int width, int height) +{ + int i; + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_paint (cr); + + for (i = 0; i < SIZE*SIZE; i++) { + cairo_set_source_rgba (cr, 1., 1., 1., + .75 * i / (double) (SIZE * SIZE)); + cairo_rectangle (cr, i % SIZE, i / SIZE, 1, 1); + cairo_fill (cr); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_test_status_t +half_reference (cairo_t *cr, int width, int height) +{ + int i; + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_paint (cr); + + for (i = 0; i < SIZE*SIZE; i++) { + cairo_set_source_rgba (cr, 1., 1., 1., + .5 * i / (double) (SIZE * SIZE)); + cairo_rectangle (cr, i % SIZE, i / SIZE, 1, 1); + cairo_fill (cr); + } + + return CAIRO_STATUS_SUCCESS; +} + +static cairo_test_status_t +rectangles (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE*SAMPLE; j++) { + if (occupancy[j]) { + cairo_rectangle (cr, + (j % SAMPLE + xs) / (double) SAMPLE, + (j / SAMPLE + ys) / (double) SAMPLE, + 1 / (double) SAMPLE, + 1 / (double) SAMPLE); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +intersecting_quads (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE*SAMPLE; j++) { + if (occupancy[j]) { + cairo_move_to (cr, + (j % SAMPLE + xs) / (double) SAMPLE, + (j / SAMPLE + ys) / (double) SAMPLE); + cairo_rel_line_to (cr, 1 / (double) SAMPLE, 1 / (double) SAMPLE); + cairo_rel_line_to (cr, 0, -1 / (double) SAMPLE); + cairo_rel_line_to (cr, -1 / (double) SAMPLE, 1 / (double) SAMPLE); + cairo_close_path (cr); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +half_triangles (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE*SAMPLE; j++) { + if (occupancy[j]) { + int x = j % SAMPLE + xs; + int y = j / SAMPLE + ys; + cairo_move_to (cr, x / (double) SAMPLE, y / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, y / (double) SAMPLE); + cairo_close_path (cr); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +overlap_half_triangles (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE/2*SAMPLE/2 * i / (SIZE * SIZE), SAMPLE/2*SAMPLE/2); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE/2*SAMPLE/2; j++) { + if (occupancy[j]) { + int x = 2 * (j % (SAMPLE/2)) + xs; + int y = 2 * (j / (SAMPLE/2)) + ys; + + /* Add a 4-tile composed of two overlapping triangles. + * .__.__. + * |\ /| + * | \ / | + * . x | + * | / \ | + * |/ \| + * . . + * + * Coverage should be computable as 50% (due to counter-winding). + */ + + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x) / (double) SAMPLE, (y+2) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y+2) / (double) SAMPLE); + cairo_close_path (cr); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +overlap_half_triangles_eo (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + cairo_paint (cr); + + cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE/2*SAMPLE/2 * i / (SIZE * SIZE), SAMPLE/2*SAMPLE/2); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE/2*SAMPLE/2; j++) { + if (occupancy[j]) { + int x = 2 * (j % (SAMPLE/2)) + xs; + int y = 2 * (j / (SAMPLE/2)) + ys; + + /* Add a 4-tile composed of two overlapping triangles. + * .__.__. + * |\ /| + * | \ / | + * . x | + * | / \ | + * |/ \| + * . . + * + * Coverage should be computable as 50%, due to even-odd fill rule. + */ + + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x) / (double) SAMPLE, (y+2) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y+2) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +overlap_three_quarter_triangles (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE/2*SAMPLE/2 * i / (SIZE * SIZE), SAMPLE/2*SAMPLE/2); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE/2*SAMPLE/2; j++) { + if (occupancy[j]) { + int x = 2 * (j % (SAMPLE/2)) + xs; + int y = 2 * (j / (SAMPLE/2)) + ys; + + /* Add a 4-tile composed of two overlapping triangles. + * .__.__. + * |\ /| + * | \ / | + * . x | + * | / \ | + * |/ \| + * . . + * + * Coverage should be computable as 75%. + */ + + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x) / (double) SAMPLE, (y+2) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y+2) / (double) SAMPLE); + cairo_line_to (cr, (x+2) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +triangles (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE*SAMPLE; j++) { + if (occupancy[j]) { + /* Add a tile composed of two non-overlapping triangles. + * .__. + * | /| + * |/ | + * .--. + */ + int x = j % SAMPLE + xs; + int y = j / SAMPLE + ys; + + /* top-left triangle */ + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_close_path (cr); + + /* bottom-right triangle */ + cairo_move_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +intersecting_triangles (cairo_t *cr, int width, int height) +{ + uint8_t *occupancy; + int i, j, channel; + + state = 0x12345678; + occupancy = xmalloc (SAMPLE*SAMPLE); + + 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 (i = 0; i < SIZE*SIZE; i++) { + int xs, ys; + + compute_occupancy (occupancy, SAMPLE*SAMPLE * i / (SIZE * SIZE), SAMPLE*SAMPLE); + + xs = i % SIZE * SAMPLE; + ys = i / SIZE * SAMPLE; + for (j = 0; j < SAMPLE*SAMPLE; j++) { + if (occupancy[j]) { + /* Add 2 overlapping tiles in a single cell, each composed + * of two non-overlapping triangles. + * .--. .--. + * | /| |\ | + * |/ | + | \| + * .--. .--. + */ + int x = j % SAMPLE + xs; + int y = j / SAMPLE + ys; + + /* first pair of triangles, diagonal bottom-left to top-right */ + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_close_path (cr); + cairo_move_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + + /* second pair of triangles, diagonal top-left to bottom-right */ + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_close_path (cr); + cairo_move_to (cr, (x) / (double) SAMPLE, (y) / (double) SAMPLE); + cairo_line_to (cr, (x+1) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_line_to (cr, (x) / (double) SAMPLE, (y+1) / (double) SAMPLE); + cairo_close_path (cr); + } + } + cairo_fill (cr); + } + } + + free (occupancy); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (partial_coverage_rectangles, + "Check the fidelity of the rasterisation.", + "coverage, raster", /* keywords */ + "target=raster slow", /* requirements */ + SIZE, SIZE, + NULL, rectangles) + +CAIRO_TEST (partial_coverage_intersecting_quads, + "Check the fidelity of the rasterisation.", + "coverage, raster", /* keywords */ + "target=raster slow", /* requirements */ + SIZE, SIZE, + NULL, intersecting_quads) + +CAIRO_TEST (partial_coverage_intersecting_triangles, + "Check the fidelity of the rasterisation.", + "coverage, raster", /* keywords */ + "target=raster slow", /* requirements */ + SIZE, SIZE, + NULL, intersecting_triangles) +CAIRO_TEST (partial_coverage_triangles, + "Check the fidelity of the rasterisation.", + "coverage, raster", /* keywords */ + "target=raster slow", /* requirements */ + SIZE, SIZE, + NULL, triangles) +CAIRO_TEST (partial_coverage_overlap_three_quarter_triangles, + "Check the fidelity of the rasterisation.", + "coverage, raster", /* keywords */ + "target=raster slow", /* requirements */ + SIZE, SIZE, + NULL, overlap_three_quarter_triangles) +CAIRO_TEST (partial_coverage_overlap_half_triangles_eo, + "Check the fidelity of the rasterisation.", + "coverage, raster", /* keywords */ + "target=raster slow", /* requirements */ + SIZE, SIZE, + NULL, overlap_half_triangles_eo) +CAIRO_TEST (partial_coverage_overlap_half_triangles, + "Check the fidelity of the rasterisation.", + "coverage, raster", /* keywords */ + "target=raster slow", /* requirements */ + SIZE, SIZE, + NULL, overlap_half_triangles) +CAIRO_TEST (partial_coverage_half_triangles, + "Check the fidelity of the rasterisation.", + "coverage, raster", /* keywords */ + "target=raster slow", /* requirements */ + SIZE, SIZE, + NULL, half_triangles) + +CAIRO_TEST (partial_coverage_reference, + "Check the fidelity of this test.", + "coverage, raster", /* keywords */ + "target=raster", /* requirements */ + SIZE, SIZE, + NULL, reference) +CAIRO_TEST (partial_coverage_three_quarter_reference, + "Check the fidelity of this test.", + "coverage, raster", /* keywords */ + "target=raster", /* requirements */ + SIZE, SIZE, + NULL, three_quarter_reference) +CAIRO_TEST (partial_coverage_half_reference, + "Check the fidelity of this test.", + "coverage, raster", /* keywords */ + "target=raster", /* requirements */ + SIZE, SIZE, + NULL, half_reference) diff --git a/test/rectilinear-dash-scale.c b/test/rectilinear-dash-scale.c index 1b69516..34f3345 100644 --- a/test/rectilinear-dash-scale.c +++ b/test/rectilinear-dash-scale.c @@ -183,14 +183,14 @@ unaligned (cairo_t *cr, int width, int height) CAIRO_TEST (rectilinear_dash_scale, "Test dashed rectilinear stroke operations (covering only whole pixels) after scaling", - "stroke dash", /* keywords */ + "stroke, dash", /* keywords */ NULL, /* requirements */ 4*SIZE, 2*SIZE, NULL, aligned) CAIRO_TEST (rectilinear_dash_scale_unaligned, "Test dashed rectilinear stroke operations (covering partial pixels) after scaling", - "stroke dash", /* keywords */ + "stroke, dash", /* keywords */ NULL, /* requirements */ 4*SIZE, 2*SIZE, NULL, unaligned) diff --git a/test/rectilinear-dash.c b/test/rectilinear-dash.c index fe998bb..954a2a0 100644 --- a/test/rectilinear-dash.c +++ b/test/rectilinear-dash.c @@ -0,0 +1,176 @@ +/* + * Copyright © 2006 Red Hat, Inc. + * Copyright © 2008 Chris Wilson + * + * 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: Carl D. Worth <cworth@cworth.org> + * Chris Wilson <chris@chris-wilson.co.uk> + * + * Based on the original test/rectilinear-stroke.c by Carl D. Worth. + */ + +#include "cairo-test.h" + +#define SIZE 50 + +static void +draw_dashes (cairo_t *cr) +{ + const double dash_square[4] = {4, 2, 2, 2}; + const double dash_butt[4] = {5, 1, 3, 1}; + + cairo_save (cr); + + cairo_set_dash (cr, dash_square, 4, 0); + + cairo_set_line_width (cr, 1.0); + cairo_translate (cr, 1, 1); + + /* Draw everything first with square caps. */ + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + + /* Draw horizontal and vertical segments, each in both + * directions. */ + cairo_move_to (cr, 4.5, 0.5); + cairo_rel_line_to (cr, 2.0, 0.0); + + cairo_move_to (cr, 10.5, 4.5); + cairo_rel_line_to (cr, 0.0, 2.0); + + cairo_move_to (cr, 6.5, 10.5); + cairo_rel_line_to (cr, -2.0, 0.0); + + cairo_move_to (cr, 0.5, 6.5); + cairo_rel_line_to (cr, 0.0, -2.0); + + /* Draw right angle turns in four directions. */ + cairo_move_to (cr, 0.5, 2.5); + cairo_rel_line_to (cr, 0.0, -2.0); + cairo_rel_line_to (cr, 2.0, 0.0); + + cairo_move_to (cr, 8.5, 0.5); + cairo_rel_line_to (cr, 2.0, 0.0); + cairo_rel_line_to (cr, 0.0, 2.0); + + cairo_move_to (cr, 10.5, 8.5); + cairo_rel_line_to (cr, 0.0, 2.0); + cairo_rel_line_to (cr, -2.0, 0.0); + + cairo_move_to (cr, 2.5, 10.5); + cairo_rel_line_to (cr, -2.0, 0.0); + cairo_rel_line_to (cr, 0.0, -2.0); + + cairo_stroke (cr); + + /* Draw a closed-path rectangle */ + cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0); + cairo_set_dash (cr, dash_square, 4, 2); + cairo_stroke (cr); + + cairo_translate (cr, 12, 0); + + /* Now draw the same results, but with butt caps. */ + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + cairo_set_dash (cr, dash_butt, 4, 0.0); + + /* Draw horizontal and vertical segments, each in both + * directions. */ + cairo_move_to (cr, 4.0, 0.5); + cairo_rel_line_to (cr, 3.0, 0.0); + + cairo_move_to (cr, 10.5, 4.0); + cairo_rel_line_to (cr, 0.0, 3.0); + + cairo_move_to (cr, 7.0, 10.5); + cairo_rel_line_to (cr, -3.0, 0.0); + + cairo_move_to (cr, 0.5, 7.0); + cairo_rel_line_to (cr, 0.0, -3.0); + + /* Draw right angle turns in four directions. */ + cairo_move_to (cr, 0.5, 3.0); + cairo_rel_line_to (cr, 0.0, -2.5); + cairo_rel_line_to (cr, 2.5, 0.0); + + cairo_move_to (cr, 8.0, 0.5); + cairo_rel_line_to (cr, 2.5, 0.0); + cairo_rel_line_to (cr, 0.0, 2.5); + + cairo_move_to (cr, 10.5, 8.0); + cairo_rel_line_to (cr, 0.0, 2.5); + cairo_rel_line_to (cr, -2.5, 0.0); + + cairo_move_to (cr, 3.0, 10.5); + cairo_rel_line_to (cr, -2.5, 0.0); + cairo_rel_line_to (cr, 0.0, -2.5); + + cairo_stroke (cr); + + /* Draw a closed-path rectangle */ + cairo_set_dash (cr, dash_butt, 4, 2.5); + cairo_rectangle (cr, 0.5, 12.5, 10.0, 10.0); + cairo_stroke (cr); + + cairo_restore (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + /* Paint background white, then draw in black. */ + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); + cairo_paint (cr); + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + draw_dashes (cr); + + cairo_save (cr); + cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); + cairo_translate (cr, 0, height); + cairo_scale (cr, 1, -1); + draw_dashes (cr); + cairo_restore (cr); + + cairo_save (cr); + cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); + cairo_translate (cr, width, 0); + cairo_scale (cr, -1, 1); + draw_dashes (cr); + cairo_restore (cr); + + cairo_save (cr); + cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); + cairo_translate (cr, width, height); + cairo_scale (cr, -1, -1); + draw_dashes (cr); + cairo_restore (cr); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (rectilinear_dash, + "Test dashed rectilinear stroke operations (covering only whole pixels)", + "stroke, dash", /* keywords */ + NULL, /* requirements */ + SIZE, SIZE, + NULL, draw) + diff --git a/test/scale-offset-image.c b/test/scale-offset-image.c index 0eef22e..a6e575a 100644 --- a/test/scale-offset-image.c +++ b/test/scale-offset-image.c @@ -0,0 +1,142 @@ +/* + * Copyright 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson <chris@chris-wilson.co.uk> + */ + +/* + * Test case derived from the bug report by Michel Iwaniec: + * http://lists.cairographics.org/archives/cairo/2008-November/015660.html + */ + +#include "cairo-test.h" + +static cairo_surface_t * +create_source (cairo_surface_t *target, int width, int height) +{ + cairo_surface_t *similar; + cairo_t *cr; + + similar = cairo_image_surface_create (CAIRO_FORMAT_RGB24, + width, height); + cr = cairo_create (similar); + cairo_surface_destroy (similar); + + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_rectangle (cr, + width - 4, height - 4, + 2, 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_rectangle (cr, + width - 2, height - 4, + 2, 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 0, 1, 0); + cairo_rectangle (cr, + width - 4, height - 2, + 2, 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 0, 0, 1); + cairo_rectangle (cr, + width - 2, height - 2, + 2, 2); + cairo_fill (cr); + + similar = cairo_surface_reference (cairo_get_target (cr)); + cairo_destroy (cr); + + return similar; +} + +static void +draw_grid (cairo_t *cr, cairo_pattern_t *pattern, int dst_x, int dst_y) +{ + cairo_matrix_t m; + + cairo_save (cr); + cairo_translate (cr, dst_x, dst_y); + cairo_scale (cr, 16, 16); + cairo_rotate (cr, 1); + + cairo_matrix_init_translate (&m, 2560-4, 1280-4); + cairo_pattern_set_matrix (pattern, &m); + cairo_set_source (cr, pattern); + cairo_rectangle (cr, 0, 0, 4, 4); + cairo_fill (cr); + + cairo_set_source_rgb (cr, .7, .7, .7); + cairo_set_line_width (cr, 1./16); + cairo_move_to (cr, 0, 0); + cairo_line_to (cr, 4, 0); + cairo_move_to (cr, 0, 2); + cairo_line_to (cr, 4, 2); + cairo_move_to (cr, 0, 4); + cairo_line_to (cr, 4, 4); + cairo_move_to (cr, 0, 0); + cairo_line_to (cr, 0, 4); + cairo_move_to (cr, 2, 0); + cairo_line_to (cr, 2, 4); + cairo_move_to (cr, 4, 0); + cairo_line_to (cr, 4, 4); + cairo_stroke (cr); + + cairo_restore (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *source; + cairo_pattern_t *pattern; + + cairo_paint (cr); + + source = create_source (cairo_get_target (cr), 2560, 1280); + pattern = cairo_pattern_create_for_surface (source); + cairo_surface_destroy (source); + + cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE); + + draw_grid (cr, pattern, 50, 0); + draw_grid (cr, pattern, 130, 0); + draw_grid (cr, pattern, 210, 0); + draw_grid (cr, pattern, 290, 0); + + draw_grid (cr, pattern, 50, 230); + draw_grid (cr, pattern, 130, 230); + draw_grid (cr, pattern, 210, 230); + draw_grid (cr, pattern, 290, 230); + + cairo_pattern_destroy (pattern); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (scale_offset_image, + "Tests drawing surfaces under various scales and transforms", + "surface, scale-offset", /* keywords */ + NULL, /* requirements */ + 320, 320, + NULL, draw) + diff --git a/test/scale-offset-similar.c b/test/scale-offset-similar.c index daf7ffe..e9e6a2b 100644 --- a/test/scale-offset-similar.c +++ b/test/scale-offset-similar.c @@ -0,0 +1,143 @@ +/* + * Copyright 2008 Chris Wilson + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Chris Wilson not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Chris Wilson makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR + * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: Chris Wilson <chris@chris-wilson.co.uk> + */ + +/* + * Test case derived from the bug report by Michel Iwaniec: + * http://lists.cairographics.org/archives/cairo/2008-November/015660.html + */ + +#include "cairo-test.h" + +static cairo_surface_t * +create_source (cairo_surface_t *target, int width, int height) +{ + cairo_surface_t *similar; + cairo_t *cr; + + similar = cairo_surface_create_similar (target, + CAIRO_CONTENT_COLOR, + width, height); + cr = cairo_create (similar); + cairo_surface_destroy (similar); + + cairo_set_source_rgb (cr, 1, 1, 1); + cairo_rectangle (cr, + width - 4, height - 4, + 2, 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_rectangle (cr, + width - 2, height - 4, + 2, 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 0, 1, 0); + cairo_rectangle (cr, + width - 4, height - 2, + 2, 2); + cairo_fill (cr); + cairo_set_source_rgb (cr, 0, 0, 1); + cairo_rectangle (cr, + width - 2, height - 2, + 2, 2); + cairo_fill (cr); + + similar = cairo_surface_reference (cairo_get_target (cr)); + cairo_destroy (cr); + + return similar; +} + +static void +draw_grid (cairo_t *cr, cairo_pattern_t *pattern, int dst_x, int dst_y) +{ + cairo_matrix_t m; + + cairo_save (cr); + cairo_translate (cr, dst_x, dst_y); + cairo_scale (cr, 16, 16); + cairo_rotate (cr, 1); + + cairo_matrix_init_translate (&m, 2560-4, 1280-4); + cairo_pattern_set_matrix (pattern, &m); + cairo_set_source (cr, pattern); + cairo_rectangle (cr, 0, 0, 4, 4); + cairo_fill (cr); + + cairo_set_source_rgb (cr, .7, .7, .7); + cairo_set_line_width (cr, 1./16); + cairo_move_to (cr, 0, 0); + cairo_line_to (cr, 4, 0); + cairo_move_to (cr, 0, 2); + cairo_line_to (cr, 4, 2); + cairo_move_to (cr, 0, 4); + cairo_line_to (cr, 4, 4); + cairo_move_to (cr, 0, 0); + cairo_line_to (cr, 0, 4); + cairo_move_to (cr, 2, 0); + cairo_line_to (cr, 2, 4); + cairo_move_to (cr, 4, 0); + cairo_line_to (cr, 4, 4); + cairo_stroke (cr); + + cairo_restore (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *source; + cairo_pattern_t *pattern; + + cairo_paint (cr); + + source = create_source (cairo_get_target (cr), 2560, 1280); + pattern = cairo_pattern_create_for_surface (source); + cairo_surface_destroy (source); + + cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE); + + draw_grid (cr, pattern, 50, 0); + draw_grid (cr, pattern, 130, 0); + draw_grid (cr, pattern, 210, 0); + draw_grid (cr, pattern, 290, 0); + + draw_grid (cr, pattern, 50, 230); + draw_grid (cr, pattern, 130, 230); + draw_grid (cr, pattern, 210, 230); + draw_grid (cr, pattern, 290, 230); + + cairo_pattern_destroy (pattern); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (scale_offset_similar, + "Tests drawing surfaces under various scales and transforms", + "surface, scale-offset", /* keywords */ + NULL, /* requirements */ + 320, 320, + NULL, draw) + diff --git a/test/unclosed-strokes.c b/test/unclosed-strokes.c index 3c0287f..40a76eb 100644 --- a/test/unclosed-strokes.c +++ b/test/unclosed-strokes.c @@ -0,0 +1,83 @@ +/* + * 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. + * + * Author: Chris Wilson <chris@chris-wilson.co.uk> + */ + +#include "cairo-test.h" + +#define LINE_WIDTH 10. +#define SIZE (5 * LINE_WIDTH) +#define PAD (2 * LINE_WIDTH) + +static void +make_path (cairo_t *cr) +{ + cairo_move_to (cr, 0, 0); + cairo_rel_line_to (cr, -SIZE/2, SIZE); + cairo_rel_line_to (cr, SIZE, 0); + /* back to the start, but do not close */ + cairo_rel_line_to (cr, -SIZE/2, -SIZE); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_save (cr); + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* white */ + cairo_paint (cr); + cairo_restore (cr); + + cairo_set_line_width (cr, LINE_WIDTH); + cairo_translate (cr, PAD + SIZE / 2., PAD); + + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL); + make_path (cr); + cairo_stroke (cr); + + cairo_translate (cr, 0, SIZE + PAD); + + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); + make_path (cr); + cairo_stroke (cr); + + cairo_translate (cr, 0, SIZE + PAD); + + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); + make_path (cr); + cairo_stroke (cr); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (unclosed_strokes, + "Test coincident end-points are capped and not joined", + "stroke, caps", /* keywords */ + NULL, /* requirements */ + PAD + SIZE + PAD, + 3 * (PAD + SIZE) + PAD, + NULL, draw) + |