test_render.c revision 03b705cf
103b705cfSriastradh#include <stdio.h>
203b705cfSriastradh#include <stdlib.h>
303b705cfSriastradh#include <string.h>
403b705cfSriastradh#include <unistd.h>
503b705cfSriastradh#include <sys/ipc.h>
603b705cfSriastradh#include <sys/shm.h>
703b705cfSriastradh
803b705cfSriastradh#include "test.h"
903b705cfSriastradh
1003b705cfSriastradhconst char *test_target_name(enum target target)
1103b705cfSriastradh{
1203b705cfSriastradh	switch (target) {
1303b705cfSriastradh	default:
1403b705cfSriastradh	case ROOT: return "root";
1503b705cfSriastradh	case CHILD: return "child";
1603b705cfSriastradh	case PIXMAP: return "pixmap";
1703b705cfSriastradh	}
1803b705cfSriastradh}
1903b705cfSriastradh
2003b705cfSriastradhvoid test_target_create_render(struct test_display *dpy,
2103b705cfSriastradh			       enum target target,
2203b705cfSriastradh			       struct test_target *tt)
2303b705cfSriastradh{
2403b705cfSriastradh	XSetWindowAttributes attr;
2503b705cfSriastradh	XGCValues gcv;
2603b705cfSriastradh
2703b705cfSriastradh	tt->dpy = dpy;
2803b705cfSriastradh	tt->target = target;
2903b705cfSriastradh
3003b705cfSriastradh	tt->draw = dpy->root;
3103b705cfSriastradh	tt->format = dpy->format;
3203b705cfSriastradh	tt->width = dpy->width;
3303b705cfSriastradh	tt->height = dpy->height;
3403b705cfSriastradh
3503b705cfSriastradh	switch (target) {
3603b705cfSriastradh	case ROOT:
3703b705cfSriastradh		break;
3803b705cfSriastradh
3903b705cfSriastradh	case CHILD:
4003b705cfSriastradh		attr.override_redirect = 1;
4103b705cfSriastradh		tt->width /= 4;
4203b705cfSriastradh		tt->height /= 4;
4303b705cfSriastradh		tt->draw = XCreateWindow(dpy->dpy, tt->draw,
4403b705cfSriastradh					 dpy->width/2, dpy->height/2,
4503b705cfSriastradh					 tt->width, tt->height,
4603b705cfSriastradh					 0, tt->format->depth,
4703b705cfSriastradh					 InputOutput,
4803b705cfSriastradh					 DefaultVisual(dpy->dpy,
4903b705cfSriastradh						       DefaultScreen(dpy->dpy)),
5003b705cfSriastradh					 CWOverrideRedirect, &attr);
5103b705cfSriastradh		XMapWindow(dpy->dpy, tt->draw);
5203b705cfSriastradh		break;
5303b705cfSriastradh
5403b705cfSriastradh	case PIXMAP:
5503b705cfSriastradh		tt->format = XRenderFindStandardFormat(dpy->dpy, PictStandardARGB32);
5603b705cfSriastradh		tt->draw = XCreatePixmap(dpy->dpy, tt->draw,
5703b705cfSriastradh					 dpy->width, dpy->height,
5803b705cfSriastradh					 tt->format->depth);
5903b705cfSriastradh		break;
6003b705cfSriastradh	}
6103b705cfSriastradh
6203b705cfSriastradh	tt->picture =
6303b705cfSriastradh		XRenderCreatePicture(dpy->dpy, tt->draw, tt->format, 0, NULL);
6403b705cfSriastradh
6503b705cfSriastradh	gcv.graphics_exposures = 0;
6603b705cfSriastradh	tt->gc = XCreateGC(dpy->dpy, tt->draw, GCGraphicsExposures, &gcv);
6703b705cfSriastradh}
6803b705cfSriastradh
6903b705cfSriastradhvoid test_target_destroy_render(struct test_display *dpy,
7003b705cfSriastradh				struct test_target *tt)
7103b705cfSriastradh{
7203b705cfSriastradh	XRenderFreePicture(dpy->dpy, tt->picture);
7303b705cfSriastradh	switch (tt->target) {
7403b705cfSriastradh	case ROOT:
7503b705cfSriastradh		break;
7603b705cfSriastradh	case CHILD:
7703b705cfSriastradh		XDestroyWindow(dpy->dpy, tt->draw);
7803b705cfSriastradh		break;
7903b705cfSriastradh	case PIXMAP:
8003b705cfSriastradh		XFreePixmap(dpy->dpy, tt->draw);
8103b705cfSriastradh		break;
8203b705cfSriastradh	}
8303b705cfSriastradh}
8403b705cfSriastradh
8503b705cfSriastradh#if 0
8603b705cfSriastradhstatic int random_bool(void)
8703b705cfSriastradh{
8803b705cfSriastradh	return rand() > RAND_MAX/2;
8903b705cfSriastradh}
9003b705cfSriastradh
9103b705cfSriastradhstatic Picture create_alpha_map(void)
9203b705cfSriastradh{
9303b705cfSriastradh	return 0;
9403b705cfSriastradh}
9503b705cfSriastradh
9603b705cfSriastradhstatic Pixmap create_clip_mask(void)
9703b705cfSriastradh{
9803b705cfSriastradh	return 0;
9903b705cfSriastradh}
10003b705cfSriastradh
10103b705cfSriastradhunsigned int test_render_randomize_picture_attributes(XRenderPictureAttributes *pa)
10203b705cfSriastradh{
10303b705cfSriastradh	unsigned int flags = 0;
10403b705cfSriastradh
10503b705cfSriastradh	memset(pa, 0, sizeof(*pa));
10603b705cfSriastradh
10703b705cfSriastradh	if (random_bool()) {
10803b705cfSriastradh		pa->repeat = repeat_modes[rand() % ARRAY_SIZE(repeat_modes)];
10903b705cfSriastradh		flags |= CPRepeat;
11003b705cfSriastradh
11103b705cfSriastradh	}
11203b705cfSriastradh
11303b705cfSriastradh	if (random_bool()) {
11403b705cfSriastradh		pa->alpha_map = create_alpha_map();
11503b705cfSriastradh		pa->alpha_x_origin = rand() % 1024;
11603b705cfSriastradh		pa->alpha_y_origin = rand() % 1024;
11703b705cfSriastradh		flags |= CPAlphaMap;
11803b705cfSriastradh	}
11903b705cfSriastradh
12003b705cfSriastradh	if (random_bool()) {
12103b705cfSriastradh		pa->clip_mask = create_clip_mask();
12203b705cfSriastradh		pa->clip_x_orgin = rand() % 1024;
12303b705cfSriastradh		pa->clip_y_orgin = rand() % 1024;
12403b705cfSriastradh		flags |= CPClipMask;
12503b705cfSriastradh	}
12603b705cfSriastradh
12703b705cfSriastradh	if (random_bool()) {
12803b705cfSriastradh		pa->subwindow_mode = random_bool();
12903b705cfSriastradh		flags |= CPSubwindowMode;
13003b705cfSriastradh	}
13103b705cfSriastradh
13203b705cfSriastradh	if (random_bool()) {
13303b705cfSriastradh		pa->poly_edge = random_bool();
13403b705cfSriastradh		flags |= CPPolyEdge;
13503b705cfSriastradh	}
13603b705cfSriastradh
13703b705cfSriastradh	if (random_bool()) {
13803b705cfSriastradh		pa->poly_mode = random_bool();
13903b705cfSriastradh		flags |= CPPolyMode;
14003b705cfSriastradh	}
14103b705cfSriastradh
14203b705cfSriastradh	if (random_bool()) {
14303b705cfSriastradh		pa->component_alpha = random_bool();
14403b705cfSriastradh		flags |= CPComponentAlpha;
14503b705cfSriastradh	}
14603b705cfSriastradh
14703b705cfSriastradh	return flags;
14803b705cfSriastradh}
14903b705cfSriastradh#endif
150