2 * Copyright © 2006 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Author: Carl D. Worth <cworth@cworth.org>
28 #include "cairo-perf.h"
30 /* This test case is designed to illustrate a performance bug that
31 * exists in cairo in which using cairo_stroke is much slower than
32 * cairo_fill to draw an identical figure, (and in particular a figure
33 * that is much more natural to draw with cairo_stroke). The figure is
34 * a 100x100 square outline 1-pixel wide, nicely pixel aligned.
36 * The performance bug should affect any path whose resulting contour
37 * consists only of pixel-aligned horizontal and vertical elements.
39 * Initial testing on on machine shows stroke as 5x slower than fill
40 * for the xlib backend and 16x slower for the image backend.
44 box_outline_stroke (cairo_t *cr, int width, int height, int loops)
46 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
51 width - 3, height - 3);
52 cairo_set_line_width (cr, 1.0);
53 cairo_set_source_rgb (cr, 1, 0, 0); /* red */
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 box_outline_alpha_stroke (cairo_t *cr, int width, int height, int loops)
74 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
79 width - 3, height - 3);
80 cairo_set_line_width (cr, 1.0);
81 cairo_set_source_rgba (cr, 1, 0, 0, .5); /* red */
83 cairo_perf_timer_start ();
84 cairo_perf_set_thread_aware (cr, FALSE);
88 cairo_perf_set_thread_aware (cr, TRUE);
89 cairo_stroke_preserve (cr);
92 cairo_perf_timer_stop ();
96 return cairo_perf_timer_elapsed ();
100 box_outline_aa_stroke (cairo_t *cr, int width, int height, int loops)
102 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
105 cairo_translate (cr, .5, .5);
108 width - 3, height - 3);
109 cairo_set_line_width (cr, 1.0);
110 cairo_set_source_rgb (cr, 1, 0, 0); /* red */
112 cairo_perf_timer_start ();
113 cairo_perf_set_thread_aware (cr, FALSE);
117 cairo_perf_set_thread_aware (cr, TRUE);
118 cairo_stroke_preserve (cr);
121 cairo_perf_timer_stop ();
125 return cairo_perf_timer_elapsed ();
129 box_outline_fill (cairo_t *cr, int width, int height, int loops)
131 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
136 width - 2, height - 2);
139 width - 4, height - 4);
140 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
141 cairo_set_source_rgb (cr, 0, 1, 0); /* green */
143 cairo_perf_timer_start ();
144 cairo_perf_set_thread_aware (cr, FALSE);
148 cairo_perf_set_thread_aware (cr, TRUE);
149 cairo_fill_preserve (cr);
152 cairo_perf_timer_stop ();
156 return cairo_perf_timer_elapsed ();
160 box_outline_alpha_fill (cairo_t *cr, int width, int height, int loops)
162 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
167 width - 2, height - 2);
170 width - 4, height - 4);
171 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
172 cairo_set_source_rgba (cr, 0, 1, 0, .5); /* green */
174 cairo_perf_timer_start ();
175 cairo_perf_set_thread_aware (cr, FALSE);
179 cairo_perf_set_thread_aware (cr, TRUE);
180 cairo_fill_preserve (cr);
183 cairo_perf_timer_stop ();
187 return cairo_perf_timer_elapsed ();
191 box_outline_aa_fill (cairo_t *cr, int width, int height, int loops)
193 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
196 cairo_translate (cr, .5, .5);
199 width - 2, height - 2);
202 width - 4, height - 4);
203 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
204 cairo_set_source_rgb (cr, 0, 1, 0); /* green */
206 cairo_perf_timer_start ();
207 cairo_perf_set_thread_aware (cr, FALSE);
211 cairo_perf_set_thread_aware (cr, TRUE);
212 cairo_fill_preserve (cr);
215 cairo_perf_timer_stop ();
219 return cairo_perf_timer_elapsed ();
223 box_outline_enabled (cairo_perf_t *perf)
225 return cairo_perf_can_run (perf, "box-outline", NULL);
229 box_outline (cairo_perf_t *perf, cairo_t *cr, int width, int height)
231 cairo_perf_run (perf, "box-outline-stroke", box_outline_stroke, NULL);
232 cairo_perf_run (perf, "box-outline-fill", box_outline_fill, NULL);
234 cairo_perf_run (perf, "box-outline-alpha-stroke", box_outline_alpha_stroke, NULL);
235 cairo_perf_run (perf, "box-outline-alpha-fill", box_outline_alpha_fill, NULL);
237 cairo_perf_run (perf, "box-outline-aa-stroke", box_outline_aa_stroke, NULL);
238 cairo_perf_run (perf, "box-outline-aa-fill", box_outline_aa_fill, NULL);