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

            
28
#include "cairo-test.h"
29

            
30
/* This test exercises code that computes the extents of a surface
31
 * pattern with CAIRO_FILTER_BILINEAR, (where the filtering
32
 * effectively increases the extents of the pattern).
33
 *
34
 * The original bug was reported by Owen Taylor here:
35
 *
36
 *	bad clipping with EXTEND_NONE
37
 *	https://bugs.freedesktop.org/show_bug.cgi?id=15349
38
 */
39

            
40
#define SCALE	10
41
#define PAD	3
42
#define WIDTH	(PAD + 3 * SCALE + PAD)
43
#define HEIGHT	WIDTH
44

            
45
static cairo_test_status_t
46
3
draw (cairo_t *cr, int width, int height)
47
{
48
    cairo_surface_t *image;
49
    cairo_t *cr2;
50

            
51
3
    image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 2, 2);
52

            
53
    /* Fill with an opaque background to avoid a separate rgb24 ref image */
54
3
    cairo_set_source_rgb (cr, 0, 0, 0);
55
3
    cairo_paint (cr);
56

            
57
    /* First check handling of pattern extents > surface extents */
58
3
    cairo_save (cr);
59
3
    cairo_scale (cr, width/2., height/2.);
60

            
61
    /* Create a solid black source to merge with the background */
62
3
    cr2 = cairo_create (image);
63
3
    cairo_set_source_rgb (cr2, 0, 0 ,0);
64
3
    cairo_paint (cr2);
65
3
    cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0);
66
3
    cairo_destroy (cr2);
67
3
    cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
68
3
    cairo_paint (cr);
69
3
    cairo_restore (cr);
70

            
71
    /* Then scale to smaller so we can see the full bilinear extents */
72
3
    cairo_save (cr);
73
3
    cairo_translate (cr, PAD, PAD);
74
3
    cairo_scale (cr, SCALE, SCALE);
75
3
    cairo_translate (cr, 0.5, 0.5);
76

            
77
    /* Create a 2x2 blue+red checkerboard source */
78
3
    cr2 = cairo_create (image);
79
3
    cairo_set_source_rgb (cr2, 1, 0 ,0); /* red */
80
3
    cairo_paint (cr2);
81
3
    cairo_set_source_rgb (cr2, 0, 0, 1); /* blue */
82
3
    cairo_rectangle (cr2, 0, 1, 1, 1);
83
3
    cairo_rectangle (cr2, 1, 0, 1, 1);
84
3
    cairo_fill (cr2);
85
3
    cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0);
86
3
    cairo_destroy (cr2);
87

            
88
3
    cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
89
3
    cairo_paint (cr);
90
3
    cairo_restore (cr);
91

            
92
3
    cairo_surface_destroy (image);
93

            
94
3
    return CAIRO_TEST_SUCCESS;
95
}
96

            
97
1
CAIRO_TEST (filter_bilinear_extents,
98
	    "Test that pattern extents are properly computed for CAIRO_FILTER_BILINEAR",
99
	    "extents", /* keywords */
100
	    NULL, /* requirements */
101
	    WIDTH, HEIGHT,
102
	    NULL, draw)