take two
[profile/ivi/xorg-x11-drv-intel.git] / test / test_render.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <sys/ipc.h>
6 #include <sys/shm.h>
7
8 #include "test.h"
9
10 const char *test_target_name(enum target target)
11 {
12         switch (target) {
13         default:
14         case ROOT: return "root";
15         case CHILD: return "child";
16         case PIXMAP: return "pixmap";
17         }
18 }
19
20 void test_target_create_render(struct test_display *dpy,
21                                enum target target,
22                                struct test_target *tt)
23 {
24         XSetWindowAttributes attr;
25         XGCValues gcv;
26
27         tt->dpy = dpy;
28         tt->target = target;
29
30         tt->draw = dpy->root;
31         tt->format = dpy->format;
32         tt->width = dpy->width;
33         tt->height = dpy->height;
34
35         switch (target) {
36         case ROOT:
37                 break;
38
39         case CHILD:
40                 attr.override_redirect = 1;
41                 tt->width /= 4;
42                 tt->height /= 4;
43                 tt->draw = XCreateWindow(dpy->dpy, tt->draw,
44                                          dpy->width/2, dpy->height/2,
45                                          tt->width, tt->height,
46                                          0, tt->format->depth,
47                                          InputOutput,
48                                          DefaultVisual(dpy->dpy,
49                                                        DefaultScreen(dpy->dpy)),
50                                          CWOverrideRedirect, &attr);
51                 XMapWindow(dpy->dpy, tt->draw);
52                 break;
53
54         case PIXMAP:
55                 tt->format = XRenderFindStandardFormat(dpy->dpy, PictStandardARGB32);
56                 tt->draw = XCreatePixmap(dpy->dpy, tt->draw,
57                                          dpy->width, dpy->height,
58                                          tt->format->depth);
59                 break;
60         }
61
62         tt->picture =
63                 XRenderCreatePicture(dpy->dpy, tt->draw, tt->format, 0, NULL);
64
65         gcv.graphics_exposures = 0;
66         tt->gc = XCreateGC(dpy->dpy, tt->draw, GCGraphicsExposures, &gcv);
67 }
68
69 void test_target_destroy_render(struct test_display *dpy,
70                                 struct test_target *tt)
71 {
72         XRenderFreePicture(dpy->dpy, tt->picture);
73         switch (tt->target) {
74         case ROOT:
75                 break;
76         case CHILD:
77                 XDestroyWindow(dpy->dpy, tt->draw);
78                 break;
79         case PIXMAP:
80                 XFreePixmap(dpy->dpy, tt->draw);
81                 break;
82         }
83 }
84
85 #if 0
86 static int random_bool(void)
87 {
88         return rand() > RAND_MAX/2;
89 }
90
91 static Picture create_alpha_map(void)
92 {
93         return 0;
94 }
95
96 static Pixmap create_clip_mask(void)
97 {
98         return 0;
99 }
100
101 unsigned int test_render_randomize_picture_attributes(XRenderPictureAttributes *pa)
102 {
103         unsigned int flags = 0;
104
105         memset(pa, 0, sizeof(*pa));
106
107         if (random_bool()) {
108                 pa->repeat = repeat_modes[rand() % ARRAY_SIZE(repeat_modes)];
109                 flags |= CPRepeat;
110
111         }
112
113         if (random_bool()) {
114                 pa->alpha_map = create_alpha_map();
115                 pa->alpha_x_origin = rand() % 1024;
116                 pa->alpha_y_origin = rand() % 1024;
117                 flags |= CPAlphaMap;
118         }
119
120         if (random_bool()) {
121                 pa->clip_mask = create_clip_mask();
122                 pa->clip_x_orgin = rand() % 1024;
123                 pa->clip_y_orgin = rand() % 1024;
124                 flags |= CPClipMask;
125         }
126
127         if (random_bool()) {
128                 pa->subwindow_mode = random_bool();
129                 flags |= CPSubwindowMode;
130         }
131
132         if (random_bool()) {
133                 pa->poly_edge = random_bool();
134                 flags |= CPPolyEdge;
135         }
136
137         if (random_bool()) {
138                 pa->poly_mode = random_bool();
139                 flags |= CPPolyMode;
140         }
141
142         if (random_bool()) {
143                 pa->component_alpha = random_bool();
144                 flags |= CPComponentAlpha;
145         }
146
147         return flags;
148 }
149 #endif