1 /*
2 * Copyright © 2005, 2007 Red Hat, Inc.
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: Carl D. Worth <cworth@cworth.org>
25 */
26
27 #include "cairo-test.h"
28
29 #define SIZE 20
30 #define PAD 2
31
32 static cairo_pattern_t *
create_image_source(int size)33 create_image_source (int size)
34 {
35 cairo_surface_t *surface;
36 cairo_pattern_t *pattern;
37 cairo_t *cr;
38
39 /* Create an image surface with my favorite four colors in each
40 * quadrant. */
41 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, size, size);
42 cr = cairo_create (surface);
43 cairo_surface_destroy (surface);
44
45 cairo_set_source_rgb (cr, 1, 1, 1);
46 cairo_rectangle (cr, 0, 0, size / 2, size / 2);
47 cairo_fill (cr);
48
49 cairo_set_source_rgb (cr, 1, 0, 0);
50 cairo_rectangle (cr, size / 2, 0, size - size / 2, size / 2);
51 cairo_fill (cr);
52
53 cairo_set_source_rgb (cr, 0, 1, 0);
54 cairo_rectangle (cr, 0, size / 2, size / 2, size - size / 2);
55 cairo_fill (cr);
56
57 cairo_set_source_rgb (cr, 0, 0, 1);
58 cairo_rectangle (cr, size / 2, size / 2, size - size / 2, size - size / 2);
59 cairo_fill (cr);
60
61 pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
62 cairo_destroy (cr);
63
64 return pattern;
65 }
66
67 static cairo_test_status_t
draw(cairo_t * cr,int width,int height)68 draw (cairo_t *cr, int width, int height)
69 {
70 cairo_pattern_t *source;
71 int surface_size = sqrt ((SIZE - 2*PAD)*(SIZE - 2*PAD)/2);
72
73 /* Use a gray (neutral) background, so we can spot if the backend pads
74 * with any other colour.
75 */
76 cairo_set_source_rgb (cr, .5, .5, .5);
77 cairo_paint (cr);
78
79 cairo_translate(cr, SIZE/2, SIZE/2);
80 cairo_rotate (cr, M_PI / 4.0);
81 cairo_translate (cr, -surface_size/2, -surface_size/2);
82
83 source = create_image_source (surface_size);
84 cairo_pattern_set_filter (source, CAIRO_FILTER_NEAREST);
85 cairo_set_source(cr, source);
86 cairo_pattern_destroy (source);
87
88 cairo_paint (cr);
89
90 return CAIRO_TEST_SUCCESS;
91 }
92
93 static cairo_test_status_t
clip_draw(cairo_t * cr,int width,int height)94 clip_draw (cairo_t *cr, int width, int height)
95 {
96 cairo_pattern_t *source;
97 int surface_size = sqrt ((SIZE - 2*PAD)*(SIZE - 2*PAD)/2);
98
99 /* Use a gray (neutral) background, so we can spot if the backend pads
100 * with any other colour.
101 */
102 cairo_set_source_rgb (cr, .5, .5, .5);
103 cairo_paint (cr);
104
105 cairo_rectangle (cr, 2*PAD, 2*PAD, SIZE-4*PAD, SIZE-4*PAD);
106 cairo_clip (cr);
107
108 cairo_translate(cr, SIZE/2, SIZE/2);
109 cairo_rotate (cr, M_PI / 4.0);
110 cairo_translate (cr, -surface_size/2, -surface_size/2);
111
112 source = create_image_source (surface_size);
113 cairo_pattern_set_filter (source, CAIRO_FILTER_NEAREST);
114 cairo_set_source(cr, source);
115 cairo_pattern_destroy (source);
116
117 cairo_paint (cr);
118
119 return CAIRO_TEST_SUCCESS;
120 }
121
122 static cairo_test_status_t
draw_clip(cairo_t * cr,int width,int height)123 draw_clip (cairo_t *cr, int width, int height)
124 {
125 cairo_pattern_t *source;
126 int surface_size = sqrt ((SIZE - 2*PAD)*(SIZE - 2*PAD)/2);
127
128 /* Use a gray (neutral) background, so we can spot if the backend pads
129 * with any other colour.
130 */
131 cairo_set_source_rgb (cr, .5, .5, .5);
132 cairo_paint (cr);
133
134 cairo_translate(cr, SIZE/2, SIZE/2);
135 cairo_rotate (cr, M_PI / 4.0);
136 cairo_translate (cr, -surface_size/2, -surface_size/2);
137
138 cairo_rectangle (cr, PAD, PAD, surface_size-2*PAD, surface_size-2*PAD);
139 cairo_clip (cr);
140
141 source = create_image_source (surface_size);
142 cairo_pattern_set_filter (source, CAIRO_FILTER_NEAREST);
143 cairo_set_source(cr, source);
144 cairo_pattern_destroy (source);
145
146 cairo_paint (cr);
147
148 return CAIRO_TEST_SUCCESS;
149 }
150
151 CAIRO_TEST (rotate_image_surface_paint,
152 "Test call sequence: image_surface_create; rotate; set_source_surface; paint"
153 "\nThis test is known to fail on the ps backend currently",
154 "image, transform, paint", /* keywords */
155 NULL, /* requirements */
156 SIZE, SIZE,
157 NULL, draw)
158
159 CAIRO_TEST (clip_rotate_image_surface_paint,
160 "Test call sequence: image_surface_create; rotate; set_source_surface; paint"
161 "\nThis test is known to fail on the ps backend currently",
162 "image, transform, paint", /* keywords */
163 NULL, /* requirements */
164 SIZE, SIZE,
165 NULL, clip_draw)
166 CAIRO_TEST (rotate_clip_image_surface_paint,
167 "Test call sequence: image_surface_create; rotate; set_source_surface; paint"
168 "\nThis test is known to fail on the ps backend currently",
169 "image, transform, paint", /* keywords */
170 NULL, /* requirements */
171 SIZE, SIZE,
172 NULL, draw_clip)
173