2 * Copyright 2010 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: Benjamin Otte <otte@gnome.org>
27 #include "cairo-test.h"
29 #define TARGET_SIZE 10
34 #define PAINT_OFFSET SUB_SIZE
35 #define PAINT_SIZE (3 * SUB_SIZE)
37 static cairo_content_t contents[] = { CAIRO_CONTENT_ALPHA,
39 CAIRO_CONTENT_COLOR_ALPHA };
41 #define N_CONTENTS ARRAY_LENGTH (contents)
42 #define N_PADS (CAIRO_EXTEND_PAD + 1)
45 static cairo_surface_t *
46 create_target (cairo_surface_t *similar_to,
47 cairo_content_t content)
49 cairo_surface_t *surface;
52 surface = cairo_surface_create_similar (similar_to,
54 TARGET_SIZE, TARGET_SIZE);
56 cr = cairo_create (surface);
57 cairo_test_paint_checkered (cr);
63 static cairo_test_status_t
64 check_surface_extents (const cairo_test_context_t *ctx,
65 cairo_surface_t * surface,
71 double x1, y1, x2, y2;
74 cr = cairo_create (surface);
75 cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
83 "surface extents should be (%g, %g, %g, %g), but are (%g, %g, %g, %g)\n",
85 x1, y1, x2 - x1, y2 - y1);
86 return CAIRO_TEST_FAILURE;
89 return CAIRO_TEST_SUCCESS;
92 static cairo_test_status_t
93 draw_for_size (cairo_t *cr,
97 cairo_surface_t *target, *subsurface;
98 cairo_extend_t extend;
99 cairo_test_status_t check, result = CAIRO_TEST_SUCCESS;
100 unsigned int content;
102 for (content = 0; content < N_CONTENTS; content++) {
105 /* create a target surface for our subsurface */
106 target = create_target (cairo_get_target (cr),
109 /* create a subsurface that extends the target surface */
110 subsurface = cairo_surface_create_for_rectangle (target,
114 /* ensure the extents are ok */
115 check = check_surface_extents (cairo_test_get_context (cr),
119 if (result == CAIRO_TEST_SUCCESS)
122 /* paint this surface with all extend modes. */
123 for (extend = 0; extend < N_PADS; extend++) {
126 cairo_rectangle (cr, 0, 0, PAINT_SIZE, PAINT_SIZE);
129 cairo_set_source_surface (cr, subsurface, PAINT_OFFSET, PAINT_OFFSET);
130 cairo_pattern_set_extend (cairo_get_source (cr), extend);
135 cairo_translate (cr, PAINT_SIZE + TARGET_SIZE, 0);
138 cairo_surface_destroy (subsurface);
139 cairo_surface_destroy (target);
143 cairo_translate (cr, 0, PAINT_SIZE + TARGET_SIZE);
149 static cairo_test_status_t
150 draw (cairo_t *cr, int width, int height)
152 cairo_test_status_t check, result = CAIRO_TEST_SUCCESS;
154 /* paint background in nice gray */
155 cairo_set_source_rgb (cr, 0.51613, 0.55555, 0.51613);
158 /* Use CAIRO_OPERATOR_SOURCE in the tests so we get the actual
159 * contents of the subsurface */
160 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
162 result = draw_for_size (cr, SUB_OFFSET, SUB_OFFSET);
164 check = draw_for_size (cr, 0, 0);
165 if (result == CAIRO_TEST_SUCCESS)
171 CAIRO_TEST (subsurface_outside_target,
172 "Tests contents of subsurfaces outside target area",
173 "subsurface, pad", /* keywords */
174 "target=raster", /* FIXME! recursion bug in subsurface/snapshot (with pdf backend) */ /* requirements */
175 (PAINT_SIZE + TARGET_SIZE) * N_PADS - TARGET_SIZE,
176 (PAINT_SIZE + TARGET_SIZE) * N_CONTENTS * 2 - TARGET_SIZE,