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

            
42
    while (loops--) {
43
	cairo_identity_matrix (cr);
44

            
45
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
46
	cairo_set_source_rgba (cr, 0.1, 0.2, 0.3, 1.0);
47
	cairo_paint (cr);
48
	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
49

            
50
	cairo_translate (cr, width/2, height/2);
51
	cairo_scale (cr, .85 * width/500, .85 * height/500);
52

            
53
	for (i = 0; i < sizeof (tiger_commands)/sizeof(tiger_commands[0]);i++) {
54
	    const struct command *cmd = &tiger_commands[i];
55
	    switch (cmd->type) {
56
	    case 'm':
57
		cairo_move_to (cr, cmd->x0, cmd->y0);
58
		break;
59
	    case 'l':
60
		cairo_line_to (cr, cmd->x0, cmd->y0);
61
		break;
62
	    case 'c':
63
		cairo_curve_to (cr,
64
				cmd->x0, cmd->y0,
65
				cmd->x1, cmd->y1,
66
				cmd->x2, cmd->y2);
67
		break;
68
	    case 'f':
69
		cairo_set_source_rgba (cr,
70
				       cmd->x0, cmd->y0, cmd->x1, cmd->y1);
71
		cairo_fill (cr);
72
		break;
73
	    }
74
	}
75
    }
76

            
77
    cairo_perf_timer_stop ();
78

            
79
    return cairo_perf_timer_elapsed ();
80
}
81

            
82
static cairo_time_t
83
do_mono_tiger (cairo_t *cr, int width, int height, int loops)
84
{
85
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
86
    return do_tiger (cr, width, height, loops);
87
}
88

            
89
static cairo_time_t
90
do_fast_tiger (cairo_t *cr, int width, int height, int loops)
91
{
92
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_FAST);
93
    return do_tiger (cr, width, height, loops);
94
}
95

            
96
static cairo_time_t
97
do_best_tiger (cairo_t *cr, int width, int height, int loops)
98
{
99
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_BEST);
100
    return do_tiger (cr, width, height, loops);
101
}
102

            
103
cairo_bool_t
104
tiger_enabled (cairo_perf_t *perf)
105
{
106
    return cairo_perf_can_run (perf, "tiger", NULL);
107
}
108

            
109
void
110
tiger (cairo_perf_t *perf, cairo_t *cr, int width, int height)
111
{
112
    cairo_perf_run (perf, "tiger-mono", do_mono_tiger, NULL);
113
    cairo_perf_run (perf, "tiger-fast", do_fast_tiger, NULL);
114
    cairo_perf_run (perf, "tiger-best", do_best_tiger, NULL);
115
}