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 /* The first eight format in the list are by far the most widely
18 * used formats, so we test those more than the others
20 #define N_MOST_LIKELY_FORMATS 8
22 /* Create random image for testing purposes */
23 static pixman_image_t *
24 create_random_image (pixman_format_code_t *allowed_formats,
28 pixman_format_code_t *used_fmt)
30 int n = 0, i, width, height, stride;
31 pixman_format_code_t fmt;
35 while (allowed_formats[n] != PIXMAN_null)
38 if (n > N_MOST_LIKELY_FORMATS && lcg_rand_n (4) != 0)
39 n = N_MOST_LIKELY_FORMATS;
40 fmt = allowed_formats[lcg_rand_n (n)];
42 width = lcg_rand_n (max_width) + 1;
43 height = lcg_rand_n (max_height) + 1;
44 stride = (width * PIXMAN_FORMAT_BPP (fmt) + 7) / 8 +
45 lcg_rand_n (max_extra_stride + 1);
46 stride = (stride + 3) & ~3;
48 /* do the allocation */
49 buf = aligned_malloc (64, stride * height);
51 /* initialize image with random data */
52 for (i = 0; i < stride * height; i++)
54 /* generation is biased to having more 0 or 255 bytes as
55 * they are more likely to be special-cased in code
57 *((uint8_t *)buf + i) = lcg_rand_n (4) ? lcg_rand_n (256) :
58 (lcg_rand_n (2) ? 0 : 255);
61 img = pixman_image_create_bits (fmt, width, height, buf, stride);
63 if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR)
65 pixman_image_set_indexed (img, &(rgb_palette[PIXMAN_FORMAT_BPP (fmt)]));
67 else if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_GRAY)
69 pixman_image_set_indexed (img, &(y_palette[PIXMAN_FORMAT_BPP (fmt)]));
72 image_endian_swap (img);
74 if (used_fmt) *used_fmt = fmt;
78 /* Free random image, and optionally update crc32 based on its data */
80 free_random_image (uint32_t initcrc,
82 pixman_format_code_t fmt)
85 int stride = pixman_image_get_stride (img);
86 uint32_t *data = pixman_image_get_data (img);
87 int height = pixman_image_get_height (img);
89 if (fmt != PIXMAN_null)
91 /* mask unused 'x' part */
92 if (PIXMAN_FORMAT_BPP (fmt) - PIXMAN_FORMAT_DEPTH (fmt) &&
93 PIXMAN_FORMAT_DEPTH (fmt) != 0)
96 uint32_t *data = pixman_image_get_data (img);
97 uint32_t mask = (1 << PIXMAN_FORMAT_DEPTH (fmt)) - 1;
99 if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_BGRA ||
100 PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_RGBA)
102 mask <<= (PIXMAN_FORMAT_BPP (fmt) - PIXMAN_FORMAT_DEPTH (fmt));
105 for (i = 0; i < 32; i++)
106 mask |= mask << (i * PIXMAN_FORMAT_BPP (fmt));
108 for (i = 0; i < stride * height / 4; i++)
112 /* swap endiannes in order to provide identical results on both big
113 * and litte endian systems
115 image_endian_swap (img);
116 crc32 = compute_crc32 (initcrc, data, stride * height);
119 pixman_image_unref (img);
125 static pixman_op_t op_list[] = {
133 PIXMAN_OP_OVER_REVERSE,
135 PIXMAN_OP_IN_REVERSE,
137 PIXMAN_OP_OUT_REVERSE,
139 PIXMAN_OP_ATOP_REVERSE,
143 PIXMAN_OP_DISJOINT_CLEAR,
144 PIXMAN_OP_DISJOINT_SRC,
145 PIXMAN_OP_DISJOINT_DST,
146 PIXMAN_OP_DISJOINT_OVER,
147 PIXMAN_OP_DISJOINT_OVER_REVERSE,
148 PIXMAN_OP_DISJOINT_IN,
149 PIXMAN_OP_DISJOINT_IN_REVERSE,
150 PIXMAN_OP_DISJOINT_OUT,
151 PIXMAN_OP_DISJOINT_OUT_REVERSE,
152 PIXMAN_OP_DISJOINT_ATOP,
153 PIXMAN_OP_DISJOINT_ATOP_REVERSE,
154 PIXMAN_OP_DISJOINT_XOR,
155 PIXMAN_OP_CONJOINT_CLEAR,
156 PIXMAN_OP_CONJOINT_SRC,
157 PIXMAN_OP_CONJOINT_DST,
158 PIXMAN_OP_CONJOINT_OVER,
159 PIXMAN_OP_CONJOINT_OVER_REVERSE,
160 PIXMAN_OP_CONJOINT_IN,
161 PIXMAN_OP_CONJOINT_IN_REVERSE,
162 PIXMAN_OP_CONJOINT_OUT,
163 PIXMAN_OP_CONJOINT_OUT_REVERSE,
164 PIXMAN_OP_CONJOINT_ATOP,
165 PIXMAN_OP_CONJOINT_ATOP_REVERSE,
166 PIXMAN_OP_CONJOINT_XOR,
172 PIXMAN_OP_COLOR_DODGE,
173 PIXMAN_OP_COLOR_BURN,
174 PIXMAN_OP_HARD_LIGHT,
175 PIXMAN_OP_DIFFERENCE,
177 #if 0 /* these use floating point math and are not always bitexact on different platforms */
178 PIXMAN_OP_SOFT_LIGHT,
180 PIXMAN_OP_HSL_SATURATION,
182 PIXMAN_OP_HSL_LUMINOSITY,
186 static pixman_format_code_t img_fmt_list[] = {
235 static pixman_format_code_t mask_fmt_list[] = {
245 * Composite operation with pseudorandom images
248 test_composite (int testnum, int verbose)
251 pixman_image_t *src_img = NULL;
252 pixman_image_t *dst_img = NULL;
253 pixman_image_t *mask_img = NULL;
254 int src_width, src_height;
255 int dst_width, dst_height;
256 int src_stride, dst_stride;
262 pixman_format_code_t src_fmt, dst_fmt, mask_fmt;
263 uint32_t *dstbuf, *srcbuf, *maskbuf;
265 int max_width, max_height, max_extra_stride;
266 FLOAT_REGS_CORRUPTION_DETECTOR_START ();
268 max_width = max_height = 24 + testnum / 10000;
269 max_extra_stride = 4 + testnum / 1000000;
277 if (max_extra_stride > 8)
278 max_extra_stride = 8;
282 op = op_list[lcg_rand_n (sizeof (op_list) / sizeof (op_list[0]))];
287 src_img = create_random_image (img_fmt_list, max_width, max_height,
288 max_extra_stride, &src_fmt);
293 src_img = create_random_image (img_fmt_list, 1, 1,
294 max_extra_stride, &src_fmt);
296 pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
299 dst_img = create_random_image (img_fmt_list, max_width, max_height,
300 max_extra_stride, &dst_fmt);
302 src_width = pixman_image_get_width (src_img);
303 src_height = pixman_image_get_height (src_img);
304 src_stride = pixman_image_get_stride (src_img);
306 dst_width = pixman_image_get_width (dst_img);
307 dst_height = pixman_image_get_height (dst_img);
308 dst_stride = pixman_image_get_stride (dst_img);
310 dstbuf = pixman_image_get_data (dst_img);
311 srcbuf = pixman_image_get_data (src_img);
313 src_x = lcg_rand_n (src_width);
314 src_y = lcg_rand_n (src_height);
315 dst_x = lcg_rand_n (dst_width);
316 dst_y = lcg_rand_n (dst_height);
319 mask_fmt = PIXMAN_null;
324 if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) &&
325 (lcg_rand_n (4) == 0))
328 mask_fmt = lcg_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8;
329 mask_img = pixman_image_create_bits (mask_fmt,
338 else if (lcg_rand_n (2))
342 mask_img = create_random_image (mask_fmt_list, max_width, max_height,
343 max_extra_stride, &mask_fmt);
348 mask_img = create_random_image (mask_fmt_list, 1, 1,
349 max_extra_stride, &mask_fmt);
350 pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL);
354 pixman_image_set_component_alpha (mask_img, 1);
356 mask_x = lcg_rand_n (pixman_image_get_width (mask_img));
357 mask_y = lcg_rand_n (pixman_image_get_height (mask_img));
361 w = lcg_rand_n (dst_width - dst_x + 1);
362 h = lcg_rand_n (dst_height - dst_y + 1);
366 printf ("op=%d, src_fmt=%08X, dst_fmt=%08X, mask_fmt=%08X\n",
367 op, src_fmt, dst_fmt, mask_fmt);
368 printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n",
369 src_width, src_height, dst_width, dst_height);
370 printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n",
371 src_x, src_y, dst_x, dst_y);
372 printf ("src_stride=%d, dst_stride=%d\n",
373 src_stride, dst_stride);
374 printf ("w=%d, h=%d\n", w, h);
377 pixman_image_composite (op, src_img, mask_img, dst_img,
378 src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);
385 for (i = 0; i < dst_height; i++)
387 for (j = 0; j < dst_stride; j++)
389 if (j == (dst_width * PIXMAN_FORMAT_BPP (dst_fmt) + 7) / 8)
392 printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j));
399 free_random_image (0, src_img, PIXMAN_null);
400 crc32 = free_random_image (0, dst_img, dst_fmt);
404 if (srcbuf == maskbuf)
405 pixman_image_unref(mask_img);
407 free_random_image (0, mask_img, PIXMAN_null);
410 FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
415 main (int argc, const char *argv[])
419 for (i = 1; i <= 8; i++)
421 initialize_palette (&(rgb_palette[i]), i, TRUE);
422 initialize_palette (&(y_palette[i]), i, FALSE);
425 return fuzzer_test_main("blitters", 2000000,
427 test_composite, argc, argv);