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; 3442542f5fSchristos tt->depth = dpy->depth; 3503b705cfSriastradh 3603b705cfSriastradh switch (target) { 3703b705cfSriastradh case ROOT: 3803b705cfSriastradh break; 3903b705cfSriastradh 4003b705cfSriastradh case CHILD: 4103b705cfSriastradh attr.override_redirect = 1; 4203b705cfSriastradh tt->width /= 4; 4303b705cfSriastradh tt->height /= 4; 4403b705cfSriastradh tt->draw = XCreateWindow(dpy->dpy, tt->draw, 4503b705cfSriastradh dpy->width/2, dpy->height/2, 4603b705cfSriastradh tt->width, tt->height, 4703b705cfSriastradh 0, tt->format->depth, 4803b705cfSriastradh InputOutput, 4903b705cfSriastradh DefaultVisual(dpy->dpy, 5003b705cfSriastradh DefaultScreen(dpy->dpy)), 5103b705cfSriastradh CWOverrideRedirect, &attr); 5203b705cfSriastradh XMapWindow(dpy->dpy, tt->draw); 5303b705cfSriastradh break; 5403b705cfSriastradh 5503b705cfSriastradh case PIXMAP: 5603b705cfSriastradh tt->format = XRenderFindStandardFormat(dpy->dpy, PictStandardARGB32); 5703b705cfSriastradh tt->draw = XCreatePixmap(dpy->dpy, tt->draw, 5803b705cfSriastradh dpy->width, dpy->height, 5903b705cfSriastradh tt->format->depth); 6042542f5fSchristos tt->depth = 32; 6103b705cfSriastradh break; 6203b705cfSriastradh } 6303b705cfSriastradh 6403b705cfSriastradh tt->picture = 6503b705cfSriastradh XRenderCreatePicture(dpy->dpy, tt->draw, tt->format, 0, NULL); 6603b705cfSriastradh 6703b705cfSriastradh gcv.graphics_exposures = 0; 6803b705cfSriastradh tt->gc = XCreateGC(dpy->dpy, tt->draw, GCGraphicsExposures, &gcv); 6903b705cfSriastradh} 7003b705cfSriastradh 7103b705cfSriastradhvoid test_target_destroy_render(struct test_display *dpy, 7203b705cfSriastradh struct test_target *tt) 7303b705cfSriastradh{ 7403b705cfSriastradh XRenderFreePicture(dpy->dpy, tt->picture); 7503b705cfSriastradh switch (tt->target) { 7603b705cfSriastradh case ROOT: 7703b705cfSriastradh break; 7803b705cfSriastradh case CHILD: 7903b705cfSriastradh XDestroyWindow(dpy->dpy, tt->draw); 8003b705cfSriastradh break; 8103b705cfSriastradh case PIXMAP: 8203b705cfSriastradh XFreePixmap(dpy->dpy, tt->draw); 8303b705cfSriastradh break; 8403b705cfSriastradh } 8503b705cfSriastradh} 8603b705cfSriastradh 8703b705cfSriastradh#if 0 8803b705cfSriastradhstatic int random_bool(void) 8903b705cfSriastradh{ 9003b705cfSriastradh return rand() > RAND_MAX/2; 9103b705cfSriastradh} 9203b705cfSriastradh 9303b705cfSriastradhstatic Picture create_alpha_map(void) 9403b705cfSriastradh{ 9503b705cfSriastradh return 0; 9603b705cfSriastradh} 9703b705cfSriastradh 9803b705cfSriastradhstatic Pixmap create_clip_mask(void) 9903b705cfSriastradh{ 10003b705cfSriastradh return 0; 10103b705cfSriastradh} 10203b705cfSriastradh 10303b705cfSriastradhunsigned int test_render_randomize_picture_attributes(XRenderPictureAttributes *pa) 10403b705cfSriastradh{ 10503b705cfSriastradh unsigned int flags = 0; 10603b705cfSriastradh 10703b705cfSriastradh memset(pa, 0, sizeof(*pa)); 10803b705cfSriastradh 10903b705cfSriastradh if (random_bool()) { 11003b705cfSriastradh pa->repeat = repeat_modes[rand() % ARRAY_SIZE(repeat_modes)]; 11103b705cfSriastradh flags |= CPRepeat; 11203b705cfSriastradh 11303b705cfSriastradh } 11403b705cfSriastradh 11503b705cfSriastradh if (random_bool()) { 11603b705cfSriastradh pa->alpha_map = create_alpha_map(); 11703b705cfSriastradh pa->alpha_x_origin = rand() % 1024; 11803b705cfSriastradh pa->alpha_y_origin = rand() % 1024; 11903b705cfSriastradh flags |= CPAlphaMap; 12003b705cfSriastradh } 12103b705cfSriastradh 12203b705cfSriastradh if (random_bool()) { 12303b705cfSriastradh pa->clip_mask = create_clip_mask(); 12403b705cfSriastradh pa->clip_x_orgin = rand() % 1024; 12503b705cfSriastradh pa->clip_y_orgin = rand() % 1024; 12603b705cfSriastradh flags |= CPClipMask; 12703b705cfSriastradh } 12803b705cfSriastradh 12903b705cfSriastradh if (random_bool()) { 13003b705cfSriastradh pa->subwindow_mode = random_bool(); 13103b705cfSriastradh flags |= CPSubwindowMode; 13203b705cfSriastradh } 13303b705cfSriastradh 13403b705cfSriastradh if (random_bool()) { 13503b705cfSriastradh pa->poly_edge = random_bool(); 13603b705cfSriastradh flags |= CPPolyEdge; 13703b705cfSriastradh } 13803b705cfSriastradh 13903b705cfSriastradh if (random_bool()) { 14003b705cfSriastradh pa->poly_mode = random_bool(); 14103b705cfSriastradh flags |= CPPolyMode; 14203b705cfSriastradh } 14303b705cfSriastradh 14403b705cfSriastradh if (random_bool()) { 14503b705cfSriastradh pa->component_alpha = random_bool(); 14603b705cfSriastradh flags |= CPComponentAlpha; 14703b705cfSriastradh } 14803b705cfSriastradh 14903b705cfSriastradh return flags; 15003b705cfSriastradh} 15103b705cfSriastradh#endif 152