1
/*
2
 * Copyright © 2023 Marc Jeanmougin
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
 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10
 * distribution of the software without specific, written prior
11
 * permission. Red Hat, Inc. 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
 * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16
 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
 * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Marc Jeanmougin <marc@jeanmougin.fr>
24
 */
25

            
26
#include "cairo-test.h"
27

            
28
static void
29
6
set_dither_source (cairo_t *cr, int width)
30
{
31
6
    cairo_pattern_t *gradient = cairo_pattern_create_linear (0, 0, width, 0);
32
6
    cairo_pattern_add_color_stop_rgba (gradient, 0., 25./255, 25./255, 25./255, 1.0);
33
6
    cairo_pattern_add_color_stop_rgba (gradient, 1., 45./255, 45./255, 45./255, 1.0);
34
    
35
6
    cairo_set_source (cr, gradient);
36
6
    cairo_pattern_set_dither (gradient, CAIRO_DITHER_BEST);
37
6
    cairo_pattern_destroy (gradient);
38
6
}
39

            
40
/* History:
41
 *
42
 * 2023: v3 of a patch to use pixman dithering with cairo
43
 */
44
static cairo_test_status_t
45
3
draw (cairo_t *cr, int width, int height)
46
{
47
3
    set_dither_source (cr, width);
48
3
    cairo_paint (cr);
49

            
50
3
    return CAIRO_TEST_SUCCESS;
51
}
52

            
53
static cairo_test_status_t
54
3
draw2 (cairo_t *cr, int width, int height)
55
{
56
3
    cairo_set_source_rgb (cr, 0, 0, 0);
57
3
    cairo_paint (cr);
58

            
59
3
    set_dither_source (cr, width);
60

            
61
3
    cairo_set_operator (cr, CAIRO_OPERATOR_ADD);
62
18
    for (int i = 0; i < 5; i++) {
63
15
        cairo_paint (cr);
64
    }
65

            
66
3
    return CAIRO_TEST_SUCCESS;
67
}
68

            
69
1
CAIRO_TEST (dithergradient,
70
	    "Testing the creation of a dithered gradient (in argb32)",
71
	    "gradient, dither", /* keywords */
72
	    NULL, /* requirements */
73
	    400, 100,
74
	    NULL, draw)
75
1
CAIRO_TEST (dithergradient2,
76
	    "Testing the creation of a dithered gradient (in argb32)",
77
	    "gradient, dither", /* keywords */
78
	    NULL, /* requirements */
79
	    400, 100,
80
	    NULL, draw2)