2 * Copyright © 2007 Red Hat, Inc.
3 * Copyright © 2009 Adrian Johnson
4 * Copyright © 2011 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use, copy,
10 * modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Behdad Esfahbod <behdad@behdad.org>
28 * Adrian Johnson <ajohnson@redneon.com>
29 * Chris Wilson <chris@chris-wilson.co.uk>
33 #include "cairo-test.h"
37 #define PAT_HEIGHT 170
38 #define SIZE PAT_WIDTH
40 #define WIDTH (PAD + SIZE + PAD)
43 /* This test is designed to paint a mesh pattern. The mesh contains
44 * two overlapping patches */
46 static cairo_pattern_t *
49 cairo_pattern_t *pattern;
51 pattern = cairo_pattern_create_mesh ();
53 cairo_mesh_pattern_begin_patch (pattern);
55 cairo_mesh_pattern_move_to (pattern, 0, 0);
56 cairo_mesh_pattern_curve_to (pattern, 30, -30, 60, 30, 100, 0);
57 cairo_mesh_pattern_curve_to (pattern, 60, 30, 130, 60, 100, 100);
58 cairo_mesh_pattern_curve_to (pattern, 60, 70, 30, 130, 0, 100);
59 cairo_mesh_pattern_curve_to (pattern, 30, 70, -30, 30, 0, 0);
61 cairo_mesh_pattern_set_corner_color_rgb (pattern, 0, 1, 0, 0);
62 cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0);
63 cairo_mesh_pattern_set_corner_color_rgb (pattern, 2, 0, 0, 1);
64 cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0);
66 cairo_mesh_pattern_end_patch (pattern);
68 cairo_mesh_pattern_begin_patch (pattern);
70 cairo_mesh_pattern_move_to (pattern, 50, 50);
71 cairo_mesh_pattern_curve_to (pattern, 80, 20, 110, 80, 150, 50);
72 cairo_mesh_pattern_curve_to (pattern, 110, 80, 180, 110, 150, 150);
73 cairo_mesh_pattern_curve_to (pattern, 110, 120, 80, 180, 50, 150);
74 cairo_mesh_pattern_curve_to (pattern, 80, 120, 20, 80, 50, 50);
76 cairo_mesh_pattern_set_corner_color_rgba (pattern, 0, 1, 0, 0, 0.3);
77 cairo_mesh_pattern_set_corner_color_rgb (pattern, 1, 0, 1, 0);
78 cairo_mesh_pattern_set_corner_color_rgba (pattern, 2, 0, 0, 1, 0.3);
79 cairo_mesh_pattern_set_corner_color_rgb (pattern, 3, 1, 1, 0);
81 cairo_mesh_pattern_end_patch (pattern);
89 cairo_pattern_t *source;
91 cairo_set_source_rgb (cr, 0, 1, 1);
95 cairo_set_source (cr, source);
96 cairo_pattern_destroy (source);
98 cairo_rectangle (cr, 10, 10, SIZE-20, SIZE-20);
106 record_create (cairo_t *target)
108 cairo_surface_t *surface;
111 surface = cairo_recording_surface_create (cairo_surface_get_content (cairo_get_target (target)), NULL);
112 cr = cairo_create (surface);
113 cairo_surface_destroy (surface);
118 static cairo_surface_t *
119 record_get (cairo_t *target)
121 cairo_surface_t *surface;
123 surface = cairo_surface_reference (cairo_get_target (target));
124 cairo_destroy (target);
129 static cairo_test_status_t
130 record_replay (cairo_t *cr, cairo_t *(*func)(cairo_t *), int width, int height)
132 cairo_surface_t *surface;
135 surface = record_get (func (record_create (cr)));
137 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
138 cairo_set_source_surface (cr, surface, 0, 0);
139 cairo_surface_destroy (surface);
140 cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_NONE);
142 for (y = 0; y < height; y += 2) {
143 for (x = 0; x < width; x += 2) {
144 cairo_rectangle (cr, x, y, 2, 2);
147 cairo_reset_clip (cr);
151 return CAIRO_TEST_SUCCESS;
154 static cairo_test_status_t
155 record_mesh (cairo_t *cr, int width, int height)
157 return record_replay (cr, draw, width, height);
160 CAIRO_TEST (record_mesh,
161 "Paint mesh pattern through a recording surface",
162 "record,mesh,pattern", /* keywords */
163 NULL, /* requirements */