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 #include "cairo-perf.h"
29 static uint32_t state;
32 uniform_random (double minval, double maxval)
34 static uint32_t const poly = 0x9a795537U;
37 state = 2*state < state ? (2*state ^ poly) : 2*state;
38 return minval + state * (maxval - minval) / 4294967296.0;
42 do_wide_strokes_ha (cairo_t *cr, int width, int height, int loops)
47 for (count = 0; count < 1000; count++) {
48 double h = floor (uniform_random (0, height));
49 cairo_move_to (cr, floor (uniform_random (0, width)), h);
50 cairo_line_to (cr, ceil (uniform_random (0, width)), h);
53 cairo_set_line_width (cr, 5.);
55 cairo_perf_timer_start ();
56 cairo_perf_set_thread_aware (cr, FALSE);
60 cairo_perf_set_thread_aware (cr, TRUE);
61 cairo_stroke_preserve (cr);
64 cairo_perf_timer_stop ();
68 return cairo_perf_timer_elapsed ();
72 do_wide_strokes_h (cairo_t *cr, int width, int height, int loops)
77 for (count = 0; count < 1000; count++) {
78 double h = uniform_random (0, height);
79 cairo_move_to (cr, uniform_random (0, width), h);
80 cairo_line_to (cr, uniform_random (0, width), h);
83 cairo_set_line_width (cr, 5.);
85 cairo_perf_timer_start ();
86 cairo_perf_set_thread_aware (cr, FALSE);
90 cairo_perf_set_thread_aware (cr, TRUE);
91 cairo_stroke_preserve (cr);
94 cairo_perf_timer_stop ();
98 return cairo_perf_timer_elapsed ();
102 do_wide_strokes_va (cairo_t *cr, int width, int height, int loops)
107 for (count = 0; count < 1000; count++) {
108 double v = floor (uniform_random (0, width));
109 cairo_move_to (cr, v, floor (uniform_random (0, height)));
110 cairo_line_to (cr, v, ceil (uniform_random (0, height)));
113 cairo_set_line_width (cr, 5.);
115 cairo_perf_timer_start ();
116 cairo_perf_set_thread_aware (cr, FALSE);
120 cairo_perf_set_thread_aware (cr, TRUE);
121 cairo_stroke_preserve (cr);
124 cairo_perf_timer_stop ();
128 return cairo_perf_timer_elapsed ();
132 do_wide_strokes_v (cairo_t *cr, int width, int height, int loops)
137 for (count = 0; count < 1000; count++) {
138 double v = uniform_random (0, width);
139 cairo_move_to (cr, v, uniform_random (0, height));
140 cairo_line_to (cr, v, uniform_random (0, height));
143 cairo_set_line_width (cr, 5.);
145 cairo_perf_timer_start ();
146 cairo_perf_set_thread_aware (cr, FALSE);
150 cairo_perf_set_thread_aware (cr, TRUE);
151 cairo_stroke_preserve (cr);
154 cairo_perf_timer_stop ();
158 return cairo_perf_timer_elapsed ();
162 do_wide_strokes (cairo_t *cr, int width, int height, int loops)
166 /* lots and lots of overlapping strokes */
168 for (count = 0; count < 1000; count++) {
170 uniform_random (0, width),
171 uniform_random (0, height));
174 cairo_set_line_width (cr, 5.);
176 cairo_perf_timer_start ();
177 cairo_perf_set_thread_aware (cr, FALSE);
181 cairo_perf_set_thread_aware (cr, TRUE);
182 cairo_stroke_preserve (cr);
185 cairo_perf_timer_stop ();
189 return cairo_perf_timer_elapsed ();
193 wide_strokes_enabled (cairo_perf_t *perf)
195 return cairo_perf_can_run (perf, "wide-strokes", NULL);
199 wide_strokes (cairo_perf_t *perf, cairo_t *cr, int width, int height)
201 cairo_set_source_rgb (cr, 1., 1., 1.);
203 cairo_perf_run (perf, "wide-strokes-halign", do_wide_strokes_ha, NULL);
204 cairo_perf_run (perf, "wide-strokes-valign", do_wide_strokes_va, NULL);
205 cairo_perf_run (perf, "wide-strokes-horizontal", do_wide_strokes_h, NULL);
206 cairo_perf_run (perf, "wide-strokes-vertical", do_wide_strokes_v, NULL);
207 cairo_perf_run (perf, "wide-strokes-random", do_wide_strokes, NULL);