1
/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
2
/* cairo - a vector graphics library with display and print output
3
 *
4
 * Copyright (c) 2011 Intel Corporation
5
 *
6
 * Permission is hereby granted, free of charge, to any person
7
 * obtaining a copy of this software and associated documentation
8
 * files (the "Software"), to deal in the Software without
9
 * restriction, including without limitation the rights to use,
10
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the
12
 * Software is furnished to do so, subject to the following
13
 * conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be
16
 * included in all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
 * OTHER DEALINGS IN THE SOFTWARE.
26
 */
27
#include "cairo-perf.h"
28
#include <assert.h>
29

            
30
#define STEP	5
31

            
32
static void path (cairo_t *cr, int width, int height)
33
{
34
    int i;
35

            
36
    cairo_rectangle (cr, 0, 0, width, height);
37
    cairo_clip (cr);
38

            
39
    cairo_translate (cr, width/2, height/2);
40
    cairo_rotate (cr, M_PI/4);
41
    cairo_translate (cr, -width/2, -height/2);
42

            
43
    for (i = 0; i < width; i += STEP) {
44
	cairo_rectangle (cr, i, -2, 1, height+4);
45
	cairo_rectangle (cr, -2, i, width+4, 1);
46
    }
47
}
48

            
49
static void clip (cairo_t *cr, int width, int height)
50
{
51
    int i, j;
52

            
53
    for (j = 0; j < height; j += 2*STEP) {
54
	for (i = 0; i < width; i += 2*STEP)
55
	    cairo_rectangle (cr, i, j, STEP, STEP);
56

            
57
	j += 2*STEP;
58
	for (i = 0; i < width; i += 2*STEP)
59
	    cairo_rectangle (cr, i+STEP/2, j, STEP, STEP);
60
    }
61

            
62
    cairo_clip (cr);
63
}
64

            
65
static cairo_time_t
66
draw (cairo_t *cr, int width, int height, int loops)
67
{
68
    cairo_save (cr);
69
    cairo_set_source_rgb (cr, 1, 1, 1);
70
    cairo_paint (cr);
71
    cairo_set_source_rgb (cr, 1, 0, 0);
72

            
73
    cairo_perf_timer_start ();
74
    while (loops--) {
75
	cairo_save (cr);
76
	clip (cr, width, height);
77
	path (cr, width, height);
78
	cairo_fill (cr);
79
	cairo_restore (cr);
80
    }
81
    cairo_perf_timer_stop ();
82

            
83
    cairo_restore (cr);
84

            
85
    return cairo_perf_timer_elapsed ();
86
}
87

            
88
cairo_bool_t
89
disjoint_enabled (cairo_perf_t *perf)
90
{
91
    return cairo_perf_can_run (perf, "disjoint", NULL);
92
}
93

            
94
void
95
disjoint (cairo_perf_t *perf, cairo_t *cr, int width, int height)
96
{
97
    if (! cairo_perf_can_run (perf, "disjoint", NULL))
98
	return;
99

            
100
    cairo_perf_run (perf, "disjoint", draw, NULL);
101
}