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
|
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xutil.h> /* for XDestroyImage */
#include "test.h"
static void fill_rect(struct test_display *t,
Picture p,
XRenderPictFormat *format,
int use_window, int tx, int ty,
uint8_t op, int x, int y, int w, int h,
int mask_x, int mask_y, int mask_w, int mask_h,
uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
{
Drawable tmp;
Pixmap pixmask;
XRenderColor c;
Picture src, mask;
if (use_window) {
XSetWindowAttributes attr;
attr.override_redirect = 1;
tmp = XCreateWindow(t->dpy, DefaultRootWindow(t->dpy),
tx, ty,
w, h,
0, format->depth,
InputOutput,
DefaultVisual(t->dpy,
DefaultScreen(t->dpy)),
CWOverrideRedirect, &attr);
XMapWindow(t->dpy, tmp);
} else
tmp = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
w, h, format->depth);
pixmask = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy), w, h, 8);
mask = XRenderCreatePicture(t->dpy, pixmask,
XRenderFindStandardFormat(t->dpy, PictStandardA8),
0, NULL);
c.red = c.green = c.blue = c.alpha = 0;
XRenderFillRectangle(t->dpy, PictOpSrc, mask, &c,
0, 0, w, h);
c.red = c.green = c.blue = c.alpha = 0xffff;
XRenderFillRectangle(t->dpy, PictOpSrc, mask, &c,
mask_x, mask_y, mask_w, mask_h);
src = XRenderCreatePicture(t->dpy, tmp, format, 0, NULL);
c.red = red * alpha;
c.green = green * alpha;
c.blue = blue * alpha;
c.alpha = alpha << 8 | alpha;
XRenderFillRectangle(t->dpy, PictOpSrc, src, &c, 0, 0, w, h);
XRenderComposite(t->dpy, op, src, mask, p, 0, 0, 0, 0, x, y, w, h);
XRenderFreePicture(t->dpy, src);
if (use_window)
XDestroyWindow(t->dpy, tmp);
else
XFreePixmap(t->dpy, tmp);
XRenderFreePicture(t->dpy, mask);
XFreePixmap(t->dpy, pixmask);
}
static void clear(struct test_display *dpy, struct test_target *tt)
{
XRenderColor render_color = {0};
XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
0, 0, tt->width, tt->height);
}
static void rect_tests(struct test *t, int reps, int sets, enum target target, int use_window)
{
struct test_target real, ref;
int r, s;
printf("Testing area fills (%s, using %s source): ",
test_target_name(target), use_window ? "window" : "pixmap");
fflush(stdout);
test_target_create_render(&t->real, target, &real);
clear(&t->real, &real);
test_target_create_render(&t->ref, target, &ref);
clear(&t->ref, &ref);
for (s = 0; s < sets; s++) {
for (r = 0; r < reps; r++) {
int x, y, w, h;
int mask_x, mask_y, mask_w, mask_h;
int tmpx, tmpy;
uint8_t red = rand();
uint8_t green = rand();
uint8_t blue = rand();
uint8_t alpha = rand();
int try = 50;
do {
x = rand() % (real.width - 1);
y = rand() % (real.height - 1);
w = 1 + rand() % (real.width - x - 1);
h = 1 + rand() % (real.height - y - 1);
tmpx = w == real.width ? 0 : rand() % (real.width - w);
tmpy = h == real.height ? 0 : rand() % (real.height - h);
} while (((tmpx+w > x && tmpx < x+w) ||
(tmpy+h > y && tmpy < y+h)) &&
--try);
mask_x = (rand() % (2*w)) - w;
mask_y = (rand() % (2*h)) - h;
mask_w = rand() % w;
mask_h = rand() % h;
if (try) {
fill_rect(&t->real, real.picture, real.format,
use_window, tmpx, tmpy,
PictOpSrc, x, y, w, h,
mask_x, mask_y, mask_w, mask_h,
red, green, blue, alpha);
fill_rect(&t->ref, ref.picture, ref.format,
use_window, tmpx, tmpy,
PictOpSrc, x, y, w, h,
mask_x, mask_y, mask_w, mask_h,
red, green, blue, alpha);
}
}
test_compare(t,
real.draw, real.format,
ref.draw, ref.format,
0, 0, real.width, real.height,
"");
}
printf("passed [%d iterations x %d]\n", reps, sets);
test_target_destroy_render(&t->real, &real);
test_target_destroy_render(&t->ref, &ref);
}
int main(int argc, char **argv)
{
struct test test;
int i;
test_init(&test, argc, argv);
for (i = 0; i <= DEFAULT_ITERATIONS; i++) {
int reps = REPS(i), sets = SETS(i);
enum target t;
for (t = TARGET_FIRST; t <= TARGET_LAST; t++) {
rect_tests(&test, reps, sets, t, 0);
if (t != PIXMAP)
rect_tests(&test, reps, sets, t, 1);
}
}
return 0;
}
|