1
/*
2
 * Copyright © 2011 Intel Corporation
3
 *
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:
11
 *
12
 * The above copyright notice and this permission notice shall be
13
 * included in all copies or substantial portions of the Software.
14
 *
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
22
 * SOFTWARE.
23
 *
24
 * Author: Chris Wilson <chris@chris-wilson.co.uk>
25
 */
26

            
27
#include "cairo-perf.h"
28

            
29
static cairo_time_t
30
horizontal (cairo_t *cr, int width, int height, int loops)
31
{
32
    double h = height/2 + .5;
33

            
34
    cairo_move_to (cr, 0, h);
35
    cairo_line_to (cr, width, h);
36

            
37
    cairo_perf_timer_start ();
38

            
39
    while (loops--)
40
	cairo_stroke_preserve (cr);
41

            
42
    cairo_perf_timer_stop ();
43

            
44
    cairo_new_path (cr);
45

            
46
    return cairo_perf_timer_elapsed ();
47
}
48

            
49
static cairo_time_t
50
horizontal_hair (cairo_t *cr, int width, int height, int loops)
51
{
52
    cairo_set_line_width (cr, 1.);
53
    return horizontal (cr, width, height, loops);
54
}
55

            
56
static cairo_time_t
57
horizontal_wide (cairo_t *cr, int width, int height, int loops)
58
{
59
    cairo_set_line_width (cr, 5.);
60
    return horizontal (cr, width, height, loops);
61
}
62

            
63
static cairo_time_t
64
nearly_horizontal (cairo_t *cr, int width, int height, int loops)
65
{
66
    double h = height/2;
67

            
68
    cairo_move_to (cr, 0, h);
69
    cairo_line_to (cr, width, h+1);
70

            
71
    cairo_perf_timer_start ();
72

            
73
    while (loops--)
74
	cairo_stroke_preserve (cr);
75

            
76
    cairo_perf_timer_stop ();
77

            
78
    cairo_new_path (cr);
79

            
80
    return cairo_perf_timer_elapsed ();
81
}
82

            
83
static cairo_time_t
84
nearly_horizontal_hair (cairo_t *cr, int width, int height, int loops)
85
{
86
    cairo_set_line_width (cr, 1.);
87
    return nearly_horizontal (cr, width, height, loops);
88
}
89

            
90
static cairo_time_t
91
nearly_horizontal_wide (cairo_t *cr, int width, int height, int loops)
92
{
93
    cairo_set_line_width (cr, 5.);
94
    return nearly_horizontal (cr, width, height, loops);
95
}
96

            
97

            
98
static cairo_time_t
99
vertical (cairo_t *cr, int width, int height, int loops)
100
{
101
    double w = width/2 + .5;
102

            
103
    cairo_move_to (cr, w, 0);
104
    cairo_line_to (cr, w, height);
105

            
106
    cairo_perf_timer_start ();
107

            
108
    while (loops--)
109
	cairo_stroke_preserve (cr);
110

            
111
    cairo_perf_timer_stop ();
112

            
113
    cairo_new_path (cr);
114

            
115
    return cairo_perf_timer_elapsed ();
116
}
117

            
118
static cairo_time_t
119
vertical_hair (cairo_t *cr, int width, int height, int loops)
120
{
121
    cairo_set_line_width (cr, 1.);
122
    return vertical (cr, width, height, loops);
123
}
124

            
125
static cairo_time_t
126
vertical_wide (cairo_t *cr, int width, int height, int loops)
127
{
128
    cairo_set_line_width (cr, 5.);
129
    return vertical (cr, width, height, loops);
130
}
131

            
132
static cairo_time_t
133
nearly_vertical (cairo_t *cr, int width, int height, int loops)
134
{
135
    double w = width/2;
136

            
137
    cairo_move_to (cr, w, 0);
138
    cairo_line_to (cr, w+1, height);
139

            
140
    cairo_perf_timer_start ();
141

            
142
    while (loops--)
143
	cairo_stroke_preserve (cr);
144

            
145
    cairo_perf_timer_stop ();
146

            
147
    cairo_new_path (cr);
148

            
149
    return cairo_perf_timer_elapsed ();
150
}
151

            
152
static cairo_time_t
153
nearly_vertical_hair (cairo_t *cr, int width, int height, int loops)
154
{
155
    cairo_set_line_width (cr, 1.);
156
    return nearly_vertical (cr, width, height, loops);
157
}
158

            
159
static cairo_time_t
160
nearly_vertical_wide (cairo_t *cr, int width, int height, int loops)
161
{
162
    cairo_set_line_width (cr, 5.);
163
    return nearly_vertical (cr, width, height, loops);
164
}
165

            
166

            
167
static cairo_time_t
168
diagonal (cairo_t *cr, int width, int height, int loops)
169
{
170
    cairo_move_to (cr, 0, 0);
171
    cairo_line_to (cr, width, height);
172

            
173
    cairo_perf_timer_start ();
174

            
175
    while (loops--)
176
	cairo_stroke_preserve (cr);
177

            
178
    cairo_perf_timer_stop ();
179

            
180
    cairo_new_path (cr);
181

            
182
    return cairo_perf_timer_elapsed ();
183
}
184

            
185
static cairo_time_t
186
diagonal_hair (cairo_t *cr, int width, int height, int loops)
187
{
188
    cairo_set_line_width (cr, 1.);
189
    return diagonal (cr, width, height, loops);
190
}
191

            
192
static cairo_time_t
193
diagonal_wide (cairo_t *cr, int width, int height, int loops)
194
{
195
    cairo_set_line_width (cr, 5.);
196
    return diagonal (cr, width, height, loops);
197
}
198

            
199
cairo_bool_t
200
line_enabled (cairo_perf_t *perf)
201
{
202
    return cairo_perf_can_run (perf, "line", NULL);
203
}
204

            
205
void
206
line (cairo_perf_t *perf, cairo_t *cr, int width, int height)
207
{
208
    cairo_set_source_rgb (cr, 1., 1., 1.);
209

            
210
    cairo_perf_run (perf, "line-hh", horizontal_hair, NULL);
211
    cairo_perf_run (perf, "line-hw", horizontal_wide, NULL);
212
    cairo_perf_run (perf, "line-nhh", nearly_horizontal_hair, NULL);
213
    cairo_perf_run (perf, "line-nhw", nearly_horizontal_wide, NULL);
214

            
215
    cairo_perf_run (perf, "line-vh", vertical_hair, NULL);
216
    cairo_perf_run (perf, "line-vw", vertical_wide, NULL);
217
    cairo_perf_run (perf, "line-nvh", nearly_vertical_hair, NULL);
218
    cairo_perf_run (perf, "line-nvw", nearly_vertical_wide, NULL);
219

            
220
    cairo_perf_run (perf, "line-dh", diagonal_hair, NULL);
221
    cairo_perf_run (perf, "line-dw", diagonal_wide, NULL);
222
}