diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-14 17:51:00 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-07-15 11:05:19 +0100 |
commit | 524809759b7c1c9f01bcdd9f195ec4366ebe8223 (patch) | |
tree | 9b7d457958222ae6abe4e108c333b6bba0387fe0 /test | |
parent | 41b5469b9523c9a8784d230e929518367dbda751 (diff) |
tests: Add clip-complex-shape
Contributed by Taekyun Kim to exercise a major bug he found in the
treatment of complex clips.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.refs | 2 | ||||
-rw-r--r-- | test/Makefile.sources | 1 | ||||
-rw-r--r-- | test/clip-complex-shape-eo-aa.ref.png | bin | 0 -> 349 bytes | |||
-rw-r--r-- | test/clip-complex-shape-eo-mono.ref.png | bin | 0 -> 349 bytes | |||
-rw-r--r-- | test/clip-complex-shape.c | 114 |
5 files changed, 117 insertions, 0 deletions
diff --git a/test/Makefile.refs b/test/Makefile.refs index 5b2acb1d0..e855a43d3 100644 --- a/test/Makefile.refs +++ b/test/Makefile.refs @@ -92,6 +92,8 @@ REFERENCE_IMAGES = \ clear.svg12.argb32.xfail.png \ clear.svg12.rgb24.xfail.png \ clip-all.ref.png \ + clip-complex-shape-eo-aa.ref.png \ + clip-complex-shape-eo-mono.ref.png \ clip-contexts.ref.png \ clip-device-offset.argb32.ref.png \ clip-device-offset.rgb24.ref.png \ diff --git a/test/Makefile.sources b/test/Makefile.sources index e4212f0ef..c4e4463a2 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -28,6 +28,7 @@ test_sources = \ clear-source.c \ clip-all.c \ clip-contexts.c \ + clip-complex-shape.c \ clip-disjoint.c \ clip-device-offset.c \ clip-draw-unbounded.c \ diff --git a/test/clip-complex-shape-eo-aa.ref.png b/test/clip-complex-shape-eo-aa.ref.png Binary files differnew file mode 100644 index 000000000..d575aa9ad --- /dev/null +++ b/test/clip-complex-shape-eo-aa.ref.png diff --git a/test/clip-complex-shape-eo-mono.ref.png b/test/clip-complex-shape-eo-mono.ref.png Binary files differnew file mode 100644 index 000000000..d575aa9ad --- /dev/null +++ b/test/clip-complex-shape-eo-mono.ref.png diff --git a/test/clip-complex-shape.c b/test/clip-complex-shape.c new file mode 100644 index 000000000..d7d530146 --- /dev/null +++ b/test/clip-complex-shape.c @@ -0,0 +1,114 @@ +/* + * Copyright 2011 SCore 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: Taekyun Kim <podain77@gmail.com> + */ + +#include "cairo-test.h" + +static void +rounded_rectangle(cairo_t *cr, + double x, double y, + double width, double height, + double radius) +{ + cairo_move_to (cr, x, y + radius); + cairo_line_to (cr, x, y + height - radius); + cairo_curve_to (cr, x, y + height - radius/2.0, + x + radius/2.0, y + height, + x + radius, y + height); + cairo_line_to (cr, x + width - radius, y + height); + cairo_curve_to (cr, x + width - radius/2.0, y + height, + x + width, y + height - radius/2.0, + x + width, y + height - radius); + cairo_line_to (cr, x + width, y + radius); + cairo_curve_to (cr, x + width, y + radius/2.0, + x + width - radius/2.0, y, + x + width - radius, y); + cairo_line_to (cr, x + radius, y); + cairo_curve_to (cr, x + radius/2.0, y, x, y + radius/2.0, x, y + radius); + cairo_close_path(cr); +} + +static void +background (cairo_t *cr) +{ + cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); + cairo_paint(cr); +} + +static void +foreground (cairo_t *cr) +{ + cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 1.0); + cairo_set_operator(cr, CAIRO_OPERATOR_OVER); + cairo_rectangle(cr, 20, 20, 60, 60); + cairo_fill(cr); +} + +static cairo_test_status_t +clip_eo_mono (cairo_t *cr, int width, int height) +{ + + background (cr); + + cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); + cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); + rounded_rectangle(cr, 0, 0, 40, 100, 10); + rounded_rectangle(cr, 60, 0, 40, 100, 10); + cairo_clip(cr); + + foreground (cr); + + return CAIRO_TEST_SUCCESS; +} + +static cairo_test_status_t +clip_eo_aa (cairo_t *cr, int width, int height) +{ + background (cr); + + cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); + cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); + rounded_rectangle(cr, 0, 0, 40, 100, 10); + rounded_rectangle(cr, 60, 0, 40, 100, 10); + cairo_clip(cr); + + foreground (cr); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (clip_complex_shape_eo_mono, + "Test clipping against a complex shape", + "clip", /* keywords */ + NULL, /* requirements */ + 100, 100, + NULL, clip_eo_mono) +CAIRO_TEST (clip_complex_shape_eo_aa, + "Test clipping against a complex shape", + "clip", /* keywords */ + NULL, /* requirements */ + 100, 100, + NULL, clip_eo_aa) |