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.
12 static pixman_indexed_t rgb_palette[9];
13 static pixman_indexed_t y_palette[9];
15 /* The first eight format in the list are by far the most widely
16 * used formats, so we test those more than the others
18 #define N_MOST_LIKELY_FORMATS 8
20 /* Create random image for testing purposes */
21 static pixman_image_t *
22 create_random_image (pixman_format_code_t *allowed_formats,
26 pixman_format_code_t *used_fmt)
28 int n = 0, width, height, stride;
29 pixman_format_code_t fmt;
33 while (allowed_formats[n] != PIXMAN_null)
36 if (n > N_MOST_LIKELY_FORMATS && prng_rand_n (4) != 0)
37 n = N_MOST_LIKELY_FORMATS;
38 fmt = allowed_formats[prng_rand_n (n)];
40 width = prng_rand_n (max_width) + 1;
41 height = prng_rand_n (max_height) + 1;
42 stride = (width * PIXMAN_FORMAT_BPP (fmt) + 7) / 8 +
43 prng_rand_n (max_extra_stride + 1);
44 stride = (stride + 3) & ~3;
46 /* do the allocation */
47 buf = aligned_malloc (64, stride * height);
49 if (prng_rand_n (4) == 0)
51 /* uniform distribution */
52 prng_randmemset (buf, stride * height, 0);
56 /* significantly increased probability for 0x00 and 0xFF */
57 prng_randmemset (buf, stride * height, RANDMEMSET_MORE_00_AND_FF);
60 /* test negative stride */
61 if (prng_rand_n (4) == 0)
63 buf += (stride / 4) * (height - 1);
67 img = pixman_image_create_bits (fmt, width, height, buf, stride);
69 if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_COLOR)
71 pixman_image_set_indexed (img, &(rgb_palette[PIXMAN_FORMAT_BPP (fmt)]));
73 else if (PIXMAN_FORMAT_TYPE (fmt) == PIXMAN_TYPE_GRAY)
75 pixman_image_set_indexed (img, &(y_palette[PIXMAN_FORMAT_BPP (fmt)]));
78 if (prng_rand_n (16) == 0)
79 pixman_image_set_filter (img, PIXMAN_FILTER_BILINEAR, NULL, 0);
81 image_endian_swap (img);
83 if (used_fmt) *used_fmt = fmt;
87 /* Free random image, and optionally update crc32 based on its data */
89 free_random_image (uint32_t initcrc,
91 pixman_format_code_t fmt)
94 uint32_t *data = pixman_image_get_data (img);
96 if (fmt != PIXMAN_null)
97 crc32 = compute_crc32_for_image (initcrc, img);
99 if (img->bits.rowstride < 0)
100 data += img->bits.rowstride * (img->bits.height - 1);
102 pixman_image_unref (img);
108 static pixman_op_t op_list[] = {
116 PIXMAN_OP_OVER_REVERSE,
118 PIXMAN_OP_IN_REVERSE,
120 PIXMAN_OP_OUT_REVERSE,
122 PIXMAN_OP_ATOP_REVERSE,
126 PIXMAN_OP_DISJOINT_CLEAR,
127 PIXMAN_OP_DISJOINT_SRC,
128 PIXMAN_OP_DISJOINT_DST,
129 PIXMAN_OP_DISJOINT_OVER,
130 PIXMAN_OP_DISJOINT_OVER_REVERSE,
131 PIXMAN_OP_DISJOINT_IN,
132 PIXMAN_OP_DISJOINT_IN_REVERSE,
133 PIXMAN_OP_DISJOINT_OUT,
134 PIXMAN_OP_DISJOINT_OUT_REVERSE,
135 PIXMAN_OP_DISJOINT_ATOP,
136 PIXMAN_OP_DISJOINT_ATOP_REVERSE,
137 PIXMAN_OP_DISJOINT_XOR,
138 PIXMAN_OP_CONJOINT_CLEAR,
139 PIXMAN_OP_CONJOINT_SRC,
140 PIXMAN_OP_CONJOINT_DST,
141 PIXMAN_OP_CONJOINT_OVER,
142 PIXMAN_OP_CONJOINT_OVER_REVERSE,
143 PIXMAN_OP_CONJOINT_IN,
144 PIXMAN_OP_CONJOINT_IN_REVERSE,
145 PIXMAN_OP_CONJOINT_OUT,
146 PIXMAN_OP_CONJOINT_OUT_REVERSE,
147 PIXMAN_OP_CONJOINT_ATOP,
148 PIXMAN_OP_CONJOINT_ATOP_REVERSE,
149 PIXMAN_OP_CONJOINT_XOR,
155 PIXMAN_OP_COLOR_DODGE,
156 PIXMAN_OP_COLOR_BURN,
157 PIXMAN_OP_HARD_LIGHT,
158 PIXMAN_OP_DIFFERENCE,
160 #if 0 /* these use floating point math and are not always bitexact on different platforms */
161 PIXMAN_OP_SOFT_LIGHT,
163 PIXMAN_OP_HSL_SATURATION,
165 PIXMAN_OP_HSL_LUMINOSITY,
169 static pixman_format_code_t img_fmt_list[] = {
186 #if 0 /* These are going to use floating point in the near future */
220 static pixman_format_code_t mask_fmt_list[] = {
230 * Composite operation with pseudorandom images
233 test_composite (int testnum, int verbose)
235 pixman_image_t *src_img = NULL;
236 pixman_image_t *dst_img = NULL;
237 pixman_image_t *mask_img = NULL;
238 int src_width, src_height;
239 int dst_width, dst_height;
240 int src_stride, dst_stride;
246 pixman_format_code_t src_fmt, dst_fmt, mask_fmt;
247 uint32_t *srcbuf, *maskbuf;
249 int max_width, max_height, max_extra_stride;
250 FLOAT_REGS_CORRUPTION_DETECTOR_START ();
252 max_width = max_height = 24 + testnum / 10000;
253 max_extra_stride = 4 + testnum / 1000000;
261 if (max_extra_stride > 8)
262 max_extra_stride = 8;
264 prng_srand (testnum);
266 op = op_list[prng_rand_n (ARRAY_LENGTH (op_list))];
271 src_img = create_random_image (img_fmt_list, max_width, max_height,
272 max_extra_stride, &src_fmt);
277 src_img = create_random_image (img_fmt_list, 1, 1,
278 max_extra_stride, &src_fmt);
280 pixman_image_set_repeat (src_img, PIXMAN_REPEAT_NORMAL);
283 dst_img = create_random_image (img_fmt_list, max_width, max_height,
284 max_extra_stride, &dst_fmt);
286 src_width = pixman_image_get_width (src_img);
287 src_height = pixman_image_get_height (src_img);
288 src_stride = pixman_image_get_stride (src_img);
290 dst_width = pixman_image_get_width (dst_img);
291 dst_height = pixman_image_get_height (dst_img);
292 dst_stride = pixman_image_get_stride (dst_img);
294 srcbuf = pixman_image_get_data (src_img);
296 src_x = prng_rand_n (src_width);
297 src_y = prng_rand_n (src_height);
298 dst_x = prng_rand_n (dst_width);
299 dst_y = prng_rand_n (dst_height);
302 mask_fmt = PIXMAN_null;
307 if ((src_fmt == PIXMAN_x8r8g8b8 || src_fmt == PIXMAN_x8b8g8r8) &&
308 (prng_rand_n (4) == 0))
311 mask_fmt = prng_rand_n (2) ? PIXMAN_a8r8g8b8 : PIXMAN_a8b8g8r8;
312 mask_img = pixman_image_create_bits (mask_fmt,
321 else if (prng_rand_n (2))
325 mask_img = create_random_image (mask_fmt_list, max_width, max_height,
326 max_extra_stride, &mask_fmt);
331 mask_img = create_random_image (mask_fmt_list, 1, 1,
332 max_extra_stride, &mask_fmt);
333 pixman_image_set_repeat (mask_img, PIXMAN_REPEAT_NORMAL);
337 pixman_image_set_component_alpha (mask_img, 1);
339 mask_x = prng_rand_n (pixman_image_get_width (mask_img));
340 mask_y = prng_rand_n (pixman_image_get_height (mask_img));
344 w = prng_rand_n (dst_width - dst_x + 1);
345 h = prng_rand_n (dst_height - dst_y + 1);
349 printf ("op=%s\n", operator_name (op));
350 printf ("src_fmt=%s, dst_fmt=%s, mask_fmt=%s\n",
351 format_name (src_fmt), format_name (dst_fmt),
352 format_name (mask_fmt));
353 printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n",
354 src_width, src_height, dst_width, dst_height);
355 printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n",
356 src_x, src_y, dst_x, dst_y);
357 printf ("src_stride=%d, dst_stride=%d\n",
358 src_stride, dst_stride);
359 printf ("w=%d, h=%d\n", w, h);
362 pixman_image_composite (op, src_img, mask_img, dst_img,
363 src_x, src_y, mask_x, mask_y, dst_x, dst_y, w, h);
366 print_image (dst_img);
368 free_random_image (0, src_img, PIXMAN_null);
369 crc32 = free_random_image (0, dst_img, dst_fmt);
373 if (srcbuf == maskbuf)
374 pixman_image_unref(mask_img);
376 free_random_image (0, mask_img, PIXMAN_null);
379 FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
384 main (int argc, const char *argv[])
390 for (i = 1; i <= 8; i++)
392 initialize_palette (&(rgb_palette[i]), i, TRUE);
393 initialize_palette (&(y_palette[i]), i, FALSE);
396 return fuzzer_test_main("blitters", 2000000,
398 test_composite, argc, argv);