2 * Copyright © 2008 Red Hat, Inc.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 * Authors: Carl D. Worth <cworth@cworth.org>
25 * Owen Taylor <otaylor@redhat.com>
28 #include "cairo-test.h"
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).
34 * The original bug was reported by Owen Taylor here:
36 * bad clipping with EXTEND_NONE
37 * http://bugs.freedesktop.org/show_bug.cgi?id=15349
42 #define WIDTH (PAD + 3 * SCALE + PAD)
45 static cairo_test_status_t
46 draw (cairo_t *cr, int width, int height)
48 cairo_surface_t *image;
51 image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 2, 2);
53 /* Fill with an opaque background to avoid a separate rgb24 ref image */
54 cairo_set_source_rgb (cr, 0, 0, 0);
57 /* First check handling of pattern extents > surface extents */
59 cairo_scale (cr, width/2., height/2.);
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);
65 cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0);
67 cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
71 /* Then scale to smaller so we can see the full bilinear extents */
73 cairo_translate (cr, PAD, PAD);
74 cairo_scale (cr, SCALE, SCALE);
75 cairo_translate (cr, 0.5, 0.5);
77 /* Create a 2x2 blue+red checkerboard source */
78 cr2 = cairo_create (image);
79 cairo_set_source_rgb (cr2, 1, 0 ,0); /* red */
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);
85 cairo_set_source_surface (cr, cairo_get_target (cr2), 0, 0);
88 cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_BILINEAR);
92 cairo_surface_destroy (image);
94 return CAIRO_TEST_SUCCESS;
97 CAIRO_TEST (filter_bilinear_extents,
98 "Test that pattern extents are properly computed for CAIRO_FILTER_BILINEAR",
99 "extents", /* keywords */
100 NULL, /* requirements */