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 *
33
9
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
9
    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, size, size);
42
9
    cr = cairo_create (surface);
43
9
    cairo_surface_destroy (surface);
44

            
45
9
    cairo_set_source_rgb (cr, 1, 1, 1);
46
9
    cairo_rectangle (cr, 0, 0, size / 2, size / 2);
47
9
    cairo_fill (cr);
48

            
49
9
    cairo_set_source_rgb (cr, 1, 0, 0);
50
9
    cairo_rectangle (cr, size / 2, 0, size - size / 2, size / 2);
51
9
    cairo_fill (cr);
52

            
53
9
    cairo_set_source_rgb (cr, 0, 1, 0);
54
9
    cairo_rectangle (cr, 0, size / 2, size / 2, size - size / 2);
55
9
    cairo_fill (cr);
56

            
57
9
    cairo_set_source_rgb (cr, 0, 0, 1);
58
9
    cairo_rectangle (cr, size / 2, size / 2, size - size / 2, size - size / 2);
59
9
    cairo_fill (cr);
60

            
61
9
    pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
62
9
    cairo_destroy (cr);
63

            
64
9
    return pattern;
65
}
66

            
67
static cairo_test_status_t
68
3
draw (cairo_t *cr, int width, int height)
69
{
70
    cairo_pattern_t *source;
71
3
    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
3
    cairo_set_source_rgb (cr, .5, .5, .5);
77
3
    cairo_paint (cr);
78

            
79
3
    cairo_translate(cr, SIZE/2, SIZE/2);
80
3
    cairo_rotate (cr, M_PI / 4.0);
81
3
    cairo_translate (cr, -surface_size/2, -surface_size/2);
82

            
83
3
    source = create_image_source (surface_size);
84
3
    cairo_pattern_set_filter (source, CAIRO_FILTER_NEAREST);
85
3
    cairo_set_source(cr, source);
86
3
    cairo_pattern_destroy (source);
87

            
88
3
    cairo_paint (cr);
89

            
90
3
    return CAIRO_TEST_SUCCESS;
91
}
92

            
93
static cairo_test_status_t
94
3
clip_draw (cairo_t *cr, int width, int height)
95
{
96
    cairo_pattern_t *source;
97
3
    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
3
    cairo_set_source_rgb (cr, .5, .5, .5);
103
3
    cairo_paint (cr);
104

            
105
3
    cairo_rectangle (cr, 2*PAD, 2*PAD, SIZE-4*PAD, SIZE-4*PAD);
106
3
    cairo_clip (cr);
107

            
108
3
    cairo_translate(cr, SIZE/2, SIZE/2);
109
3
    cairo_rotate (cr, M_PI / 4.0);
110
3
    cairo_translate (cr, -surface_size/2, -surface_size/2);
111

            
112
3
    source = create_image_source (surface_size);
113
3
    cairo_pattern_set_filter (source, CAIRO_FILTER_NEAREST);
114
3
    cairo_set_source(cr, source);
115
3
    cairo_pattern_destroy (source);
116

            
117
3
    cairo_paint (cr);
118

            
119
3
    return CAIRO_TEST_SUCCESS;
120
}
121

            
122
static cairo_test_status_t
123
3
draw_clip (cairo_t *cr, int width, int height)
124
{
125
    cairo_pattern_t *source;
126
3
    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
3
    cairo_set_source_rgb (cr, .5, .5, .5);
132
3
    cairo_paint (cr);
133

            
134
3
    cairo_translate(cr, SIZE/2, SIZE/2);
135
3
    cairo_rotate (cr, M_PI / 4.0);
136
3
    cairo_translate (cr, -surface_size/2, -surface_size/2);
137

            
138
3
    cairo_rectangle (cr, PAD, PAD, surface_size-2*PAD, surface_size-2*PAD);
139
3
    cairo_clip (cr);
140

            
141
3
    source = create_image_source (surface_size);
142
3
    cairo_pattern_set_filter (source, CAIRO_FILTER_NEAREST);
143
3
    cairo_set_source(cr, source);
144
3
    cairo_pattern_destroy (source);
145

            
146
3
    cairo_paint (cr);
147

            
148
3
    return CAIRO_TEST_SUCCESS;
149
}
150

            
151
1
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
1
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
1
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)