2 * Copyright © 2005, 2007 Red Hat, Inc.
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: Carl D. Worth <cworth@cworth.org>
27 #include "cairo-test.h"
32 static cairo_pattern_t *
33 create_image_source (int size)
35 cairo_surface_t *surface;
36 cairo_pattern_t *pattern;
39 /* Create an image surface with my favorite four colors in each
41 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, size, size);
42 cr = cairo_create (surface);
43 cairo_surface_destroy (surface);
45 cairo_set_source_rgb (cr, 1, 1, 1);
46 cairo_rectangle (cr, 0, 0, size / 2, size / 2);
49 cairo_set_source_rgb (cr, 1, 0, 0);
50 cairo_rectangle (cr, size / 2, 0, size - size / 2, size / 2);
53 cairo_set_source_rgb (cr, 0, 1, 0);
54 cairo_rectangle (cr, 0, size / 2, size / 2, size - size / 2);
57 cairo_set_source_rgb (cr, 0, 0, 1);
58 cairo_rectangle (cr, size / 2, size / 2, size - size / 2, size - size / 2);
61 pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
67 static cairo_test_status_t
68 draw (cairo_t *cr, int width, int height)
70 cairo_pattern_t *source;
71 int surface_size = sqrt ((SIZE - 2*PAD)*(SIZE - 2*PAD)/2);
73 /* Use a gray (neutral) background, so we can spot if the backend pads
74 * with any other colour.
76 cairo_set_source_rgb (cr, .5, .5, .5);
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);
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);
90 return CAIRO_TEST_SUCCESS;
93 static cairo_test_status_t
94 clip_draw (cairo_t *cr, int width, int height)
96 cairo_pattern_t *source;
97 int surface_size = sqrt ((SIZE - 2*PAD)*(SIZE - 2*PAD)/2);
99 /* Use a gray (neutral) background, so we can spot if the backend pads
100 * with any other colour.
102 cairo_set_source_rgb (cr, .5, .5, .5);
105 cairo_rectangle (cr, 2*PAD, 2*PAD, SIZE-4*PAD, SIZE-4*PAD);
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);
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);
119 return CAIRO_TEST_SUCCESS;
122 static cairo_test_status_t
123 draw_clip (cairo_t *cr, int width, int height)
125 cairo_pattern_t *source;
126 int surface_size = sqrt ((SIZE - 2*PAD)*(SIZE - 2*PAD)/2);
128 /* Use a gray (neutral) background, so we can spot if the backend pads
129 * with any other colour.
131 cairo_set_source_rgb (cr, .5, .5, .5);
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);
138 cairo_rectangle (cr, PAD, PAD, surface_size-2*PAD, surface_size-2*PAD);
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);
148 return CAIRO_TEST_SUCCESS;
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 */
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 */
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 */