98fd17d8376882b125c412f28318a4c2cd923c6a
[framework/graphics/cairo.git] / perf / micro / a1-line.c
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     cairo_perf_set_thread_aware (cr, FALSE);
39
40     while (loops--) {
41         if (loops == 0)
42             cairo_perf_set_thread_aware (cr, TRUE);
43         cairo_stroke_preserve (cr);
44     }
45
46     cairo_perf_timer_stop ();
47
48     cairo_new_path (cr);
49
50     return cairo_perf_timer_elapsed ();
51 }
52
53 static cairo_time_t
54 horizontal_hair (cairo_t *cr, int width, int height, int loops)
55 {
56     cairo_set_line_width (cr, 1.);
57     return horizontal (cr, width, height, loops);
58 }
59
60 static cairo_time_t
61 horizontal_wide (cairo_t *cr, int width, int height, int loops)
62 {
63     cairo_set_line_width (cr, 5.);
64     return horizontal (cr, width, height, loops);
65 }
66
67 static cairo_time_t
68 nearly_horizontal (cairo_t *cr, int width, int height, int loops)
69 {
70     double h = height/2;
71
72     cairo_move_to (cr, 0, h);
73     cairo_line_to (cr, width, h+1);
74
75     cairo_perf_timer_start ();
76     cairo_perf_set_thread_aware (cr, FALSE);
77
78     while (loops--) {
79         if (loops == 0)
80             cairo_perf_set_thread_aware (cr, TRUE);
81         cairo_stroke_preserve (cr);
82     }
83
84     cairo_perf_timer_stop ();
85
86     cairo_new_path (cr);
87
88     return cairo_perf_timer_elapsed ();
89 }
90
91 static cairo_time_t
92 nearly_horizontal_hair (cairo_t *cr, int width, int height, int loops)
93 {
94     cairo_set_line_width (cr, 1.);
95     return nearly_horizontal (cr, width, height, loops);
96 }
97
98 static cairo_time_t
99 nearly_horizontal_wide (cairo_t *cr, int width, int height, int loops)
100 {
101     cairo_set_line_width (cr, 5.);
102     return nearly_horizontal (cr, width, height, loops);
103 }
104
105
106 static cairo_time_t
107 vertical (cairo_t *cr, int width, int height, int loops)
108 {
109     double w = width/2 + .5;
110
111     cairo_move_to (cr, w, 0);
112     cairo_line_to (cr, w, height);
113
114     cairo_perf_timer_start ();
115     cairo_perf_set_thread_aware (cr, FALSE);
116
117     while (loops--) {
118         if (loops == 0)
119                 cairo_perf_set_thread_aware (cr, TRUE);
120         cairo_stroke_preserve (cr);
121     }
122
123     cairo_perf_timer_stop ();
124
125     cairo_new_path (cr);
126
127     return cairo_perf_timer_elapsed ();
128 }
129
130 static cairo_time_t
131 vertical_hair (cairo_t *cr, int width, int height, int loops)
132 {
133     cairo_set_line_width (cr, 1.);
134     return vertical (cr, width, height, loops);
135 }
136
137 static cairo_time_t
138 vertical_wide (cairo_t *cr, int width, int height, int loops)
139 {
140     cairo_set_line_width (cr, 5.);
141     return vertical (cr, width, height, loops);
142 }
143
144 static cairo_time_t
145 nearly_vertical (cairo_t *cr, int width, int height, int loops)
146 {
147     double w = width/2;
148
149     cairo_move_to (cr, w, 0);
150     cairo_line_to (cr, w+1, height);
151
152     cairo_perf_timer_start ();
153     cairo_perf_set_thread_aware (cr, FALSE);
154
155     while (loops--) {
156         if (loops == 0)
157                 cairo_perf_set_thread_aware (cr, TRUE);
158         cairo_stroke_preserve (cr);
159     }
160
161     cairo_perf_timer_stop ();
162
163     cairo_new_path (cr);
164
165     return cairo_perf_timer_elapsed ();
166 }
167
168 static cairo_time_t
169 nearly_vertical_hair (cairo_t *cr, int width, int height, int loops)
170 {
171     cairo_set_line_width (cr, 1.);
172     return nearly_vertical (cr, width, height, loops);
173 }
174
175 static cairo_time_t
176 nearly_vertical_wide (cairo_t *cr, int width, int height, int loops)
177 {
178     cairo_set_line_width (cr, 5.);
179     return nearly_vertical (cr, width, height, loops);
180 }
181
182
183 static cairo_time_t
184 diagonal (cairo_t *cr, int width, int height, int loops)
185 {
186     cairo_move_to (cr, 0, 0);
187     cairo_line_to (cr, width, height);
188
189     cairo_perf_timer_start ();
190     cairo_perf_set_thread_aware (cr, FALSE);
191
192     while (loops--) {
193         if (loops == 0)
194                 cairo_perf_set_thread_aware (cr, TRUE);
195         cairo_stroke_preserve (cr);
196     }
197
198     cairo_perf_timer_stop ();
199
200     cairo_new_path (cr);
201
202     return cairo_perf_timer_elapsed ();
203 }
204
205 static cairo_time_t
206 diagonal_hair (cairo_t *cr, int width, int height, int loops)
207 {
208     cairo_set_line_width (cr, 1.);
209     return diagonal (cr, width, height, loops);
210 }
211
212 static cairo_time_t
213 diagonal_wide (cairo_t *cr, int width, int height, int loops)
214 {
215     cairo_set_line_width (cr, 5.);
216     return diagonal (cr, width, height, loops);
217 }
218
219 cairo_bool_t
220 a1_line_enabled (cairo_perf_t *perf)
221 {
222     return cairo_perf_can_run (perf, "a1-line", NULL);
223 }
224
225 void
226 a1_line (cairo_perf_t *perf, cairo_t *cr, int width, int height)
227 {
228     cairo_set_source_rgb (cr, 1., 1., 1.);
229     cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
230
231     cairo_perf_run (perf, "a1-line-hh", horizontal_hair, NULL);
232     cairo_perf_run (perf, "a1-line-hw", horizontal_wide, NULL);
233     cairo_perf_run (perf, "a1-line-nhh", nearly_horizontal_hair, NULL);
234     cairo_perf_run (perf, "a1-line-nhw", nearly_horizontal_wide, NULL);
235
236     cairo_perf_run (perf, "a1-line-vh", vertical_hair, NULL);
237     cairo_perf_run (perf, "a1-line-vw", vertical_wide, NULL);
238     cairo_perf_run (perf, "a1-line-nvh", nearly_vertical_hair, NULL);
239     cairo_perf_run (perf, "a1-line-nvw", nearly_vertical_wide, NULL);
240
241     cairo_perf_run (perf, "a1-line-dh", diagonal_hair, NULL);
242     cairo_perf_run (perf, "a1-line-dw", diagonal_wide, NULL);
243 }