1 /* Based loosely on scaling-test */
8 #define MAX_SRC_WIDTH 48
9 #define MAX_SRC_HEIGHT 48
10 #define MAX_DST_WIDTH 48
11 #define MAX_DST_HEIGHT 48
14 static pixman_format_code_t formats[] =
16 PIXMAN_a8r8g8b8, PIXMAN_a8, PIXMAN_r5g6b5, PIXMAN_a1, PIXMAN_a4
19 static pixman_format_code_t mask_formats[] =
21 PIXMAN_a1, PIXMAN_a4, PIXMAN_a8,
24 static pixman_op_t operators[] =
26 PIXMAN_OP_OVER, PIXMAN_OP_ADD, PIXMAN_OP_SRC, PIXMAN_OP_IN
29 #define RANDOM_ELT(array) \
30 ((array)[lcg_rand_n(ARRAY_LENGTH((array)))])
33 destroy_bits (pixman_image_t *image, void *data)
41 return lcg_rand_N (n << 16);
45 * Composite operation with pseudorandom images
48 test_composite (int testnum,
52 pixman_image_t * src_img;
53 pixman_image_t * dst_img;
54 pixman_region16_t clip;
55 int dst_width, dst_height;
62 pixman_format_code_t mask_format, dst_format;
63 pixman_trapezoid_t *traps;
67 static pixman_color_t colors[] =
69 { 0xffff, 0xffff, 0xffff, 0xffff },
70 { 0x0000, 0x0000, 0x0000, 0x0000 },
71 { 0xabcd, 0xabcd, 0x0000, 0xabcd },
72 { 0x0000, 0x0000, 0x0000, 0xffff },
73 { 0x0101, 0x0101, 0x0101, 0x0101 },
74 { 0x7777, 0x6666, 0x5555, 0x9999 },
77 FLOAT_REGS_CORRUPTION_DETECTOR_START ();
81 op = RANDOM_ELT (operators);
82 mask_format = RANDOM_ELT (mask_formats);
84 /* Create source image */
86 if (lcg_rand_n (4) == 0)
88 src_img = pixman_image_create_solid_fill (
89 &(colors[lcg_rand_n (ARRAY_LENGTH (colors))]));
96 pixman_format_code_t src_format = RANDOM_ELT(formats);
97 int src_bpp = (PIXMAN_FORMAT_BPP (src_format) + 7) / 8;
98 int src_width = lcg_rand_n (MAX_SRC_WIDTH) + 1;
99 int src_height = lcg_rand_n (MAX_SRC_HEIGHT) + 1;
100 int src_stride = src_width * src_bpp + lcg_rand_n (MAX_STRIDE) * src_bpp;
103 src_x = -(src_width / 4) + lcg_rand_n (src_width * 3 / 2);
104 src_y = -(src_height / 4) + lcg_rand_n (src_height * 3 / 2);
106 src_stride = (src_stride + 3) & ~3;
108 bits = (uint32_t *)make_random_bytes (src_stride * src_height);
110 src_img = pixman_image_create_bits (
111 src_format, src_width, src_height, bits, src_stride);
113 pixman_image_set_destroy_function (src_img, destroy_bits, bits);
115 if (lcg_rand_n (8) == 0)
117 pixman_box16_t clip_boxes[2];
118 int n = lcg_rand_n (2) + 1;
120 for (i = 0; i < n; i++)
122 clip_boxes[i].x1 = lcg_rand_n (src_width);
123 clip_boxes[i].y1 = lcg_rand_n (src_height);
125 clip_boxes[i].x1 + lcg_rand_n (src_width - clip_boxes[i].x1);
127 clip_boxes[i].y1 + lcg_rand_n (src_height - clip_boxes[i].y1);
131 printf ("source clip box: [%d,%d-%d,%d]\n",
132 clip_boxes[i].x1, clip_boxes[i].y1,
133 clip_boxes[i].x2, clip_boxes[i].y2);
137 pixman_region_init_rects (&clip, clip_boxes, n);
138 pixman_image_set_clip_region (src_img, &clip);
139 pixman_image_set_source_clipping (src_img, 1);
140 pixman_region_fini (&clip);
143 image_endian_swap (src_img);
146 /* Create destination image */
148 dst_format = RANDOM_ELT(formats);
149 dst_bpp = (PIXMAN_FORMAT_BPP (dst_format) + 7) / 8;
150 dst_width = lcg_rand_n (MAX_DST_WIDTH) + 1;
151 dst_height = lcg_rand_n (MAX_DST_HEIGHT) + 1;
152 dst_stride = dst_width * dst_bpp + lcg_rand_n (MAX_STRIDE) * dst_bpp;
153 dst_stride = (dst_stride + 3) & ~3;
155 dst_bits = (uint32_t *)make_random_bytes (dst_stride * dst_height);
157 dst_x = -(dst_width / 4) + lcg_rand_n (dst_width * 3 / 2);
158 dst_y = -(dst_height / 4) + lcg_rand_n (dst_height * 3 / 2);
160 dst_img = pixman_image_create_bits (
161 dst_format, dst_width, dst_height, dst_bits, dst_stride);
163 image_endian_swap (dst_img);
170 n_traps = lcg_rand_n (25);
171 traps = fence_malloc (n_traps * sizeof (pixman_trapezoid_t));
173 for (i = 0; i < n_traps; ++i)
175 pixman_trapezoid_t *t = &(traps[i]);
177 t->top = random_fixed (MAX_DST_HEIGHT) - MAX_DST_HEIGHT / 2;
178 t->bottom = t->top + random_fixed (MAX_DST_HEIGHT);
179 t->left.p1.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2;
180 t->left.p1.y = t->top - random_fixed (50);
181 t->left.p2.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2;
182 t->left.p2.y = t->bottom + random_fixed (50);
183 t->right.p1.x = t->left.p1.x + random_fixed (MAX_DST_WIDTH);
184 t->right.p1.y = t->top - random_fixed (50);
185 t->right.p2.x = t->left.p2.x + random_fixed (MAX_DST_WIDTH);
186 t->right.p2.y = t->bottom - random_fixed (50);
190 if (lcg_rand_n (8) == 0)
192 pixman_box16_t clip_boxes[2];
193 int n = lcg_rand_n (2) + 1;
194 for (i = 0; i < n; i++)
196 clip_boxes[i].x1 = lcg_rand_n (dst_width);
197 clip_boxes[i].y1 = lcg_rand_n (dst_height);
199 clip_boxes[i].x1 + lcg_rand_n (dst_width - clip_boxes[i].x1);
201 clip_boxes[i].y1 + lcg_rand_n (dst_height - clip_boxes[i].y1);
205 printf ("destination clip box: [%d,%d-%d,%d]\n",
206 clip_boxes[i].x1, clip_boxes[i].y1,
207 clip_boxes[i].x2, clip_boxes[i].y2);
210 pixman_region_init_rects (&clip, clip_boxes, n);
211 pixman_image_set_clip_region (dst_img, &clip);
212 pixman_region_fini (&clip);
215 pixman_composite_trapezoids (op, src_img, dst_img, mask_format,
216 src_x, src_y, dst_x, dst_y, n_traps, traps);
218 if (dst_format == PIXMAN_x8r8g8b8)
220 /* ignore unused part */
221 for (i = 0; i < dst_stride * dst_height / 4; i++)
222 dst_bits[i] &= 0xFFFFFF;
225 image_endian_swap (dst_img);
231 for (i = 0; i < dst_height; i++)
233 for (j = 0; j < dst_stride; j++)
234 printf ("%02X ", *((uint8_t *)dst_bits + i * dst_stride + j));
240 crc32 = compute_crc32 (0, dst_bits, dst_stride * dst_height);
242 fence_free (dst_bits);
244 pixman_image_unref (src_img);
245 pixman_image_unref (dst_img);
248 FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
253 main (int argc, const char *argv[])
255 return fuzzer_test_main("composite traps", 40000, 0xE3112106,
256 test_composite, argc, argv);