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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
#include <stdbool.h>
#ifndef SNA_TRAPEZOIDS_H
#define SNA_TRAPEZOIDS_H
#define NO_ACCEL 0
#define FORCE_FALLBACK 0
#define NO_ALIGNED_BOXES 0
#define NO_UNALIGNED_BOXES 0
#define NO_SCAN_CONVERTER 0
#define NO_GPU_THREADS 0
#define NO_IMPRECISE 0
#define NO_PRECISE 0
#if 0
#define __DBG DBG
#else
#define __DBG(x)
#endif
bool
composite_aligned_boxes(struct sna *sna,
CARD8 op,
PicturePtr src,
PicturePtr dst,
PictFormatPtr maskFormat,
INT16 src_x, INT16 src_y,
int ntrap, const xTrapezoid *traps,
bool force_fallback);
bool
composite_unaligned_boxes(struct sna *sna,
CARD8 op,
PicturePtr src,
PicturePtr dst,
PictFormatPtr maskFormat,
INT16 src_x, INT16 src_y,
int ntrap, const xTrapezoid *traps,
bool force_fallback);
bool
mono_trapezoids_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps);
bool
mono_trapezoid_span_inplace(struct sna *sna,
CARD8 op,
PicturePtr src,
PicturePtr dst,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps);
bool
mono_trap_span_converter(struct sna *sna,
PicturePtr dst,
INT16 x, INT16 y,
int ntrap, xTrap *traps);
bool
mono_triangles_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
INT16 src_x, INT16 src_y,
int count, xTriangle *tri);
bool
imprecise_trapezoid_span_inplace(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps,
bool fallback);
bool
imprecise_trapezoid_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned int flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps);
bool
imprecise_trapezoid_mask_converter(CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps);
bool
imprecise_trapezoid_span_fallback(CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps);
bool
precise_trapezoid_span_inplace(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps,
bool fallback);
bool
precise_trapezoid_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned int flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps);
bool
precise_trapezoid_mask_converter(CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps);
bool
precise_trapezoid_span_fallback(CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps);
static inline bool is_mono(PicturePtr dst, PictFormatPtr mask)
{
return mask ? mask->depth < 8 : dst->polyEdge==PolyEdgeSharp;
}
static inline bool is_precise(PicturePtr dst, PictFormatPtr mask)
{
return dst->polyMode == PolyModePrecise && !is_mono(dst, mask);
}
static inline bool
trapezoid_span_inplace(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps,
bool fallback)
{
if (NO_SCAN_CONVERTER)
return false;
if (dst->alphaMap) {
DBG(("%s: fallback -- dst alphamap\n",
__FUNCTION__));
return false;
}
if (!fallback && is_gpu(sna, dst->pDrawable, PREFER_GPU_SPANS)) {
DBG(("%s: fallback -- can not perform operation in place, destination busy\n",
__FUNCTION__));
return false;
}
if (is_mono(dst, maskFormat))
return mono_trapezoid_span_inplace(sna, op, src, dst, src_x, src_y, ntrap, traps);
else if (is_precise(dst, maskFormat))
return precise_trapezoid_span_inplace(sna, op, src, dst, maskFormat, flags, src_x, src_y, ntrap, traps, fallback);
else
return imprecise_trapezoid_span_inplace(sna, op, src, dst, maskFormat, flags, src_x, src_y, ntrap, traps, fallback);
}
static inline bool
trapezoid_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned int flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps)
{
if (NO_SCAN_CONVERTER)
return false;
if (is_mono(dst, maskFormat))
return mono_trapezoids_span_converter(sna, op, src, dst, src_x, src_y, ntrap, traps);
else if (is_precise(dst, maskFormat))
return precise_trapezoid_span_converter(sna, op, src, dst, maskFormat, flags, src_x, src_y, ntrap, traps);
else
return imprecise_trapezoid_span_converter(sna, op, src, dst, maskFormat, flags, src_x, src_y, ntrap, traps);
}
static inline bool
trapezoid_mask_converter(CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps)
{
if (NO_SCAN_CONVERTER)
return false;
if (is_precise(dst, maskFormat))
return precise_trapezoid_mask_converter(op, src, dst, maskFormat, flags, src_x, src_y, ntrap, traps);
else
return imprecise_trapezoid_mask_converter(op, src, dst, maskFormat, flags, src_x, src_y, ntrap, traps);
}
static inline bool
trapezoid_span_fallback(CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, unsigned flags,
INT16 src_x, INT16 src_y,
int ntrap, xTrapezoid *traps)
{
if (NO_SCAN_CONVERTER)
return false;
if (is_precise(dst, maskFormat))
return precise_trapezoid_span_fallback(op, src, dst, maskFormat, flags, src_x, src_y, ntrap, traps);
else
return imprecise_trapezoid_span_fallback(op, src, dst, maskFormat, flags, src_x, src_y, ntrap, traps);
}
bool
trap_span_converter(struct sna *sna,
PicturePtr dst,
INT16 src_x, INT16 src_y,
int ntrap, xTrap *trap);
bool
trap_mask_converter(struct sna *sna,
PicturePtr picture,
INT16 x, INT16 y,
int ntrap, xTrap *trap);
bool
triangles_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
int count, xTriangle *tri);
bool
triangles_mask_converter(CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
int count, xTriangle *tri);
bool
mono_tristrip_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
INT16 src_x, INT16 src_y,
int count, xPointFixed *points);
bool
imprecise_tristrip_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
int count, xPointFixed *points);
bool
precise_tristrip_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
int count, xPointFixed *points);
static inline bool
tristrip_span_converter(struct sna *sna,
CARD8 op, PicturePtr src, PicturePtr dst,
PictFormatPtr maskFormat, INT16 src_x, INT16 src_y,
int count, xPointFixed *points)
{
if (NO_SCAN_CONVERTER)
return false;
if (is_mono(dst, maskFormat))
return mono_tristrip_span_converter(sna, op, src, dst, src_x, src_y, count, points);
else if (is_precise(dst, maskFormat))
return precise_tristrip_span_converter(sna, op, src, dst, maskFormat, src_x, src_y, count, points);
else
return imprecise_tristrip_span_converter(sna, op, src, dst, maskFormat, src_x, src_y, count, points);
}
inline static void trapezoid_origin(const xLineFixed *l, int16_t *x, int16_t *y)
{
if (l->p1.y < l->p2.y) {
*x = pixman_fixed_to_int(l->p1.x);
*y = pixman_fixed_to_int(l->p1.y);
} else {
*x = pixman_fixed_to_int(l->p2.x);
*y = pixman_fixed_to_int(l->p2.y);
}
}
#define ONE_HALF 0x7f
#define RB_MASK 0x00ff00ff
#define RB_ONE_HALF 0x007f007f
#define RB_MASK_PLUS_ONE 0x01000100
#define G_SHIFT 8
static force_inline uint32_t
mul8x2_8 (uint32_t a, uint8_t b)
{
uint32_t t = (a & RB_MASK) * b + RB_ONE_HALF;
return ((t + ((t >> G_SHIFT) & RB_MASK)) >> G_SHIFT) & RB_MASK;
}
static force_inline uint32_t
add8x2_8x2(uint32_t a, uint32_t b)
{
uint32_t t = a + b;
t |= RB_MASK_PLUS_ONE - ((t >> G_SHIFT) & RB_MASK);
return t & RB_MASK;
}
static force_inline uint32_t
lerp8x4(uint32_t src, uint8_t a, uint32_t dst)
{
return (add8x2_8x2(mul8x2_8(src, a),
mul8x2_8(dst, ~a)) |
add8x2_8x2(mul8x2_8(src >> G_SHIFT, a),
mul8x2_8(dst >> G_SHIFT, ~a)) << G_SHIFT);
}
static force_inline uint8_t
mul_8_8(uint8_t a, uint8_t b)
{
uint16_t t = a * (uint16_t)b + 0x7f;
return ((t >> 8) + t) >> 8;
}
static inline uint32_t multa(uint32_t s, uint8_t a, int shift)
{
return mul_8_8((s >> shift) & 0xff, a) << shift;
}
static inline uint32_t mul_4x8_8(uint32_t color, uint8_t alpha)
{
uint32_t v;
v = 0;
v |= multa(color, alpha, 24);
v |= multa(color, alpha, 16);
v |= multa(color, alpha, 8);
v |= multa(color, alpha, 0);
return v;
}
static inline bool
xTriangleValid(const xTriangle *t)
{
xPointFixed v1, v2;
v1.x = t->p2.x - t->p1.x;
v1.y = t->p2.y - t->p1.y;
v2.x = t->p3.x - t->p1.x;
v2.y = t->p3.y - t->p1.y;
/* if the length of any edge is zero, the area must be zero */
if (v1.x == 0 && v1.y == 0)
return false;
if (v2.x == 0 && v2.y == 0)
return false;
/* if the cross-product is zero, so it the size */
return v2.y * v1.x != v1.y * v2.x;
}
#define SAMPLES_X 17
#define SAMPLES_Y 15
#define FAST_SAMPLES_shift 2
#define FAST_SAMPLES_X (1<<FAST_SAMPLES_shift)
#define FAST_SAMPLES_Y (1<<FAST_SAMPLES_shift)
#define FAST_SAMPLES_mask ((1<<FAST_SAMPLES_shift)-1)
#define pixman_fixed_integer_floor(V) pixman_fixed_to_int(V)
#define pixman_fixed_integer_ceil(V) pixman_fixed_to_int(pixman_fixed_ceil(V))
static inline int pixman_fixed_to_fast(pixman_fixed_t v)
{
return (v + ((1<<(16-FAST_SAMPLES_shift-1))-1)) >> (16 - FAST_SAMPLES_shift);
}
bool trapezoids_bounds(int n, const xTrapezoid *t, BoxPtr box);
#define TOR_INPLACE_SIZE 128
#endif /* SNA_TRAPEZOIDS_H */
|