VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/x11include/xorg-server-1.6.99-20090831/fbpict.h@ 32224

Last change on this file since 32224 was 22658, checked in by vboxsync, 15 years ago

export Xorg 1.6.99 headers to OSE

  • Property svn:eol-style set to native
File size: 18.3 KB
Line 
1/*
2 *
3 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Keith Packard not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission. Keith Packard makes no
12 * representations about the suitability of this software for any purpose. It
13 * is provided "as is" without express or implied warranty.
14 *
15 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#ifdef HAVE_DIX_CONFIG_H
25#include <dix-config.h>
26#endif
27
28#ifndef _FBPICT_H_
29#define _FBPICT_H_
30
31#include "renderedge.h"
32
33
34#if defined(__GNUC__)
35#define INLINE __inline__
36#else
37#define INLINE
38#endif
39
40#define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
41#define FbIntDiv(a,b) (((CARD16) (a) * 255) / (b))
42
43#define FbGet8(v,i) ((CARD16) (CARD8) ((v) >> i))
44
45/*
46 * There are two ways of handling alpha -- either as a single unified value or
47 * a separate value for each component, hence each macro must have two
48 * versions. The unified alpha version has a 'U' at the end of the name,
49 * the component version has a 'C'. Similarly, functions which deal with
50 * this difference will have two versions using the same convention.
51 */
52
53#define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i),\
54 (CARD32) ((CARD8) ((t) | (0 - ((t) >> 8)))) << (i))
55
56#define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i),\
57 (CARD32) ((CARD8) ((t) | (0 - ((t) >> 8)))) << (i))
58
59#define FbInU(x,i,a,t) ((CARD32) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
60
61#define FbInC(x,i,a,t) ((CARD32) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
62
63#define FbGen(x,y,i,ax,ay,t,u,v) ((t) = (FbIntMult(FbGet8(y,i),ay,(u)) + \
64 FbIntMult(FbGet8(x,i),ax,(v))),\
65 (CARD32) ((CARD8) ((t) | \
66 (0 - ((t) >> 8)))) << (i))
67
68#define FbAdd(x,y,i,t) ((t) = FbGet8(x,i) + FbGet8(y,i), \
69 (CARD32) ((CARD8) ((t) | (0 - ((t) >> 8)))) << (i))
70
71
72#define Alpha(x) ((x) >> 24)
73#define Red(x) (((x) >> 16) & 0xff)
74#define Green(x) (((x) >> 8) & 0xff)
75#define Blue(x) ((x) & 0xff)
76
77/**
78 * Returns TRUE if the fbComposeGetSolid can be used to get a single solid
79 * color representing every source sampling location of the picture.
80 */
81static INLINE Bool
82fbCanGetSolid(PicturePtr pict)
83{
84 if (pict->pDrawable == NULL ||
85 pict->pDrawable->width != 1 ||
86 pict->pDrawable->height != 1)
87 {
88 return FALSE;
89 }
90 if (pict->repeat != RepeatNormal)
91 return FALSE;
92
93 switch (pict->format) {
94 case PICT_a8r8g8b8:
95 case PICT_x8r8g8b8:
96 case PICT_a8b8g8r8:
97 case PICT_x8b8g8r8:
98 case PICT_b8g8r8a8:
99 case PICT_b8g8r8x8:
100 case PICT_r8g8b8:
101 case PICT_b8g8r8:
102 case PICT_r5g6b5:
103 case PICT_b5g6r5:
104 return TRUE;
105 default:
106 return FALSE;
107 }
108}
109
110#define fbComposeGetSolid(pict, bits, fmt) { \
111 FbBits *__bits__; \
112 FbStride __stride__; \
113 int __bpp__; \
114 int __xoff__,__yoff__; \
115\
116 fbGetDrawable((pict)->pDrawable,__bits__,__stride__,__bpp__,__xoff__,__yoff__); \
117 switch (__bpp__) { \
118 case 32: \
119 (bits) = READ((CARD32 *) __bits__); \
120 break; \
121 case 24: \
122 (bits) = Fetch24 ((CARD8 *) __bits__); \
123 break; \
124 case 16: \
125 (bits) = READ((CARD16 *) __bits__); \
126 (bits) = cvt0565to0888(bits); \
127 break; \
128 case 8: \
129 (bits) = READ((CARD8 *) __bits__); \
130 (bits) = (bits) << 24; \
131 break; \
132 case 1: \
133 (bits) = READ((CARD32 *) __bits__); \
134 (bits) = FbLeftStipBits((bits),1) ? 0xff000000 : 0x00000000;\
135 break; \
136 default: \
137 return; \
138 } \
139 /* If necessary, convert RGB <--> BGR. */ \
140 if (PICT_FORMAT_TYPE((pict)->format) != PICT_FORMAT_TYPE(fmt)) \
141 { \
142 (bits) = (((bits) & 0xff000000) | \
143 (((bits) & 0x00ff0000) >> 16) | \
144 (((bits) & 0x0000ff00) >> 0) | \
145 (((bits) & 0x000000ff) << 16)); \
146 } \
147 /* manage missing src alpha */ \
148 if ((pict)->pFormat->direct.alphaMask == 0) \
149 (bits) |= 0xff000000; \
150 fbFinishAccess ((pict)->pDrawable); \
151}
152
153#define fbComposeGetStart(pict,x,y,type,stride,line,mul) {\
154 FbBits *__bits__; \
155 FbStride __stride__; \
156 int __bpp__; \
157 int __xoff__,__yoff__; \
158\
159 fbGetDrawable((pict)->pDrawable,__bits__,__stride__,__bpp__,__xoff__,__yoff__); \
160 (stride) = __stride__ * sizeof (FbBits) / sizeof (type); \
161 (line) = ((type *) __bits__) + (stride) * ((y) + __yoff__) + (mul) * ((x) + __xoff__); \
162}
163#define cvt8888to0565(s) ((((s) >> 3) & 0x001f) | \
164 (((s) >> 5) & 0x07e0) | \
165 (((s) >> 8) & 0xf800))
166#define cvt0565to0888(s) (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
167 ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
168 ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
169
170#if IMAGE_BYTE_ORDER == MSBFirst
171#define Fetch24(a) ((unsigned long) (a) & 1 ? \
172 ((READ(a) << 16) | READ((CARD16 *) ((a)+1))) : \
173 ((READ((CARD16 *) (a)) << 8) | READ((a)+2)))
174#define Store24(a,v) ((unsigned long) (a) & 1 ? \
175 (WRITE(a, (CARD8) ((v) >> 16)), \
176 WRITE((CARD16 *) ((a)+1), (CARD16) (v))) : \
177 (WRITE((CARD16 *) (a), (CARD16) ((v) >> 8)), \
178 WRITE((a)+2, (CARD8) (v))))
179#else
180#define Fetch24(a) ((unsigned long) (a) & 1 ? \
181 (READ(a) | (READ((CARD16 *) ((a)+1)) << 8)) : \
182 (READ((CARD16 *) (a)) | (READ((a)+2) << 16)))
183#define Store24(a,v) ((unsigned long) (a) & 1 ? \
184 (WRITE(a, (CARD8) (v)), \
185 WRITE((CARD16 *) ((a)+1), (CARD16) ((v) >> 8))) : \
186 (WRITE((CARD16 *) (a), (CARD16) (v)),\
187 WRITE((a)+2, (CARD8) ((v) >> 16))))
188#endif
189
190/*
191 The methods below use some tricks to be able to do two color
192 components at the same time.
193*/
194
195/*
196 x_c = (x_c * a) / 255
197*/
198#define FbByteMul(x, a) do { \
199 CARD32 t = ((x & 0xff00ff) * a) + 0x800080; \
200 t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
201 t &= 0xff00ff; \
202 \
203 x = (((x >> 8) & 0xff00ff) * a) + 0x800080; \
204 x = (x + ((x >> 8) & 0xff00ff)); \
205 x &= 0xff00ff00; \
206 x += t; \
207 } while (0)
208
209/*
210 x_c = (x_c * a) / 255 + y
211*/
212#define FbByteMulAdd(x, a, y) do { \
213 CARD32 t = ((x & 0xff00ff) * a) + 0x800080; \
214 t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
215 t &= 0xff00ff; \
216 t += y & 0xff00ff; \
217 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
218 t &= 0xff00ff; \
219 \
220 x = (((x >> 8) & 0xff00ff) * a) + 0x800080; \
221 x = (x + ((x >> 8) & 0xff00ff)) >> 8; \
222 x &= 0xff00ff; \
223 x += (y >> 8) & 0xff00ff; \
224 x |= 0x1000100 - ((x >> 8) & 0xff00ff); \
225 x &= 0xff00ff; \
226 x <<= 8; \
227 x += t; \
228 } while (0)
229
230/*
231 x_c = (x_c * a + y_c * b) / 255
232*/
233#define FbByteAddMul(x, a, y, b) do { \
234 CARD32 t; \
235 CARD32 r = (x >> 24) * a + (y >> 24) * b + 0x80; \
236 r += (r >> 8); \
237 r >>= 8; \
238 \
239 t = (x & 0xff00) * a + (y & 0xff00) * b; \
240 t += (t >> 8) + 0x8000; \
241 t >>= 16; \
242 \
243 t |= r << 16; \
244 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
245 t &= 0xff00ff; \
246 t <<= 8; \
247 \
248 r = ((x >> 16) & 0xff) * a + ((y >> 16) & 0xff) * b + 0x80; \
249 r += (r >> 8); \
250 r >>= 8; \
251 \
252 x = (x & 0xff) * a + (y & 0xff) * b + 0x80; \
253 x += (x >> 8); \
254 x >>= 8; \
255 x |= r << 16; \
256 x |= 0x1000100 - ((x >> 8) & 0xff00ff); \
257 x &= 0xff00ff; \
258 x |= t; \
259} while (0)
260
261/*
262 x_c = (x_c * a + y_c *b) / 256
263*/
264#define FbByteAddMul_256(x, a, y, b) do { \
265 CARD32 t = (x & 0xff00ff) * a + (y & 0xff00ff) * b; \
266 t >>= 8; \
267 t &= 0xff00ff; \
268 \
269 x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b; \
270 x &= 0xff00ff00; \
271 x += t; \
272} while (0)
273/*
274 x_c = (x_c * a_c) / 255
275*/
276#define FbByteMulC(x, a) do { \
277 CARD32 t; \
278 CARD32 r = (x & 0xff) * (a & 0xff); \
279 r |= (x & 0xff0000) * ((a >> 16) & 0xff); \
280 r += 0x800080; \
281 r = (r + ((r >> 8) & 0xff00ff)) >> 8; \
282 r &= 0xff00ff; \
283 \
284 x >>= 8; \
285 t = (x & 0xff) * ((a >> 8) & 0xff); \
286 t |= (x & 0xff0000) * (a >> 24); \
287 t += 0x800080; \
288 t = t + ((t >> 8) & 0xff00ff); \
289 x = r | (t & 0xff00ff00); \
290 \
291 } while (0)
292
293/*
294 x_c = (x_c * a) / 255 + y
295*/
296#define FbByteMulAddC(x, a, y) do { \
297 CARD32 t; \
298 CARD32 r = (x & 0xff) * (a & 0xff); \
299 r |= (x & 0xff0000) * ((a >> 16) & 0xff); \
300 r += 0x800080; \
301 r = (r + ((r >> 8) & 0xff00ff)) >> 8; \
302 r &= 0xff00ff; \
303 r += y & 0xff00ff; \
304 r |= 0x1000100 - ((r >> 8) & 0xff00ff); \
305 r &= 0xff00ff; \
306 \
307 x >>= 8; \
308 t = (x & 0xff) * ((a >> 8) & 0xff); \
309 t |= (x & 0xff0000) * (a >> 24); \
310 t += 0x800080; \
311 t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
312 t &= 0xff00ff; \
313 t += (y >> 8) & 0xff00ff; \
314 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
315 t &= 0xff00ff; \
316 x = r | (t << 8); \
317 } while (0)
318
319/*
320 x_c = (x_c * a_c + y_c * b) / 255
321*/
322#define FbByteAddMulC(x, a, y, b) do { \
323 CARD32 t; \
324 CARD32 r = (x >> 24) * (a >> 24) + (y >> 24) * b; \
325 r += (r >> 8) + 0x80; \
326 r >>= 8; \
327 \
328 t = (x & 0xff00) * ((a >> 8) & 0xff) + (y & 0xff00) * b; \
329 t += (t >> 8) + 0x8000; \
330 t >>= 16; \
331 \
332 t |= r << 16; \
333 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
334 t &= 0xff00ff; \
335 t <<= 8; \
336 \
337 r = ((x >> 16) & 0xff) * ((a >> 16) & 0xff) + ((y >> 16) & 0xff) * b + 0x80; \
338 r += (r >> 8); \
339 r >>= 8; \
340 \
341 x = (x & 0xff) * (a & 0xff) + (y & 0xff) * b + 0x80; \
342 x += (x >> 8); \
343 x >>= 8; \
344 x |= r << 16; \
345 x |= 0x1000100 - ((x >> 8) & 0xff00ff); \
346 x &= 0xff00ff; \
347 x |= t; \
348 } while (0)
349
350/*
351 x_c = min(x_c + y_c, 255)
352*/
353#define FbByteAdd(x, y) do { \
354 CARD32 t; \
355 CARD32 r = (x & 0xff00ff) + (y & 0xff00ff); \
356 r |= 0x1000100 - ((r >> 8) & 0xff00ff); \
357 r &= 0xff00ff; \
358 \
359 t = ((x >> 8) & 0xff00ff) + ((y >> 8) & 0xff00ff); \
360 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
361 r |= (t & 0xff00ff) << 8; \
362 x = r; \
363 } while (0)
364
365#define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
366
367#if defined(__i386__) && defined(__GNUC__)
368#define FASTCALL __attribute__((regparm(3)))
369#else
370#define FASTCALL
371#endif
372
373typedef struct _FbComposeData {
374 CARD8 op;
375 PicturePtr src;
376 PicturePtr mask;
377 PicturePtr dest;
378 INT16 xSrc;
379 INT16 ySrc;
380 INT16 xMask;
381 INT16 yMask;
382 INT16 xDest;
383 INT16 yDest;
384 CARD16 width;
385 CARD16 height;
386} FbComposeData;
387
388extern _X_EXPORT void
389fbCompositeRect (const FbComposeData *data, CARD32 *scanline_buffer);
390
391typedef FASTCALL void (*CombineMaskU) (CARD32 *src, const CARD32 *mask, int width);
392typedef FASTCALL void (*CombineFuncU) (CARD32 *dest, const CARD32 *src, int width);
393typedef FASTCALL void (*CombineFuncC) (CARD32 *dest, CARD32 *src, CARD32 *mask, int width);
394
395typedef struct _FbComposeFunctions {
396 CombineFuncU *combineU;
397 CombineFuncC *combineC;
398 CombineMaskU combineMaskU;
399} FbComposeFunctions;
400
401/* fbcompose.c */
402
403extern _X_EXPORT void
404fbCompositeGeneral (CARD8 op,
405 PicturePtr pSrc,
406 PicturePtr pMask,
407 PicturePtr pDst,
408 INT16 xSrc,
409 INT16 ySrc,
410 INT16 xMask,
411 INT16 yMask,
412 INT16 xDst,
413 INT16 yDst,
414 CARD16 width,
415 CARD16 height);
416
417/* fbpict.c */
418extern _X_EXPORT void
419fbComposite (CARD8 op,
420 PicturePtr pSrc,
421 PicturePtr pMask,
422 PicturePtr pDst,
423 INT16 xSrc,
424 INT16 ySrc,
425 INT16 xMask,
426 INT16 yMask,
427 INT16 xDst,
428 INT16 yDst,
429 CARD16 width,
430 CARD16 height);
431
432typedef void (*CompositeFunc) (CARD8 op,
433 PicturePtr pSrc,
434 PicturePtr pMask,
435 PicturePtr pDst,
436 INT16 xSrc,
437 INT16 ySrc,
438 INT16 xMask,
439 INT16 yMask,
440 INT16 xDst,
441 INT16 yDst,
442 CARD16 width,
443 CARD16 height);
444
445extern _X_EXPORT void
446fbWalkCompositeRegion (CARD8 op,
447 PicturePtr pSrc,
448 PicturePtr pMask,
449 PicturePtr pDst,
450 INT16 xSrc,
451 INT16 ySrc,
452 INT16 xMask,
453 INT16 yMask,
454 INT16 xDst,
455 INT16 yDst,
456 CARD16 width,
457 CARD16 height,
458 Bool srcRepeat,
459 Bool maskRepeat,
460 CompositeFunc compositeRect);
461
462/* fbtrap.c */
463
464extern _X_EXPORT void
465fbAddTraps (PicturePtr pPicture,
466 INT16 xOff,
467 INT16 yOff,
468 int ntrap,
469 xTrap *traps);
470
471extern _X_EXPORT void
472fbRasterizeTrapezoid (PicturePtr alpha,
473 xTrapezoid *trap,
474 int x_off,
475 int y_off);
476
477extern _X_EXPORT void
478fbAddTriangles (PicturePtr pPicture,
479 INT16 xOff,
480 INT16 yOff,
481 int ntri,
482 xTriangle *tris);
483
484#endif /* _FBPICT_H_ */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette