1#include <stdint.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5#include <X11/Xutil.h> /* for XDestroyImage */
6
7#include "test.h"
8
9#define SIZE 20000
10struct draw {
11	Pixmap a, b;
12	GC gc;
13	XRenderPictFormat *format;
14};
15
16static void target_init(struct test_display *t, struct draw *tt, int size)
17{
18	XGCValues val;
19
20	tt->a = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
21			      size, size, 32);
22	tt->b = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
23			      size, size, 32);
24
25	val.graphics_exposures = 0;
26	tt->gc = XCreateGC(t->dpy, tt->a, GCGraphicsExposures, &val);
27
28	tt->format = XRenderFindStandardFormat(t->dpy, PictStandardARGB32);
29
30	val.foreground = 0xffff0000;
31	XChangeGC(t->dpy, tt->gc, GCForeground, &val);
32	XFillRectangle(t->dpy, tt->a, tt->gc, 0, 0, size, size);
33
34	val.foreground = 0xff0000ff;
35	XChangeGC(t->dpy, tt->gc, GCForeground, &val);
36	XFillRectangle(t->dpy, tt->b, tt->gc, 0, 0, size, size);
37}
38
39static void target_fini(struct test_display *t, struct draw *tt)
40{
41	XFreePixmap(t->dpy, tt->a);
42	XFreePixmap(t->dpy, tt->b);
43}
44
45int main(int argc, char **argv)
46{
47	struct test test;
48	struct draw out, ref;
49	int size, i;
50
51	test_init(&test, argc, argv);
52
53	/* Copy back and forth betwenn two pixmaps, gradually getting larger */
54	for (size = 1; size <= SIZE; size = (size * 3 + 1) / 2) {
55		target_init(&test.out, &out, size);
56		target_init(&test.ref, &ref, size);
57
58		printf("size=%d\n", size);
59		for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
60			int reps = REPS(i);
61			do {
62				int sx = rand() % (2*size) - size;
63				int sy = rand() % (2*size) - size;
64
65				int dx = rand() % (2*size) - size;
66				int dy = rand() % (2*size) - size;
67
68				int order = rand() & 1;
69
70				XCopyArea(test.out.dpy,
71					  order ? out.a : out.b,
72					  (!order) ? out.a : out.b,
73					  out.gc,
74					  sx, sy,
75					  size, size,
76					  dx, dy);
77
78				XCopyArea(test.ref.dpy,
79					  order ? ref.a : ref.b,
80					  (!order) ? ref.a : ref.b,
81					  ref.gc,
82					  sx, sy,
83					  size, size,
84					  dx, dy);
85			} while (--reps);
86		}
87
88		test_compare(&test,
89			     out.a, out.format,
90			     ref.a, ref.format,
91			     0, 0, size, size,
92			     "");
93		test_compare(&test,
94			     out.b, out.format,
95			     ref.b, ref.format,
96			     0, 0, size, size,
97			     "");
98
99		target_fini(&test.out, &out);
100		target_fini(&test.ref, &ref);
101	}
102
103	return 0;
104}
105