5 #include <X11/Xutil.h> /* for XDestroyImage */
10 static void fill_rect(struct test_target *tt,
12 int x, int y, int w, int h)
17 val.foreground = color;
18 XChangeGC(tt->dpy->dpy, tt->gc, GCFunction | GCForeground, &val);
20 XFillRectangle(tt->dpy->dpy, tt->draw, tt->gc, x, y, w, h);
23 static void clear(struct test_target *tt)
27 0, 0, tt->width, tt->height);
30 static void fill(struct test_target *real,
31 struct test_target *ref)
33 int x = rand() % (2*real->width) - real->width;
34 int y = rand() % (2*real->height) - real->height;
35 int w = rand() % (2*real->width);
36 int h = rand() % (2*real->height);
38 int alu = rand() % 16;
40 fill_rect(real, alu, color, x, y, w, h);
41 fill_rect(ref, alu, color, x, y, w, h);
44 static void copy(struct test_target *real,
45 struct test_target *ref)
47 int sx = rand() % (2*real->width) - ref->width;
48 int sy = rand() % (2*real->height) - ref->height;
49 int dx = rand() % (2*real->width) - ref->width;
50 int dy = rand() % (2*real->height) - ref->height;
51 int w = rand() % (2*real->width);
52 int h = rand() % (2*real->height);
55 val.function = rand() % 16;
57 XChangeGC(real->dpy->dpy, real->gc, GCFunction, &val);
58 XCopyArea(real->dpy->dpy,
59 real->draw, real->draw, real->gc,
60 sx, sy, w, h, dx, dy);
62 XChangeGC(ref->dpy->dpy, ref->gc, GCFunction, &val);
63 XCopyArea(ref->dpy->dpy,
64 ref->draw, ref->draw, ref->gc,
65 sx, sy, w, h, dx, dy);
68 static void _put(struct test_target *tt,
69 int x, int y, int w,int h, int color, int alu)
76 test_init_image(&image, &tt->dpy->shm, tt->format, w, h);
77 pixman_fill((uint32_t*)image.data,
78 image.bytes_per_line/sizeof(uint32_t),
82 XChangeGC(tt->dpy->dpy, tt->gc, GCFunction, &val);
84 XShmPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image,
86 XSync(tt->dpy->dpy, 1);
88 XPutImage(tt->dpy->dpy, tt->draw, tt->gc, &image,
93 static void put(struct test_target *real,
94 struct test_target *ref)
96 int x = rand() % (2*real->width) - real->width;
97 int y = rand() % (2*real->height) - real->height;
98 int w = rand() % real->width;
99 int h = rand() % real->height;
101 int alu = rand() % 16;
103 _put(real, x, y, w, h, color, alu);
104 _put(ref, x, y, w, h, color, alu);
107 static void rect_tests(struct test *test, int iterations, enum target target)
109 struct test_target real, ref;
110 void (* const ops[])(struct test_target *, struct test_target *) = {
117 printf("Running mixed ops stress against %s: ",
118 test_target_name(target));
121 test_target_create_render(&test->real, target, &real);
122 test_target_create_render(&test->ref, target, &ref);
127 for (n = 0; n < iterations; n++)
128 ops[rand() % ARRAY_SIZE(ops)](&real, &ref);
131 real.draw, real.format,
132 ref.draw, ref.format,
133 0, 0, real.width, real.height,
136 printf("passed [%d iterations]\n", n);
138 test_target_destroy_render(&test->real, &real);
139 test_target_destroy_render(&test->ref, &ref);
142 int main(int argc, char **argv)
147 test_init(&test, argc, argv);
149 for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
150 int iterations = 1 << i;
151 rect_tests(&test, iterations, 0);
152 rect_tests(&test, iterations, 1);