1
/*
2
 * Copyright © 2010 Mozilla Corporation
3
 * Copyright © 2010 Intel Corporation
4
 *
5
 * Permission is hereby granted, free of charge, to any person
6
 * obtaining a copy of this software and associated documentation
7
 * files (the "Software"), to deal in the Software without
8
 * restriction, including without limitation the rights to use, copy,
9
 * modify, merge, publish, distribute, sublicense, and/or sell copies
10
 * of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 *
25
 * Author: Chris Wilson <chris@chris-wilson.co.uk>
26
 */
27

            
28
#include "cairo-test.h"
29

            
30
static cairo_test_status_t
31
3
draw (cairo_t *cr, int width, int height)
32
{
33
    cairo_surface_t *mask;
34
    cairo_t *cr2;
35

            
36
3
    cairo_set_source_rgb (cr, 0, 1, 0);
37
3
    cairo_paint (cr);
38

            
39
    /* clip twice, note that the intersection is smaller then the extents */
40
3
    cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
41
3
    cairo_rectangle (cr, 10, 10, 80, 80);
42
3
    cairo_rectangle (cr, 20, 20, 60, 60);
43
3
    cairo_clip (cr);
44

            
45
3
    cairo_rectangle (cr, 0, 40, 40, 30);
46
3
    cairo_clip (cr);
47

            
48
    /* and exercise the bug found by Jeff Muizelaar */
49
3
    mask = cairo_surface_create_similar (cairo_get_target (cr),
50
					 CAIRO_CONTENT_ALPHA,
51
					 width-20, height-20);
52
3
    cr2 = cairo_create (mask);
53
3
    cairo_surface_destroy (mask);
54

            
55
3
    cairo_set_source_rgba (cr2, 1, 1, 1, 1);
56
3
    cairo_paint (cr2);
57

            
58
3
    cairo_set_source_rgb (cr, 1, 0, 0);
59
3
    cairo_mask_surface (cr, cairo_get_target (cr2), 0, 0);
60
3
    cairo_destroy (cr2);
61

            
62
3
    return CAIRO_TEST_SUCCESS;
63
}
64

            
65
1
CAIRO_TEST (clip_twice_rectangle,
66
	    "Tests clipping twice using rectangles",
67
	    "clip", /* keywords */
68
	    NULL, /* requirements */
69
	    100, 100,
70
	    NULL, draw)