2 * Copyright © 2005 Mozilla Corporation
3 * Copyright © 2009 Intel Corporation
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of
10 * Mozilla Corporation not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. Mozilla Corporation makes no representations about the
13 * suitability of this software for any purpose. It is provided "as
14 * is" without express or implied warranty.
16 * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL,
19 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
22 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: Vladimir Vukicevic <vladimir@pobox.com>
25 * Chris Wilson <chris@chris-wilson.co.uk>
28 #include "cairo-test.h"
34 #define WIDTH (UNIT_SIZE + PAD) + PAD
35 #define HEIGHT (UNIT_SIZE + PAD) + PAD
37 static cairo_pattern_t *
40 cairo_surface_t *surface;
41 cairo_pattern_t *pattern;
44 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 16, 16);
45 cr = cairo_create (surface);
46 cairo_surface_destroy (surface);
48 cairo_set_source_rgb (cr, 1, 0, 0);
49 cairo_rectangle (cr, 8, 0, 8, 8);
52 cairo_set_source_rgb (cr, 0, 1, 0);
53 cairo_rectangle (cr, 0, 8, 8, 8);
56 cairo_set_source_rgb (cr, 0, 0, 1);
57 cairo_rectangle (cr, 8, 8, 8, 8);
60 pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
66 static cairo_test_status_t
67 draw (cairo_t *cr, int width, int height)
69 cairo_pattern_t *gradient, *image;
71 cairo_set_source_rgb (cr, 1,1,1);
74 cairo_translate (cr, PAD, PAD);
76 /* clip to the unit size */
77 cairo_rectangle (cr, 0, 0,
78 UNIT_SIZE, UNIT_SIZE);
81 cairo_rectangle (cr, 0, 0,
82 UNIT_SIZE, UNIT_SIZE);
83 cairo_set_source_rgba (cr, 0, 0, 0, 1);
84 cairo_set_line_width (cr, 2);
88 cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR);
90 /* draw a gradient background */
92 cairo_translate (cr, INNER_PAD, INNER_PAD);
94 cairo_rectangle (cr, 0, 0,
95 UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
96 gradient = cairo_pattern_create_linear (UNIT_SIZE - (INNER_PAD*2), 0,
97 UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
98 cairo_pattern_add_color_stop_rgba (gradient, 0.0, 0.3, 0.3, 0.3, 1.0);
99 cairo_pattern_add_color_stop_rgba (gradient, 1.0, 1.0, 1.0, 1.0, 1.0);
100 cairo_set_source (cr, gradient);
101 cairo_pattern_destroy (gradient);
106 cairo_move_to (cr, UNIT_SIZE / 2, 0);
107 cairo_line_to (cr, UNIT_SIZE , UNIT_SIZE / 2);
108 cairo_line_to (cr, UNIT_SIZE / 2, UNIT_SIZE);
109 cairo_line_to (cr, 0 , UNIT_SIZE / 2);
110 cairo_close_path (cr);
111 cairo_set_source_rgba (cr, 0, 0, 1, 1);
116 UNIT_SIZE / 2, UNIT_SIZE / 2,
119 cairo_set_source_rgba (cr, 1, 0, 0, 1);
122 /* and put the image on top */
123 cairo_translate (cr, UNIT_SIZE/2 - 8, UNIT_SIZE/2 - 8);
124 image = argb32_source ();
125 cairo_set_source (cr, image);
126 cairo_pattern_destroy (image);
129 cairo_pop_group_to_source (cr);
130 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
133 return CAIRO_TEST_SUCCESS;
136 CAIRO_TEST (push_group_color,
137 "Verify that cairo_push_group_with_content works.",
138 "group", /* keywords */
139 NULL, /* requirements */