1#include <stdint.h> 2#include <stdio.h> 3#include <stdlib.h> 4 5#include <X11/Xutil.h> /* for XDestroyImage */ 6#include <pixman.h> /* for pixman blt functions */ 7 8#include "test.h" 9 10static uint8_t clock_bits[] = {0x3C, 0x5E, 0xEF, 0xF7, 0x87, 0xFF, 0x7E, 0x3C}; 11 12/* https://bugs.freedesktop.org/show_bug.cgi?id=91499 */ 13static void draw_clock(struct test_display *t, Drawable d, 14 uint8_t alu, int x, int y, uint32_t fg, uint32_t bg) 15{ 16 Pixmap pixmap; 17 XGCValues val; 18 GC gc; 19 20 val.graphics_exposures = 0; 21 val.function = alu; 22 val.foreground = fg; 23 val.background = fg; 24 25 gc = XCreateGC(t->dpy, d, 26 GCGraphicsExposures | GCForeground | GCBackground | GCFunction, 27 &val); 28 pixmap = XCreateBitmapFromData(t->dpy, d, (char *)clock_bits, 8, 8); 29 30 XCopyPlane(t->dpy, pixmap, d, gc, 0, 0, 8, 8, x, y, 1); 31 32 XFreePixmap(t->dpy, pixmap); 33 XFreeGC(t->dpy, gc); 34} 35 36static void clear(struct test_display *dpy, struct test_target *tt) 37{ 38 XRenderColor render_color = {0}; 39 XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color, 40 0, 0, tt->width, tt->height); 41} 42 43static void clock_tests(struct test *t, int reps, int sets, enum target target) 44{ 45 struct test_target out, ref; 46 int r, s; 47 48 printf("Testing clock (%s): ", test_target_name(target)); 49 fflush(stdout); 50 51 test_target_create_render(&t->out, target, &out); 52 clear(&t->out, &out); 53 54 test_target_create_render(&t->ref, target, &ref); 55 clear(&t->ref, &ref); 56 57 for (s = 0; s < sets; s++) { 58 for (r = 0; r < reps; r++) { 59 int x = rand() % (out.width - 8); 60 int y = rand() % (out.height - 8); 61 uint8_t alu = rand() % (GXset + 1); 62 uint32_t bg = rand(); 63 uint32_t fg = rand(); 64 65 draw_clock(&t->out, out.draw, alu, x, y, fg, bg); 66 draw_clock(&t->ref, ref.draw, alu, x, y, fg, bg); 67 } 68 69 test_compare(t, 70 out.draw, out.format, 71 ref.draw, ref.format, 72 0, 0, out.width, out.height, 73 ""); 74 } 75 76 printf("passed [%d iterations x %d]\n", reps, sets); 77 78 test_target_destroy_render(&t->out, &out); 79 test_target_destroy_render(&t->ref, &ref); 80} 81 82int main(int argc, char **argv) 83{ 84 struct test test; 85 int i; 86 87 test_init(&test, argc, argv); 88 89 for (i = 0; i <= DEFAULT_ITERATIONS; i++) { 90 int reps = REPS(i), sets = SETS(i); 91 enum target t; 92 93 for (t = TARGET_FIRST; t <= TARGET_LAST; t++) { 94 clock_tests(&test, reps, sets, t); 95 } 96 } 97 98 return 0; 99} 100