2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Author: Chris Wilson <chris@chris-wilson.co.uk>
27 /* Measure the overhead in setting a single pixel */
29 #include "cairo-perf.h"
34 pixel_direct (cairo_t *cr, int width, int height, int loops)
36 cairo_surface_t *surface, *image;
40 surface = cairo_get_target (cr);
41 image = cairo_surface_map_to_image (surface, NULL);
42 data = (uint32_t *) cairo_image_surface_get_data (image);
43 stride = cairo_image_surface_get_stride (image) / sizeof (uint32_t);
45 switch (cairo_image_surface_get_format (image)) {
47 case CAIRO_FORMAT_INVALID:
48 case CAIRO_FORMAT_A1: bpp = 0; break;
49 case CAIRO_FORMAT_A8: bpp = 8; break;
50 case CAIRO_FORMAT_RGB16_565: bpp = 16; break;
51 case CAIRO_FORMAT_RGB24:
52 case CAIRO_FORMAT_RGB30:
53 case CAIRO_FORMAT_ARGB32: bpp = 32; break;
56 cairo_perf_timer_start ();
59 pixman_fill (data, stride, bpp, 0, 0, 1, 1, -1);
61 cairo_perf_timer_stop ();
63 cairo_surface_unmap_image (surface, image);
65 return cairo_perf_timer_elapsed ();
69 pixel_paint (cairo_t *cr, int width, int height, int loops)
71 cairo_perf_timer_start ();
76 cairo_perf_timer_stop ();
78 return cairo_perf_timer_elapsed ();
82 pixel_mask (cairo_t *cr, int width, int height, int loops)
84 cairo_surface_t *mask;
87 mask = cairo_surface_create_similar (cairo_get_target (cr),
90 cr2 = cairo_create (mask);
91 cairo_set_source_rgb (cr2, 1,1,1);
95 cairo_perf_timer_start ();
98 cairo_mask_surface (cr, mask, 0, 0);
100 cairo_perf_timer_stop ();
102 cairo_surface_destroy (mask);
104 return cairo_perf_timer_elapsed ();
108 pixel_rectangle (cairo_t *cr, int width, int height, int loops)
111 cairo_rectangle (cr, 0, 0, 1, 1);
113 cairo_perf_timer_start ();
116 cairo_fill_preserve (cr);
118 cairo_perf_timer_stop ();
121 return cairo_perf_timer_elapsed ();
125 pixel_subrectangle (cairo_t *cr, int width, int height, int loops)
128 cairo_rectangle (cr, 0.1, 0.1, .8, .8);
130 cairo_perf_timer_start ();
133 cairo_fill_preserve (cr);
135 cairo_perf_timer_stop ();
138 return cairo_perf_timer_elapsed ();
142 pixel_triangle (cairo_t *cr, int width, int height, int loops)
145 cairo_move_to (cr, 0, 0);
146 cairo_line_to (cr, 1, 1);
147 cairo_line_to (cr, 0, 1);
149 cairo_perf_timer_start ();
152 cairo_fill_preserve (cr);
154 cairo_perf_timer_stop ();
157 return cairo_perf_timer_elapsed ();
161 pixel_circle (cairo_t *cr, int width, int height, int loops)
164 cairo_arc (cr, 0.5, 0.5, 0.5, 0, 2 * M_PI);
166 cairo_perf_timer_start ();
169 cairo_fill_preserve (cr);
171 cairo_perf_timer_stop ();
174 return cairo_perf_timer_elapsed ();
178 pixel_stroke (cairo_t *cr, int width, int height, int loops)
180 cairo_set_line_width (cr, 1.);
182 cairo_move_to (cr, 0, 0.5);
183 cairo_line_to (cr, 1, 0.5);
185 cairo_perf_timer_start ();
188 cairo_stroke_preserve (cr);
190 cairo_perf_timer_stop ();
193 return cairo_perf_timer_elapsed ();
197 pixel_enabled (cairo_perf_t *perf)
199 return cairo_perf_can_run (perf, "pixel", NULL);
203 pixel (cairo_perf_t *perf, cairo_t *cr, int width, int height)
205 cairo_set_source_rgb (cr, 1., 1., 1.);
207 cairo_perf_run (perf, "pixel-direct", pixel_direct, NULL);
208 cairo_perf_run (perf, "pixel-paint", pixel_paint, NULL);
209 cairo_perf_run (perf, "pixel-mask", pixel_mask, NULL);
210 cairo_perf_run (perf, "pixel-rectangle", pixel_rectangle, NULL);
211 cairo_perf_run (perf, "pixel-subrectangle", pixel_subrectangle, NULL);
212 cairo_perf_run (perf, "pixel-triangle", pixel_triangle, NULL);
213 cairo_perf_run (perf, "pixel-circle", pixel_circle, NULL);
214 cairo_perf_run (perf, "pixel-stroke", pixel_stroke, NULL);
218 a1_pixel_enabled (cairo_perf_t *perf)
220 return cairo_perf_can_run (perf, "a1-pixel", NULL);
224 a1_pixel (cairo_perf_t *perf, cairo_t *cr, int width, int height)
226 cairo_set_source_rgb (cr, 1., 1., 1.);
227 cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
229 cairo_perf_run (perf, "a1-pixel-direct", pixel_direct, NULL);
230 cairo_perf_run (perf, "a1-pixel-paint", pixel_paint, NULL);
231 cairo_perf_run (perf, "a1-pixel-mask", pixel_mask, NULL);
232 cairo_perf_run (perf, "a1-pixel-rectangle", pixel_rectangle, NULL);
233 cairo_perf_run (perf, "a1-pixel-subrectangle", pixel_subrectangle, NULL);
234 cairo_perf_run (perf, "a1-pixel-triangle", pixel_triangle, NULL);
235 cairo_perf_run (perf, "a1-pixel-circle", pixel_circle, NULL);
236 cairo_perf_run (perf, "a1-pixel-stroke", pixel_stroke, NULL);