2 * Copyright © 2006 Red Hat, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Carl D. Worth <cworth@cworth.org>
26 #include "cairo-perf.h"
29 init_and_set_source_surface (cairo_t *cr,
30 cairo_surface_t *source,
36 /* Fill it with something known */
37 cr2 = cairo_create (source);
38 cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
39 cairo_set_source_rgb (cr2, 0, 0, 1); /* blue */
42 cairo_set_source_rgba (cr2, 1, 0, 0, 0.5); /* 50% red */
44 cairo_rectangle (cr2, 0, 0, width/2.0, height/2.0);
45 cairo_rectangle (cr2, width/2.0, height/2.0, width/2.0, height/2.0);
48 cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0);
53 set_source_solid_rgb (cairo_t *cr,
57 cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
61 set_source_solid_rgba (cairo_t *cr,
65 cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
69 set_source_image_surface_rgb (cairo_t *cr,
73 cairo_surface_t *source;
75 source = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
77 init_and_set_source_surface (cr, source, width, height);
79 cairo_surface_destroy (source);
83 set_source_image_surface_rgba (cairo_t *cr,
87 cairo_surface_t *source;
89 source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
91 init_and_set_source_surface (cr, source, width, height);
93 cairo_surface_destroy (source);
97 set_source_image_surface_rgba_mag (cairo_t *cr,
101 cairo_surface_t *source;
103 source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
105 cairo_scale(cr, 2.1, 2.1);
106 init_and_set_source_surface (cr, source, width/2, height/2);
107 cairo_scale(cr, 1/2.1, 1/2.1);
109 cairo_surface_destroy (source);
113 set_source_image_surface_rgba_min (cairo_t *cr,
117 cairo_surface_t *source;
119 source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
121 cairo_scale(cr, 1/1.9, 1/1.9);
122 init_and_set_source_surface (cr, source, width*2, height*2);
123 cairo_scale(cr, 1.9, 1.9);
125 cairo_surface_destroy (source);
129 set_source_similar_surface_rgb (cairo_t *cr,
133 cairo_surface_t *source;
135 source = cairo_surface_create_similar (cairo_get_group_target (cr),
138 init_and_set_source_surface (cr, source, width, height);
140 cairo_surface_destroy (source);
144 set_source_similar_surface_rgba (cairo_t *cr,
148 cairo_surface_t *source;
150 source = cairo_surface_create_similar (cairo_get_group_target (cr),
151 CAIRO_CONTENT_COLOR_ALPHA,
153 init_and_set_source_surface (cr, source, width, height);
155 cairo_surface_destroy (source);
159 set_source_similar_surface_rgba_mag (cairo_t *cr,
163 cairo_surface_t *source;
165 source = cairo_surface_create_similar (cairo_get_group_target (cr),
166 CAIRO_CONTENT_COLOR_ALPHA,
168 cairo_scale(cr, 2.1, 2.1);
169 init_and_set_source_surface (cr, source, width/2, height/2);
170 cairo_scale(cr, 1/2.1, 1/2.1);
172 cairo_surface_destroy (source);
176 set_source_similar_surface_rgba_min (cairo_t *cr,
180 cairo_surface_t *source;
182 source = cairo_surface_create_similar (cairo_get_group_target (cr),
183 CAIRO_CONTENT_COLOR_ALPHA,
185 cairo_scale(cr, 1/1.9, 1/1.9);
186 init_and_set_source_surface (cr, source, width*2, height*2);
187 cairo_scale(cr, 1.9, 1.9);
189 cairo_surface_destroy (source);
193 set_source_linear_rgb (cairo_t *cr,
197 cairo_pattern_t *linear;
199 linear = cairo_pattern_create_linear (0.0, 0.0, width, height);
200 cairo_pattern_add_color_stop_rgb (linear, 0.0, 1, 0, 0); /* red */
201 cairo_pattern_add_color_stop_rgb (linear, 1.0, 0, 0, 1); /* blue */
203 cairo_set_source (cr, linear);
205 cairo_pattern_destroy (linear);
209 set_source_linear_rgba (cairo_t *cr,
213 cairo_pattern_t *linear;
215 linear = cairo_pattern_create_linear (0.0, 0.0, width, height);
216 cairo_pattern_add_color_stop_rgba (linear, 0.0, 1, 0, 0, 0.5); /* 50% red */
217 cairo_pattern_add_color_stop_rgba (linear, 1.0, 0, 0, 1, 0.0); /* 0% blue */
219 cairo_set_source (cr, linear);
221 cairo_pattern_destroy (linear);
225 set_source_linear3_rgb (cairo_t *cr,
229 cairo_pattern_t *linear;
231 linear = cairo_pattern_create_linear (0.0, 0.0, width, height);
232 cairo_pattern_add_color_stop_rgb (linear, 0.0, 1, 0, 0); /* red */
233 cairo_pattern_add_color_stop_rgb (linear, 0.5, 0, 1, 0); /* green */
234 cairo_pattern_add_color_stop_rgb (linear, 1.0, 0, 0, 1); /* blue */
236 cairo_set_source (cr, linear);
238 cairo_pattern_destroy (linear);
242 set_source_linear3_rgba (cairo_t *cr,
246 cairo_pattern_t *linear;
248 linear = cairo_pattern_create_linear (0.0, 0.0, width, height);
249 cairo_pattern_add_color_stop_rgba (linear, 0.0, 1, 0, 0, 0.5); /* 50% red */
250 cairo_pattern_add_color_stop_rgba (linear, 0.5, 0, 1, 0, 0.0); /* 0% green */
251 cairo_pattern_add_color_stop_rgba (linear, 1.0, 0, 0, 1, 0.5); /* 50% blue */
253 cairo_set_source (cr, linear);
255 cairo_pattern_destroy (linear);
259 set_source_radial_rgb (cairo_t *cr,
263 cairo_pattern_t *radial;
265 radial = cairo_pattern_create_radial (width/2.0, height/2.0, 0.0,
266 width/2.0, height/2.0, width/2.0);
267 cairo_pattern_add_color_stop_rgb (radial, 0.0, 1, 0, 0); /* red */
268 cairo_pattern_add_color_stop_rgb (radial, 1.0, 0, 0, 1); /* blue */
270 cairo_set_source (cr, radial);
272 cairo_pattern_destroy (radial);
276 set_source_radial_rgba (cairo_t *cr,
280 cairo_pattern_t *radial;
282 radial = cairo_pattern_create_radial (width/2.0, height/2.0, 0.0,
283 width/2.0, height/2.0, width/2.0);
284 cairo_pattern_add_color_stop_rgba (radial, 0.0, 1, 0, 0, 0.5); /* 50% red */
285 cairo_pattern_add_color_stop_rgba (radial, 1.0, 0, 0, 1, 0.0); /* 0% blue */
287 cairo_set_source (cr, radial);
289 cairo_pattern_destroy (radial);
292 typedef void (*set_source_func_t) (cairo_t *cr, int width, int height);
293 #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
296 cairo_perf_cover_sources_and_operators (cairo_perf_t *perf,
298 cairo_perf_func_t perf_func,
299 cairo_count_func_t count_func)
304 struct { set_source_func_t set_source; const char *name; } sources[] = {
305 { set_source_solid_rgb, "solid-rgb" },
306 { set_source_solid_rgba, "solid-rgba" },
307 { set_source_image_surface_rgb, "image-rgb" },
308 { set_source_image_surface_rgba, "image-rgba" },
309 { set_source_image_surface_rgba_mag, "image-rgba-mag" },
310 { set_source_image_surface_rgba_min, "image-rgba-min" },
311 { set_source_similar_surface_rgb, "similar-rgb" },
312 { set_source_similar_surface_rgba, "similar-rgba" },
313 { set_source_similar_surface_rgba_mag, "similar-rgba-mag" },
314 { set_source_similar_surface_rgba_min, "similar-rgba-min" },
315 { set_source_linear_rgb, "linear-rgb" },
316 { set_source_linear_rgba, "linear-rgba" },
317 { set_source_linear3_rgb, "linear3-rgb" },
318 { set_source_linear3_rgba, "linear3-rgba" },
319 { set_source_radial_rgb, "radial-rgb" },
320 { set_source_radial_rgba, "radial-rgba" }
323 struct { cairo_operator_t op; const char *name; } operators[] = {
324 { CAIRO_OPERATOR_OVER, "over" },
325 { CAIRO_OPERATOR_SOURCE, "source" }
328 for (i = 0; i < ARRAY_SIZE (sources); i++) {
329 (sources[i].set_source) (perf->cr, perf->size, perf->size);
331 for (j = 0; j < ARRAY_SIZE (operators); j++) {
332 cairo_set_operator (perf->cr, operators[j].op);
334 xasprintf (&expanded_name, "%s_%s_%s",
335 name, sources[i].name, operators[j].name);
336 cairo_perf_run (perf, expanded_name, perf_func, count_func);
337 free (expanded_name);