1#ifndef TEST_H 2#define TEST_H 3 4#include <stdint.h> 5#include <time.h> 6 7#include <X11/Xlib.h> 8#include <X11/extensions/XShm.h> 9#include <X11/extensions/Xrender.h> 10 11#define DEFAULT_ITERATIONS 20 12 13enum target { 14 ROOT, 15 CHILD, 16 PIXMAP, 17}; 18#define TARGET_FIRST ROOT 19#define TARGET_LAST PIXMAP 20 21enum mask { 22 MASK_NONE, 23 MASK_NONE_AA, 24 MASK_A1, 25 MASK_A8, 26}; 27 28struct test { 29 struct test_display { 30 Display *dpy; 31 Window root; 32 XShmSegmentInfo shm; 33 int max_shm_size; 34 int has_shm_pixmaps; 35 int width, height, depth; 36 XRenderPictFormat *format; 37 enum { REF, OUT } target; 38 } out, ref; 39}; 40 41void die(const char *fmt, ...); 42 43#define die_unless(expr) do{ if (!(expr)) die("verification failed: %s\n", #expr); } while(0) 44 45void test_init(struct test *test, int argc, char **argv); 46 47void test_compare(struct test *out, 48 Drawable out_draw, XRenderPictFormat *out_format, 49 Drawable ref_draw, XRenderPictFormat *ref_format, 50 int x, int y, int w, int h, const char *info); 51 52#define MAX_DELTA 3 53int pixel_difference(uint32_t a, uint32_t b); 54 55static inline int pixel_equal(int depth, uint32_t a, uint32_t b) 56{ 57 if (depth != 32) { 58 uint32_t mask = (1 << depth) - 1; 59 a &= mask; 60 b &= mask; 61 } 62 63 if (a == b) 64 return 1; 65 66 return pixel_difference(a, b) < MAX_DELTA; 67} 68 69void 70test_init_image(XImage *ximage, 71 XShmSegmentInfo *shm, 72 XRenderPictFormat *format, 73 int width, int height); 74 75const char *test_target_name(enum target target); 76 77struct test_target { 78 struct test_display *dpy; 79 Drawable draw; 80 GC gc; 81 XRenderPictFormat *format; 82 Picture picture; 83 int width, height, depth; 84 enum target target; 85}; 86 87void test_target_create_render(struct test_display *dpy, 88 enum target target, 89 struct test_target *tt); 90void test_target_destroy_render(struct test_display *dpy, 91 struct test_target *tt); 92 93static inline uint32_t depth_mask(int depth) 94{ 95 if (depth == 32) 96 return 0xffffffff; 97 else 98 return (1 << depth) - 1; 99} 100 101static inline uint32_t color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) 102{ 103 uint16_t ra = red * alpha; 104 uint16_t ga = green * alpha; 105 uint16_t ba = blue * alpha; 106 107 return alpha << 24 | ra >> 8 << 16 | ga >> 8 << 8 | ba >> 8; 108} 109 110void test_timer_start(struct test_display *t, struct timespec *tv); 111double test_timer_stop(struct test_display *t, struct timespec *tv); 112 113#ifndef MAX 114#define MAX(a,b) ((a) > (b) ? (a) : (b)) 115#endif 116 117#ifndef ARRAY_SIZE 118#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 119#endif 120 121#define SETS(I) ((I) >= 12 ? 1 : 1 << (12 - (I))) 122#define REPS(I) (1 << (I)) 123 124#endif 125