1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright © 2006 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Author: Carl D. Worth <cworth@cworth.org>
*/
#include "cairo-perf.h"
/* This test case is designed to illustrate a performance bug in
* drawing very long lines, where most of the line is out of bounds of
* the destination surface, (but some portion of the line is
* visibile). These results are in the "long-lines-uncropped" report.
*
* For comparison, this test also renders the visible portions of the
* same lines, (this is the "long-lines-cropped" report).
*/
typedef enum { LONG_LINES_UNCROPPED, LONG_LINES_CROPPED } long_lines_crop_t;
#define NUM_LINES 20
#define LONG_FACTOR 50.0
static cairo_perf_ticks_t
do_long_lines (cairo_t *cr, int width, int height, long_lines_crop_t crop)
{
int i;
double x, y, dx, dy, min_x, min_y, max_x, max_y;
double outer_width, outer_height;
cairo_save (cr);
cairo_translate (cr, width / 2, height / 2);
if (crop == LONG_LINES_UNCROPPED) {
outer_width = LONG_FACTOR * width;
outer_height = LONG_FACTOR * height;
cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); /* red */
} else {
outer_width = width;
outer_height = height;
cairo_set_source_rgb (cr, 0.0, 1.0, 0.0); /* green */
}
min_x = x = - outer_width / 2.0;
min_y = y = - outer_height / 2.0;
max_x = outer_width / 2.0;
max_y = outer_width / 2.0;
dx = outer_width / NUM_LINES;
dy = outer_height / NUM_LINES;
cairo_perf_timer_start ();
for (i = 0; i < NUM_LINES; i++) {
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, x, min_y);
cairo_stroke (cr);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, x, max_y);
cairo_stroke (cr);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, min_x, y);
cairo_stroke (cr);
cairo_move_to (cr, 0, 0);
cairo_line_to (cr, max_x, y);
cairo_stroke (cr);
x += dx;
y += dy;
}
cairo_perf_timer_stop ();
cairo_restore (cr);
return cairo_perf_timer_elapsed ();
}
static cairo_perf_ticks_t
long_lines_uncropped (cairo_t *cr, int width, int height)
{
return do_long_lines (cr, width, height, LONG_LINES_UNCROPPED);
}
static cairo_perf_ticks_t
long_lines_cropped (cairo_t *cr, int width, int height)
{
return do_long_lines (cr, width, height, LONG_LINES_CROPPED);
}
void
long_lines (cairo_perf_t *perf, cairo_t *cr, int width, int height)
{
if (! cairo_perf_can_run (perf, "long-lines"))
return;
cairo_perf_run (perf, "long-lines-uncropped", long_lines_uncropped);
cairo_perf_run (perf, "long-lines-cropped", long_lines_cropped);
}
|