1
/*
2
 * Copyright 2010 Soeren Sandmann Pedersen
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
 * Author: Soeren Sandmann <sandmann@daimi.au.dk>
25
 */
26

            
27
/* Exercises a case of seam appearing between two polygons in the image
28
 * backend but not in xlib [using pixman].
29
 *
30
 * The test case draws two abutting quads both individually on the
31
 * leftm combining them with operator ADD, and in one go on the right.
32
 * Both methods should show no signs of seaming at the common edge
33
 * between the two quads, but the individually drawn ones have a
34
 * slight seam.
35
 *
36
 * The cause of the seam is that there are slight differences in the
37
 * output of the analytical coverage rasterization and the
38
 * supersampling rasterization methods, both employed by
39
 * cairo-tor-scan-converter.  When drawn individually, the scan
40
 * converter gets a partial view of the geometry at a time, so it ends
41
 * up making different decisions about which scanlines it rasterizes
42
 * with which method, compared to when the geometry is draw all at
43
 * once.  Though both methods produce seamless results individually
44
 * (where applicable), they don't produce bit-exact identical results,
45
 * and hence we get seaming where they meet.
46
 */
47

            
48
#include "cairo-test.h"
49

            
50
static void
51
12
draw_quad (cairo_t *cr,
52
	   double x1, double y1, double x2, double y2,
53
	   double x3, double y3, double x4, double y4)
54
{
55
12
    cairo_move_to (cr, x1, y1);
56
12
    cairo_line_to (cr, x2, y2);
57
12
    cairo_line_to (cr, x3, y3);
58
12
    cairo_line_to (cr, x4, y4);
59
12
    cairo_close_path (cr);
60
12
}
61

            
62
static cairo_test_status_t
63
3
draw (cairo_t *cr, int width, int height)
64
{
65
3
    cairo_set_source_rgb (cr, 0, 0, 0);
66
3
    cairo_paint (cr);
67

            
68
3
    cairo_scale (cr, 20, 20);
69
3
    cairo_translate (cr, 5, 1);
70

            
71
    /* On the left side, we have two quads drawn one at a time and
72
     * combined with OPERATOR_ADD.  This should be seamless, but
73
     * isn't. */
74
3
    cairo_push_group (cr);
75
3
    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
76

            
77
3
    cairo_set_source_rgb (cr, 0, 0.6, 0);
78
3
    draw_quad (cr,
79
	       1.50, 1.50,
80
	       2.64, 1.63,
81
	       1.75, 2.75,
82
	       0.55, 2.63);
83
3
    cairo_fill (cr);
84
3
    draw_quad (cr,
85
	       0.55, 2.63,
86
	       1.75, 2.75,
87
	       0.98, 4.11,
88
	       -0.35, 4.05);
89
3
    cairo_fill (cr);
90

            
91
3
    cairo_pop_group_to_source (cr);
92
3
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
93
3
    cairo_paint (cr);
94

            
95
    /* On the right side, we have the same two quads drawn both at the
96
     * same time.  This is seamless. */
97
3
    cairo_translate (cr, 10, 0);
98

            
99
3
    cairo_set_source_rgb (cr, 0, 0.6, 0);
100
3
    draw_quad (cr,
101
	       1.50, 1.50,
102
	       2.64, 1.63,
103
	       1.75, 2.75,
104
	       0.55, 2.63);
105
3
    draw_quad (cr,
106
	       0.55, 2.63,
107
	       1.75, 2.75,
108
	       0.98, 4.11,
109
	       -0.35, 4.05);
110
3
    cairo_fill (cr);
111

            
112
3
    return CAIRO_TEST_SUCCESS;
113
}
114

            
115
1
CAIRO_TEST (bug_seams,
116
	    "Check the fidelity of the rasterisation.",
117
	    "raster", /* keywords */
118
	    "target=raster", /* requirements */
119
	    500, 300,
120
	    NULL, draw)