summaryrefslogtreecommitdiff
path: root/rendercheck.h
blob: 18417a8efa7ba38774657ce3c2de8427e950543e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
 * Copyright © 2004 Eric Anholt
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Eric Anholt not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Eric Anholt makes no
 * representations about the suitability of this software for any purpose.  It
 * is provided "as is" without express or implied warranty.
 *
 * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL ERIC ANHOLT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
#include <stdio.h>

#if HAVE_ERR_H
# include <err.h>
#else
# include <stdarg.h>
# include <stdlib.h>
static inline void errx(int eval, const char *fmt, ...) {
    va_list args;

    va_start(args, fmt);
    fprintf(stderr, "Fatal Error: ");
    fprintf(stderr, fmt, args);
    fprintf(stderr, "\n", args);
    va_end(args);
    exit(eval);
}
#endif

#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

typedef struct _color4d
{
	double r, g, b, a;
} color4d;

typedef struct _picture_info {
	Drawable d;
	Picture pict;
	XRenderPictFormat *format;
	char *name;		/* Possibly, some descriptive name. */
	color4d color;		/* If a 1x1R pict, the (corrected) color.*/
} picture_info;

struct op_info {
	int op;
	char *name;
	Bool disabled;
};

#define TEST_FILL		0x0001
#define TEST_DSTCOORDS		0x0002
#define TEST_SRCCOORDS		0x0004
#define TEST_MASKCOORDS		0x0008
#define TEST_TSRCCOORDS		0x0010
#define TEST_TMASKCOORDS	0x0020
#define TEST_BLEND		0x0040
#define TEST_COMPOSITE		0x0080
#define TEST_CACOMPOSITE	0x0100
#define TEST_GRADIENTS  	0x0200
#define TEST_REPEAT	  	0x0400
#define TEST_TRIANGLES  	0x0800
#define TEST_BUG7366		0x1000

extern int pixmap_move_iter;
extern int win_width, win_height;
extern struct op_info ops[];
extern Bool is_verbose, minimalrendering;
extern color4d colors[];
extern int enabled_tests;
extern int format_whitelist_len;
extern char **format_whitelist;
extern picture_info *argb32white, *argb32red, *argb32green, *argb32blue;
extern int num_ops;
extern int num_colors;

/* main.c */
void
describe_format(char *desc, int len, XRenderPictFormat *format);

int
bit_count(int i);

void
print_tests(FILE *file, int tests);

/* tests.c */
void
color_correct(picture_info *pi, color4d *color);

void
get_pixel(Display *dpy,
	  const picture_info *pi,
	  int x, int y,
	  color4d *color);

void
get_pixel_from_image(XImage *image,
		     const picture_info *pi,
		     int x, int y,
		     color4d *color);

void
accuracy(XRenderDirectFormat *result,
	 const XRenderDirectFormat *a,
	 const XRenderDirectFormat *b);

double
eval_diff(const XRenderDirectFormat *accuracy,
	  const color4d *expected,
	  const color4d *test);

void print_fail(const char *name,
		const color4d *expected,
		const color4d *test,
		int x, int y,
		double d);

void print_pass(const char *name,
		const color4d *expected,
		int x, int y,
		double d);

void
argb_fill(Display *dpy, picture_info *p, int x, int y, int w, int h, float a,
    float r, float g, float b);

Bool
do_tests(Display *dpy, picture_info *win);

void
copy_pict_to_win(Display *dpy, picture_info *pict, picture_info *win,
    int width, int height);

/* ops.c */
void
do_composite(int op,
	     const color4d *src,
	     const color4d *mask,
	     const color4d *dst,
	     color4d *result,
	     Bool componentAlpha);

/* The tests */
Bool
blend_test(Display *dpy, picture_info *win, picture_info *dst,
	   const int *op, int num_op,
	   const picture_info **src_color, int num_src,
	   const picture_info **dst_color, int num_dst);

Bool
composite_test(Display *dpy, picture_info *win, picture_info *dst,
	       const int *op, int num_op,
	       const picture_info **src_color, int num_src,
	       const picture_info **mask_color, int num_mask,
	       const picture_info **dst_color, int num_dst,
	       Bool componentAlpha);

Bool
dstcoords_test(Display *dpy, picture_info *win, int op, picture_info *dst,
    picture_info *bg, picture_info *fg);

Bool
fill_test(Display *dpy, picture_info *win, picture_info *src);

Bool
srccoords_test(Display *dpy, picture_info *win, picture_info *white,
    Bool test_mask);

Bool
trans_coords_test(Display *dpy, picture_info *win, picture_info *white,
    Bool test_mask);

Bool
trans_srccoords_test_2(Display *dpy, picture_info *win, picture_info *white,
    Bool test_mask);

Bool render_to_gradient_test(Display *dpy, picture_info *src);

Bool linear_gradient_test(Display *dpy, picture_info *win,
                          picture_info *dst, int op, picture_info *dst_color);

Bool
repeat_test(Display *dpy, picture_info *win, picture_info *dst, int op,
    picture_info *dst_color, picture_info *c1, picture_info *c2,
    Bool test_mask);

Bool
triangles_test(Display *dpy, picture_info *win, picture_info *dst, int op,
    picture_info *src_color, picture_info *dst_color);

Bool
tristrip_test(Display *dpy, picture_info *win, picture_info *dst, int op,
    picture_info *src_color, picture_info *dst_color);

Bool
trifan_test(Display *dpy, picture_info *win, picture_info *dst, int op,
    picture_info *src_color, picture_info *dst_color);

Bool
bug7366_test(Display *dpy);