2 * Copyright (c) 2010 M Joonas Pihlaja
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Author: M Joonas Pihlaja <jpihlaja@cc.helsinki.fi>
26 #include "cairo-test.h"
28 /* Tests specific clipping fast paths and their interaction with
29 * groups: It shouldn't matter if the clip is set before or after
32 * There's some overlap with the following tests, but they test for
35 * group-clip.c (tests preserving paths), clipped-group.c (tests
36 * clipping the same thing different ways), clip-push-group (tests
37 * for a specific bug).
40 #define GENERATE_REF 0
42 /* For determining whether we establish the clip path before or after
49 typedef void (*clipper_t)(cairo_t *cr, int w, int h);
51 static cairo_test_status_t
52 clip_and_paint (cairo_t *cr,
62 if (clip_where == CLIP_OUTSIDE_GROUP)
64 cairo_push_group (cr); {
65 if (clip_where == CLIP_INSIDE_GROUP)
69 cairo_pop_group_to_source (cr);
70 if (clip_where == CLIP_OUTSIDE_GROUP)
71 cairo_reset_clip (cr);
76 return CAIRO_TEST_SUCCESS;
79 static cairo_test_status_t
80 run_clip_test (cairo_t *cr, int w, int h, clipper_t do_clip)
82 cairo_set_source_rgb (cr, 1,1,1);
84 cairo_set_source_rgb (cr, 1,0,0);
87 clip_and_paint (cr, w/2, h, do_clip, CLIP_OUTSIDE_GROUP);
90 cairo_translate(cr, w/2, 0);
91 clip_and_paint (cr, w/2, h, do_clip, CLIP_INSIDE_GROUP);
93 return CAIRO_TEST_SUCCESS;
97 clip_aligned_rectangles (cairo_t *cr, int w, int h)
104 cairo_rectangle (cr, x1, y1, w, h);
107 cairo_rectangle (cr, x2, y2, -w, -h);
112 clip_unaligned_rectangles (cairo_t *cr, int w, int h)
114 /* This clip stresses the antialiased edges produced by an
115 * unaligned rectangular clip. The edges should be produced by
116 * compositing red on white with alpha = 0.5 on the sides, and with
117 * alpha = 0.25 in the corners. */
123 cairo_rectangle (cr, x1+0.5, y1+0.5, w, h);
126 cairo_rectangle (cr, x2+0.5, y2+0.5, -w, -h);
129 cairo_rectangle (cr, x2, y1+1, -w+1, h-1);
134 clip_circles (cairo_t *cr, int w, int h)
140 int r = 0.4*MIN(w,h);
142 cairo_arc (cr, x1, y1, r, 0, 6.28);
143 cairo_close_path (cr);
146 cairo_arc (cr, x2, y2, r, 0, 6.28);
147 cairo_close_path (cr);
151 static cairo_test_status_t
152 draw_aligned_rectangles (cairo_t *cr, int width, int height)
154 return run_clip_test (cr, width, height, clip_aligned_rectangles);
157 static cairo_test_status_t
158 draw_unaligned_rectangles (cairo_t *cr, int width, int height)
160 return run_clip_test (cr, width, height, clip_unaligned_rectangles);
163 static cairo_test_status_t
164 draw_circles (cairo_t *cr, int width, int height)
166 return run_clip_test (cr, width, height, clip_circles);
169 CAIRO_TEST (clip_group_shapes_aligned_rectangles,
170 "Test clip and group interaction with aligned rectangle clips",
171 "clip", /* keywords */
172 NULL, /* requirements */
174 NULL, draw_aligned_rectangles)
176 CAIRO_TEST (clip_group_shapes_unaligned_rectangles,
177 "Test clip and group interaction with unaligned rectangle clips",
178 "clip", /* keywords */
179 "target=raster", /* requirements */
181 NULL, draw_unaligned_rectangles)
183 CAIRO_TEST (clip_group_shapes_circles,
184 "Test clip and group interaction with circular clips",
185 "clip", /* keywords */
186 NULL, /* requirements */