2 * Copyright © 2006 Red Hat, Inc.
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: Carl D. Worth <cworth@cworth.org>
27 #include "cairo-perf.h"
29 /* This test case is designed to illustrate a performance bug in
30 * drawing very long lines, where most of the line is out of bounds of
31 * the destination surface, (but some portion of the line is
32 * visibile). These results are in the "long-lines-uncropped" report.
34 * For comparison, this test also renders the visible portions of the
35 * same lines, (this is the "long-lines-cropped" report).
38 typedef enum { LONG_LINES_UNCROPPED
, LONG_LINES_CROPPED
} long_lines_crop_t
;
40 #define LONG_FACTOR 50.0
42 static cairo_perf_ticks_t
43 do_long_lines (cairo_t
*cr
, int width
, int height
, long_lines_crop_t crop
)
46 double x
, y
, dx
, dy
, min_x
, min_y
, max_x
, max_y
;
47 double outer_width
, outer_height
;
51 cairo_translate (cr
, width
/ 2, height
/ 2);
53 if (crop
== LONG_LINES_UNCROPPED
) {
54 outer_width
= LONG_FACTOR
* width
;
55 outer_height
= LONG_FACTOR
* height
;
56 cairo_set_source_rgb (cr
, 1.0, 0.0, 0.0); /* red */
59 outer_height
= height
;
60 cairo_set_source_rgb (cr
, 0.0, 1.0, 0.0); /* green */
63 min_x
= x
= - outer_width
/ 2.0;
64 min_y
= y
= - outer_height
/ 2.0;
65 max_x
= outer_width
/ 2.0;
66 max_y
= outer_width
/ 2.0;
67 dx
= outer_width
/ NUM_LINES
;
68 dy
= outer_height
/ NUM_LINES
;
70 cairo_perf_timer_start ();
72 for (i
= 0; i
< NUM_LINES
; i
++) {
73 cairo_move_to (cr
, 0, 0);
74 cairo_line_to (cr
, x
, min_y
);
77 cairo_move_to (cr
, 0, 0);
78 cairo_line_to (cr
, x
, max_y
);
81 cairo_move_to (cr
, 0, 0);
82 cairo_line_to (cr
, min_x
, y
);
85 cairo_move_to (cr
, 0, 0);
86 cairo_line_to (cr
, max_x
, y
);
93 cairo_perf_timer_stop ();
97 return cairo_perf_timer_elapsed ();
100 static cairo_perf_ticks_t
101 long_lines_uncropped (cairo_t
*cr
, int width
, int height
)
103 return do_long_lines (cr
, width
, height
, LONG_LINES_UNCROPPED
);
106 static cairo_perf_ticks_t
107 long_lines_cropped (cairo_t
*cr
, int width
, int height
)
109 return do_long_lines (cr
, width
, height
, LONG_LINES_CROPPED
);
113 long_lines (cairo_perf_t
*perf
, cairo_t
*cr
, int width
, int height
)
115 cairo_perf_run (perf
, "long-lines-uncropped", long_lines_uncropped
);
116 cairo_perf_run (perf
, "long-lines-cropped", long_lines_cropped
);