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>
28 /* This is a variant on many strokes where we precompute
29 * a simplified stroke-to-path.
30 * When we have a real stroke-to-path, it would useful to compare the cost
31 * of stroking vs filling the "identical" paths.
34 #include "cairo-perf.h"
36 static uint32_t state;
39 uniform_random (double minval, double maxval)
41 static uint32_t const poly = 0x9a795537U;
44 state = 2*state < state ? (2*state ^ poly) : 2*state;
45 return minval + state * (maxval - minval) / 4294967296.0;
49 do_many_fills_ha (cairo_t *cr, int width, int height, int loops)
54 for (count = 0; count < 1000; count++) {
55 double y = floor (uniform_random (0, height));
56 double x = floor (uniform_random (0, width));
57 cairo_rectangle (cr, x, y, ceil (uniform_random (0, width)) - x, 1);
60 cairo_perf_timer_start ();
61 cairo_perf_set_thread_aware (cr, FALSE);
65 cairo_perf_set_thread_aware (cr, TRUE);
66 cairo_fill_preserve (cr);
69 cairo_perf_timer_stop ();
73 return cairo_perf_timer_elapsed ();
77 do_many_fills_h (cairo_t *cr, int width, int height, int loops)
82 for (count = 0; count < 1000; count++) {
83 double y = uniform_random (0, height);
84 double x = uniform_random (0, width);
85 cairo_rectangle (cr, x, y, uniform_random (0, width) - x, 1);
88 cairo_perf_timer_start ();
89 cairo_perf_set_thread_aware (cr, FALSE);
93 cairo_perf_set_thread_aware (cr, TRUE);
94 cairo_fill_preserve (cr);
97 cairo_perf_timer_stop ();
101 return cairo_perf_timer_elapsed ();
105 do_many_fills_va (cairo_t *cr, int width, int height, int loops)
110 for (count = 0; count < 1000; count++) {
111 double x = floor (uniform_random (0, width));
112 double y = floor (uniform_random (0, height));
113 cairo_rectangle (cr, x, y, 1, ceil (uniform_random (0, height) - y));
116 cairo_perf_timer_start ();
117 cairo_perf_set_thread_aware (cr, FALSE);
121 cairo_perf_set_thread_aware (cr, TRUE);
122 cairo_fill_preserve (cr);
125 cairo_perf_timer_stop ();
129 return cairo_perf_timer_elapsed ();
133 do_many_fills_v (cairo_t *cr, int width, int height, int loops)
138 for (count = 0; count < 1000; count++) {
139 double x = uniform_random (0, width);
140 double y = uniform_random (0, height);
141 cairo_rectangle (cr, x, y, 1, uniform_random (0, height) - y);
144 cairo_perf_timer_start ();
145 cairo_perf_set_thread_aware (cr, FALSE);
149 cairo_perf_set_thread_aware (cr, TRUE);
150 cairo_fill_preserve (cr);
153 cairo_perf_timer_stop ();
157 return cairo_perf_timer_elapsed ();
161 do_many_fills (cairo_t *cr, int width, int height, int loops)
165 /* lots and lots of overlapping stroke-like fills */
167 for (count = 0; count < 1000; count++) {
170 uniform_random (0, width),
171 uniform_random (0, height));
172 cairo_rotate (cr, uniform_random (-M_PI,M_PI));
173 cairo_rectangle (cr, 0, 0, uniform_random (0, width), 1);
177 cairo_perf_timer_start ();
178 cairo_perf_set_thread_aware (cr, FALSE);
182 cairo_perf_set_thread_aware (cr, TRUE);
183 cairo_fill_preserve (cr);
186 cairo_perf_timer_stop ();
190 return cairo_perf_timer_elapsed ();
194 many_fills_enabled (cairo_perf_t *perf)
196 return cairo_perf_can_run (perf, "many-fills", NULL);
200 many_fills (cairo_perf_t *perf, cairo_t *cr, int width, int height)
202 cairo_perf_run (perf, "many-fills-halign", do_many_fills_ha, NULL);
203 cairo_perf_run (perf, "many-fills-valign", do_many_fills_va, NULL);
204 cairo_perf_run (perf, "many-fills-horizontal", do_many_fills_h, NULL);
205 cairo_perf_run (perf, "many-fills-vertical", do_many_fills_v, NULL);
206 cairo_perf_run (perf, "many-fills-random", do_many_fills, NULL);