2 * Copyright © 2007 Adrian Johnson
3 * Copyright © 2011 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Adrian Johnson <ajohnson@redneon.com>
27 * Chris Wilson <chris@chris-wilson.co.uk>
30 #include "cairo-test.h"
33 #define PAT_HEIGHT 120
34 #define SIZE (PAT_WIDTH*2)
36 #define WIDTH (PAD + SIZE + PAD)
40 /* This test is designed to test painting a recording surface pattern with
41 * CAIRO_EXTEND_NONE and a non identity pattern matrix.
43 static cairo_pattern_t *create_pattern (cairo_t *target)
45 cairo_surface_t *surface;
46 cairo_pattern_t *pattern;
49 surface = cairo_surface_create_similar (cairo_get_group_target (target),
50 CAIRO_CONTENT_COLOR_ALPHA,
51 PAT_WIDTH, PAT_HEIGHT);
52 cr = cairo_create (surface);
53 cairo_surface_destroy (surface);
55 cairo_set_source_rgba (cr, 1, 0, 1, 0.5);
56 cairo_rectangle (cr, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
59 cairo_set_source_rgba (cr, 0, 1, 1, 0.5);
60 cairo_rectangle (cr, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
63 cairo_set_line_width (cr, 1);
64 cairo_move_to (cr, PAT_WIDTH/6.0, 0);
65 cairo_line_to (cr, 0, 0);
66 cairo_line_to (cr, 0, PAT_HEIGHT/6.0);
67 cairo_set_source_rgb (cr, 1, 0, 0);
69 cairo_move_to (cr, PAT_WIDTH/6.0, PAT_HEIGHT);
70 cairo_line_to (cr, 0, PAT_HEIGHT);
71 cairo_line_to (cr, 0, 5*PAT_HEIGHT/6.0);
72 cairo_set_source_rgb (cr, 0, 1, 0);
74 cairo_move_to (cr, 5*PAT_WIDTH/6.0, 0);
75 cairo_line_to (cr, PAT_WIDTH, 0);
76 cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/6.0);
77 cairo_set_source_rgb (cr, 0, 0, 1);
79 cairo_move_to (cr, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
80 cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT);
81 cairo_line_to (cr, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
82 cairo_set_source_rgb (cr, 1, 1, 0);
85 cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
86 cairo_set_line_width (cr, PAT_WIDTH/10.0);
88 cairo_move_to (cr, 0, PAT_HEIGHT/4.0);
89 cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/4.0);
92 cairo_move_to (cr, PAT_WIDTH/4.0, 0);
93 cairo_line_to (cr, PAT_WIDTH/4.0, PAT_WIDTH);
96 pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
102 static cairo_test_status_t
103 draw (cairo_t *cr, cairo_extend_t extend)
105 cairo_pattern_t *pattern;
108 cairo_translate (cr, PAD, PAD);
110 pattern = create_pattern (cr);
112 cairo_matrix_init_identity (&mat);
113 cairo_matrix_scale (&mat, 2, 1.5);
114 cairo_matrix_rotate (&mat, 1);
115 cairo_matrix_translate (&mat, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
116 cairo_pattern_set_matrix (pattern, &mat);
117 cairo_pattern_set_extend (pattern, extend);
119 cairo_set_source (cr, pattern);
122 cairo_pattern_destroy (pattern);
124 return CAIRO_TEST_SUCCESS;
127 static cairo_test_status_t
128 none (cairo_t *cr, int width, int height)
130 return draw (cr, CAIRO_EXTEND_NONE);
133 static cairo_test_status_t
134 repeat (cairo_t *cr, int width, int height)
136 return draw (cr, CAIRO_EXTEND_REPEAT);
139 static cairo_test_status_t
140 reflect (cairo_t *cr, int width, int height)
142 return draw (cr, CAIRO_EXTEND_REFLECT);
145 static cairo_test_status_t
146 pad (cairo_t *cr, int width, int height)
148 return draw (cr, CAIRO_EXTEND_PAD);
151 CAIRO_TEST (recording_surface_extend_none,
152 "Paint recording surface pattern with extend modes",
153 "recording, extend", /* keywords */
154 NULL, /* requirements */
157 CAIRO_TEST (recording_surface_extend_repeat,
158 "Paint recording surface pattern with extend modes",
159 "recording, extend", /* keywords */
160 NULL, /* requirements */
163 CAIRO_TEST (recording_surface_extend_reflect,
164 "Paint recording surface pattern with extend modes",
165 "recording, extend", /* keywords */
166 NULL, /* requirements */
169 CAIRO_TEST (recording_surface_extend_pad,
170 "Paint recording surface pattern with extend modes",
171 "recording, extend", /* keywords */
172 NULL, /* requirements */