~ubuntu-branches/ubuntu/hardy/cairo/hardy-updates

« back to all changes in this revision

Viewing changes to perf/cairo-perf-cover.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-01-17 13:00:59 UTC
  • Revision ID: james.westby@ubuntu.com-20080117130059-3gbudaudr2w8bl4w
Tags: upstream-1.5.6
Import upstream version 1.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2006 Red Hat, Inc.
 
3
 *
 
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.
 
14
 *
 
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.
 
22
 *
 
23
 * Author: Carl D. Worth <cworth@cworth.org>
 
24
 */
 
25
 
 
26
#include "cairo-perf.h"
 
27
 
 
28
static void
 
29
init_and_set_source_surface (cairo_t            *cr,
 
30
                             cairo_surface_t    *source,
 
31
                             int                 width,
 
32
                             int                 height)
 
33
{
 
34
    cairo_t *cr2;
 
35
 
 
36
    /* Fill it with something known */
 
37
    cr2 = cairo_create (source);
 
38
    cairo_set_operator (cr2, CAIRO_OPERATOR_CLEAR);
 
39
    cairo_paint (cr2);
 
40
 
 
41
    cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE);
 
42
    cairo_set_source_rgb (cr2, 0, 0, 1); /* blue */
 
43
    cairo_paint (cr2);
 
44
 
 
45
    cairo_set_source_rgba (cr2, 1, 0, 0, 0.5); /* 50% red */
 
46
    cairo_new_path (cr2);
 
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);
 
49
    cairo_fill (cr2);
 
50
    cairo_destroy (cr2);
 
51
 
 
52
    cairo_set_source_surface (cr, source, 0, 0);
 
53
}
 
54
 
 
55
static void
 
56
set_source_solid_rgb (cairo_t   *cr,
 
57
                      int        width,
 
58
                      int        height)
 
59
{
 
60
    cairo_set_source_rgb (cr, 0.2, 0.6, 0.9);
 
61
}
 
62
 
 
63
static void
 
64
set_source_solid_rgba (cairo_t  *cr,
 
65
                       int       width,
 
66
                       int       height)
 
67
{
 
68
    cairo_set_source_rgba (cr, 0.2, 0.6, 0.9, 0.7);
 
69
}
 
70
 
 
71
static void
 
72
set_source_image_surface_rgb (cairo_t   *cr,
 
73
                              int        width,
 
74
                              int        height)
 
75
{
 
76
    cairo_surface_t *source;
 
77
 
 
78
    source = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
 
79
                                         width, height);
 
80
    init_and_set_source_surface (cr, source, width, height);
 
81
 
 
82
    cairo_surface_destroy (source);
 
83
}
 
84
 
 
85
static void
 
86
set_source_image_surface_rgba (cairo_t  *cr,
 
87
                               int       width,
 
88
                               int       height)
 
89
{
 
90
    cairo_surface_t *source;
 
91
 
 
92
    source = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
 
93
                                         width, height);
 
94
    init_and_set_source_surface (cr, source, width, height);
 
95
 
 
96
    cairo_surface_destroy (source);
 
97
}
 
98
 
 
99
static void
 
100
set_source_similar_surface_rgb (cairo_t *cr,
 
101
                                int      width,
 
102
                                int      height)
 
103
{
 
104
    cairo_surface_t *source;
 
105
 
 
106
    source = cairo_surface_create_similar (cairo_get_group_target (cr),
 
107
                                           CAIRO_CONTENT_COLOR,
 
108
                                           width, height);
 
109
    init_and_set_source_surface (cr, source, width, height);
 
110
 
 
111
    cairo_surface_destroy (source);
 
112
}
 
113
 
 
114
static void
 
115
set_source_similar_surface_rgba (cairo_t        *cr,
 
116
                                 int             width,
 
117
                                 int             height)
 
118
{
 
119
    cairo_surface_t *source;
 
120
 
 
121
    source = cairo_surface_create_similar (cairo_get_group_target (cr),
 
122
                                           CAIRO_CONTENT_COLOR_ALPHA,
 
123
                                           width, height);
 
124
    init_and_set_source_surface (cr, source, width, height);
 
125
 
 
126
    cairo_surface_destroy (source);
 
127
}
 
128
 
 
129
static void
 
130
set_source_linear_rgb (cairo_t *cr,
 
131
                       int      width,
 
132
                       int      height)
 
133
{
 
134
    cairo_pattern_t *linear;
 
135
 
 
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 */
 
139
 
 
140
    cairo_set_source (cr, linear);
 
141
 
 
142
    cairo_pattern_destroy (linear);
 
143
}
 
144
 
 
145
static void
 
146
set_source_linear_rgba (cairo_t *cr,
 
147
                        int     width,
 
148
                        int     height)
 
149
{
 
150
    cairo_pattern_t *linear;
 
151
 
 
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 */
 
155
 
 
156
    cairo_set_source (cr, linear);
 
157
 
 
158
    cairo_pattern_destroy (linear);
 
159
}
 
160
 
 
161
static void
 
162
set_source_radial_rgb (cairo_t *cr,
 
163
                       int      width,
 
164
                       int      height)
 
165
{
 
166
    cairo_pattern_t *radial;
 
167
 
 
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 */
 
172
 
 
173
    cairo_set_source (cr, radial);
 
174
 
 
175
    cairo_pattern_destroy (radial);
 
176
}
 
177
 
 
178
static void
 
179
set_source_radial_rgba (cairo_t *cr,
 
180
                        int     width,
 
181
                        int     height)
 
182
{
 
183
    cairo_pattern_t *radial;
 
184
 
 
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 */
 
189
 
 
190
    cairo_set_source (cr, radial);
 
191
 
 
192
    cairo_pattern_destroy (radial);
 
193
}
 
194
 
 
195
typedef void (*set_source_func_t) (cairo_t *cr, int width, int height);
 
196
#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0]))
 
197
 
 
198
void
 
199
cairo_perf_cover_sources_and_operators (cairo_perf_t            *perf,
 
200
                                        const char              *name,
 
201
                                        cairo_perf_func_t        perf_func)
 
202
{
 
203
    unsigned int i, j;
 
204
    char *expanded_name;
 
205
 
 
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" }
 
217
    };
 
218
 
 
219
    struct { cairo_operator_t op; const char *name; } operators[] = {
 
220
        { CAIRO_OPERATOR_OVER, "over" },
 
221
        { CAIRO_OPERATOR_SOURCE, "source" }
 
222
    };
 
223
 
 
224
    for (i = 0; i < ARRAY_SIZE (sources); i++) {
 
225
        (sources[i].set_source) (perf->cr, perf->size, perf->size);
 
226
 
 
227
        for (j = 0; j < ARRAY_SIZE (operators); j++) {
 
228
            cairo_set_operator (perf->cr, operators[j].op);
 
229
 
 
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);
 
234
        }
 
235
    }
 
236
}