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
10const 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
20void 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	tt->depth = dpy->depth;
35
36	switch (target) {
37	case ROOT:
38		break;
39
40	case CHILD:
41		attr.override_redirect = 1;
42		tt->width /= 4;
43		tt->height /= 4;
44		tt->draw = XCreateWindow(dpy->dpy, tt->draw,
45					 dpy->width/2, dpy->height/2,
46					 tt->width, tt->height,
47					 0, tt->format->depth,
48					 InputOutput,
49					 DefaultVisual(dpy->dpy,
50						       DefaultScreen(dpy->dpy)),
51					 CWOverrideRedirect, &attr);
52		XMapWindow(dpy->dpy, tt->draw);
53		break;
54
55	case PIXMAP:
56		tt->format = XRenderFindStandardFormat(dpy->dpy, PictStandardARGB32);
57		tt->draw = XCreatePixmap(dpy->dpy, tt->draw,
58					 dpy->width, dpy->height,
59					 tt->format->depth);
60		tt->depth = 32;
61		break;
62	}
63
64	tt->picture =
65		XRenderCreatePicture(dpy->dpy, tt->draw, tt->format, 0, NULL);
66
67	gcv.graphics_exposures = 0;
68	tt->gc = XCreateGC(dpy->dpy, tt->draw, GCGraphicsExposures, &gcv);
69}
70
71void test_target_destroy_render(struct test_display *dpy,
72				struct test_target *tt)
73{
74	XRenderFreePicture(dpy->dpy, tt->picture);
75	switch (tt->target) {
76	case ROOT:
77		break;
78	case CHILD:
79		XDestroyWindow(dpy->dpy, tt->draw);
80		break;
81	case PIXMAP:
82		XFreePixmap(dpy->dpy, tt->draw);
83		break;
84	}
85}
86
87#if 0
88static int random_bool(void)
89{
90	return rand() > RAND_MAX/2;
91}
92
93static Picture create_alpha_map(void)
94{
95	return 0;
96}
97
98static Pixmap create_clip_mask(void)
99{
100	return 0;
101}
102
103unsigned int test_render_randomize_picture_attributes(XRenderPictureAttributes *pa)
104{
105	unsigned int flags = 0;
106
107	memset(pa, 0, sizeof(*pa));
108
109	if (random_bool()) {
110		pa->repeat = repeat_modes[rand() % ARRAY_SIZE(repeat_modes)];
111		flags |= CPRepeat;
112
113	}
114
115	if (random_bool()) {
116		pa->alpha_map = create_alpha_map();
117		pa->alpha_x_origin = rand() % 1024;
118		pa->alpha_y_origin = rand() % 1024;
119		flags |= CPAlphaMap;
120	}
121
122	if (random_bool()) {
123		pa->clip_mask = create_clip_mask();
124		pa->clip_x_orgin = rand() % 1024;
125		pa->clip_y_orgin = rand() % 1024;
126		flags |= CPClipMask;
127	}
128
129	if (random_bool()) {
130		pa->subwindow_mode = random_bool();
131		flags |= CPSubwindowMode;
132	}
133
134	if (random_bool()) {
135		pa->poly_edge = random_bool();
136		flags |= CPPolyEdge;
137	}
138
139	if (random_bool()) {
140		pa->poly_mode = random_bool();
141		flags |= CPPolyMode;
142	}
143
144	if (random_bool()) {
145		pa->component_alpha = random_bool();
146		flags |= CPComponentAlpha;
147	}
148
149	return flags;
150}
151#endif
152