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.
13 static pixman_indexed_t rgb_palette[9];
14 static pixman_indexed_t y_palette[9];
16 /* The first eight format in the list are by far the most widely
17 * used formats, so we test those more than the others
19 #define N_MOST_LIKELY_FORMATS 8
21 /* Create random image for testing purposes */
22 static pixman_image_t *
23 create_random_image (pixman_format_code_t *allowed_formats,
27 pixman_format_code_t *used_fmt)
29 int n = 0, i, width, height, stride;
30 pixman_format_code_t fmt;
34 while (allowed_formats[n] != PIXMAN_null)
37 if (n > N_MOST_LIKELY_FORMATS && lcg_rand_n (4) != 0)
38 n = N_MOST_LIKELY_FORMATS;
39 fmt = allowed_formats[lcg_rand_n (n)];
41 width = lcg_rand_n (max_width) + 1;
42 height = lcg_rand_n (max_height) + 1;
43 stride = (width * PIXMAN_FORMAT_BPP (fmt) + 7) / 8 +
44 lcg_rand_n (max_extra_stride + 1);
45 stride = (stride + 3) & ~3;
47 /* do the allocation */
48 buf = aligned_malloc (64, stride * height);
50 /* initialize image with random data */
51 for (i = 0; i < stride * height; i++)
53 /* generation is biased to having more 0 or 255 bytes as
54 * they are more likely to be special-cased in code
56 *((uint8_t *)buf + i) = lcg_rand_n (4) ? lcg_rand_n (256) :
57 (lcg_rand_n (2) ? 0 : 255);
60 img = pixman_image_create_bits (fmt, width, height, buf, stride);
62 if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR)
64 pixman_image_set_indexed (img, &(rgb_palette[PIXMAN_FORMAT_BPP (fmt)]));
66 else if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_GRAY)
68 pixman_image_set_indexed (img, &(y_palette[PIXMAN_FORMAT_BPP (fmt)]));
71 image_endian_swap (img);
73 if (used_fmt) *used_fmt = fmt;
77 /* Free random image, and optionally update crc32 based on its data */
79 free_random_image (uint32_t initcrc,
81 pixman_format_code_t fmt)
84 int stride = pixman_image_get_stride (img);
85 uint32_t *data = pixman_image_get_data (img);
86 int height = pixman_image_get_height (img);
88 if (fmt != PIXMAN_null)
90 /* mask unused 'x' part */
91 if (PIXMAN_FORMAT_BPP (fmt) - PIXMAN_FORMAT_DEPTH (fmt) &&
92 PIXMAN_FORMAT_DEPTH (fmt) != 0)
95 uint32_t *data = pixman_image_get_data (img);
96 uint32_t mask = (1 << PIXMAN_FORMAT_DEPTH (fmt)) - 1;
98 if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_BGRA ||
99 PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_RGBA)
101 mask <<= (PIXMAN_FORMAT_BPP (fmt) - PIXMAN_FORMAT_DEPTH (fmt));
104 for (i = 0; i < 32; i++)
105 mask |= mask << (i * PIXMAN_FORMAT_BPP (fmt));
107 for (i = 0; i < stride * height / 4; i++)
111 /* swap endiannes in order to provide identical results on both big
112 * and litte endian systems
114 image_endian_swap (img);
115 crc32 = compute_crc32 (initcrc, data, stride * height);
118 pixman_image_unref (img);
124 static pixman_op_t op_list[] = {
132 PIXMAN_OP_OVER_REVERSE,
134 PIXMAN_OP_IN_REVERSE,
136 PIXMAN_OP_OUT_REVERSE,
138 PIXMAN_OP_ATOP_REVERSE,
142 PIXMAN_OP_DISJOINT_CLEAR,
143 PIXMAN_OP_DISJOINT_SRC,
144 PIXMAN_OP_DISJOINT_DST,
145 PIXMAN_OP_DISJOINT_OVER,
146 PIXMAN_OP_DISJOINT_OVER_REVERSE,
147 PIXMAN_OP_DISJOINT_IN,
148 PIXMAN_OP_DISJOINT_IN_REVERSE,
149 PIXMAN_OP_DISJOINT_OUT,
150 PIXMAN_OP_DISJOINT_OUT_REVERSE,
151 PIXMAN_OP_DISJOINT_ATOP,
152 PIXMAN_OP_DISJOINT_ATOP_REVERSE,
153 PIXMAN_OP_DISJOINT_XOR,
154 PIXMAN_OP_CONJOINT_CLEAR,
155 PIXMAN_OP_CONJOINT_SRC,
156 PIXMAN_OP_CONJOINT_DST,
157 PIXMAN_OP_CONJOINT_OVER,
158 PIXMAN_OP_CONJOINT_OVER_REVERSE,
159 PIXMAN_OP_CONJOINT_IN,
160 PIXMAN_OP_CONJOINT_IN_REVERSE,
161 PIXMAN_OP_CONJOINT_OUT,
162 PIXMAN_OP_CONJOINT_OUT_REVERSE,
163 PIXMAN_OP_CONJOINT_ATOP,
164 PIXMAN_OP_CONJOINT_ATOP_REVERSE,
165 PIXMAN_OP_CONJOINT_XOR,
171 PIXMAN_OP_COLOR_DODGE,
172 PIXMAN_OP_COLOR_BURN,
173 PIXMAN_OP_HARD_LIGHT,
174 PIXMAN_OP_DIFFERENCE,
176 #if 0 /* these use floating point math and are not always bitexact on different platforms */
177 PIXMAN_OP_SOFT_LIGHT,
179 PIXMAN_OP_HSL_SATURATION,
181 PIXMAN_OP_HSL_LUMINOSITY,
185 static pixman_format_code_t img_fmt_list[] = {
234 static pixman_format_code_t mask_fmt_list[] = {
244 * Composite operation with pseudorandom images
247 test_composite (int testnum, int verbose)
250 pixman_image_t *src_img = NULL;
251 pixman_image_t *dst_img = NULL;
252 pixman_image_t *mask_img = NULL;
253 int src_width, src_height;
254 int dst_width, dst_height;
255 int src_stride, dst_stride;
261 pixman_format_code_t src_fmt, dst_fmt, mask_fmt;
262 uint32_t *dstbuf, *srcbuf, *maskbuf;
264 int max_width, max_height, max_extra_stride;
265 FLOAT_REGS_CORRUPTION_DETECTOR_START ();
267 max_width = max_height = 24 + testnum / 10000;
268 max_extra_stride = 4 + testnum / 1000000;
276 if (max_extra_stride > 8)
277 max_extra_stride = 8;
281 op = op_list[lcg_rand_n (sizeof (op_list) / sizeof (op_list[0]))];
286 src_img = create_random_image (img_fmt_list, max_width, max_height,
287 max_extra_stride, &src_fmt);
292 src_img = create_random_image (img_fmt_list, 1, 1,
293 max_extra_stride, &src_fmt);
295 pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
298 dst_img = create_random_image (img_fmt_list, max_width, max_height,
299 max_extra_stride, &dst_fmt);
301 src_width = pixman_image_get_width (src_img);
302 src_height = pixman_image_get_height (src_img);
303 src_stride = pixman_image_get_stride (src_img);
305 dst_width = pixman_image_get_width (dst_img);
306 dst_height = pixman_image_get_height (dst_img);
307 dst_stride = pixman_image_get_stride (dst_img);
309 dstbuf = pixman_image_get_data (dst_img);
310 srcbuf = pixman_image_get_data (src_img);
312 src_x = lcg_rand_n (src_width);
313 src_y = lcg_rand_n (src_height);
314 dst_x = lcg_rand_n (dst_width);
315 dst_y = lcg_rand_n (dst_height);
318 mask_fmt = PIXMAN_null;
323 if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) &&
324 (lcg_rand_n (4) == 0))
327 mask_fmt = lcg_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8;
328 mask_img = pixman_image_create_bits (mask_fmt,
337 else if (lcg_rand_n (2))
341 mask_img = create_random_image (mask_fmt_list, max_width, max_height,
342 max_extra_stride, &mask_fmt);
347 mask_img = create_random_image (mask_fmt_list, 1, 1,
348 max_extra_stride, &mask_fmt);
349 pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL);
353 pixman_image_set_component_alpha (mask_img, 1);
355 mask_x = lcg_rand_n (pixman_image_get_width (mask_img));
356 mask_y = lcg_rand_n (pixman_image_get_height (mask_img));
360 w = lcg_rand_n (dst_width - dst_x + 1);
361 h = lcg_rand_n (dst_height - dst_y + 1);
365 printf ("op=%d, src_fmt=%08X, dst_fmt=%08X, mask_fmt=%08X\n",
366 op, src_fmt, dst_fmt, mask_fmt);
367 printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n",
368 src_width, src_height, dst_width, dst_height);
369 printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n",
370 src_x, src_y, dst_x, dst_y);
371 printf ("src_stride=%d, dst_stride=%d\n",
372 src_stride, dst_stride);
373 printf ("w=%d, h=%d\n", w, h);
376 pixman_image_composite (op, src_img, mask_img, dst_img,
377 src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);
384 for (i = 0; i < dst_height; i++)
386 for (j = 0; j < dst_stride; j++)
388 if (j == (dst_width * PIXMAN_FORMAT_BPP (dst_fmt) + 7) / 8)
391 printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j));
398 free_random_image (0, src_img, PIXMAN_null);
399 crc32 = free_random_image (0, dst_img, dst_fmt);
403 if (srcbuf == maskbuf)
404 pixman_image_unref(mask_img);
406 free_random_image (0, mask_img, PIXMAN_null);
409 FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
414 main (int argc, const char *argv[])
418 for (i = 1; i <= 8; i++)
420 initialize_palette (&(rgb_palette[i]), i, TRUE);
421 initialize_palette (&(y_palette[i]), i, FALSE);
424 return fuzzer_test_main("blitters", 2000000,
426 test_composite, argc, argv);