1
/*
2
 * Copyright 2010 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-test.h"
28

            
29
/* Test the fidelity of the rasterisation, because Cairo is my favourite
30
 * driver test suite.
31
 */
32

            
33
#define SIZE 256
34
#define WIDTH 2
35
#define HEIGHT 10
36

            
37
static cairo_test_status_t
38
rectangles (cairo_t *cr, int width, int height)
39
{
40
    int i;
41

            
42
    cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
43
    cairo_paint (cr);
44
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
45

            
46
    for (i = 1; i <= SIZE; i++) {
47
	int x, y;
48

            
49
	cairo_save (cr);
50
	cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
51
	cairo_clip (cr);
52

            
53
	cairo_scale (cr, 1./SIZE, 1./SIZE);
54
	for (x = -i; x < SIZE*WIDTH; x += 2*i) {
55
	    for (y = -i; y < SIZE*HEIGHT; y += 2*i) {
56
		/* Add a little tile composed of two non-overlapping squares
57
		 *   +--+
58
		 *   |  |
59
		 *   |__|__
60
		 *      |  |
61
		 *      |  |
62
		 *      +--+
63
		 */
64
		cairo_rectangle (cr, x, y, i, i);
65
		cairo_rectangle (cr, x+i, y+i, i, i);
66
	    }
67
	}
68
	cairo_fill (cr);
69
	cairo_restore (cr);
70

            
71
	cairo_translate (cr, WIDTH, 0);
72
    }
73

            
74
    return CAIRO_TEST_SUCCESS;
75
}
76

            
77
static cairo_test_status_t
78
triangles (cairo_t *cr, int width, int height)
79
{
80
    int i;
81

            
82
    cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
83
    cairo_paint (cr);
84
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
85

            
86
    for (i = 1; i <= SIZE; i++) {
87
	int x, y;
88

            
89
	cairo_save (cr);
90
	cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
91
	cairo_clip (cr);
92

            
93
	cairo_scale (cr, 1./SIZE, 1./SIZE);
94
	for (x = -i; x < SIZE*WIDTH; x += 2*i) {
95
	    for (y = -i; y < SIZE*HEIGHT; y += 2*i) {
96
		/* Add a tile composed of four non-overlapping
97
		 * triangles.  The plus and minus signs inside the
98
		 * triangles denote the orientation of the triangle's
99
		 * edges: + for clockwise and - for anticlockwise.
100
		 *
101
		 *   +-----+
102
		 *    \-|+/
103
		 *     \|/
104
		 *     /|\
105
		 *    /-|-\
106
		 *   +-----+
107
		 */
108

            
109
		/* top left triangle */
110
		cairo_move_to (cr, x, y);
111
		cairo_line_to (cr, x+i, y+i);
112
		cairo_line_to (cr, x+i, y);
113
		cairo_close_path (cr);
114

            
115
		/* top right triangle */
116
		cairo_move_to (cr, x+i, y);
117
		cairo_line_to (cr, x+2*i, y);
118
		cairo_line_to (cr, x+i, y+i);
119
		cairo_close_path (cr);
120

            
121
		/* bottom left triangle */
122
		cairo_move_to (cr, x+i, y+i);
123
		cairo_line_to (cr, x, y+2*i);
124
		cairo_line_to (cr, x+i, y+2*i);
125
		cairo_close_path (cr);
126

            
127
		/* bottom right triangle */
128
		cairo_move_to (cr, x+i, y+i);
129
		cairo_line_to (cr, x+i, y+2*i);
130
		cairo_line_to (cr, x+2*i, y+2*i);
131
		cairo_close_path (cr);
132
	    }
133
	}
134
	cairo_fill (cr);
135
	cairo_restore (cr);
136

            
137
	cairo_translate (cr, WIDTH, 0);
138
    }
139

            
140
    return CAIRO_TEST_SUCCESS;
141
}
142

            
143
1
CAIRO_TEST (half_coverage_rectangles,
144
	    "Check the fidelity of the rasterisation.",
145
	    NULL, /* keywords */
146
	    "target=raster slow", /* requirements */
147
	    WIDTH * SIZE, HEIGHT,
148
	    NULL, rectangles)
149

            
150
1
CAIRO_TEST (half_coverage_triangles,
151
	    "Check the fidelity of the rasterisation.",
152
	    NULL, /* keywords */
153
	    "target=raster slow", /* requirements */
154
	    WIDTH * SIZE, HEIGHT,
155
	    NULL, triangles)