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
|
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "test.h"
enum edge {
EDGE_SHARP = PolyEdgeSharp,
EDGE_SMOOTH,
};
static void set_edge(Display *dpy, Picture p, enum edge edge)
{
XRenderPictureAttributes a;
a.poly_edge = edge;
XRenderChangePicture(dpy, p, CPPolyEdge, &a);
}
static XRenderPictFormat *mask_format(Display *dpy, enum mask mask)
{
switch (mask) {
default:
case MASK_NONE: return NULL;
case MASK_A1: return XRenderFindStandardFormat(dpy, PictStandardA1);
case MASK_A8: return XRenderFindStandardFormat(dpy, PictStandardA8);
}
}
static const char *mask_name(enum mask mask)
{
switch (mask) {
default:
case MASK_NONE: return "none";
case MASK_A1: return "a1";
case MASK_A8: return "a8";
}
}
static const char *edge_name(enum edge edge)
{
switch (edge) {
default:
case EDGE_SHARP: return "sharp";
case EDGE_SMOOTH: return "smooth";
}
}
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 step_to_point(int step, int width, int height, XPointFixed *p)
{
do {
p->x = (step - 64) << 16;
p->y = -64 << 16;
step -= width - 128;
if (step <= 0)
return;
p->x = (width + 64) << 16;
p->y = (step - 64) << 16;
step -= height - 128;
if (step <= 0)
return;
p->x = (width + 64 - step) << 16;
p->y = (height + 64) << 16;
step -= width - 128;
if (step <= 0)
return;
p->x = -64 << 16;
p->y = (height + 64 - step) << 16;
step -= height - 128;
} while (step > 0);
}
static void edge_test(struct test *t,
enum mask mask,
enum edge edge,
enum target target)
{
struct test_target out, ref;
XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
Picture src_ref, src_out;
XTriangle tri;
unsigned step, max;
test_target_create_render(&t->out, target, &out);
set_edge(t->out.dpy, out.picture, edge);
src_out = XRenderCreateSolidFill(t->out.dpy, &white);
test_target_create_render(&t->ref, target, &ref);
set_edge(t->ref.dpy, ref.picture, edge);
src_ref = XRenderCreateSolidFill(t->ref.dpy, &white);
printf("Testing edges (with mask %s and %s edges) (%s): ",
mask_name(mask),
edge_name(edge),
test_target_name(target));
fflush(stdout);
max = 2*(out.width + 128 + out.height+128);
step = 0;
for (step = 0; step <= max; step++) {
char buf[80];
step_to_point(step, out.width, out.height, &tri.p1);
step_to_point(step + out.width + 128,
out.width, out.height,
&tri.p2);
step_to_point(step + out.height + 128 + 2*(out.width + 128),
out.width, out.height,
&tri.p3);
sprintf(buf,
"tri=((%d, %d), (%d, %d), (%d, %d))\n",
tri.p1.x >> 16, tri.p1.y >> 16,
tri.p2.x >> 16, tri.p2.y >> 16,
tri.p3.x >> 16, tri.p3.y >> 16);
clear(&t->out, &out);
XRenderCompositeTriangles(t->out.dpy,
PictOpSrc,
src_out,
out.picture,
mask_format(t->out.dpy, mask),
0, 0,
&tri, 1);
clear(&t->ref, &ref);
XRenderCompositeTriangles(t->ref.dpy,
PictOpSrc,
src_ref,
ref.picture,
mask_format(t->ref.dpy, mask),
0, 0,
&tri, 1);
test_compare(t,
out.draw, out.format,
ref.draw, ref.format,
0, 0, out.width, out.height,
buf);
}
XRenderFreePicture(t->out.dpy, src_out);
test_target_destroy_render(&t->out, &out);
XRenderFreePicture(t->ref.dpy, src_ref);
test_target_destroy_render(&t->ref, &ref);
printf("pass\n");
}
int main(int argc, char **argv)
{
struct test test;
enum target target;
enum mask mask;
enum edge edge;
test_init(&test, argc, argv);
for (target = TARGET_FIRST; target <= TARGET_LAST; target++) {
for (mask = MASK_NONE; mask <= MASK_A8; mask++)
for (edge = EDGE_SHARP; edge <= EDGE_SMOOTH; edge++)
edge_test(&test, mask, edge, target);
}
return 0;
}
|