1 /* Based loosely on scaling-test */
7 #define MAX_SRC_WIDTH 48
8 #define MAX_SRC_HEIGHT 48
9 #define MAX_DST_WIDTH 48
10 #define MAX_DST_HEIGHT 48
13 static pixman_format_code_t formats[] =
15 PIXMAN_a8r8g8b8, PIXMAN_a8, PIXMAN_r5g6b5, PIXMAN_a1, PIXMAN_a4
18 static pixman_format_code_t mask_formats[] =
20 PIXMAN_a1, PIXMAN_a4, PIXMAN_a8,
23 static pixman_op_t operators[] =
25 PIXMAN_OP_OVER, PIXMAN_OP_ADD, PIXMAN_OP_SRC, PIXMAN_OP_IN
28 #define RANDOM_ELT(array) \
29 ((array)[lcg_rand_n(ARRAY_LENGTH((array)))])
32 destroy_bits (pixman_image_t *image, void *data)
40 return lcg_rand_N (n << 16);
44 * Composite operation with pseudorandom images
47 test_composite (int testnum,
51 pixman_image_t * src_img;
52 pixman_image_t * dst_img;
53 pixman_region16_t clip;
54 int dst_width, dst_height;
61 pixman_format_code_t mask_format, dst_format;
62 pixman_trapezoid_t *traps;
66 static pixman_color_t colors[] =
68 { 0xffff, 0xffff, 0xffff, 0xffff },
69 { 0x0000, 0x0000, 0x0000, 0x0000 },
70 { 0xabcd, 0xabcd, 0x0000, 0xabcd },
71 { 0x0000, 0x0000, 0x0000, 0xffff },
72 { 0x0101, 0x0101, 0x0101, 0x0101 },
73 { 0x7777, 0x6666, 0x5555, 0x9999 },
76 FLOAT_REGS_CORRUPTION_DETECTOR_START ();
80 op = RANDOM_ELT (operators);
81 mask_format = RANDOM_ELT (mask_formats);
83 /* Create source image */
85 if (lcg_rand_n (4) == 0)
87 src_img = pixman_image_create_solid_fill (
88 &(colors[lcg_rand_n (ARRAY_LENGTH (colors))]));
95 pixman_format_code_t src_format = RANDOM_ELT(formats);
96 int src_bpp = (PIXMAN_FORMAT_BPP (src_format) + 7) / 8;
97 int src_width = lcg_rand_n (MAX_SRC_WIDTH) + 1;
98 int src_height = lcg_rand_n (MAX_SRC_HEIGHT) + 1;
99 int src_stride = src_width * src_bpp + lcg_rand_n (MAX_STRIDE) * src_bpp;
102 src_x = -(src_width / 4) + lcg_rand_n (src_width * 3 / 2);
103 src_y = -(src_height / 4) + lcg_rand_n (src_height * 3 / 2);
105 src_stride = (src_stride + 3) & ~3;
107 bits = (uint32_t *)make_random_bytes (src_stride * src_height);
109 src_img = pixman_image_create_bits (
110 src_format, src_width, src_height, bits, src_stride);
112 pixman_image_set_destroy_function (src_img, destroy_bits, bits);
114 if (lcg_rand_n (8) == 0)
116 pixman_box16_t clip_boxes[2];
117 int n = lcg_rand_n (2) + 1;
119 for (i = 0; i < n; i++)
121 clip_boxes[i].x1 = lcg_rand_n (src_width);
122 clip_boxes[i].y1 = lcg_rand_n (src_height);
124 clip_boxes[i].x1 + lcg_rand_n (src_width - clip_boxes[i].x1);
126 clip_boxes[i].y1 + lcg_rand_n (src_height - clip_boxes[i].y1);
130 printf ("source clip box: [%d,%d-%d,%d]\n",
131 clip_boxes[i].x1, clip_boxes[i].y1,
132 clip_boxes[i].x2, clip_boxes[i].y2);
136 pixman_region_init_rects (&clip, clip_boxes, n);
137 pixman_image_set_clip_region (src_img, &clip);
138 pixman_image_set_source_clipping (src_img, 1);
139 pixman_region_fini (&clip);
142 image_endian_swap (src_img);
145 /* Create destination image */
147 dst_format = RANDOM_ELT(formats);
148 dst_bpp = (PIXMAN_FORMAT_BPP (dst_format) + 7) / 8;
149 dst_width = lcg_rand_n (MAX_DST_WIDTH) + 1;
150 dst_height = lcg_rand_n (MAX_DST_HEIGHT) + 1;
151 dst_stride = dst_width * dst_bpp + lcg_rand_n (MAX_STRIDE) * dst_bpp;
152 dst_stride = (dst_stride + 3) & ~3;
154 dst_bits = (uint32_t *)make_random_bytes (dst_stride * dst_height);
156 dst_x = -(dst_width / 4) + lcg_rand_n (dst_width * 3 / 2);
157 dst_y = -(dst_height / 4) + lcg_rand_n (dst_height * 3 / 2);
159 dst_img = pixman_image_create_bits (
160 dst_format, dst_width, dst_height, dst_bits, dst_stride);
162 image_endian_swap (dst_img);
169 n_traps = lcg_rand_n (25);
170 traps = fence_malloc (n_traps * sizeof (pixman_trapezoid_t));
172 for (i = 0; i < n_traps; ++i)
174 pixman_trapezoid_t *t = &(traps[i]);
176 t->top = random_fixed (MAX_DST_HEIGHT) - MAX_DST_HEIGHT / 2;
177 t->bottom = t->top + random_fixed (MAX_DST_HEIGHT);
178 t->left.p1.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2;
179 t->left.p1.y = t->top - random_fixed (50);
180 t->left.p2.x = random_fixed (MAX_DST_WIDTH) - MAX_DST_WIDTH / 2;
181 t->left.p2.y = t->bottom + random_fixed (50);
182 t->right.p1.x = t->left.p1.x + random_fixed (MAX_DST_WIDTH);
183 t->right.p1.y = t->top - random_fixed (50);
184 t->right.p2.x = t->left.p2.x + random_fixed (MAX_DST_WIDTH);
185 t->right.p2.y = t->bottom - random_fixed (50);
189 if (lcg_rand_n (8) == 0)
191 pixman_box16_t clip_boxes[2];
192 int n = lcg_rand_n (2) + 1;
193 for (i = 0; i < n; i++)
195 clip_boxes[i].x1 = lcg_rand_n (dst_width);
196 clip_boxes[i].y1 = lcg_rand_n (dst_height);
198 clip_boxes[i].x1 + lcg_rand_n (dst_width - clip_boxes[i].x1);
200 clip_boxes[i].y1 + lcg_rand_n (dst_height - clip_boxes[i].y1);
204 printf ("destination clip box: [%d,%d-%d,%d]\n",
205 clip_boxes[i].x1, clip_boxes[i].y1,
206 clip_boxes[i].x2, clip_boxes[i].y2);
209 pixman_region_init_rects (&clip, clip_boxes, n);
210 pixman_image_set_clip_region (dst_img, &clip);
211 pixman_region_fini (&clip);
214 pixman_composite_trapezoids (op, src_img, dst_img, mask_format,
215 src_x, src_y, dst_x, dst_y, n_traps, traps);
217 if (dst_format == PIXMAN_x8r8g8b8)
219 /* ignore unused part */
220 for (i = 0; i < dst_stride * dst_height / 4; i++)
221 dst_bits[i] &= 0xFFFFFF;
224 image_endian_swap (dst_img);
230 for (i = 0; i < dst_height; i++)
232 for (j = 0; j < dst_stride; j++)
233 printf ("%02X ", *((uint8_t *)dst_bits + i * dst_stride + j));
239 crc32 = compute_crc32 (0, dst_bits, dst_stride * dst_height);
241 fence_free (dst_bits);
243 pixman_image_unref (src_img);
244 pixman_image_unref (dst_img);
247 FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
252 main (int argc, const char *argv[])
254 return fuzzer_test_main("composite traps", 40000, 0xE3112106,
255 test_composite, argc, argv);