5 #include <X11/Xutil.h> /* for XDestroyImage */
6 #include <pixman.h> /* for pixman blt functions */
12 const uint32_t *real, const uint32_t *ref,
13 int x, int y, int w, int h)
17 for (j = y - 2; j <= y + 2; j++) {
21 for (i = x - 2; i <= x + 2; i++) {
25 len += sprintf(buf+len, "%08x ", real[j*w+i]);
28 len += sprintf(buf+len, "\t");
30 for (i = x - 2; i <= x + 2; i++) {
34 len += sprintf(buf+len, "%08x ", ref[j*w+i]);
37 len += sprintf(buf+len, "\n");
41 static void fill_rect(struct test_display *t,
43 XRenderPictFormat *format,
44 int use_window, int tx, int ty,
45 uint8_t alu, int x, int y, int w, int h, uint32_t fg)
51 val.graphics_exposures = 0;
56 XSetWindowAttributes attr;
58 attr.override_redirect = 1;
59 tmp = XCreateWindow(t->dpy, DefaultRootWindow(t->dpy),
65 DefaultScreen(t->dpy)),
66 CWOverrideRedirect, &attr);
67 XMapWindow(t->dpy, tmp);
69 tmp = XCreatePixmap(t->dpy, d, w, h, format->depth);
71 gc = XCreateGC(t->dpy, d, GCGraphicsExposures | GCForeground, &val);
72 XFillRectangle(t->dpy, tmp, gc, 0, 0, w, h);
74 XChangeGC(t->dpy, gc, GCFunction, &val);
75 XCopyArea(t->dpy, tmp, d, gc, 0, 0, w, h, x, y);
79 XDestroyWindow(t->dpy, tmp);
81 XFreePixmap(t->dpy, tmp);
84 static void pixel_tests(struct test *t, int reps, int sets, enum target target)
86 struct test_target tt;
88 uint32_t *cells = malloc(t->real.width*t->real.height*4);
91 } *pixels = malloc(reps*sizeof(*pixels));
94 test_target_create_render(&t->real, target, &tt);
96 printf("Testing setting of single pixels (%s): ",
97 test_target_name(target));
100 for (s = 0; s < sets; s++) {
101 for (r = 0; r < reps; r++) {
102 int x = rand() % (tt.width - 1);
103 int y = rand() % (tt.height - 1);
104 uint32_t fg = rand();
106 fill_rect(&t->real, tt.draw, tt.format,
108 GXcopy, x, y, 1, 1, fg);
112 cells[y*tt.width+x] = fg;
115 test_init_image(&image, &t->real.shm, tt.format, 1, 1);
117 for (r = 0; r < reps; r++) {
118 uint32_t x = pixels[r].x;
119 uint32_t y = pixels[r].y;
122 XShmGetImage(t->real.dpy, tt.draw, &image,
125 result = *(uint32_t *)image.data;
126 if (!pixel_equal(image.depth, result,
127 cells[y*tt.width+x])) {
128 uint32_t mask = depth_mask(image.depth);
130 die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n",
132 cells[y*tt.width+x] & mask,
139 printf("passed [%d iterations x %d]\n", reps, sets);
141 test_target_destroy_render(&t->real, &tt);
146 static void clear(struct test_display *dpy, struct test_target *tt)
148 XRenderColor render_color = {0};
149 XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
150 0, 0, tt->width, tt->height);
153 static void area_tests(struct test *t, int reps, int sets, enum target target)
155 struct test_target tt;
157 uint32_t *cells = calloc(sizeof(uint32_t), t->real.width*t->real.height);
160 printf("Testing area sets (%s): ", test_target_name(target));
163 test_target_create_render(&t->real, target, &tt);
164 clear(&t->real, &tt);
166 test_init_image(&image, &t->real.shm, tt.format, tt.width, tt.height);
168 for (s = 0; s < sets; s++) {
169 for (r = 0; r < reps; r++) {
170 int w = 1 + rand() % (tt.width - 1);
171 int h = 1 + rand() % (tt.height - 1);
172 uint32_t fg = rand();
174 x = rand() % (2*tt.width) - tt.width;
175 y = rand() % (2*tt.height) - tt.height;
177 fill_rect(&t->real, tt.draw, tt.format,
179 GXcopy, x, y, w, h, fg);
185 if (x >= tt.width || y >= tt.height)
188 if (x + w > tt.width)
190 if (y + h > tt.height)
192 if (w <= 0 || h <= 0)
195 pixman_fill(cells, tt.width, 32, x, y, w, h, fg);
198 XShmGetImage(t->real.dpy, tt.draw, &image, 0, 0, AllPlanes);
200 for (y = 0; y < tt.height; y++) {
201 for (x = 0; x < tt.width; x++) {
202 uint32_t result = *(uint32_t *)
204 y*image.bytes_per_line +
205 x*image.bits_per_pixel/8);
206 if (!pixel_equal(image.depth, result, cells[y*tt.width+x])) {
208 uint32_t mask = depth_mask(image.depth);
210 (uint32_t*)image.data, cells,
211 x, y, tt.width, tt.height);
213 die("failed to set pixel (%d,%d) to %08x [%08x], found %08x [%08x] instead\n%s",
215 cells[y*tt.width+x] & mask,
224 printf("passed [%d iterations x %d]\n", reps, sets);
226 test_target_destroy_render(&t->real, &tt);
230 static void rect_tests(struct test *t, int reps, int sets, enum target target, int use_window)
232 struct test_target real, ref;
235 printf("Testing area fills (%s, using %s source): ",
236 test_target_name(target), use_window ? "window" : "pixmap");
239 test_target_create_render(&t->real, target, &real);
240 clear(&t->real, &real);
242 test_target_create_render(&t->ref, target, &ref);
243 clear(&t->ref, &ref);
245 for (s = 0; s < sets; s++) {
246 for (r = 0; r < reps; r++) {
247 int x = rand() % (real.width - 1);
248 int y = rand() % (real.height - 1);
249 int w = 1 + rand() % (real.width - x - 1);
250 int h = 1 + rand() % (real.height - y - 1);
251 int tmpx = w == real.width ? 0 : rand() % (real.width - w);
252 int tmpy = h == real.height ? 0 : rand() % (real.height - h);
253 uint8_t alu = rand() % (GXset + 1);
254 uint32_t fg = rand();
256 fill_rect(&t->real, real.draw, real.format,
257 use_window, tmpx, tmpy,
258 alu, x, y, w, h, fg);
259 fill_rect(&t->ref, ref.draw, ref.format,
260 use_window, tmpx, tmpy,
261 alu, x, y, w, h, fg);
265 real.draw, real.format,
266 ref.draw, ref.format,
267 0, 0, real.width, real.height,
271 printf("passed [%d iterations x %d]\n", reps, sets);
273 test_target_destroy_render(&t->real, &real);
274 test_target_destroy_render(&t->ref, &ref);
277 int main(int argc, char **argv)
282 test_init(&test, argc, argv);
284 for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
286 int sets = 1 << (12 - i);
292 for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
293 pixel_tests(&test, reps, sets, t);
294 area_tests(&test, reps, sets, t);
295 rect_tests(&test, reps, sets, t, 0);
297 rect_tests(&test, reps, sets, t, 1);