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);
63 static cairo_perf_ticks_t
64 do_rectangle (cairo_t
*cr
, int width
, int height
)
66 cairo_perf_timer_start ();
68 rounded_rectangle (cr
, 0, 0, width
, height
, 3.0);
71 cairo_perf_timer_stop ();
73 return cairo_perf_timer_elapsed ();
76 static cairo_perf_ticks_t
77 do_rectangles (cairo_t
*cr
, int width
, int height
)
81 cairo_perf_timer_start ();
83 for (i
= 0; i
< RECTANGLE_COUNT
; i
++) {
84 rounded_rectangle (cr
,
85 rects
[i
].x
, rects
[i
].y
,
86 rects
[i
].width
, rects
[i
].height
,
91 cairo_perf_timer_stop ();
93 return cairo_perf_timer_elapsed ();
97 rounded_rectangles (cairo_perf_t
*perf
, cairo_t
*cr
, int width
, int height
)
102 for (i
= 0; i
< RECTANGLE_COUNT
; i
++) {
103 rects
[i
].x
= rand () % width
;
104 rects
[i
].y
= rand () % height
;
105 rects
[i
].width
= (rand () % (width
/ 10)) + 1;
106 rects
[i
].height
= (rand () % (height
/ 10)) + 1;
109 MODE (perf
, "one-rounded-rectangle", do_rectangle
);
110 MODE (perf
, "rounded-rectangles", do_rectangles
);