2 * Test program, which stresses the use of different color formats and
3 * compositing operations.
5 * Script 'fuzzer-find-diff.pl' can be used to narrow down the problem in
6 * the case of test failure.
14 static pixman_indexed_t rgb_palette[9];
15 static pixman_indexed_t y_palette[9];
17 /* Create random image for testing purposes */
18 static pixman_image_t *
19 create_random_image (pixman_format_code_t *allowed_formats,
23 pixman_format_code_t *used_fmt)
25 int n = 0, i, width, height, stride;
26 pixman_format_code_t fmt;
30 while (allowed_formats[n] != PIXMAN_null)
32 fmt = allowed_formats[lcg_rand_n (n)];
34 width = lcg_rand_n (max_width) + 1;
35 height = lcg_rand_n (max_height) + 1;
36 stride = (width * PIXMAN_FORMAT_BPP (fmt) + 7) / 8 +
37 lcg_rand_n (max_extra_stride + 1);
38 stride = (stride + 3) & ~3;
40 /* do the allocation */
41 buf = aligned_malloc (64, stride * height);
43 /* initialize image with random data */
44 for (i = 0; i < stride * height; i++)
46 /* generation is biased to having more 0 or 255 bytes as
47 * they are more likely to be special-cased in code
49 *((uint8_t *)buf + i) = lcg_rand_n (4) ? lcg_rand_n (256) :
50 (lcg_rand_n (2) ? 0 : 255);
53 img = pixman_image_create_bits (fmt, width, height, buf, stride);
55 if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR)
57 pixman_image_set_indexed (img, &(rgb_palette[PIXMAN_FORMAT_BPP (fmt)]));
59 else if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_GRAY)
61 pixman_image_set_indexed (img, &(y_palette[PIXMAN_FORMAT_BPP (fmt)]));
64 image_endian_swap (img);
66 if (used_fmt) *used_fmt = fmt;
70 /* Free random image, and optionally update crc32 based on its data */
72 free_random_image (uint32_t initcrc,
74 pixman_format_code_t fmt)
77 int stride = pixman_image_get_stride (img);
78 uint32_t *data = pixman_image_get_data (img);
79 int height = pixman_image_get_height (img);
81 if (fmt != PIXMAN_null)
83 /* mask unused 'x' part */
84 if (PIXMAN_FORMAT_BPP (fmt) - PIXMAN_FORMAT_DEPTH (fmt) &&
85 PIXMAN_FORMAT_DEPTH (fmt) != 0)
88 uint32_t *data = pixman_image_get_data (img);
89 uint32_t mask = (1 << PIXMAN_FORMAT_DEPTH (fmt)) - 1;
91 if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_BGRA ||
92 PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_RGBA)
94 mask <<= (PIXMAN_FORMAT_BPP (fmt) - PIXMAN_FORMAT_DEPTH (fmt));
97 for (i = 0; i < 32; i++)
98 mask |= mask << (i * PIXMAN_FORMAT_BPP (fmt));
100 for (i = 0; i < stride * height / 4; i++)
104 /* swap endiannes in order to provide identical results on both big
105 * and litte endian systems
107 image_endian_swap (img);
108 crc32 = compute_crc32 (initcrc, data, stride * height);
111 pixman_image_unref (img);
117 static pixman_op_t op_list[] = {
125 PIXMAN_OP_OVER_REVERSE,
127 PIXMAN_OP_IN_REVERSE,
129 PIXMAN_OP_OUT_REVERSE,
131 PIXMAN_OP_ATOP_REVERSE,
135 PIXMAN_OP_DISJOINT_CLEAR,
136 PIXMAN_OP_DISJOINT_SRC,
137 PIXMAN_OP_DISJOINT_DST,
138 PIXMAN_OP_DISJOINT_OVER,
139 PIXMAN_OP_DISJOINT_OVER_REVERSE,
140 PIXMAN_OP_DISJOINT_IN,
141 PIXMAN_OP_DISJOINT_IN_REVERSE,
142 PIXMAN_OP_DISJOINT_OUT,
143 PIXMAN_OP_DISJOINT_OUT_REVERSE,
144 PIXMAN_OP_DISJOINT_ATOP,
145 PIXMAN_OP_DISJOINT_ATOP_REVERSE,
146 PIXMAN_OP_DISJOINT_XOR,
147 PIXMAN_OP_CONJOINT_CLEAR,
148 PIXMAN_OP_CONJOINT_SRC,
149 PIXMAN_OP_CONJOINT_DST,
150 PIXMAN_OP_CONJOINT_OVER,
151 PIXMAN_OP_CONJOINT_OVER_REVERSE,
152 PIXMAN_OP_CONJOINT_IN,
153 PIXMAN_OP_CONJOINT_IN_REVERSE,
154 PIXMAN_OP_CONJOINT_OUT,
155 PIXMAN_OP_CONJOINT_OUT_REVERSE,
156 PIXMAN_OP_CONJOINT_ATOP,
157 PIXMAN_OP_CONJOINT_ATOP_REVERSE,
158 PIXMAN_OP_CONJOINT_XOR,
164 PIXMAN_OP_COLOR_DODGE,
165 PIXMAN_OP_COLOR_BURN,
166 PIXMAN_OP_HARD_LIGHT,
167 PIXMAN_OP_DIFFERENCE,
169 #if 0 /* these use floating point math and are not always bitexact on different platforms */
170 PIXMAN_OP_SOFT_LIGHT,
172 PIXMAN_OP_HSL_SATURATION,
174 PIXMAN_OP_HSL_LUMINOSITY,
178 static pixman_format_code_t img_fmt_list[] = {
229 static pixman_format_code_t mask_fmt_list[] = {
239 * Composite operation with pseudorandom images
242 test_composite (int testnum, int verbose)
245 pixman_image_t *src_img = NULL;
246 pixman_image_t *dst_img = NULL;
247 pixman_image_t *mask_img = NULL;
248 int src_width, src_height;
249 int dst_width, dst_height;
250 int src_stride, dst_stride;
256 pixman_format_code_t src_fmt, dst_fmt, mask_fmt;
257 uint32_t *dstbuf, *srcbuf, *maskbuf;
259 int max_width, max_height, max_extra_stride;
260 FLOAT_REGS_CORRUPTION_DETECTOR_START ();
262 max_width = max_height = 24 + testnum / 10000;
263 max_extra_stride = 4 + testnum / 1000000;
271 if (max_extra_stride > 8)
272 max_extra_stride = 8;
276 op = op_list[lcg_rand_n (sizeof (op_list) / sizeof (op_list[0]))];
281 src_img = create_random_image (img_fmt_list, max_width, max_height,
282 max_extra_stride, &src_fmt);
287 src_img = create_random_image (img_fmt_list, 1, 1,
288 max_extra_stride, &src_fmt);
290 pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
293 dst_img = create_random_image (img_fmt_list, max_width, max_height,
294 max_extra_stride, &dst_fmt);
296 src_width = pixman_image_get_width (src_img);
297 src_height = pixman_image_get_height (src_img);
298 src_stride = pixman_image_get_stride (src_img);
300 dst_width = pixman_image_get_width (dst_img);
301 dst_height = pixman_image_get_height (dst_img);
302 dst_stride = pixman_image_get_stride (dst_img);
304 dstbuf = pixman_image_get_data (dst_img);
305 srcbuf = pixman_image_get_data (src_img);
307 src_x = lcg_rand_n (src_width);
308 src_y = lcg_rand_n (src_height);
309 dst_x = lcg_rand_n (dst_width);
310 dst_y = lcg_rand_n (dst_height);
313 mask_fmt = PIXMAN_null;
318 if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) &&
319 (lcg_rand_n (4) == 0))
322 mask_fmt = lcg_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8;
323 mask_img = pixman_image_create_bits (mask_fmt,
332 else if (lcg_rand_n (2))
336 mask_img = create_random_image (mask_fmt_list, max_width, max_height,
337 max_extra_stride, &mask_fmt);
342 mask_img = create_random_image (mask_fmt_list, 1, 1,
343 max_extra_stride, &mask_fmt);
344 pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL);
348 pixman_image_set_component_alpha (mask_img, 1);
350 mask_x = lcg_rand_n (pixman_image_get_width (mask_img));
351 mask_y = lcg_rand_n (pixman_image_get_height (mask_img));
355 w = lcg_rand_n (dst_width - dst_x + 1);
356 h = lcg_rand_n (dst_height - dst_y + 1);
360 printf ("op=%d, src_fmt=%08X, dst_fmt=%08X, mask_fmt=%08X\n",
361 op, src_fmt, dst_fmt, mask_fmt);
362 printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n",
363 src_width, src_height, dst_width, dst_height);
364 printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n",
365 src_x, src_y, dst_x, dst_y);
366 printf ("src_stride=%d, dst_stride=%d\n",
367 src_stride, dst_stride);
368 printf ("w=%d, h=%d\n", w, h);
371 pixman_image_composite (op, src_img, mask_img, dst_img,
372 src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);
379 for (i = 0; i < dst_height; i++)
381 for (j = 0; j < dst_stride; j++)
383 if (j == (dst_width * PIXMAN_FORMAT_BPP (dst_fmt) + 7) / 8)
386 printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j));
393 free_random_image (0, src_img, PIXMAN_null);
394 crc32 = free_random_image (0, dst_img, dst_fmt);
398 if (srcbuf == maskbuf)
399 pixman_image_unref(mask_img);
401 free_random_image (0, mask_img, PIXMAN_null);
404 FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
409 main (int argc, const char *argv[])
413 for (i = 1; i <= 8; i++)
415 initialize_palette (&(rgb_palette[i]), i, TRUE);
416 initialize_palette (&(y_palette[i]), i, FALSE);
419 return fuzzer_test_main("blitters", 2000000,
421 test_composite, argc, argv);