103b705cfSriastradh#ifndef TEST_H
203b705cfSriastradh#define TEST_H
303b705cfSriastradh
403b705cfSriastradh#include <stdint.h>
503b705cfSriastradh#include <time.h>
603b705cfSriastradh
703b705cfSriastradh#include <X11/Xlib.h>
803b705cfSriastradh#include <X11/extensions/XShm.h>
903b705cfSriastradh#include <X11/extensions/Xrender.h>
1003b705cfSriastradh
1103b705cfSriastradh#define DEFAULT_ITERATIONS 20
1203b705cfSriastradh
1303b705cfSriastradhenum target {
1403b705cfSriastradh	ROOT,
1503b705cfSriastradh	CHILD,
1603b705cfSriastradh	PIXMAP,
1703b705cfSriastradh};
1803b705cfSriastradh#define TARGET_FIRST ROOT
1903b705cfSriastradh#define TARGET_LAST PIXMAP
2003b705cfSriastradh
2103b705cfSriastradhenum mask {
2203b705cfSriastradh	MASK_NONE,
2303b705cfSriastradh	MASK_NONE_AA,
2403b705cfSriastradh	MASK_A1,
2503b705cfSriastradh	MASK_A8,
2603b705cfSriastradh};
2703b705cfSriastradh
2803b705cfSriastradhstruct test {
2903b705cfSriastradh	struct test_display {
3003b705cfSriastradh		Display *dpy;
3103b705cfSriastradh		Window root;
3203b705cfSriastradh		XShmSegmentInfo shm;
3303b705cfSriastradh		int max_shm_size;
3442542f5fSchristos		int has_shm_pixmaps;
3542542f5fSchristos		int width, height, depth;
3603b705cfSriastradh		XRenderPictFormat *format;
3742542f5fSchristos		enum { REF, OUT } target;
3842542f5fSchristos	} out, ref;
3903b705cfSriastradh};
4003b705cfSriastradh
4103b705cfSriastradhvoid die(const char *fmt, ...);
4203b705cfSriastradh
4303b705cfSriastradh#define die_unless(expr) do{ if (!(expr)) die("verification failed: %s\n", #expr); } while(0)
4403b705cfSriastradh
4503b705cfSriastradhvoid test_init(struct test *test, int argc, char **argv);
4603b705cfSriastradh
4742542f5fSchristosvoid test_compare(struct test *out,
4842542f5fSchristos		  Drawable out_draw, XRenderPictFormat *out_format,
4903b705cfSriastradh		  Drawable ref_draw, XRenderPictFormat *ref_format,
5003b705cfSriastradh		  int x, int y, int w, int h, const char *info);
5103b705cfSriastradh
5203b705cfSriastradh#define MAX_DELTA 3
5303b705cfSriastradhint pixel_difference(uint32_t a, uint32_t b);
5403b705cfSriastradh
5503b705cfSriastradhstatic inline int pixel_equal(int depth, uint32_t a, uint32_t b)
5603b705cfSriastradh{
5742542f5fSchristos	if (depth != 32) {
5842542f5fSchristos		uint32_t mask = (1 << depth) - 1;
5942542f5fSchristos		a &= mask;
6042542f5fSchristos		b &= mask;
6142542f5fSchristos	}
6203b705cfSriastradh
6303b705cfSriastradh	if (a == b)
6403b705cfSriastradh		return 1;
6503b705cfSriastradh
6603b705cfSriastradh	return pixel_difference(a, b) < MAX_DELTA;
6703b705cfSriastradh}
6803b705cfSriastradh
6903b705cfSriastradhvoid
7003b705cfSriastradhtest_init_image(XImage *ximage,
7103b705cfSriastradh		XShmSegmentInfo *shm,
7203b705cfSriastradh		XRenderPictFormat *format,
7303b705cfSriastradh		int width, int height);
7403b705cfSriastradh
7503b705cfSriastradhconst char *test_target_name(enum target target);
7603b705cfSriastradh
7703b705cfSriastradhstruct test_target {
7803b705cfSriastradh	struct test_display *dpy;
7903b705cfSriastradh	Drawable draw;
8003b705cfSriastradh	GC gc;
8103b705cfSriastradh	XRenderPictFormat *format;
8203b705cfSriastradh	Picture picture;
8342542f5fSchristos	int width, height, depth;
8403b705cfSriastradh	enum target target;
8503b705cfSriastradh};
8603b705cfSriastradh
8703b705cfSriastradhvoid test_target_create_render(struct test_display *dpy,
8803b705cfSriastradh			       enum target target,
8903b705cfSriastradh			       struct test_target *tt);
9003b705cfSriastradhvoid test_target_destroy_render(struct test_display *dpy,
9103b705cfSriastradh				struct test_target *tt);
9203b705cfSriastradh
9303b705cfSriastradhstatic inline uint32_t depth_mask(int depth)
9403b705cfSriastradh{
9503b705cfSriastradh	if (depth == 32)
9603b705cfSriastradh		return 0xffffffff;
9703b705cfSriastradh	else
9803b705cfSriastradh		return (1 << depth) - 1;
9903b705cfSriastradh}
10003b705cfSriastradh
10103b705cfSriastradhstatic inline uint32_t color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
10203b705cfSriastradh{
10303b705cfSriastradh	uint16_t ra = red * alpha;
10403b705cfSriastradh	uint16_t ga = green * alpha;
10503b705cfSriastradh	uint16_t ba = blue * alpha;
10603b705cfSriastradh
10703b705cfSriastradh	return alpha << 24 | ra >> 8 << 16 | ga >> 8 << 8 | ba >> 8;
10803b705cfSriastradh}
10903b705cfSriastradh
110fe8aea9eSmrgstatic inline uint32_t xrender_color(const XRenderColor *c)
111fe8aea9eSmrg{
112fe8aea9eSmrg	uint32_t ra = c->red * c->alpha;
113fe8aea9eSmrg	uint32_t ga = c->green * c->alpha;
114fe8aea9eSmrg	uint32_t ba = c->blue * c->alpha;
115fe8aea9eSmrg
116fe8aea9eSmrg	return c->alpha >> 8 << 24 | ra >> 24 << 16 | ga >> 24 << 8 | ba >> 24;
117fe8aea9eSmrg}
118fe8aea9eSmrg
11903b705cfSriastradhvoid test_timer_start(struct test_display *t, struct timespec *tv);
12003b705cfSriastradhdouble test_timer_stop(struct test_display *t, struct timespec *tv);
12103b705cfSriastradh
12203b705cfSriastradh#ifndef MAX
12303b705cfSriastradh#define MAX(a,b) ((a) > (b) ? (a) : (b))
12403b705cfSriastradh#endif
12503b705cfSriastradh
12603b705cfSriastradh#ifndef ARRAY_SIZE
12703b705cfSriastradh#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
12803b705cfSriastradh#endif
12903b705cfSriastradh
13042542f5fSchristos#define SETS(I) ((I) >= 12 ? 1 : 1 << (12 - (I)))
13142542f5fSchristos#define REPS(I) (1 << (I))
13242542f5fSchristos
13303b705cfSriastradh#endif
134