dfd3554d7f63b275badd1873b64eeae8a9cb7f1e
[platform/core/graphics/cairo.git] / test / large-source-roi.c
1 /*
2  * Copyright © 2009 Joonas Pihlaja
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22
23 #include "cairo-test.h"
24
25 /* This test attempts to trigger failures in those clone_similar
26  * backend methods that have size restrictions. */
27
28 static cairo_surface_t *
29 create_large_source (int width, int height)
30 {
31     cairo_surface_t *surface;
32     cairo_t *cr;
33
34     surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height);
35     cr = cairo_create (surface);
36     cairo_surface_destroy (surface);
37
38     cairo_set_source_rgb (cr, 1,0,0); /* red */
39     cairo_paint (cr);
40     surface = cairo_surface_reference (cairo_get_target (cr));
41     cairo_destroy (cr);
42
43     return surface;
44 }
45
46 static cairo_test_status_t
47 draw (cairo_t *cr, int width, int height)
48 {
49     cairo_surface_t *source;
50     /* Since 1cc750ed92a936d84b47cac696aaffd226e1c02e pixman will not
51      * paint on the source surface if source_width > 30582. */
52     double source_width = 30000.0;
53
54     cairo_set_source_rgb (cr, 1,1,1);
55     cairo_paint (cr);
56
57     /* Create an excessively wide source image, all red. */
58     source = create_large_source (source_width, height);
59
60     /* Set a transform so that the source is scaled down to fit in the
61      * destination horizontally and then paint the entire source to
62      * the context. */
63     cairo_scale (cr, width/source_width, 1.0);
64     cairo_set_source_surface (cr, source, 0, 0);
65     cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
66     cairo_paint (cr);
67
68     cairo_surface_destroy (source);
69
70     return CAIRO_TEST_SUCCESS;
71 }
72
73 CAIRO_TEST (large_source_roi,
74             "Uses a all of a large source image.",
75             "stress, source", /* keywords */
76             NULL, /* requirements */
77             7, 7,
78             NULL, draw)