2009-12-07 Rolf Bjarne Kvinge <RKvinge@novell.com>
[moon.git] / cairo / perf / box-outline.c
blob74dd19ad627e9b0b02ed2f53a86fdd808364a837
1 /*
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
23 * SOFTWARE.
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.
43 static cairo_perf_ticks_t
44 box_outline_stroke (cairo_t *cr, int width, int height)
46 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
47 cairo_paint (cr);
49 cairo_rectangle (cr,
50 1.5, 1.5,
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 ();
57 cairo_stroke (cr);
59 cairo_perf_timer_stop ();
61 return cairo_perf_timer_elapsed ();
64 static cairo_perf_ticks_t
65 box_outline_fill (cairo_t *cr, int width, int height)
67 cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
68 cairo_paint (cr);
70 cairo_rectangle (cr,
71 1.0, 1.0,
72 width - 2, height - 2);
73 cairo_rectangle (cr,
74 2.0, 2.0,
75 width - 4, height - 4);
76 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
77 cairo_set_source_rgb (cr, 0, 1, 0); /* green */
79 cairo_perf_timer_start ();
81 cairo_fill (cr);
83 cairo_perf_timer_stop ();
85 return cairo_perf_timer_elapsed ();
88 void
89 box_outline (cairo_perf_t *perf, cairo_t *cr, int width, int height)
91 cairo_perf_run (perf, "box-outline-stroke", box_outline_stroke);
92 cairo_perf_run (perf, "box-outline-fill", box_outline_fill);