2 * Copyright © 2005 Red Hat, Inc.
3 * Copyright © 2007 Emmanuel Pacaud
4 * Copyright © 2008 Benjamin Otte
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without
8 * fee, provided that the above copyright notice appear in all copies
9 * and that both that copyright notice and this permission notice
10 * appear in supporting documentation, and that the name of
11 * Red Hat, Inc. not be used in advertising or publicity pertaining to
12 * distribution of the software without specific, written prior
13 * permission. Red Hat, Inc. makes no representations about the
14 * suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
17 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
20 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
22 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
23 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * Authors: Owen Taylor <otaylor@redhat.com>
26 * Kristian Høgsberg <krh@redhat.com>
27 * Emmanuel Pacaud <emmanuel.pacaud@lapp.in2p3.fr>
30 #include "cairo-test.h"
35 #define START_OPERATOR CAIRO_OPERATOR_MULTIPLY
36 #define STOP_OPERATOR CAIRO_OPERATOR_HSL_LUMINOSITY
40 #define FULL_WIDTH ((STEPS + 1) * COUNT - 1)
41 #define FULL_HEIGHT ((COUNT + STOP_OPERATOR - START_OPERATOR) / COUNT) * (STEPS + 1)
44 set_solid_pattern (cairo_t *cr,
51 a = ((double) step) / (STEPS - 1);
59 if (bg) /* draw a yellow background fading in using discrete steps */
60 cairo_set_source_rgba (cr, c, c, 0, a);
61 else /* draw a teal foreground pattern fading in using discrete steps */
62 cairo_set_source_rgba (cr, 0, c, c, a);
65 /* expects a STEP*STEP pixel rectangle */
67 do_blend_solid (cairo_t *cr, cairo_operator_t op, cairo_bool_t alpha)
72 cairo_scale (cr, SIZE, SIZE);
74 /* not using CAIRO_OPERATOR_SOURCE here, it triggers a librsvg bug */
75 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
76 for (x = 0; x < STEPS; x++) {
77 /* draw the background using discrete steps */
78 set_solid_pattern (cr, x, TRUE, alpha);
79 cairo_rectangle (cr, x, 0, 1, STEPS);
83 cairo_set_operator (cr, op);
84 for (x = 0; x < STEPS; x++) {
85 /* draw an orthogonal foreground pattern using discrete steps */
86 set_solid_pattern (cr, x, FALSE, alpha);
87 cairo_rectangle (cr, 0, x, STEPS, 1);
95 create_patterns (cairo_t *cr,
100 cairo_t *bgcr, *fgcr;
102 *bg = cairo_surface_create_similar (cairo_get_target (cr),
103 CAIRO_CONTENT_COLOR_ALPHA,
106 *fg = cairo_surface_create_similar (cairo_get_target (cr),
107 CAIRO_CONTENT_COLOR_ALPHA,
111 bgcr = cairo_create (*bg);
112 fgcr = cairo_create (*fg);
114 do_blend_solid (bgcr, CAIRO_OPERATOR_DEST, alpha);
115 do_blend_solid (fgcr, CAIRO_OPERATOR_SOURCE, alpha);
117 cairo_destroy (bgcr);
118 cairo_destroy (fgcr);
121 /* expects a STEP*STEP pixel rectangle */
123 do_blend (cairo_t *cr, cairo_operator_t op, cairo_bool_t alpha)
125 cairo_surface_t *bg, *fg;
127 create_patterns (cr, &bg, &fg, alpha);
129 /* not using CAIRO_OPERATOR_SOURCE here, it triggers a librsvg bug */
130 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
131 cairo_set_source_surface (cr, bg, 0, 0);
134 cairo_set_operator (cr, op);
135 cairo_set_source_surface (cr, fg, 0, 0);
138 cairo_surface_destroy (fg);
139 cairo_surface_destroy (bg);
143 do_blend_mask (cairo_t *cr, cairo_operator_t op, cairo_bool_t alpha)
145 cairo_surface_t *bg, *fg;
147 create_patterns (cr, &bg, &fg, alpha);
149 /* not using CAIRO_OPERATOR_SOURCE here, it triggers a librsvg bug */
150 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
151 cairo_set_source_surface (cr, bg, 0, 0);
154 cairo_set_operator (cr, op);
155 cairo_set_source_surface (cr, fg, 0, 0);
156 cairo_paint_with_alpha (cr, .5);
158 cairo_surface_destroy (fg);
159 cairo_surface_destroy (bg);
162 static cairo_test_status_t
163 draw (cairo_t *cr, cairo_bool_t alpha,
164 void (*blend)(cairo_t *, cairo_operator_t, cairo_bool_t))
169 for (op = START_OPERATOR; op <= STOP_OPERATOR; op++, i++) {
172 SIZE * (STEPS + 1) * (i % COUNT),
173 SIZE * (STEPS + 1) * (i / COUNT));
174 blend (cr, op, alpha);
178 return CAIRO_TEST_SUCCESS;
181 static cairo_test_status_t
182 draw_extended_blend (cairo_t *cr, int width, int height)
184 return draw (cr, FALSE, do_blend);
187 static cairo_test_status_t
188 draw_extended_blend_alpha (cairo_t *cr, int width, int height)
190 return draw (cr, TRUE, do_blend);
193 static cairo_test_status_t
194 draw_extended_blend_solid (cairo_t *cr, int width, int height)
196 return draw (cr, FALSE, do_blend_solid);
199 static cairo_test_status_t
200 draw_extended_blend_solid_alpha (cairo_t *cr, int width, int height)
202 return draw (cr, TRUE, do_blend_solid);
205 static cairo_test_status_t
206 draw_extended_blend_mask (cairo_t *cr, int width, int height)
208 return draw (cr, FALSE, do_blend_mask);
210 static cairo_test_status_t
211 draw_extended_blend_alpha_mask (cairo_t *cr, int width, int height)
213 return draw (cr, TRUE, do_blend_mask);
216 CAIRO_TEST (extended_blend,
217 "Tests extended blend modes without alpha",
218 "operator", /* keywords */
219 NULL, /* requirements */
220 FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
221 NULL, draw_extended_blend)
223 CAIRO_TEST (extended_blend_alpha,
224 "Tests extended blend modes with alpha",
225 "operator", /* keywords */
226 NULL, /* requirements */
227 FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
228 NULL, draw_extended_blend_alpha)
230 CAIRO_TEST (extended_blend_mask,
231 "Tests extended blend modes with an alpha mask",
232 "operator,mask", /* keywords */
233 NULL, /* requirements */
234 FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
235 NULL, draw_extended_blend_mask)
236 CAIRO_TEST (extended_blend_alpha_mask,
237 "Tests extended blend modes with an alpha mask",
238 "operator,mask", /* keywords */
239 NULL, /* requirements */
240 FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
241 NULL, draw_extended_blend_alpha_mask)
244 CAIRO_TEST (extended_blend_solid,
245 "Tests extended blend modes on solid patterns without alpha",
246 "operator", /* keywords */
247 NULL, /* requirements */
248 FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
249 NULL, draw_extended_blend_solid)
251 CAIRO_TEST (extended_blend_solid_alpha,
252 "Tests extended blend modes on solid patterns with alpha",
253 "operator", /* keywords */
254 NULL, /* requirements */
255 FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
256 NULL, draw_extended_blend_solid_alpha)