1
/*
2
 * Copyright © 2006 Mozilla Corporation
3
 *
4
 * Permission to use, copy, modify, distribute, and sell this software
5
 * and its documentation for any purpose is hereby granted without
6
 * fee, provided that the above copyright notice appear in all copies
7
 * and that both that copyright notice and this permission notice
8
 * appear in supporting documentation, and that the name of
9
 * Mozilla Corporation not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Mozilla Corporation makes no representations about the
12
 * suitability of this software for any purpose.  It is provided "as
13
 * is" without express or implied warranty.
14
 *
15
 * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL,
18
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19
 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
 *
23
 * Author: Vladimir Vukicevic <vladimir@pobox.com>
24
 */
25

            
26
#include "cairo-test.h"
27

            
28
#define SRC_WIDTH 2048
29
#define SRC_HEIGHT 32
30

            
31
static cairo_surface_t *
32
3
create_source_surface (int w, int h)
33
{
34
    cairo_surface_t *surface;
35
    cairo_t *cr;
36

            
37
3
    surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SRC_WIDTH, SRC_HEIGHT);
38
3
    cr = cairo_create (surface);
39
3
    cairo_surface_destroy (surface);
40

            
41
3
    cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
42
3
    cairo_rectangle (cr, 0, 0, w/2, h/2);
43
3
    cairo_fill (cr);
44

            
45
3
    cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
46
3
    cairo_rectangle (cr, w/2, 0, w/2, h/2);
47
3
    cairo_fill (cr);
48

            
49
3
    cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
50
3
    cairo_rectangle (cr, 0, h/2, w/2, h/2);
51
3
    cairo_fill (cr);
52

            
53
3
    cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);
54
3
    cairo_rectangle (cr, w/2, h/2, w/2, h/2);
55
3
    cairo_fill (cr);
56

            
57
3
    surface = cairo_surface_reference (cairo_get_target (cr));
58
3
    cairo_destroy (cr);
59

            
60
3
    return surface;
61
}
62

            
63
static void
64
6
draw_n (cairo_t *cr, cairo_pattern_t *pat, double dest_size, int n)
65
{
66
  cairo_matrix_t mat;
67

            
68
6
  cairo_matrix_init_scale (&mat, SRC_WIDTH / dest_size, SRC_HEIGHT / dest_size);
69
6
  cairo_matrix_translate (&mat, n * -dest_size, 0.0);
70
6
  cairo_pattern_set_matrix (pat, &mat);
71

            
72
6
  cairo_set_source (cr, pat);
73
6
  cairo_new_path (cr);
74
6
  cairo_rectangle (cr, n * dest_size, 0.0, dest_size, dest_size);
75
6
  cairo_fill (cr);
76
6
}
77

            
78
static cairo_test_status_t
79
3
draw (cairo_t *cr, int width, int height)
80
{
81
    cairo_surface_t *surface;
82
    cairo_pattern_t *pat;
83

            
84
3
    cairo_set_source_rgb (cr, 0, 0, 0);
85
3
    cairo_paint (cr);
86

            
87
3
    surface = create_source_surface (SRC_WIDTH, SRC_HEIGHT);
88

            
89
3
    pat = cairo_pattern_create_for_surface (surface);
90
3
    cairo_surface_destroy (surface);
91

            
92
    /* We want to draw at a position such that n * SRC_WIDTH * (SRC_WIDTH/16.0) > 32768.
93
     * x = n * 16.
94
     *
95
     * To show the bug, we want to draw on either side of the boundary;
96
     * in our case here, n = 16 results in 32768, and n = 17 results in > 32768.
97
     *
98
     * Drawing at 16 and 17 is sufficient to show the problem.
99
     */
100

            
101
#if 1
102
    /* n = 16 */
103
3
    draw_n (cr, pat, 16.0, 16);
104

            
105
    /* n = 17 */
106
3
    draw_n (cr, pat, 16.0, 17);
107
#else
108
    {
109
	int n;
110
	for (n = 0; n < 32; n++)
111
	    draw_n (cr, pat, 16.0, n);
112
    }
113
#endif
114

            
115
3
    cairo_pattern_destroy (pat);
116

            
117
3
    return CAIRO_TEST_SUCCESS;
118
}
119

            
120
1
CAIRO_TEST (surface_pattern_big_scale_down,
121
	    "Test scaled-down transformed not-repeated surface patterns with large images and offsets",
122
	    "transform", /* keywords */
123
	    NULL, /* requirements */
124
	    512, 16,
125
	    NULL, draw)