2 * Copyright 2010 Intel Corporation
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 * Author: Chris Wilson <chris@chris-wilson.co.uk>
27 #include "cairo-test.h"
29 /* Test the fidelity of the rasterisation, because Cairo is my favourite
37 static cairo_test_status_t
38 rectangles (cairo_t *cr, int width, int height)
42 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
44 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
46 for (i = 1; i <= SIZE; i++) {
50 cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
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
64 cairo_rectangle (cr, x, y, i, i);
65 cairo_rectangle (cr, x+i, y+i, i, i);
71 cairo_translate (cr, WIDTH, 0);
74 return CAIRO_TEST_SUCCESS;
77 static cairo_test_status_t
78 triangles (cairo_t *cr, int width, int height)
82 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
84 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
86 for (i = 1; i <= SIZE; i++) {
90 cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
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.
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);
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);
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);
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);
137 cairo_translate (cr, WIDTH, 0);
140 return CAIRO_TEST_SUCCESS;
143 CAIRO_TEST (half_coverage_rectangles,
144 "Check the fidelity of the rasterisation.",
146 "target=raster slow", /* requirements */
147 WIDTH * SIZE, HEIGHT,
150 CAIRO_TEST (half_coverage_triangles,
151 "Check the fidelity of the rasterisation.",
153 "target=raster slow", /* requirements */
154 WIDTH * SIZE, HEIGHT,