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 10struct draw { 11 Pixmap a, b; 12 Picture pa, pb; 13 GC gc; 14 XRenderPictFormat *format; 15}; 16 17static void target_init(struct test_display *t, struct draw *tt, int size) 18{ 19 XRenderColor color; 20 21 tt->format = XRenderFindStandardFormat(t->dpy, PictStandardARGB32); 22 23 tt->a = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy), 24 size, size, tt->format->depth); 25 tt->pa = XRenderCreatePicture(t->dpy, tt->a, tt->format, 0, NULL); 26 27 color.alpha = 0xffff; 28 color.red = 0xffff; 29 color.green = 0; 30 color.blue = 0; 31 XRenderFillRectangle(t->dpy, PictOpSrc, tt->pa, &color, 0, 0, size, size); 32 33 tt->b = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy), 34 size, size, tt->format->depth); 35 tt->pb = XRenderCreatePicture(t->dpy, tt->b, tt->format, 0, NULL); 36 37 color.alpha = 0xffff; 38 color.red = 0; 39 color.green = 0; 40 color.blue = 0xffff; 41 XRenderFillRectangle(t->dpy, PictOpSrc, tt->pb, &color, 0, 0, size, size); 42} 43 44static void target_fini(struct test_display *t, struct draw *tt) 45{ 46 XRenderFreePicture(t->dpy, tt->pa); 47 XFreePixmap(t->dpy, tt->a); 48 49 XRenderFreePicture(t->dpy, tt->pb); 50 XFreePixmap(t->dpy, tt->b); 51} 52 53int main(int argc, char **argv) 54{ 55 struct test test; 56 struct draw out, ref; 57 int size, i; 58 59 test_init(&test, argc, argv); 60 61 /* Copy back and forth betwenn two pixmaps, gradually getting larger */ 62 for (size = 1; size <= SIZE; size = (size * 3 + 1) / 2) { 63 target_init(&test.out, &out, size); 64 target_init(&test.ref, &ref, size); 65 66 printf("size=%d\n", size); 67 for (i = 0; i <= DEFAULT_ITERATIONS; i++) { 68 int reps = REPS(i); 69 do { 70 int sx = rand() % (2*size) - size; 71 int sy = rand() % (2*size) - size; 72 73 int dx = rand() % (2*size) - size; 74 int dy = rand() % (2*size) - size; 75 76 int w = rand() % size; 77 int h = rand() % size; 78 79 int order = rand() & 1; 80 81 XRenderComposite(test.out.dpy, PictOpSrc, 82 order ? out.pa : out.pb, 83 0, 84 (!order) ? out.pa : out.pb, 85 sx, sy, 86 0, 0, 87 dx, dy, 88 w, h); 89 90 XRenderComposite(test.ref.dpy, PictOpSrc, 91 order ? ref.pa : ref.pb, 92 0, 93 (!order) ? ref.pa : ref.pb, 94 sx, sy, 95 0, 0, 96 dx, dy, 97 w, h); 98 } while (--reps); 99 } 100 101 test_compare(&test, 102 out.a, out.format, 103 ref.a, ref.format, 104 0, 0, size, size, 105 ""); 106 test_compare(&test, 107 out.b, out.format, 108 ref.b, ref.format, 109 0, 0, size, size, 110 ""); 111 112 target_fini(&test.out, &out); 113 target_fini(&test.ref, &ref); 114 } 115 116 return 0; 117} 118