1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*
* Copyright © 2006 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of
* Red Hat, Inc. not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. Red Hat, Inc. makes no representations about the
* suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Carl D. Worth <cworth@cworth.org>
*/
#include "cairo-perf.h"
static int
iters_for_size (int size)
{
if (size <= 64)
return 8;
else if (size <= 128)
return 4;
else if (size <= 256)
return 2;
else
return 1;
}
static cairo_perf_ticks_t
do_paint (cairo_t *cr, int size)
{
int i;
int iters = iters_for_size (size);
cairo_perf_timer_start ();
for (i=0; i < iters; i++)
cairo_paint (cr);
cairo_perf_timer_stop ();
return cairo_perf_timer_elapsed ();
}
/*
* paint with solid color
*/
static cairo_perf_ticks_t
paint_over_solid (cairo_t *cr, int width, int height)
{
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
return do_paint (cr, width);
}
static cairo_perf_ticks_t
paint_over_solid_alpha (cairo_t *cr, int width, int height)
{
cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
return do_paint (cr, width);
}
static cairo_perf_ticks_t
paint_source_solid (cairo_t *cr, int width, int height)
{
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
return do_paint (cr, width);
}
static cairo_perf_ticks_t
paint_source_solid_alpha (cairo_t *cr, int width, int height)
{
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
return do_paint (cr, width);
}
/*
* paint with surface
*/
int cached_surface_width = 0;
int cached_surface_height = 0;
cairo_content_t cached_surface_content = 0;
cairo_surface_t *cached_surface = NULL;
static void
ensure_cached_surface (cairo_t *cr, cairo_content_t content, int w, int h)
{
cairo_surface_t *target_surface = cairo_get_target (cr);
cairo_t *cr2;
if (w == cached_surface_width && h == cached_surface_height &&
content == cached_surface_content &&
cached_surface &&
cairo_surface_get_type (target_surface) == cairo_surface_get_type (cached_surface))
{
return;
}
if (cached_surface)
cairo_surface_destroy (cached_surface);
cached_surface = cairo_surface_create_similar (target_surface, content, w, h);
cached_surface_width = w;
cached_surface_height = h;
cached_surface_content = content;
/* Fill it with something known */
cr2 = cairo_create (cached_surface);
cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr2);
cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgb (cr2, 0, 0, 1);
cairo_paint (cr2);
cairo_set_source_rgba (cr2, 1, 0, 0, 0.5);
cairo_new_path (cr2);
cairo_rectangle (cr2, 0, 0, w/2.0, h/2.0);
cairo_rectangle (cr2, w/2.0, h/2.0, w/2.0, h/2.0);
cairo_fill (cr2);
cairo_destroy (cr2);
}
static cairo_perf_ticks_t
paint_over_surface_rgb24 (cairo_t *cr, int width, int height)
{
ensure_cached_surface (cr, CAIRO_CONTENT_COLOR, width, height);
cairo_set_source_surface (cr, cached_surface, 0, 0);
return do_paint (cr, width);
}
static cairo_perf_ticks_t
paint_over_surface_argb32 (cairo_t *cr, int width, int height)
{
ensure_cached_surface (cr, CAIRO_CONTENT_COLOR_ALPHA, width, height);
cairo_set_source_surface (cr, cached_surface, 0, 0);
return do_paint (cr, width);
}
static cairo_perf_ticks_t
paint_source_surface_rgb24 (cairo_t *cr, int width, int height)
{
ensure_cached_surface (cr, CAIRO_CONTENT_COLOR, width, height);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface (cr, cached_surface, 0, 0);
return do_paint (cr, width);
}
static cairo_perf_ticks_t
paint_source_surface_argb32 (cairo_t *cr, int width, int height)
{
ensure_cached_surface (cr, CAIRO_CONTENT_COLOR_ALPHA, width, height);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface (cr, cached_surface, 0, 0);
return do_paint (cr, width);
}
void
paint (cairo_perf_t *perf)
{
cairo_perf_run (perf, "paint_over_solid", paint_over_solid);
cairo_perf_run (perf, "paint_over_solid_alpha", paint_over_solid_alpha);
cairo_perf_run (perf, "paint_source_solid", paint_source_solid);
cairo_perf_run (perf, "paint_source_solid_alpha", paint_source_solid_alpha);
cairo_perf_run (perf, "paint_over_surf_rgb24", paint_over_surface_rgb24);
cairo_perf_run (perf, "paint_over_surf_argb32", paint_over_surface_argb32);
cairo_perf_run (perf, "paint_source_surf_rgb24", paint_source_surface_rgb24);
cairo_perf_run (perf, "paint_source_surf_argb32", paint_source_surface_argb32);
}
|