VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/x11include/xorg-server-1.3.0.0/fbpict.h@ 32915

Last change on this file since 32915 was 25078, checked in by vboxsync, 15 years ago

Additions/x11/x11include: exported and set eol-style on new headers

  • Property svn:eol-style set to native
File size: 21.4 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_r8g8b8:
99 case PICT_b8g8r8:
100 case PICT_r5g6b5:
101 case PICT_b5g6r5:
102 return TRUE;
103 default:
104 return FALSE;
105 }
106}
107
108#define fbComposeGetSolid(pict, bits, fmt) { \
109 FbBits *__bits__; \
110 FbStride __stride__; \
111 int __bpp__; \
112 int __xoff__,__yoff__; \
113\
114 fbGetDrawable((pict)->pDrawable,__bits__,__stride__,__bpp__,__xoff__,__yoff__); \
115 switch (__bpp__) { \
116 case 32: \
117 (bits) = *(CARD32 *) __bits__; \
118 break; \
119 case 24: \
120 (bits) = Fetch24 ((CARD8 *) __bits__); \
121 break; \
122 case 16: \
123 (bits) = *(CARD16 *) __bits__; \
124 (bits) = cvt0565to8888(bits); \
125 break; \
126 default: \
127 return; \
128 } \
129 /* If necessary, convert RGB <--> BGR. */ \
130 if (PICT_FORMAT_TYPE((pict)->format) != PICT_FORMAT_TYPE(fmt)) \
131 { \
132 (bits) = (((bits) & 0xff000000) | \
133 (((bits) & 0x00ff0000) >> 16) | \
134 (((bits) & 0x0000ff00) >> 0) | \
135 (((bits) & 0x000000ff) << 16)); \
136 } \
137 /* manage missing src alpha */ \
138 if ((pict)->pFormat->direct.alphaMask == 0) \
139 (bits) |= 0xff000000; \
140}
141
142#define fbComposeGetStart(pict,x,y,type,stride,line,mul) {\
143 FbBits *__bits__; \
144 FbStride __stride__; \
145 int __bpp__; \
146 int __xoff__,__yoff__; \
147\
148 fbGetDrawable((pict)->pDrawable,__bits__,__stride__,__bpp__,__xoff__,__yoff__); \
149 (stride) = __stride__ * sizeof (FbBits) / sizeof (type); \
150 (line) = ((type *) __bits__) + (stride) * ((y) + __yoff__) + (mul) * ((x) + __xoff__); \
151}
152#define cvt8888to0565(s) ((((s) >> 3) & 0x001f) | \
153 (((s) >> 5) & 0x07e0) | \
154 (((s) >> 8) & 0xf800))
155#define cvt0565to8888(s) (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
156 ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
157 ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
158
159#if IMAGE_BYTE_ORDER == MSBFirst
160#define Fetch24(a) ((unsigned long) (a) & 1 ? \
161 ((*(a) << 16) | *((CARD16 *) ((a)+1))) : \
162 ((*((CARD16 *) (a)) << 8) | *((a)+2)))
163#define Store24(a,v) ((unsigned long) (a) & 1 ? \
164 ((*(a) = (CARD8) ((v) >> 16)), \
165 (*((CARD16 *) ((a)+1)) = (CARD16) (v))) : \
166 ((*((CARD16 *) (a)) = (CARD16) ((v) >> 8)), \
167 (*((a)+2) = (CARD8) (v))))
168#else
169#define Fetch24(a) ((unsigned long) (a) & 1 ? \
170 ((*(a)) | (*((CARD16 *) ((a)+1)) << 8)) : \
171 ((*((CARD16 *) (a))) | (*((a)+2) << 16)))
172#define Store24(a,v) ((unsigned long) (a) & 1 ? \
173 ((*(a) = (CARD8) (v)), \
174 (*((CARD16 *) ((a)+1)) = (CARD16) ((v) >> 8))) : \
175 ((*((CARD16 *) (a)) = (CARD16) (v)),\
176 (*((a)+2) = (CARD8) ((v) >> 16))))
177#endif
178
179/*
180 The methods below use some tricks to be able to do two color
181 components at the same time.
182*/
183
184/*
185 x_c = (x_c * a) / 255
186*/
187#define FbByteMul(x, a) do { \
188 CARD32 t = ((x & 0xff00ff) * a) + 0x800080; \
189 t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
190 t &= 0xff00ff; \
191 \
192 x = (((x >> 8) & 0xff00ff) * a) + 0x800080; \
193 x = (x + ((x >> 8) & 0xff00ff)); \
194 x &= 0xff00ff00; \
195 x += t; \
196 } while (0)
197
198/*
199 x_c = (x_c * a) / 255 + y
200*/
201#define FbByteMulAdd(x, a, y) do { \
202 CARD32 t = ((x & 0xff00ff) * a) + 0x800080; \
203 t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
204 t &= 0xff00ff; \
205 t += y & 0xff00ff; \
206 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
207 t &= 0xff00ff; \
208 \
209 x = (((x >> 8) & 0xff00ff) * a) + 0x800080; \
210 x = (x + ((x >> 8) & 0xff00ff)) >> 8; \
211 x &= 0xff00ff; \
212 x += (y >> 8) & 0xff00ff; \
213 x |= 0x1000100 - ((x >> 8) & 0xff00ff); \
214 x &= 0xff00ff; \
215 x <<= 8; \
216 x += t; \
217 } while (0)
218
219/*
220 x_c = (x_c * a + y_c * b) / 255
221*/
222#define FbByteAddMul(x, a, y, b) do { \
223 CARD32 t; \
224 CARD32 r = (x >> 24) * a + (y >> 24) * b + 0x80; \
225 r += (r >> 8); \
226 r >>= 8; \
227 \
228 t = (x & 0xff00) * a + (y & 0xff00) * b; \
229 t += (t >> 8) + 0x8000; \
230 t >>= 16; \
231 \
232 t |= r << 16; \
233 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
234 t &= 0xff00ff; \
235 t <<= 8; \
236 \
237 r = ((x >> 16) & 0xff) * a + ((y >> 16) & 0xff) * b + 0x80; \
238 r += (r >> 8); \
239 r >>= 8; \
240 \
241 x = (x & 0xff) * a + (y & 0xff) * b + 0x80; \
242 x += (x >> 8); \
243 x >>= 8; \
244 x |= r << 16; \
245 x |= 0x1000100 - ((x >> 8) & 0xff00ff); \
246 x &= 0xff00ff; \
247 x |= t; \
248} while (0)
249
250/*
251 x_c = (x_c * a + y_c *b) / 256
252*/
253#define FbByteAddMul_256(x, a, y, b) do { \
254 CARD32 t = (x & 0xff00ff) * a + (y & 0xff00ff) * b; \
255 t >>= 8; \
256 t &= 0xff00ff; \
257 \
258 x = ((x >> 8) & 0xff00ff) * a + ((y >> 8) & 0xff00ff) * b; \
259 x &= 0xff00ff00; \
260 x += t; \
261} while (0)
262/*
263 x_c = (x_c * a_c) / 255
264*/
265#define FbByteMulC(x, a) do { \
266 CARD32 t; \
267 CARD32 r = (x & 0xff) * (a & 0xff); \
268 r |= (x & 0xff0000) * ((a >> 16) & 0xff); \
269 r += 0x800080; \
270 r = (r + ((r >> 8) & 0xff00ff)) >> 8; \
271 r &= 0xff00ff; \
272 \
273 x >>= 8; \
274 t = (x & 0xff) * ((a >> 8) & 0xff); \
275 t |= (x & 0xff0000) * (a >> 24); \
276 t += 0x800080; \
277 t = t + ((t >> 8) & 0xff00ff); \
278 x = r | (t & 0xff00ff00); \
279 \
280 } while (0)
281
282/*
283 x_c = (x_c * a) / 255 + y
284*/
285#define FbByteMulAddC(x, a, y) do { \
286 CARD32 t; \
287 CARD32 r = (x & 0xff) * (a & 0xff); \
288 r |= (x & 0xff0000) * ((a >> 16) & 0xff); \
289 r += 0x800080; \
290 r = (r + ((r >> 8) & 0xff00ff)) >> 8; \
291 r &= 0xff00ff; \
292 r += y & 0xff00ff; \
293 r |= 0x1000100 - ((r >> 8) & 0xff00ff); \
294 r &= 0xff00ff; \
295 \
296 x >>= 8; \
297 t = (x & 0xff) * ((a >> 8) & 0xff); \
298 t |= (x & 0xff0000) * (a >> 24); \
299 t += 0x800080; \
300 t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
301 t &= 0xff00ff; \
302 t += (y >> 8) & 0xff00ff; \
303 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
304 t &= 0xff00ff; \
305 x = r | (t << 8); \
306 } while (0)
307
308/*
309 x_c = (x_c * a_c + y_c * b) / 255
310*/
311#define FbByteAddMulC(x, a, y, b) do { \
312 CARD32 t; \
313 CARD32 r = (x >> 24) * (a >> 24) + (y >> 24) * b; \
314 r += (r >> 8) + 0x80; \
315 r >>= 8; \
316 \
317 t = (x & 0xff00) * ((a >> 8) & 0xff) + (y & 0xff00) * b; \
318 t += (t >> 8) + 0x8000; \
319 t >>= 16; \
320 \
321 t |= r << 16; \
322 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
323 t &= 0xff00ff; \
324 t <<= 8; \
325 \
326 r = ((x >> 16) & 0xff) * ((a >> 16) & 0xff) + ((y >> 16) & 0xff) * b + 0x80; \
327 r += (r >> 8); \
328 r >>= 8; \
329 \
330 x = (x & 0xff) * (a & 0xff) + (y & 0xff) * b + 0x80; \
331 x += (x >> 8); \
332 x >>= 8; \
333 x |= r << 16; \
334 x |= 0x1000100 - ((x >> 8) & 0xff00ff); \
335 x &= 0xff00ff; \
336 x |= t; \
337 } while (0)
338
339/*
340 x_c = min(x_c + y_c, 255)
341*/
342#define FbByteAdd(x, y) do { \
343 CARD32 t; \
344 CARD32 r = (x & 0xff00ff) + (y & 0xff00ff); \
345 r |= 0x1000100 - ((r >> 8) & 0xff00ff); \
346 r &= 0xff00ff; \
347 \
348 t = ((x >> 8) & 0xff00ff) + ((y >> 8) & 0xff00ff); \
349 t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
350 r |= (t & 0xff00ff) << 8; \
351 x = r; \
352 } while (0)
353
354#define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
355
356#if defined(__i386__) && defined(__GNUC__)
357#define FASTCALL __attribute__((regparm(3)))
358#else
359#define FASTCALL
360#endif
361
362typedef struct _FbComposeData {
363 CARD8 op;
364 PicturePtr src;
365 PicturePtr mask;
366 PicturePtr dest;
367 INT16 xSrc;
368 INT16 ySrc;
369 INT16 xMask;
370 INT16 yMask;
371 INT16 xDest;
372 INT16 yDest;
373 CARD16 width;
374 CARD16 height;
375} FbComposeData;
376
377typedef FASTCALL void (*CombineMaskU) (CARD32 *src, const CARD32 *mask, int width);
378typedef FASTCALL void (*CombineFuncU) (CARD32 *dest, const CARD32 *src, int width);
379typedef FASTCALL void (*CombineFuncC) (CARD32 *dest, CARD32 *src, CARD32 *mask, int width);
380
381typedef struct _FbComposeFunctions {
382 CombineFuncU *combineU;
383 CombineFuncC *combineC;
384 CombineMaskU combineMaskU;
385} FbComposeFunctions;
386
387/* fbcompose.c */
388
389void
390fbCompositeGeneral (CARD8 op,
391 PicturePtr pSrc,
392 PicturePtr pMask,
393 PicturePtr pDst,
394 INT16 xSrc,
395 INT16 ySrc,
396 INT16 xMask,
397 INT16 yMask,
398 INT16 xDst,
399 INT16 yDst,
400 CARD16 width,
401 CARD16 height);
402
403
404/* fbedge.c */
405void
406fbRasterizeEdges (FbBits *buf,
407 int bpp,
408 int width,
409 int stride,
410 RenderEdge *l,
411 RenderEdge *r,
412 xFixed t,
413 xFixed b);
414
415/* fbpict.c */
416CARD32
417fbOver (CARD32 x, CARD32 y);
418
419CARD32
420fbOver24 (CARD32 x, CARD32 y);
421
422CARD32
423fbIn (CARD32 x, CARD8 y);
424
425void
426fbCompositeSolidMask_nx8x8888 (CARD8 op,
427 PicturePtr pSrc,
428 PicturePtr pMask,
429 PicturePtr pDst,
430 INT16 xSrc,
431 INT16 ySrc,
432 INT16 xMask,
433 INT16 yMask,
434 INT16 xDst,
435 INT16 yDst,
436 CARD16 width,
437 CARD16 height);
438
439void
440fbCompositeSolidMask_nx8x0888 (CARD8 op,
441 PicturePtr pSrc,
442 PicturePtr pMask,
443 PicturePtr pDst,
444 INT16 xSrc,
445 INT16 ySrc,
446 INT16 xMask,
447 INT16 yMask,
448 INT16 xDst,
449 INT16 yDst,
450 CARD16 width,
451 CARD16 height);
452
453void
454fbCompositeSolidMask_nx8888x8888C (CARD8 op,
455 PicturePtr pSrc,
456 PicturePtr pMask,
457 PicturePtr pDst,
458 INT16 xSrc,
459 INT16 ySrc,
460 INT16 xMask,
461 INT16 yMask,
462 INT16 xDst,
463 INT16 yDst,
464 CARD16 width,
465 CARD16 height);
466
467void
468fbCompositeSolidMask_nx8x0565 (CARD8 op,
469 PicturePtr pSrc,
470 PicturePtr pMask,
471 PicturePtr pDst,
472 INT16 xSrc,
473 INT16 ySrc,
474 INT16 xMask,
475 INT16 yMask,
476 INT16 xDst,
477 INT16 yDst,
478 CARD16 width,
479 CARD16 height);
480
481void
482fbCompositeSolidMask_nx8888x0565C (CARD8 op,
483 PicturePtr pSrc,
484 PicturePtr pMask,
485 PicturePtr pDst,
486 INT16 xSrc,
487 INT16 ySrc,
488 INT16 xMask,
489 INT16 yMask,
490 INT16 xDst,
491 INT16 yDst,
492 CARD16 width,
493 CARD16 height);
494
495void
496fbCompositeSrc_8888x8888 (CARD8 op,
497 PicturePtr pSrc,
498 PicturePtr pMask,
499 PicturePtr pDst,
500 INT16 xSrc,
501 INT16 ySrc,
502 INT16 xMask,
503 INT16 yMask,
504 INT16 xDst,
505 INT16 yDst,
506 CARD16 width,
507 CARD16 height);
508
509void
510fbCompositeSrc_8888x0888 (CARD8 op,
511 PicturePtr pSrc,
512 PicturePtr pMask,
513 PicturePtr pDst,
514 INT16 xSrc,
515 INT16 ySrc,
516 INT16 xMask,
517 INT16 yMask,
518 INT16 xDst,
519 INT16 yDst,
520 CARD16 width,
521 CARD16 height);
522
523void
524fbCompositeSrc_8888x0565 (CARD8 op,
525 PicturePtr pSrc,
526 PicturePtr pMask,
527 PicturePtr pDst,
528 INT16 xSrc,
529 INT16 ySrc,
530 INT16 xMask,
531 INT16 yMask,
532 INT16 xDst,
533 INT16 yDst,
534 CARD16 width,
535 CARD16 height);
536
537void
538fbCompositeSrc_0565x0565 (CARD8 op,
539 PicturePtr pSrc,
540 PicturePtr pMask,
541 PicturePtr pDst,
542 INT16 xSrc,
543 INT16 ySrc,
544 INT16 xMask,
545 INT16 yMask,
546 INT16 xDst,
547 INT16 yDst,
548 CARD16 width,
549 CARD16 height);
550
551void
552fbCompositeSrcAdd_8000x8000 (CARD8 op,
553 PicturePtr pSrc,
554 PicturePtr pMask,
555 PicturePtr pDst,
556 INT16 xSrc,
557 INT16 ySrc,
558 INT16 xMask,
559 INT16 yMask,
560 INT16 xDst,
561 INT16 yDst,
562 CARD16 width,
563 CARD16 height);
564
565void
566fbCompositeSrcAdd_8888x8888 (CARD8 op,
567 PicturePtr pSrc,
568 PicturePtr pMask,
569 PicturePtr pDst,
570 INT16 xSrc,
571 INT16 ySrc,
572 INT16 xMask,
573 INT16 yMask,
574 INT16 xDst,
575 INT16 yDst,
576 CARD16 width,
577 CARD16 height);
578
579void
580fbCompositeSrcAdd_1000x1000 (CARD8 op,
581 PicturePtr pSrc,
582 PicturePtr pMask,
583 PicturePtr pDst,
584 INT16 xSrc,
585 INT16 ySrc,
586 INT16 xMask,
587 INT16 yMask,
588 INT16 xDst,
589 INT16 yDst,
590 CARD16 width,
591 CARD16 height);
592
593void
594fbCompositeSolidMask_nx1xn (CARD8 op,
595 PicturePtr pSrc,
596 PicturePtr pMask,
597 PicturePtr pDst,
598 INT16 xSrc,
599 INT16 ySrc,
600 INT16 xMask,
601 INT16 yMask,
602 INT16 xDst,
603 INT16 yDst,
604 CARD16 width,
605 CARD16 height);
606
607void
608fbComposite (CARD8 op,
609 PicturePtr pSrc,
610 PicturePtr pMask,
611 PicturePtr pDst,
612 INT16 xSrc,
613 INT16 ySrc,
614 INT16 xMask,
615 INT16 yMask,
616 INT16 xDst,
617 INT16 yDst,
618 CARD16 width,
619 CARD16 height);
620
621/* fbtrap.c */
622
623void
624fbAddTraps (PicturePtr pPicture,
625 INT16 xOff,
626 INT16 yOff,
627 int ntrap,
628 xTrap *traps);
629
630void
631fbRasterizeTrapezoid (PicturePtr alpha,
632 xTrapezoid *trap,
633 int x_off,
634 int y_off);
635
636void
637fbAddTriangles (PicturePtr pPicture,
638 INT16 xOff,
639 INT16 yOff,
640 int ntri,
641 xTriangle *tris);
642
643#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