2 * Copyright © 2005 Owen Taylor
3 * Copyright © 2007 Dan Amelang
4 * Copyright © 2007 Chris Wilson
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without
8 * fee, provided that the above copyright notice appear in all copies
9 * and that both that copyright notice and this permission notice
10 * appear in supporting documentation, and that the name of
11 * the authors not be used in advertising or publicity pertaining to
12 * distribution of the software without specific, written prior
13 * permission. The authors make no representations about the
14 * suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
17 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
20 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
22 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
23 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 * Authors: Chris Wilson <chris@chris-wilson.co.uk>
28 /* This perf case is derived from the bug report
29 * Gradient on 'rounded rectangle' MUCH slower than normal rectangle
30 * https://bugs.freedesktop.org/show_bug.cgi?id=4263.
33 #include "cairo-perf.h"
35 #define RECTANGLE_COUNT (1000)
38 #define MODE cairo_perf_run
40 #define MODE cairo_perf_cover_sources_and_operators
49 } rects[RECTANGLE_COUNT];
52 rounded_rectangle (cairo_t *cr,
53 double x, double y, double w, double h,
56 cairo_move_to (cr, x+radius, y);
57 cairo_arc (cr, x+w-radius, y+radius, radius, M_PI + M_PI / 2, M_PI * 2 );
58 cairo_arc (cr, x+w-radius, y+h-radius, radius, 0, M_PI / 2 );
59 cairo_arc (cr, x+radius, y+h-radius, radius, M_PI/2, M_PI );
60 cairo_arc (cr, x+radius, y+radius, radius, M_PI, 270 * M_PI / 180);
64 do_rectangle (cairo_t *cr, int width, int height, int loops)
66 cairo_perf_timer_start ();
67 cairo_perf_set_thread_aware (cr, FALSE);
71 cairo_perf_set_thread_aware (cr, TRUE);
72 rounded_rectangle (cr, 0, 0, width, height, 3.0);
76 cairo_perf_timer_stop ();
78 return cairo_perf_timer_elapsed ();
82 do_rectangles (cairo_t *cr, int width, int height, int loops)
86 cairo_perf_timer_start ();
87 cairo_perf_set_thread_aware (cr, FALSE);
91 cairo_perf_set_thread_aware (cr, TRUE);
92 for (i = 0; i < RECTANGLE_COUNT; i++) {
93 rounded_rectangle (cr,
94 rects[i].x, rects[i].y,
95 rects[i].width, rects[i].height,
101 cairo_perf_timer_stop ();
103 return cairo_perf_timer_elapsed ();
107 do_rectangles_once (cairo_t *cr, int width, int height, int loops)
111 cairo_perf_timer_start ();
112 cairo_perf_set_thread_aware (cr, FALSE);
116 cairo_perf_set_thread_aware (cr, TRUE);
117 for (i = 0; i < RECTANGLE_COUNT; i++) {
118 rounded_rectangle (cr,
119 rects[i].x, rects[i].y,
120 rects[i].width, rects[i].height,
126 cairo_perf_timer_stop ();
128 return cairo_perf_timer_elapsed ();
132 rounded_rectangles_enabled (cairo_perf_t *perf)
134 return cairo_perf_can_run (perf, "rounded-rectangles", NULL);
138 rounded_rectangles (cairo_perf_t *perf, cairo_t *cr, int width, int height)
143 for (i = 0; i < RECTANGLE_COUNT; i++) {
144 rects[i].x = rand () % width;
145 rects[i].y = rand () % height;
146 rects[i].width = (rand () % (width / 10)) + 1;
147 rects[i].height = (rand () % (height / 10)) + 1;
150 MODE (perf, "one-rounded-rectangle", do_rectangle, NULL);
151 MODE (perf, "rounded-rectangles", do_rectangles, NULL);
152 MODE (perf, "rounded-rectangles-once", do_rectangles_once, NULL);