613f6e0c8f4ab36d652a8407ee56b95a442d3850
[framework/graphics/cairo.git] / perf / micro / tiger.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.o.uk>
25  */
26
27 #include "cairo-perf.h"
28
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
32
33 #include "../../test/tiger.inc"
34
35 static cairo_time_t
36 do_tiger (cairo_t *cr, int width, int height, int loops)
37 {
38     unsigned int i;
39
40     cairo_perf_timer_start ();
41     cairo_perf_set_thread_aware (cr, FALSE);
42
43     while (loops--) {
44         if (loops == 0)
45                 cairo_perf_set_thread_aware (cr, TRUE);
46         cairo_identity_matrix (cr);
47
48         cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
49         cairo_set_source_rgba (cr, 0.1, 0.2, 0.3, 1.0);
50         cairo_paint (cr);
51         cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
52
53         cairo_translate (cr, width/2, height/2);
54         cairo_scale (cr, .85 * width/500, .85 * height/500);
55
56         for (i = 0; i < sizeof (tiger_commands)/sizeof(tiger_commands[0]);i++) {
57             const struct command *cmd = &tiger_commands[i];
58             switch (cmd->type) {
59             case 'm':
60                 cairo_move_to (cr, cmd->x0, cmd->y0);
61                 break;
62             case 'l':
63                 cairo_line_to (cr, cmd->x0, cmd->y0);
64                 break;
65             case 'c':
66                 cairo_curve_to (cr,
67                                 cmd->x0, cmd->y0,
68                                 cmd->x1, cmd->y1,
69                                 cmd->x2, cmd->y2);
70                 break;
71             case 'f':
72                 cairo_set_source_rgba (cr,
73                                        cmd->x0, cmd->y0, cmd->x1, cmd->y1);
74                 cairo_fill (cr);
75                 break;
76             }
77         }
78     }
79
80     cairo_perf_timer_stop ();
81
82     return cairo_perf_timer_elapsed ();
83 }
84
85 static cairo_time_t
86 do_mono_tiger (cairo_t *cr, int width, int height, int loops)
87 {
88     cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
89     return do_tiger (cr, width, height, loops);
90 }
91
92 static cairo_time_t
93 do_fast_tiger (cairo_t *cr, int width, int height, int loops)
94 {
95     cairo_set_antialias (cr, CAIRO_ANTIALIAS_FAST);
96     return do_tiger (cr, width, height, loops);
97 }
98
99 static cairo_time_t
100 do_best_tiger (cairo_t *cr, int width, int height, int loops)
101 {
102     cairo_set_antialias (cr, CAIRO_ANTIALIAS_BEST);
103     return do_tiger (cr, width, height, loops);
104 }
105
106 cairo_bool_t
107 tiger_enabled (cairo_perf_t *perf)
108 {
109     return cairo_perf_can_run (perf, "tiger", NULL);
110 }
111
112 void
113 tiger (cairo_perf_t *perf, cairo_t *cr, int width, int height)
114 {
115     cairo_perf_run (perf, "tiger-mono", do_mono_tiger, NULL);
116     cairo_perf_run (perf, "tiger-fast", do_fast_tiger, NULL);
117     cairo_perf_run (perf, "tiger-best", do_best_tiger, NULL);
118 }