5 #include <X11/Xutil.h> /* for XDestroyImage */
6 #include <pixman.h> /* for pixman blt functions */
10 static const uint8_t ops[] = {
16 static void fill_rect(struct test_display *dpy, Picture p, uint8_t op,
17 int x, int y, int w, int h,
18 uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
20 XRenderColor render_color;
22 render_color.red = red * alpha;
23 render_color.green = green * alpha;
24 render_color.blue = blue * alpha;
25 render_color.alpha = alpha << 8;
27 XRenderFillRectangle(dpy->dpy, op, p, &render_color, x, y, w,h);
30 static void pixel_tests(struct test *t, int reps, int sets, enum target target)
32 struct test_target tt;
34 uint32_t *cells = malloc(t->real.width*t->real.height*4);
37 } *pixels = malloc(reps*sizeof(*pixels));
40 test_target_create_render(&t->real, target, &tt);
42 printf("Testing setting of single pixels (%s): ",
43 test_target_name(target));
46 for (s = 0; s < sets; s++) {
47 for (r = 0; r < reps; r++) {
48 int x = rand() % (tt.width - 1);
49 int y = rand() % (tt.height - 1);
50 int red = rand() % 0xff;
51 int green = rand() % 0xff;
52 int blue = rand() % 0xff;
53 int alpha = rand() % 0xff;
55 fill_rect(&t->real, tt.picture, PictOpSrc,
57 red, green, blue, alpha);
61 cells[y*tt.width+x] = color(red, green, blue, alpha);
64 test_init_image(&image, &t->real.shm, tt.format, 1, 1);
66 for (r = 0; r < reps; r++) {
68 uint32_t x = pixels[r].x;
69 uint32_t y = pixels[r].y;
71 XShmGetImage(t->real.dpy, tt.draw, &image,
74 result = *(uint32_t *)image.data;
75 if (!pixel_equal(image.depth, result,
76 cells[y*tt.width+x])) {
77 uint32_t mask = depth_mask(image.depth);
78 die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
80 cells[y*tt.width+x] & mask,
86 printf("passed [%d iterations x %d]\n", reps, sets);
88 test_target_destroy_render(&t->real, &tt);
93 static void clear(struct test_display *dpy, struct test_target *tt)
95 XRenderColor render_color = {0};
96 XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
97 0, 0, tt->width, tt->height);
100 static void area_tests(struct test *t, int reps, int sets, enum target target)
102 struct test_target tt;
104 uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
107 printf("Testing area sets (%s): ", test_target_name(target));
110 test_target_create_render(&t->real, target, &tt);
111 clear(&t->real, &tt);
113 test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
115 for (s = 0; s < sets; s++) {
116 for (r = 0; r < reps; r++) {
117 int w = rand() % tt.width;
118 int h = rand() % tt.height;
119 int red = rand() % 0xff;
120 int green = rand() % 0xff;
121 int blue = rand() % 0xff;
122 int alpha = rand() % 0xff;
124 x = rand() % (2*tt.width) - tt.width;
125 y = rand() % (2*tt.height) - tt.height;
127 fill_rect(&t->real, tt.picture, PictOpSrc,
128 x, y, w, h, red, green, blue, alpha);
134 if (x >= tt.width || y >= tt.height)
137 if (x + w > tt.width)
139 if (y + h > tt.height)
141 if (w <= 0 || h <= 0)
144 pixman_fill(cells, tt.width, 32, x, y, w, h,
145 color(red, green, blue, alpha));
148 XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
150 for (y = 0; y < tt.height; y++) {
151 for (x = 0; x < tt.width; x++) {
153 *(uint32_t *)(image.data +
154 y*image.bytes_per_line +
155 image.bits_per_pixel*x/8);
156 if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
158 if (image.depth == 32)
161 mask = (1 << image.depth) - 1;
162 die("failed to set pixel (%d,%d) to %08x[%08x], found %08x instead\n",
164 cells[y*tt.width+x] & mask,
172 printf("passed [%d iterations x %d]\n", reps, sets);
174 test_target_destroy_render(&t->real, &tt);
178 static void rect_tests(struct test *t, int reps, int sets, enum target target)
180 struct test_target real, ref;
183 printf("Testing area fills (%s): ", test_target_name(target));
186 test_target_create_render(&t->real, target, &real);
187 clear(&t->real, &real);
189 test_target_create_render(&t->ref, target, &ref);
190 clear(&t->ref, &ref);
192 for (s = 0; s < sets; s++) {
193 for (r = 0; r < reps; r++) {
194 int x = rand() % (2*real.width) - real.width;
195 int y = rand() % (2*real.height) - real.height;
196 int w = rand() % real.width;
197 int h = rand() % real.height;
198 int op = ops[rand() % sizeof(ops)];
199 int red = rand() % 0xff;
200 int green = rand() % 0xff;
201 int blue = rand() % 0xff;
202 int alpha = rand() % 0xff;
204 fill_rect(&t->real, real.picture,
206 red, green, blue, alpha);
207 fill_rect(&t->ref, ref.picture,
209 red, green, blue, alpha);
213 real.draw, real.format,
214 ref.draw, ref.format,
215 0, 0, real.width, real.height,
219 printf("passed [%d iterations x %d]\n", reps, sets);
221 test_target_destroy_render(&t->real, &real);
222 test_target_destroy_render(&t->ref, &ref);
225 int main(int argc, char **argv)
230 test_init(&test, argc, argv);
232 for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
234 int sets = 1 << (12 - i);
240 for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
241 pixel_tests(&test, reps, sets, t);
242 area_tests(&test, reps, sets, t);
243 rect_tests(&test, reps, sets, t);