take two
[profile/ivi/xorg-x11-drv-intel.git] / test / basic-copyarea-size.c
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
10 struct draw {
11         Pixmap a, b;
12         GC gc;
13         XRenderPictFormat *format;
14 };
15
16 static 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
39 static 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
45 int main(int argc, char **argv)
46 {
47         struct test test;
48         struct draw real, 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.real, &real, 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 = 1 << 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.real.dpy,
71                                           order ? real.a : real.b,
72                                           (!order) ? real.a : real.b,
73                                           real.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                              real.a, real.format,
90                              ref.a, ref.format,
91                              0, 0, size, size,
92                              "");
93                 test_compare(&test,
94                              real.b, real.format,
95                              ref.b, ref.format,
96                              0, 0, size, size,
97                              "");
98
99                 target_fini(&test.real, &real);
100                 target_fini(&test.ref, &ref);
101         }
102
103         return 0;
104 }