1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* Copyright © 2009 Benjamin Otte
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of
* Red Hat, Inc. not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. Red Hat, Inc. makes no representations about the
* suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#include "cairo-test.h"
#include <pixman.h>
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
pixman_format_code_t formats[] = {
PIXMAN_a8r8g8b8,
PIXMAN_x8r8g8b8,
PIXMAN_a8b8g8r8,
PIXMAN_x8b8g8r8,
PIXMAN_b8g8r8a8,
PIXMAN_b8g8r8x8,
PIXMAN_x2r10g10b10,
PIXMAN_a2r10g10b10,
PIXMAN_x2b10g10r10,
PIXMAN_a2b10g10r10,
PIXMAN_r8g8b8,
PIXMAN_b8g8r8,
PIXMAN_r5g6b5,
PIXMAN_b5g6r5,
PIXMAN_a1r5g5b5,
PIXMAN_x1r5g5b5,
PIXMAN_a1b5g5r5,
PIXMAN_x1b5g5r5,
PIXMAN_a4r4g4b4,
PIXMAN_x4r4g4b4,
PIXMAN_a4b4g4r4,
PIXMAN_x4b4g4r4,
PIXMAN_r3g3b2,
PIXMAN_b2g3r3,
PIXMAN_a2r2g2b2,
PIXMAN_a2b2g2r2
};
#define SIZE 20
#define SPACE 5
#define STRIDE 10
static void
paint (cairo_t *cr, pixman_format_code_t format)
{
pixman_color_t red = { 0xFFFF, 0, 0, 0xFFFF };
pixman_rectangle16_t rect = { 0, 0, SIZE, SIZE };
pixman_image_t *image;
cairo_surface_t *surface;
image = pixman_image_create_bits (format, SIZE, SIZE, NULL, 0);
if (!image)
return;
pixman_image_fill_rectangles (PIXMAN_OP_SRC, image, &red, 1, &rect);
surface = cairo_image_surface_create_with_pixman_format (
(unsigned char *) pixman_image_get_data (image),
format,
SIZE,
SIZE,
pixman_image_get_stride (image));
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (surface);
pixman_image_unref (image);
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
{
unsigned i;
/* fill with black so output of tests is always the same */
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_paint (cr);
for (i = 0; i < ARRAY_SIZE (formats); i++) {
cairo_save (cr);
cairo_translate (cr, (SIZE + SPACE) * (i % STRIDE), (SIZE + SPACE) * (i / STRIDE));
paint (cr, formats[i]);
cairo_restore (cr);
}
return CAIRO_TEST_SUCCESS;
}
CAIRO_TEST (pixman_formats,
"Tests all pixman formats are handled properly",
"pixman", /* keywords */
NULL, /* requirements */
STRIDE * (SIZE + SPACE), (ARRAY_SIZE (formats) + STRIDE - 1) / STRIDE * (SIZE + SPACE),
NULL, draw)
|