1
/*
2
 * Copyright © 2005 Mozilla Corporation
3
 * Copyright © 2009 Intel Corporation
4
 *
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.
15
 *
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.
23
 *
24
 * Author: Vladimir Vukicevic <vladimir@pobox.com>
25
 *         Chris Wilson <chris@chris-wilson.co.uk>
26
 */
27

            
28
#include "cairo-test.h"
29

            
30
#define UNIT_SIZE 100
31
#define PAD 5
32
#define INNER_PAD 10
33

            
34
#define WIDTH (UNIT_SIZE + PAD) + PAD
35
#define HEIGHT (UNIT_SIZE + PAD) + PAD
36

            
37
static cairo_pattern_t *
38
3
argb32_source (void)
39
{
40
    cairo_surface_t *surface;
41
    cairo_pattern_t *pattern;
42
    cairo_t *cr;
43

            
44
3
    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 16, 16);
45
3
    cr = cairo_create (surface);
46
3
    cairo_surface_destroy (surface);
47

            
48
3
    cairo_set_source_rgb (cr, 1, 0, 0);
49
3
    cairo_rectangle (cr, 8, 0, 8, 8);
50
3
    cairo_fill (cr);
51

            
52
3
    cairo_set_source_rgb (cr, 0, 1, 0);
53
3
    cairo_rectangle (cr, 0, 8, 8, 8);
54
3
    cairo_fill (cr);
55

            
56
3
    cairo_set_source_rgb (cr, 0, 0, 1);
57
3
    cairo_rectangle (cr, 8, 8, 8, 8);
58
3
    cairo_fill (cr);
59

            
60
3
    pattern = cairo_pattern_create_for_surface (cairo_get_target (cr));
61
3
    cairo_destroy (cr);
62

            
63
3
    return pattern;
64
}
65

            
66
static cairo_test_status_t
67
3
draw (cairo_t *cr, int width, int height)
68
{
69
    cairo_pattern_t *gradient, *image;
70

            
71
3
    cairo_set_source_rgb (cr, 1,1,1);
72
3
    cairo_paint (cr);
73

            
74
3
    cairo_translate (cr, PAD, PAD);
75

            
76
    /* clip to the unit size */
77
3
    cairo_rectangle (cr, 0, 0,
78
		     UNIT_SIZE, UNIT_SIZE);
79
3
    cairo_clip (cr);
80

            
81
3
    cairo_rectangle (cr, 0, 0,
82
		     UNIT_SIZE, UNIT_SIZE);
83
3
    cairo_set_source_rgba (cr, 0, 0, 0, 1);
84
3
    cairo_set_line_width (cr, 2);
85
3
    cairo_stroke (cr);
86

            
87
    /* start a group */
88
3
    cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR);
89

            
90
    /* draw a gradient background */
91
3
    cairo_save (cr);
92
3
    cairo_translate (cr, INNER_PAD, INNER_PAD);
93
3
    cairo_new_path (cr);
94
3
    cairo_rectangle (cr, 0, 0,
95
		     UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
96
3
    gradient = cairo_pattern_create_linear (UNIT_SIZE - (INNER_PAD*2), 0,
97
                                            UNIT_SIZE - (INNER_PAD*2), UNIT_SIZE - (INNER_PAD*2));
98
3
    cairo_pattern_add_color_stop_rgba (gradient, 0.0, 0.3, 0.3, 0.3, 1.0);
99
3
    cairo_pattern_add_color_stop_rgba (gradient, 1.0, 1.0, 1.0, 1.0, 1.0);
100
3
    cairo_set_source (cr, gradient);
101
3
    cairo_pattern_destroy (gradient);
102
3
    cairo_fill (cr);
103
3
    cairo_restore (cr);
104

            
105
    /* draw diamond */
106
3
    cairo_move_to (cr, UNIT_SIZE / 2, 0);
107
3
    cairo_line_to (cr, UNIT_SIZE    , UNIT_SIZE / 2);
108
3
    cairo_line_to (cr, UNIT_SIZE / 2, UNIT_SIZE);
109
3
    cairo_line_to (cr, 0            , UNIT_SIZE / 2);
110
3
    cairo_close_path (cr);
111
3
    cairo_set_source_rgba (cr, 0, 0, 1, 1);
112
3
    cairo_fill (cr);
113

            
114
    /* draw circle */
115
3
    cairo_arc (cr,
116
	       UNIT_SIZE / 2, UNIT_SIZE / 2,
117
	       UNIT_SIZE / 3.5,
118
	       0, M_PI * 2);
119
3
    cairo_set_source_rgba (cr, 1, 0, 0, 1);
120
3
    cairo_fill (cr);
121

            
122
    /* and put the image on top */
123
3
    cairo_translate (cr, UNIT_SIZE/2 - 8, UNIT_SIZE/2 - 8);
124
3
    image = argb32_source ();
125
3
    cairo_set_source (cr, image);
126
3
    cairo_pattern_destroy (image);
127
3
    cairo_paint (cr);
128

            
129
3
    cairo_pop_group_to_source (cr);
130
3
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
131
3
    cairo_paint (cr);
132

            
133
3
    return CAIRO_TEST_SUCCESS;
134
}
135

            
136
1
CAIRO_TEST (push_group_color,
137
	    "Verify that cairo_push_group_with_content works.",
138
	    "group", /* keywords */
139
	    NULL, /* requirements */
140
	    WIDTH, HEIGHT,
141
	    NULL, draw)