test.h revision 03b705cf
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 width, height;
35		XRenderPictFormat *format;
36	} real, ref;
37};
38
39void die(const char *fmt, ...);
40
41#define die_unless(expr) do{ if (!(expr)) die("verification failed: %s\n", #expr); } while(0)
42
43void test_init(struct test *test, int argc, char **argv);
44
45void test_compare(struct test *real,
46		  Drawable real_draw, XRenderPictFormat *real_format,
47		  Drawable ref_draw, XRenderPictFormat *ref_format,
48		  int x, int y, int w, int h, const char *info);
49
50#define MAX_DELTA 3
51int pixel_difference(uint32_t a, uint32_t b);
52
53static inline int pixel_equal(int depth, uint32_t a, uint32_t b)
54{
55	uint32_t mask;
56
57	if (depth == 32)
58		mask = 0xffffffff;
59	else
60		mask = (1 << depth) - 1;
61
62	a &= mask;
63	b &= mask;
64
65	if (a == b)
66		return 1;
67
68	return pixel_difference(a, b) < MAX_DELTA;
69}
70
71void
72test_init_image(XImage *ximage,
73		XShmSegmentInfo *shm,
74		XRenderPictFormat *format,
75		int width, int height);
76
77const char *test_target_name(enum target target);
78
79struct test_target {
80	struct test_display *dpy;
81	Drawable draw;
82	GC gc;
83	XRenderPictFormat *format;
84	Picture picture;
85	int width, height;
86	enum target target;
87};
88
89void test_target_create_render(struct test_display *dpy,
90			       enum target target,
91			       struct test_target *tt);
92void test_target_destroy_render(struct test_display *dpy,
93				struct test_target *tt);
94
95static inline uint32_t depth_mask(int depth)
96{
97	if (depth == 32)
98		return 0xffffffff;
99	else
100		return (1 << depth) - 1;
101}
102
103static inline uint32_t color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
104{
105	uint16_t ra = red * alpha;
106	uint16_t ga = green * alpha;
107	uint16_t ba = blue * alpha;
108
109	return alpha << 24 | ra >> 8 << 16 | ga >> 8 << 8 | ba >> 8;
110}
111
112void test_timer_start(struct test_display *t, struct timespec *tv);
113double test_timer_stop(struct test_display *t, struct timespec *tv);
114
115#ifndef MAX
116#define MAX(a,b) ((a) > (b) ? (a) : (b))
117#endif
118
119#ifndef ARRAY_SIZE
120#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
121#endif
122
123#endif
124