Upload Tizen2.0 source
[framework/graphics/cairo.git] / perf / micro / zrusin.c
1 /*
2  * Copyright © 2006 Red Hat, Inc.
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: Carl D. Worth <cworth@cworth.org>
25  */
26
27 #include "cairo-perf.h"
28
29 typedef struct {
30     double x;
31     double y;
32 } point_t;
33
34 #include "zrusin-another.h"
35
36 #define ARRAY_SIZE(arr) sizeof(arr)/sizeof(arr[0])
37
38 static void
39 zrusin_another_path (cairo_t *cr)
40 {
41     unsigned int i;
42
43     for (i=0; i < ARRAY_SIZE (zrusin_another); i++)
44         cairo_line_to (cr, zrusin_another[i].x, zrusin_another[i].y);
45 }
46
47 static cairo_time_t
48 zrusin_another_tessellate (cairo_t *cr, int width, int height, int loops)
49 {
50     zrusin_another_path (cr);
51
52     cairo_perf_timer_start ();
53     cairo_perf_set_thread_aware (cr, FALSE);
54
55     /* We'd like to measure just tessellation without
56      * rasterization. For now, we can do that with cairo_in_fill. But
57      * we'll have to be careful since cairo_in_fill might eventually
58      * be optimized to have an implementation that doesn't necessarily
59      * include tessellation. */
60     while (loops--) {
61         if (loops == 0)
62                 cairo_perf_set_thread_aware (cr, TRUE);
63         cairo_in_fill (cr, 50, 50);
64     }
65
66     cairo_perf_timer_stop ();
67
68     cairo_new_path (cr);
69
70     return cairo_perf_timer_elapsed ();
71 }
72
73 static cairo_time_t
74 zrusin_another_fill (cairo_t *cr, int width, int height, int loops)
75 {
76     zrusin_another_path (cr);
77     cairo_set_source_rgb (cr, 0.0, 0.0, 0.8); /* blue */
78
79     cairo_perf_timer_start ();
80     cairo_perf_set_thread_aware (cr, FALSE);
81
82     while (loops--) {
83         if (loops == 0)
84                 cairo_perf_set_thread_aware (cr, TRUE);
85         cairo_fill_preserve (cr);
86     }
87
88     cairo_perf_timer_stop ();
89
90     cairo_new_path (cr);
91
92     return cairo_perf_timer_elapsed ();
93 }
94
95 cairo_bool_t
96 zrusin_enabled (cairo_perf_t *perf)
97 {
98     return cairo_perf_can_run (perf, "zrusin", NULL);
99 }
100
101 void
102 zrusin (cairo_perf_t *perf, cairo_t *cr, int width, int height)
103 {
104
105     cairo_perf_run (perf, "zrusin-another-tessellate", zrusin_another_tessellate, NULL);
106     cairo_perf_run (perf, "zrusin-another-fill", zrusin_another_fill, NULL);
107 }