2 * Copyright © 2006 Red Hat, Inc.
3 * Copyright © 2009 Chris Wilson
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of
10 * Red Hat, Inc. not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. Red Hat, Inc. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as
14 * is" without express or implied warranty.
16 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
19 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: Carl D. Worth <cworth@cworth.org>
25 * Chris Wilson <chris@chris-wilson.co.uk>
28 #include "cairo-perf.h"
31 do_mask_solid (cairo_t *cr, int width, int height, int loops)
33 cairo_pattern_t *mask;
35 mask = cairo_pattern_create_rgba (0, 0, 0, .5);
37 cairo_perf_timer_start ();
38 cairo_perf_set_thread_aware (cr, FALSE);
42 cairo_perf_set_thread_aware (cr, TRUE);
43 cairo_mask (cr, mask);
46 cairo_perf_timer_stop ();
48 cairo_pattern_destroy (mask);
50 return cairo_perf_timer_elapsed ();
53 static cairo_surface_t *
54 init_surface (cairo_surface_t *surface, int width, int height)
58 cr = cairo_create (surface);
59 cairo_surface_destroy (surface);
61 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
62 cairo_set_source_rgb (cr, 0, 0, 0); /* back */
65 cairo_set_source_rgba (cr, 1, 1, 1, 0.5); /* 50% */
67 cairo_rectangle (cr, 0, 0, width/2.0, height/2.0);
68 cairo_rectangle (cr, width/2.0, height/2.0, width/2.0, height/2.0);
71 surface = cairo_surface_reference (cairo_get_target (cr));
78 do_mask_image (cairo_t *cr, int width, int height, int loops)
80 cairo_surface_t *surface;
81 cairo_pattern_t *mask;
83 surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
84 mask = cairo_pattern_create_for_surface (init_surface (surface,
87 cairo_surface_destroy (surface);
89 cairo_perf_timer_start ();
90 cairo_perf_set_thread_aware (cr, FALSE);
94 cairo_perf_set_thread_aware (cr, TRUE);
95 cairo_mask (cr, mask);
98 cairo_perf_timer_stop ();
100 cairo_pattern_destroy (mask);
102 return cairo_perf_timer_elapsed ();
106 do_mask_image_half (cairo_t *cr, int width, int height, int loops)
108 cairo_surface_t *surface;
109 cairo_pattern_t *mask;
110 cairo_matrix_t matrix;
112 surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
113 mask = cairo_pattern_create_for_surface (init_surface (surface,
116 cairo_surface_destroy (surface);
117 cairo_matrix_init_scale (&matrix, .5, .5);
118 cairo_pattern_set_matrix (mask, &matrix);
120 cairo_perf_timer_start ();
121 cairo_perf_set_thread_aware (cr, FALSE);
125 cairo_perf_set_thread_aware (cr, TRUE);
126 cairo_mask (cr, mask);
129 cairo_perf_timer_stop ();
131 cairo_pattern_destroy (mask);
133 return cairo_perf_timer_elapsed ();
137 do_mask_image_double (cairo_t *cr, int width, int height, int loops)
139 cairo_surface_t *surface;
140 cairo_pattern_t *mask;
141 cairo_matrix_t matrix;
143 surface = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height);
144 mask = cairo_pattern_create_for_surface (init_surface (surface,
147 cairo_surface_destroy (surface);
148 cairo_matrix_init_scale (&matrix, 2., 2.);
149 cairo_pattern_set_matrix (mask, &matrix);
151 cairo_perf_timer_start ();
152 cairo_perf_set_thread_aware (cr, FALSE);
156 cairo_perf_set_thread_aware (cr, TRUE);
157 cairo_mask (cr, mask);
160 cairo_perf_timer_stop ();
162 cairo_pattern_destroy (mask);
164 return cairo_perf_timer_elapsed ();
168 do_mask_similar (cairo_t *cr, int width, int height, int loops)
170 cairo_surface_t *surface;
171 cairo_pattern_t *mask;
173 surface = cairo_surface_create_similar (cairo_get_group_target (cr),
174 CAIRO_CONTENT_ALPHA, width, height);
175 mask = cairo_pattern_create_for_surface (init_surface (surface,
178 cairo_surface_destroy (surface);
180 cairo_perf_timer_start ();
181 cairo_perf_set_thread_aware (cr, FALSE);
185 cairo_perf_set_thread_aware (cr, TRUE);
186 cairo_mask (cr, mask);
189 cairo_perf_timer_stop ();
191 cairo_pattern_destroy (mask);
193 return cairo_perf_timer_elapsed ();
197 do_mask_similar_half (cairo_t *cr, int width, int height, int loops)
199 cairo_surface_t *surface;
200 cairo_pattern_t *mask;
201 cairo_matrix_t matrix;
203 surface = cairo_surface_create_similar (cairo_get_group_target (cr),
204 CAIRO_CONTENT_ALPHA, width, height);
205 mask = cairo_pattern_create_for_surface (init_surface (surface,
208 cairo_surface_destroy (surface);
209 cairo_matrix_init_scale (&matrix, .5, .5);
210 cairo_pattern_set_matrix (mask, &matrix);
212 cairo_perf_timer_start ();
213 cairo_perf_set_thread_aware (cr, FALSE);
217 cairo_perf_set_thread_aware (cr, TRUE);
218 cairo_mask (cr, mask);
221 cairo_perf_timer_stop ();
223 cairo_pattern_destroy (mask);
225 return cairo_perf_timer_elapsed ();
229 do_mask_similar_double (cairo_t *cr, int width, int height, int loops)
231 cairo_surface_t *surface;
232 cairo_pattern_t *mask;
233 cairo_matrix_t matrix;
235 surface = cairo_surface_create_similar (cairo_get_group_target (cr),
236 CAIRO_CONTENT_ALPHA, width, height);
237 mask = cairo_pattern_create_for_surface (init_surface (surface,
240 cairo_surface_destroy (surface);
241 cairo_matrix_init_scale (&matrix, 2., 2.);
242 cairo_pattern_set_matrix (mask, &matrix);
244 cairo_perf_timer_start ();
245 cairo_perf_set_thread_aware (cr, FALSE);
249 cairo_perf_set_thread_aware (cr, TRUE);
250 cairo_mask (cr, mask);
253 cairo_perf_timer_stop ();
255 cairo_pattern_destroy (mask);
257 return cairo_perf_timer_elapsed ();
261 do_mask_linear (cairo_t *cr, int width, int height, int loops)
263 cairo_pattern_t *mask;
265 mask = cairo_pattern_create_linear (0.0, 0.0, width, height);
266 cairo_pattern_add_color_stop_rgba (mask, 0.0, 0, 0, 0, 0.5); /* 50% */
267 cairo_pattern_add_color_stop_rgba (mask, 0.0, 0, 0, 0, 1.0); /* 100% */
269 cairo_perf_timer_start ();
270 cairo_perf_set_thread_aware (cr, FALSE);
274 cairo_perf_set_thread_aware (cr, TRUE);
275 cairo_mask (cr, mask);
278 cairo_perf_timer_stop ();
280 cairo_pattern_destroy (mask);
282 return cairo_perf_timer_elapsed ();
286 do_mask_radial (cairo_t *cr, int width, int height, int loops)
288 cairo_pattern_t *mask;
290 mask = cairo_pattern_create_radial (width/2.0, height/2.0, 0.0,
291 width/2.0, height/2.0, width/2.0);
292 cairo_pattern_add_color_stop_rgba (mask, 0.0, 0, 0, 0, 0.5); /* 50% */
293 cairo_pattern_add_color_stop_rgba (mask, 0.0, 0, 0, 0, 1.0); /* 100% */
295 cairo_perf_timer_start ();
296 cairo_perf_set_thread_aware (cr, FALSE);
300 cairo_perf_set_thread_aware (cr, TRUE);
301 cairo_mask (cr, mask);
304 cairo_perf_timer_stop ();
306 cairo_pattern_destroy (mask);
308 return cairo_perf_timer_elapsed ();
312 mask_enabled (cairo_perf_t *perf)
314 return cairo_perf_can_run (perf, "mask", NULL);
318 mask (cairo_perf_t *perf, cairo_t *cr, int width, int height)
320 if (! cairo_perf_can_run (perf, "mask", NULL))
323 cairo_perf_cover_sources_and_operators (perf, "mask-solid",
324 do_mask_solid, NULL);
325 cairo_perf_cover_sources_and_operators (perf, "mask-image",
326 do_mask_image, NULL);
327 cairo_perf_cover_sources_and_operators (perf, "mask-image-half",
328 do_mask_image_half, NULL);
329 cairo_perf_cover_sources_and_operators (perf, "mask-image-double",
330 do_mask_image_double, NULL);
331 cairo_perf_cover_sources_and_operators (perf, "mask-similar",
332 do_mask_similar, NULL);
333 cairo_perf_cover_sources_and_operators (perf, "mask-similar-half",
334 do_mask_similar_half, NULL);
335 cairo_perf_cover_sources_and_operators (perf, "mask-similar-double",
336 do_mask_similar_double, NULL);
337 cairo_perf_cover_sources_and_operators (perf, "mask-linear",
338 do_mask_linear, NULL);
339 cairo_perf_cover_sources_and_operators (perf, "mask-radial",
340 do_mask_radial, NULL);