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_CLEAR);
41
cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
42
cairo_set_source_rgb (cr2, 0, 0, 1); /* blue */
45
cairo_set_source_rgba (cr2, 1, 0, 0, 0.5); /* 50% red */
47
cairo_rectangle (cr2, 0, 0, width/2.0, height/2.0);
48
cairo_rectangle (cr2, width/2.0, height/2.0, width/2.0, height/2.0);
52
cairo_set_source_surface (cr, source, 0, 0);
56
set_source_solid_rgb (cairo_t *cr,
60
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
64
set_source_solid_rgba (cairo_t *cr,
68
cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
72
set_source_image_surface_rgb (cairo_t *cr,
76
cairo_surface_t *source;
78
source = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
80
init_and_set_source_surface (cr, source, width, height);
82
cairo_surface_destroy (source);
86
set_source_image_surface_rgba (cairo_t *cr,
90
cairo_surface_t *source;
92
source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
94
init_and_set_source_surface (cr, source, width, height);
96
cairo_surface_destroy (source);
100
set_source_similar_surface_rgb (cairo_t *cr,
104
cairo_surface_t *source;
106
source = cairo_surface_create_similar (cairo_get_group_target (cr),
109
init_and_set_source_surface (cr, source, width, height);
111
cairo_surface_destroy (source);
115
set_source_similar_surface_rgba (cairo_t *cr,
119
cairo_surface_t *source;
121
source = cairo_surface_create_similar (cairo_get_group_target (cr),
122
CAIRO_CONTENT_COLOR_ALPHA,
124
init_and_set_source_surface (cr, source, width, height);
126
cairo_surface_destroy (source);
130
set_source_linear_rgb (cairo_t *cr,
134
cairo_pattern_t *linear;
136
linear = cairo_pattern_create_linear (0.0, 0.0, width, height);
137
cairo_pattern_add_color_stop_rgb (linear, 0.0, 1, 0, 0); /* red */
138
cairo_pattern_add_color_stop_rgb (linear, 1.0, 0, 0, 1); /* blue */
140
cairo_set_source (cr, linear);
142
cairo_pattern_destroy (linear);
146
set_source_linear_rgba (cairo_t *cr,
150
cairo_pattern_t *linear;
152
linear = cairo_pattern_create_linear (0.0, 0.0, width, height);
153
cairo_pattern_add_color_stop_rgba (linear, 0.0, 1, 0, 0, 0.5); /* 50% red */
154
cairo_pattern_add_color_stop_rgba (linear, 1.0, 0, 0, 1, 0.0); /* 0% blue */
156
cairo_set_source (cr, linear);
158
cairo_pattern_destroy (linear);
162
set_source_radial_rgb (cairo_t *cr,
166
cairo_pattern_t *radial;
168
radial = cairo_pattern_create_radial (width/2.0, height/2.0, 0.0,
169
width/2.0, height/2.0, width/2.0);
170
cairo_pattern_add_color_stop_rgb (radial, 0.0, 1, 0, 0); /* red */
171
cairo_pattern_add_color_stop_rgb (radial, 1.0, 0, 0, 1); /* blue */
173
cairo_set_source (cr, radial);
175
cairo_pattern_destroy (radial);
179
set_source_radial_rgba (cairo_t *cr,
183
cairo_pattern_t *radial;
185
radial = cairo_pattern_create_radial (width/2.0, height/2.0, 0.0,
186
width/2.0, height/2.0, width/2.0);
187
cairo_pattern_add_color_stop_rgba (radial, 0.0, 1, 0, 0, 0.5); /* 50% red */
188
cairo_pattern_add_color_stop_rgba (radial, 1.0, 0, 0, 1, 0.0); /* 0% blue */
190
cairo_set_source (cr, radial);
192
cairo_pattern_destroy (radial);
195
typedef void (*set_source_func_t) (cairo_t *cr, int width, int height);
196
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
199
cairo_perf_cover_sources_and_operators (cairo_perf_t *perf,
201
cairo_perf_func_t perf_func)
206
struct { set_source_func_t set_source; const char *name; } sources[] = {
207
{ set_source_solid_rgb, "solid_rgb" },
208
{ set_source_solid_rgba, "solid_rgba" },
209
{ set_source_image_surface_rgb, "image_rgb" },
210
{ set_source_image_surface_rgba, "image_rgba" },
211
{ set_source_similar_surface_rgb, "similar_rgb" },
212
{ set_source_similar_surface_rgba, "similar_rgba" },
213
{ set_source_linear_rgb, "linear_rgb" },
214
{ set_source_linear_rgba, "linear_rgba" },
215
{ set_source_radial_rgb, "radial_rgb" },
216
{ set_source_radial_rgba, "radial_rgba" }
219
struct { cairo_operator_t op; const char *name; } operators[] = {
220
{ CAIRO_OPERATOR_OVER, "over" },
221
{ CAIRO_OPERATOR_SOURCE, "source" }
224
for (i = 0; i < ARRAY_SIZE (sources); i++) {
225
(sources[i].set_source) (perf->cr, perf->size, perf->size);
227
for (j = 0; j < ARRAY_SIZE (operators); j++) {
228
cairo_set_operator (perf->cr, operators[j].op);
230
xasprintf (&expanded_name, "%s_%s_%s",
231
name, sources[i].name, operators[j].name);
232
cairo_perf_run (perf, expanded_name, perf_func);
233
free (expanded_name);