Initialize Tizen 2.3
[framework/graphics/cairo.git] / test / filter-bilinear-extents.c
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  *      http://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 draw (cairo_t *cr, int width, int height)
47 {
48     cairo_surface_t *image;
49     cairo_t *cr2;
50
51     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     cairo_set_source_rgb (cr, 0, 0, 0);
55     cairo_paint (cr);
56
57     /* First check handling of pattern extents > surface extents */
58     cairo_save (cr);
59     cairo_scale (cr, width/2., height/2.);
60
61     /* Create a solid black source to merge with the background */
62     cr2 = cairo_create (image);
63     cairo_set_source_rgb (cr2, 0, 0 ,0);
64     cairo_paint (cr2);
65     cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0);
66     cairo_destroy (cr2);
67     cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
68     cairo_paint (cr);
69     cairo_restore (cr);
70
71     /* Then scale to smaller so we can see the full bilinear extents */
72     cairo_save (cr);
73     cairo_translate (cr, PAD, PAD);
74     cairo_scale (cr, SCALE, SCALE);
75     cairo_translate (cr, 0.5, 0.5);
76
77     /* Create a 2x2 blue+red checkerboard source */
78     cr2 = cairo_create (image);
79     cairo_set_source_rgb (cr2, 1, 0 ,0); /* red */
80     cairo_paint (cr2);
81     cairo_set_source_rgb (cr2, 0, 0, 1); /* blue */
82     cairo_rectangle (cr2, 0, 1, 1, 1);
83     cairo_rectangle (cr2, 1, 0, 1, 1);
84     cairo_fill (cr2);
85     cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0);
86     cairo_destroy (cr2);
87
88     cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
89     cairo_paint (cr);
90     cairo_restore (cr);
91
92     cairo_surface_destroy (image);
93
94     return CAIRO_TEST_SUCCESS;
95 }
96
97 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)