1
/*
2
 * Copyright © 2007 Adrian Johnson
3
 * Copyright © 2011 Intel Corporation
4
 *
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:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
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
23
 * SOFTWARE.
24
 *
25
 * Authors:
26
 * 	Adrian Johnson <ajohnson@redneon.com>
27
 * 	Chris Wilson <chris@chris-wilson.co.uk>
28
 */
29

            
30
#include "cairo-test.h"
31

            
32
#define PAT_WIDTH  120
33
#define PAT_HEIGHT 120
34
#define SIZE (PAT_WIDTH*2)
35
#define PAD 2
36
#define WIDTH (PAD + SIZE + PAD)
37
#define HEIGHT WIDTH
38

            
39

            
40
/* This test is designed to test painting a recording surface pattern with
41
 * CAIRO_EXTEND_NONE and a non identity pattern matrix.
42
 */
43
12
static cairo_pattern_t *create_pattern (cairo_t *target)
44
{
45
    cairo_surface_t *surface;
46
    cairo_pattern_t *pattern;
47
    cairo_t *cr;
48

            
49
12
    surface = cairo_surface_create_similar (cairo_get_group_target (target),
50
					    CAIRO_CONTENT_COLOR_ALPHA,
51
					    PAT_WIDTH, PAT_HEIGHT);
52
12
    cr = cairo_create (surface);
53
12
    cairo_surface_destroy (surface);
54

            
55
12
    cairo_set_source_rgba (cr, 1, 0, 1, 0.5);
56
12
    cairo_rectangle (cr, PAT_WIDTH/6.0, PAT_HEIGHT/6.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
57
12
    cairo_fill (cr);
58

            
59
12
    cairo_set_source_rgba (cr, 0, 1, 1, 0.5);
60
12
    cairo_rectangle (cr, PAT_WIDTH/2.0, PAT_HEIGHT/2.0, PAT_WIDTH/4.0, PAT_HEIGHT/4.0);
61
12
    cairo_fill (cr);
62

            
63
12
    cairo_set_line_width (cr, 1);
64
12
    cairo_move_to (cr, PAT_WIDTH/6.0, 0);
65
12
    cairo_line_to (cr, 0, 0);
66
12
    cairo_line_to (cr, 0, PAT_HEIGHT/6.0);
67
12
    cairo_set_source_rgb (cr, 1, 0, 0);
68
12
    cairo_stroke (cr);
69
12
    cairo_move_to (cr, PAT_WIDTH/6.0, PAT_HEIGHT);
70
12
    cairo_line_to (cr, 0, PAT_HEIGHT);
71
12
    cairo_line_to (cr, 0, 5*PAT_HEIGHT/6.0);
72
12
    cairo_set_source_rgb (cr, 0, 1, 0);
73
12
    cairo_stroke (cr);
74
12
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, 0);
75
12
    cairo_line_to (cr, PAT_WIDTH, 0);
76
12
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/6.0);
77
12
    cairo_set_source_rgb (cr, 0, 0, 1);
78
12
    cairo_stroke (cr);
79
12
    cairo_move_to (cr, 5*PAT_WIDTH/6.0, PAT_HEIGHT);
80
12
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT);
81
12
    cairo_line_to (cr, PAT_WIDTH, 5*PAT_HEIGHT/6.0);
82
12
    cairo_set_source_rgb (cr, 1, 1, 0);
83
12
    cairo_stroke (cr);
84

            
85
12
    cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
86
12
    cairo_set_line_width (cr, PAT_WIDTH/10.0);
87

            
88
12
    cairo_move_to (cr, 0,         PAT_HEIGHT/4.0);
89
12
    cairo_line_to (cr, PAT_WIDTH, PAT_HEIGHT/4.0);
90
12
    cairo_stroke (cr);
91

            
92
12
    cairo_move_to (cr, PAT_WIDTH/4.0,         0);
93
12
    cairo_line_to (cr, PAT_WIDTH/4.0, PAT_WIDTH);
94
12
    cairo_stroke (cr);
95

            
96
12
    pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
97
12
    cairo_destroy (cr);
98

            
99
12
    return pattern;
100
}
101

            
102
static cairo_test_status_t
103
12
draw (cairo_t *cr, cairo_extend_t extend)
104
{
105
    cairo_pattern_t *pattern;
106
    cairo_matrix_t   mat;
107

            
108
12
    cairo_translate (cr, PAD, PAD);
109

            
110
12
    pattern = create_pattern (cr);
111

            
112
12
    cairo_matrix_init_identity (&mat);
113
12
    cairo_matrix_scale (&mat, 2, 1.5);
114
12
    cairo_matrix_rotate (&mat, 1);
115
12
    cairo_matrix_translate (&mat, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
116
12
    cairo_pattern_set_matrix (pattern, &mat);
117
12
    cairo_pattern_set_extend (pattern, extend);
118

            
119
12
    cairo_set_source (cr, pattern);
120
12
    cairo_paint (cr);
121

            
122
12
    cairo_pattern_destroy (pattern);
123

            
124
12
    return CAIRO_TEST_SUCCESS;
125
}
126

            
127
static cairo_test_status_t
128
3
none (cairo_t *cr, int width, int height)
129
{
130
3
    return draw (cr, CAIRO_EXTEND_NONE);
131
}
132

            
133
static cairo_test_status_t
134
3
repeat (cairo_t *cr, int width, int height)
135
{
136
3
    return draw (cr, CAIRO_EXTEND_REPEAT);
137
}
138

            
139
static cairo_test_status_t
140
3
reflect (cairo_t *cr, int width, int height)
141
{
142
3
    return draw (cr, CAIRO_EXTEND_REFLECT);
143
}
144

            
145
static cairo_test_status_t
146
3
pad (cairo_t *cr, int width, int height)
147
{
148
3
    return draw (cr, CAIRO_EXTEND_PAD);
149
}
150

            
151
1
CAIRO_TEST (recording_surface_extend_none,
152
	    "Paint recording surface pattern with extend modes",
153
	    "recording, extend", /* keywords */
154
	    NULL, /* requirements */
155
	    WIDTH, HEIGHT,
156
	    NULL, none)
157
1
CAIRO_TEST (recording_surface_extend_repeat,
158
	    "Paint recording surface pattern with extend modes",
159
	    "recording, extend", /* keywords */
160
	    NULL, /* requirements */
161
	    WIDTH, HEIGHT,
162
	    NULL, repeat)
163
1
CAIRO_TEST (recording_surface_extend_reflect,
164
	    "Paint recording surface pattern with extend modes",
165
	    "recording, extend", /* keywords */
166
	    NULL, /* requirements */
167
	    WIDTH, HEIGHT,
168
	    NULL, reflect)
169
1
CAIRO_TEST (recording_surface_extend_pad,
170
	    "Paint recording surface pattern with extend modes",
171
	    "recording, extend", /* keywords */
172
	    NULL, /* requirements */
173
	    WIDTH, HEIGHT,
174
	    NULL, pad)