1
/*
2
 * Copyright 2009 Chris Wilson
3
 * Copyright 2011 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
 * Chris Wilson not be used in advertising or publicity pertaining to
11
 * distribution of the software without specific, written prior
12
 * permission. Chris Wilson 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
 * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18
 * FITNESS, IN NO EVENT SHALL CHRIS WILSON 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: Chris Wilson <chris@chris-wilson.co.uk>
25
 */
26

            
27
#include "cairo-test.h"
28

            
29
#define WIDTH 20
30
#define HEIGHT 20
31

            
32
18
static void clip_mask (cairo_t *cr)
33
{
34
18
    cairo_move_to (cr, 10, 0);
35
18
    cairo_line_to (cr, 0, 10);
36
18
    cairo_line_to (cr, 10, 20);
37
18
    cairo_line_to (cr, 20, 10);
38
18
    cairo_clip (cr);
39
18
}
40

            
41
static cairo_test_status_t
42
3
draw (cairo_t *cr, int width, int height)
43
{
44
3
    cairo_set_source_rgb (cr, 1, 1, 1);
45
3
    cairo_paint (cr);
46

            
47
3
    clip_mask (cr);
48
3
    cairo_set_source_rgb (cr, 0, 1, 0);
49
3
    cairo_paint (cr);
50
3
    cairo_reset_clip (cr);
51

            
52
3
    cairo_set_source_rgb (cr, 1, 0, 0);
53

            
54
3
    cairo_rectangle (cr, 0, 0, 4, 4);
55
3
    cairo_clip (cr);
56
3
    clip_mask (cr);
57
3
    cairo_paint (cr);
58
3
    cairo_reset_clip (cr);
59

            
60
3
    cairo_rectangle (cr, 20, 0, -4, 4);
61
3
    cairo_clip (cr);
62
3
    clip_mask (cr);
63
3
    cairo_paint (cr);
64
3
    cairo_reset_clip (cr);
65

            
66
3
    cairo_rectangle (cr, 20, 20, -4, -4);
67
3
    cairo_clip (cr);
68
3
    clip_mask (cr);
69
3
    cairo_paint (cr);
70
3
    cairo_reset_clip (cr);
71

            
72
3
    cairo_rectangle (cr, 0, 20, 4, -4);
73
3
    cairo_clip (cr);
74
3
    clip_mask (cr);
75
3
    cairo_paint (cr);
76
3
    cairo_reset_clip (cr);
77

            
78
3
    cairo_set_source_rgb (cr, 0, 0, 1);
79

            
80
3
    cairo_rectangle (cr, 8, 8, 4, 4);
81
3
    cairo_clip (cr);
82
3
    clip_mask (cr);
83
3
    cairo_paint (cr);
84
3
    cairo_reset_clip (cr);
85

            
86
3
    return CAIRO_TEST_SUCCESS;
87
}
88

            
89
1
CAIRO_TEST (clip_intersect,
90
	    "Tests intersection of a simple clip with a clip-mask",
91
	    "clip, paint", /* keywords */
92
	    NULL, /* requirements */
93
	    WIDTH, HEIGHT,
94
	    NULL, draw)