Merge branch 'master' into region32
[profile/ivi/pixman.git] / pixman / pixman-private.h
1 #ifndef PACKAGE
2 #  error config.h must be included before pixman-private.h
3 #endif
4
5 #ifndef PIXMAN_PRIVATE_H
6 #define PIXMAN_PRIVATE_H
7
8 #include "pixman.h"
9 #include <time.h>
10
11 #ifndef FALSE
12 #define FALSE 0
13 #endif
14
15 #ifndef TRUE
16 #define TRUE 1
17 #endif
18
19 #define MSBFirst 0
20 #define LSBFirst 1
21
22 #ifdef WORDS_BIGENDIAN
23 #  define IMAGE_BYTE_ORDER MSBFirst
24 #  define BITMAP_BIT_ORDER MSBFirst
25 #else
26 #  define IMAGE_BYTE_ORDER LSBFirst
27 #  define BITMAP_BIT_ORDER LSBFirst
28 #endif
29
30 #undef DEBUG
31 #define DEBUG 0
32
33 #if defined (__GNUC__)
34 #  define FUNC     ((const char*) (__PRETTY_FUNCTION__))
35 #elif defined (__sun) || (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
36 #  define FUNC     ((const char*) (__func__))
37 #else
38 #  define FUNC     ((const char*) ("???"))
39 #endif
40
41 #ifndef INT16_MIN
42 # define INT16_MIN              (-32767-1)
43 #endif
44
45 #ifndef INT16_MAX
46 # define INT16_MAX              (32767)
47 #endif
48
49 #ifndef INT32_MIN
50 # define INT32_MIN              (-2147483647-1)
51 #endif
52
53 #ifndef INT32_MAX
54 # define INT32_MAX              (2147483647)
55 #endif
56
57 #ifndef UINT32_MIN
58 # define UINT32_MIN             (0)
59 #endif
60
61 #ifndef UINT32_MAX
62 # define UINT32_MAX             (4294967295U)
63 #endif
64
65 #ifndef M_PI
66 # define M_PI                   3.14159265358979323846
67 #endif
68
69 #ifdef _MSC_VER
70 #define inline __inline
71 #endif
72
73 #define FB_SHIFT    5
74 #define FB_UNIT     (1 << FB_SHIFT)
75 #define FB_HALFUNIT (1 << (FB_SHIFT-1))
76 #define FB_MASK     (FB_UNIT - 1)
77 #define FB_ALLONES  ((uint32_t) -1)
78
79 /* Memory allocation helpers */
80 void *pixman_malloc_ab (unsigned int n, unsigned int b);
81 void *pixman_malloc_abc (unsigned int a, unsigned int b, unsigned int c);
82 pixman_bool_t pixman_multiply_overflows_int (unsigned int a, unsigned int b);
83 pixman_bool_t pixman_addition_overflows_int (unsigned int a, unsigned int b);
84
85 #if DEBUG
86
87 #define return_if_fail(expr)                                            \
88     do                                                                  \
89     {                                                                   \
90         if (!(expr))                                                    \
91         {                                                               \
92             fprintf(stderr, "In %s: %s failed\n", FUNC, #expr);         \
93             return;                                                     \
94         }                                                               \
95     }                                                                   \
96     while (0)
97
98 #define return_val_if_fail(expr, retval)                                \
99     do                                                                  \
100     {                                                                   \
101         if (!(expr))                                                    \
102         {                                                               \
103             fprintf(stderr, "In %s: %s failed\n", FUNC, #expr);         \
104             return (retval);                                            \
105         }                                                               \
106     }                                                                   \
107     while (0)
108
109 #else
110
111 #define return_if_fail(expr)                                            \
112     do                                                                  \
113     {                                                                   \
114         if (!(expr))                                                    \
115             return;                                                     \
116     }                                                                   \
117     while (0)
118
119 #define return_val_if_fail(expr, retval)                                \
120     do                                                                  \
121     {                                                                   \
122         if (!(expr))                                                    \
123             return (retval);                                            \
124     }                                                                   \
125     while (0)
126
127 #endif
128
129 typedef struct image_common image_common_t;
130 typedef struct source_image source_image_t;
131 typedef struct solid_fill solid_fill_t;
132 typedef struct gradient gradient_t;
133 typedef struct linear_gradient linear_gradient_t;
134 typedef struct horizontal_gradient horizontal_gradient_t;
135 typedef struct vertical_gradient vertical_gradient_t;
136 typedef struct conical_gradient conical_gradient_t;
137 typedef struct radial_gradient radial_gradient_t;
138 typedef struct bits_image bits_image_t;
139 typedef struct circle circle_t;
140 typedef struct point point_t;
141
142 /* FIXME - the types and structures below should be give proper names
143  */
144
145 #define FASTCALL
146 typedef FASTCALL void (*CombineMaskU32) (uint32_t *src, const uint32_t *mask, int width);
147 typedef FASTCALL void (*CombineFuncU32) (uint32_t *dest, const uint32_t *src, int width);
148 typedef FASTCALL void (*CombineFuncC32) (uint32_t *dest, uint32_t *src, uint32_t *mask, int width);
149 typedef FASTCALL void (*fetchProc32)(bits_image_t *pict, int x, int y, int width,
150                                      uint32_t *buffer);
151 typedef FASTCALL uint32_t (*fetchPixelProc32)(bits_image_t *pict, int offset, int line);
152 typedef FASTCALL void (*storeProc32)(pixman_image_t *, uint32_t *bits,
153                                      const uint32_t *values, int x, int width,
154                                      const pixman_indexed_t *);
155
156 typedef FASTCALL void (*CombineMaskU64) (uint64_t *src, const uint64_t *mask, int width);
157 typedef FASTCALL void (*CombineFuncU64) (uint64_t *dest, const uint64_t *src, int width);
158 typedef FASTCALL void (*CombineFuncC64) (uint64_t *dest, uint64_t *src, uint64_t *mask, int width);
159 typedef FASTCALL void (*fetchProc64)(bits_image_t *pict, int x, int y, int width,
160                                      uint64_t *buffer);
161 typedef FASTCALL uint64_t (*fetchPixelProc64)(bits_image_t *pict, int offset, int line);
162 typedef FASTCALL void (*storeProc64)(pixman_image_t *, uint32_t *bits,
163                                      const uint64_t *values, int x, int width,
164                                      const pixman_indexed_t *);
165
166 typedef struct _FbComposeData {
167     uint8_t      op;
168     pixman_image_t      *src;
169     pixman_image_t      *mask;
170     pixman_image_t      *dest;
171     int16_t      xSrc;
172     int16_t      ySrc;
173     int16_t      xMask;
174     int16_t      yMask;
175     int16_t      xDest;
176     int16_t      yDest;
177     uint16_t     width;
178     uint16_t     height;
179 } FbComposeData;
180
181 typedef struct _FbComposeFunctions32 {
182     CombineFuncU32 *combineU;
183     CombineFuncC32 *combineC;
184     CombineMaskU32 combineMaskU;
185 } FbComposeFunctions32;
186
187 typedef struct _FbComposeFunctions64 {
188     CombineFuncU64 *combineU;
189     CombineFuncC64 *combineC;
190     CombineMaskU64 combineMaskU;
191 } FbComposeFunctions64;
192
193 extern FbComposeFunctions32 pixman_composeFunctions;
194 extern FbComposeFunctions64 pixman_composeFunctions64;
195
196 void pixman_composite_rect_general_accessors (const FbComposeData *data,
197                                               void *src_buffer,
198                                               void *mask_buffer,
199                                               void *dest_buffer,
200                                               const int wide);
201 void pixman_composite_rect_general (const FbComposeData *data);
202
203 fetchProc32 pixman_fetchProcForPicture32 (bits_image_t *);
204 fetchPixelProc32 pixman_fetchPixelProcForPicture32 (bits_image_t *);
205 storeProc32 pixman_storeProcForPicture32 (bits_image_t *);
206 fetchProc32 pixman_fetchProcForPicture32_accessors (bits_image_t *);
207 fetchPixelProc32 pixman_fetchPixelProcForPicture32_accessors (bits_image_t *);
208 storeProc32 pixman_storeProcForPicture32_accessors (bits_image_t *);
209
210 fetchProc64 pixman_fetchProcForPicture64 (bits_image_t *);
211 fetchPixelProc64 pixman_fetchPixelProcForPicture64 (bits_image_t *);
212 storeProc64 pixman_storeProcForPicture64 (bits_image_t *);
213 fetchProc64 pixman_fetchProcForPicture64_accessors (bits_image_t *);
214 fetchPixelProc64 pixman_fetchPixelProcForPicture64_accessors (bits_image_t *);
215 storeProc64 pixman_storeProcForPicture64_accessors (bits_image_t *);
216
217 void pixmanFetchSourcePict(source_image_t *, int x, int y, int width,
218                            uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
219
220 void fbFetchTransformed(bits_image_t *, int x, int y, int width,
221                         uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
222 void fbStoreExternalAlpha(bits_image_t *, int x, int y, int width,
223                           uint32_t *buffer);
224 void fbFetchExternalAlpha(bits_image_t *, int x, int y, int width,
225                           uint32_t *buffer, uint32_t *mask, uint32_t maskBits);
226
227 void fbFetchTransformed_accessors(bits_image_t *, int x, int y, int width,
228                                   uint32_t *buffer, uint32_t *mask,
229                                   uint32_t maskBits);
230 void fbStoreExternalAlpha_accessors(bits_image_t *, int x, int y, int width,
231                                     uint32_t *buffer);
232 void fbFetchExternalAlpha_accessors(bits_image_t *, int x, int y, int width,
233                                     uint32_t *buffer, uint32_t *mask,
234                                     uint32_t maskBits);
235
236 /* end */
237
238 typedef enum
239 {
240     BITS,
241     LINEAR,
242     CONICAL,
243     RADIAL,
244     SOLID
245 } image_type_t;
246
247 #define IS_SOURCE_IMAGE(img)     (((image_common_t *)img)->type > BITS)
248
249 typedef enum
250 {
251     SOURCE_IMAGE_CLASS_UNKNOWN,
252     SOURCE_IMAGE_CLASS_HORIZONTAL,
253     SOURCE_IMAGE_CLASS_VERTICAL
254 } source_pict_class_t;
255
256 struct point
257 {
258     int16_t x, y;
259 };
260
261 struct image_common
262 {
263     image_type_t                type;
264     int32_t                     ref_count;
265     pixman_region32_t           full_region;
266     pixman_region32_t           clip_region;
267     pixman_region32_t          *src_clip;
268     pixman_bool_t               has_client_clip;
269     pixman_transform_t         *transform;
270     pixman_repeat_t             repeat;
271     pixman_filter_t             filter;
272     pixman_fixed_t             *filter_params;
273     int                         n_filter_params;
274     bits_image_t               *alpha_map;
275     point_t                     alpha_origin;
276     pixman_bool_t               component_alpha;
277     pixman_read_memory_func_t   read_func;
278     pixman_write_memory_func_t  write_func;
279 };
280
281 struct source_image
282 {
283     image_common_t      common;
284     source_pict_class_t class;
285 };
286
287 struct solid_fill
288 {
289     source_image_t      common;
290     uint32_t            color;          /* FIXME: shouldn't this be a pixman_color_t? */
291 };
292
293 struct gradient
294 {
295     source_image_t              common;
296     int                         n_stops;
297     pixman_gradient_stop_t *    stops;
298     int                         stop_range;
299     uint32_t *                  color_table;
300     int                         color_table_size;
301 };
302
303 struct linear_gradient
304 {
305     gradient_t                  common;
306     pixman_point_fixed_t        p1;
307     pixman_point_fixed_t        p2;
308 };
309
310 struct circle
311 {
312     pixman_fixed_t x;
313     pixman_fixed_t y;
314     pixman_fixed_t radius;
315 };
316
317 struct radial_gradient
318 {
319     gradient_t  common;
320
321     circle_t    c1;
322     circle_t    c2;
323     double      cdx;
324     double      cdy;
325     double      dr;
326     double      A;
327 };
328
329 struct conical_gradient
330 {
331     gradient_t                  common;
332     pixman_point_fixed_t        center;
333     pixman_fixed_t              angle;
334 };
335
336 struct bits_image
337 {
338     image_common_t              common;
339     pixman_format_code_t        format;
340     const pixman_indexed_t     *indexed;
341     int                         width;
342     int                         height;
343     uint32_t *                  bits;
344     uint32_t *                  free_me;
345     int                         rowstride; /* in number of uint32_t's */
346 };
347
348 union pixman_image
349 {
350     image_type_t                type;
351     image_common_t              common;
352     bits_image_t                bits;
353     gradient_t                  gradient;
354     linear_gradient_t           linear;
355     conical_gradient_t          conical;
356     radial_gradient_t           radial;
357     solid_fill_t                solid;
358 };
359
360
361 #define LOG2_BITMAP_PAD 5
362 #define FB_STIP_SHIFT   LOG2_BITMAP_PAD
363 #define FB_STIP_UNIT    (1 << FB_STIP_SHIFT)
364 #define FB_STIP_MASK    (FB_STIP_UNIT - 1)
365 #define FB_STIP_ALLONES ((uint32_t) -1)
366
367 #if BITMAP_BIT_ORDER == LSBFirst
368 #define FbScrLeft(x,n)  ((x) >> (n))
369 #define FbScrRight(x,n) ((x) << (n))
370 #define FbLeftStipBits(x,n) ((x) & ((((uint32_t) 1) << (n)) - 1))
371 #else
372 #define FbScrLeft(x,n)  ((x) << (n))
373 #define FbScrRight(x,n) ((x) >> (n))
374 #define FbLeftStipBits(x,n) ((x) >> (FB_STIP_UNIT - (n)))
375 #endif
376
377 #define FbStipLeft(x,n) FbScrLeft(x,n)
378 #define FbStipRight(x,n) FbScrRight(x,n)
379 #define FbStipMask(x,w) (FbStipRight(FB_STIP_ALLONES,(x) & FB_STIP_MASK) & \
380                          FbStipLeft(FB_STIP_ALLONES,(FB_STIP_UNIT - ((x)+(w))) & FB_STIP_MASK))
381
382 #define FbLeftMask(x)       ( ((x) & FB_MASK) ? \
383                               FbScrRight(FB_ALLONES,(x) & FB_MASK) : 0)
384 #define FbRightMask(x)      ( ((FB_UNIT - (x)) & FB_MASK) ? \
385                               FbScrLeft(FB_ALLONES,(FB_UNIT - (x)) & FB_MASK) : 0)
386
387 #define FbMaskBits(x,w,l,n,r) {                                         \
388         n = (w); \
389         r = FbRightMask((x)+n); \
390         l = FbLeftMask(x); \
391         if (l) { \
392             n -= FB_UNIT - ((x) & FB_MASK); \
393             if (n < 0) { \
394                 n = 0; \
395                 l &= r; \
396                 r = 0; \
397             } \
398         } \
399         n >>= FB_SHIFT; \
400     }
401
402 #if IMAGE_BYTE_ORDER == MSBFirst
403 #define Fetch24(img, a)  ((unsigned long) (a) & 1 ?           \
404     ((READ(img, a) << 16) | READ(img, (uint16_t *) ((a)+1))) : \
405     ((READ(img, (uint16_t *) (a)) << 8) | READ(img, (a)+2)))
406 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
407     (WRITE(img, a, (uint8_t) ((v) >> 16)),                \
408      WRITE(img, (uint16_t *) ((a)+1), (uint16_t) (v))) :  \
409     (WRITE(img, (uint16_t *) (a), (uint16_t) ((v) >> 8)), \
410      WRITE(img, (a)+2, (uint8_t) (v))))
411 #else
412 #define Fetch24(img,a)  ((unsigned long) (a) & 1 ?                           \
413     (READ(img, a) | (READ(img, (uint16_t *) ((a)+1)) << 8)) : \
414     (READ(img, (uint16_t *) (a)) | (READ(img, (a)+2) << 16)))
415 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
416     (WRITE(img, a, (uint8_t) (v)),                              \
417      WRITE(img, (uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
418     (WRITE(img, (uint16_t *) (a), (uint16_t) (v)),              \
419      WRITE(img, (a)+2, (uint8_t) ((v) >> 16))))
420 #endif
421
422 #define CvtR8G8B8toY15(s)       (((((s) >> 16) & 0xff) * 153 + \
423                                   (((s) >>  8) & 0xff) * 301 +          \
424                                   (((s)      ) & 0xff) * 58) >> 2)
425 #define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) |  \
426                             (((s) >> 6) & 0x03e0) |  \
427                             (((s) >> 9) & 0x7c00))
428 #define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
429 #define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
430
431 #define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(rgb24)])
432
433
434 #define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
435 #define FbIntDiv(a,b)    (((uint16_t) (a) * 255) / (b))
436
437 #define FbGet8(v,i)   ((uint16_t) (uint8_t) ((v) >> i))
438
439
440 #define cvt8888to0565(s)    ((((s) >> 3) & 0x001f) | \
441                              (((s) >> 5) & 0x07e0) | \
442                              (((s) >> 8) & 0xf800))
443 #define cvt0565to0888(s)    (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
444                              ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
445                              ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
446
447 /*
448  * There are two ways of handling alpha -- either as a single unified value or
449  * a separate value for each component, hence each macro must have two
450  * versions.  The unified alpha version has a 'U' at the end of the name,
451  * the component version has a 'C'.  Similarly, functions which deal with
452  * this difference will have two versions using the same convention.
453  */
454
455 #define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i), \
456                             (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
457
458 #define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i), \
459                             (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
460
461 #define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
462
463 #define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
464
465 #define FbAdd(x,y,i,t)  ((t) = FbGet8(x,i) + FbGet8(y,i),               \
466                          (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
467
468 #define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
469
470 #define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
471
472 #define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) :                \
473                   ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
474
475 #define CLIP(a,b,c) ((a) < (b) ? (b) : ((a) > (c) ? (c) : (a)))
476
477 #if 0
478 /* FIXME: the MOD macro above is equivalent, but faster I think */
479 #define mod(a,b) ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a) % (b))
480 #endif
481
482 /* FIXME: the (void)__read_func hides lots of warnings (which is what they
483  * are supposed to do), but some of them are real. For example the one
484  * where Fetch4 doesn't have a READ
485  */
486
487 #if 0
488 /* Framebuffer access support macros */
489 #define ACCESS_MEM(code)                                                \
490     do {                                                                \
491         const image_common_t *const com__ =                             \
492             (image_common_t *)image;                                    \
493                                                                         \
494         if (!com__->read_func && !com__->write_func)                    \
495         {                                                               \
496             const int do_access__ = 0;                                  \
497             const pixman_read_memory_func_t read_func__ = NULL;         \
498             const pixman_write_memory_func_t write_func__ = NULL;       \
499             (void)read_func__;                                          \
500             (void)write_func__;                                         \
501             (void)do_access__;                                          \
502                                                                         \
503             {code}                                                      \
504         }                                                               \
505         else                                                            \
506         {                                                               \
507             const int do_access__ = 1;                                  \
508             const pixman_read_memory_func_t read_func__ =               \
509                 com__->read_func;                                       \
510             const pixman_write_memory_func_t write_func__ =             \
511                 com__->write_func;                                      \
512             (void)read_func__;                                          \
513             (void)write_func__;                                         \
514             (void)do_access__;                                          \
515                                                                         \
516             {code}                                                      \
517         }                                                               \
518     } while (0)
519 #endif
520
521 #ifdef PIXMAN_FB_ACCESSORS
522
523 #define ACCESS(sym) sym##_accessors
524
525 #define READ(img, ptr)                                                  \
526     ((img)->common.read_func ((ptr), sizeof(*(ptr))))
527 #define WRITE(img, ptr,val)                                             \
528     ((img)->common.write_func ((ptr), (val), sizeof (*(ptr))))
529
530 #define MEMCPY_WRAPPED(img, dst, src, size)                             \
531     do {                                                                \
532         size_t _i;                                                      \
533         uint8_t *_dst = (uint8_t*)(dst), *_src = (uint8_t*)(src);       \
534         for(_i = 0; _i < size; _i++) {                                  \
535             WRITE((img), _dst +_i, READ((img), _src + _i));             \
536         }                                                               \
537     } while (0)
538
539 #define MEMSET_WRAPPED(img, dst, val, size)                             \
540     do {                                                                \
541         size_t _i;                                                      \
542         uint8_t *_dst = (uint8_t*)(dst);                                \
543         for(_i = 0; _i < (size_t) size; _i++) {                         \
544             WRITE((img), _dst +_i, (val));                              \
545         }                                                               \
546     } while (0)
547
548 #else
549
550 #define ACCESS(sym) sym
551
552 #define READ(img, ptr)          (*(ptr))
553 #define WRITE(img, ptr, val)    (*(ptr) = (val))
554 #define MEMCPY_WRAPPED(img, dst, src, size)                                     \
555     memcpy(dst, src, size)
556 #define MEMSET_WRAPPED(img, dst, val, size)                                     \
557     memset(dst, val, size)
558
559 #endif
560
561 #define fbComposeGetSolid(img, res, fmt)                                \
562     do                                                                  \
563     {                                                                   \
564         pixman_format_code_t format__;                                  \
565         if (img->type == SOLID)                                         \
566         {                                                               \
567             format__ = PIXMAN_a8r8g8b8;                                 \
568             (res) = img->solid.color;                                   \
569         }                                                               \
570         else                                                            \
571         {                                                               \
572             uint32_t           *bits__   = (img)->bits.bits;            \
573             format__ = (img)->bits.format;                              \
574                                                                         \
575             switch (PIXMAN_FORMAT_BPP((img)->bits.format))              \
576             {                                                           \
577             case 32:                                                    \
578                 (res) = READ(img, (uint32_t *)bits__);                  \
579                 break;                                                  \
580             case 24:                                                    \
581                 (res) = Fetch24(img, (uint8_t *) bits__);                       \
582                 break;                                                  \
583             case 16:                                                    \
584                 (res) = READ(img, (uint16_t *) bits__);                 \
585                 (res) = cvt0565to0888(res);                             \
586                 break;                                                  \
587             case 8:                                                     \
588                 (res) = READ(img, (uint8_t *) bits__);                  \
589                 (res) = (res) << 24;                                    \
590                 break;                                                  \
591             case 1:                                                     \
592                 (res) = READ(img, (uint32_t *) bits__);                 \
593                 (res) = FbLeftStipBits((res),1) ? 0xff000000 : 0x00000000; \
594                 break;                                                  \
595             default:                                                    \
596                 return;                                                 \
597             }                                                           \
598             /* manage missing src alpha */                              \
599             if (!PIXMAN_FORMAT_A((img)->bits.format))                   \
600                 (res) |= 0xff000000;                                    \
601         }                                                               \
602                                                                         \
603         /* If necessary, convert RGB <--> BGR. */                       \
604         if (PIXMAN_FORMAT_TYPE (format__) != PIXMAN_FORMAT_TYPE(fmt))   \
605         {                                                               \
606             (res) = ((((res) & 0xff000000) >>  0) |                     \
607                      (((res) & 0x00ff0000) >> 16) |                     \
608                      (((res) & 0x0000ff00) >>  0) |                     \
609                      (((res) & 0x000000ff) << 16));                     \
610         }                                                               \
611     }                                                                   \
612     while (0)
613
614 #define fbComposeGetStart(pict,x,y,type,out_stride,line,mul) do {       \
615         uint32_t        *__bits__;                                      \
616         int             __stride__;                                     \
617         int             __bpp__;                                        \
618                                                                         \
619         __bits__ = pict->bits.bits;                                     \
620         __stride__ = pict->bits.rowstride;                              \
621         __bpp__ = PIXMAN_FORMAT_BPP(pict->bits.format);                 \
622         (out_stride) = __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type);      \
623         (line) = ((type *) __bits__) +                                  \
624             (out_stride) * (y) + (mul) * (x);                           \
625     } while (0)
626
627
628 /*
629  * Edges
630  */
631
632 #define MAX_ALPHA(n)    ((1 << (n)) - 1)
633 #define N_Y_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
634 #define N_X_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n)/2)) + 1)
635
636 #define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC(n))
637 #define STEP_Y_BIG(n)   (pixman_fixed_1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
638
639 #define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
640 #define Y_FRAC_LAST(n)  (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
641
642 #define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC(n))
643 #define STEP_X_BIG(n)   (pixman_fixed_1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
644
645 #define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
646 #define X_FRAC_LAST(n)  (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
647
648 #define RenderSamplesX(x,n)     ((n) == 1 ? 0 : (pixman_fixed_frac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
649
650 /*
651  * Step across a small sample grid gap
652  */
653 #define RenderEdgeStepSmall(edge) { \
654     edge->x += edge->stepx_small;   \
655     edge->e += edge->dx_small;      \
656     if (edge->e > 0)                \
657     {                               \
658         edge->e -= edge->dy;        \
659         edge->x += edge->signdx;    \
660     }                               \
661 }
662
663 /*
664  * Step across a large sample grid gap
665  */
666 #define RenderEdgeStepBig(edge) {   \
667     edge->x += edge->stepx_big;     \
668     edge->e += edge->dx_big;        \
669     if (edge->e > 0)                \
670     {                               \
671         edge->e -= edge->dy;        \
672         edge->x += edge->signdx;    \
673     }                               \
674 }
675
676 void
677 pixman_rasterize_edges_accessors (pixman_image_t *image,
678                                   pixman_edge_t *l,
679                                   pixman_edge_t *r,
680                                   pixman_fixed_t        t,
681                                   pixman_fixed_t        b);
682
683 pixman_bool_t
684 pixman_image_is_opaque(pixman_image_t *image);
685
686 pixman_bool_t
687 pixman_image_can_get_solid (pixman_image_t *image);
688
689
690 /* GCC visibility */
691 #if defined(__GNUC__) && __GNUC__ >= 4
692 #define PIXMAN_EXPORT __attribute__ ((visibility("default")))
693 #else
694 #define PIXMAN_EXPORT
695 #endif
696
697 /* Helper for 32 bit regions */
698 pixman_bool_t
699 pixman_region32_copy_from_region16 (pixman_region32_t *dst,
700                                     pixman_region16_t *src);
701
702 #ifdef PIXMAN_TIMING
703
704 /* Timing */
705 static inline uint64_t
706 oil_profile_stamp_rdtsc (void)
707 {
708     uint64_t ts;
709     __asm__ __volatile__("rdtsc\n" : "=A" (ts));
710     return ts;
711 }
712 #define OIL_STAMP oil_profile_stamp_rdtsc
713
714 typedef struct PixmanTimer PixmanTimer;
715
716 struct PixmanTimer
717 {
718     int initialized;
719     const char *name;
720     uint64_t n_times;
721     uint64_t total;
722     PixmanTimer *next;
723 };
724
725 extern int timer_defined;
726 void pixman_timer_register (PixmanTimer *timer);
727
728 #define TIMER_BEGIN(tname)                                              \
729     {                                                                   \
730         static PixmanTimer      timer##tname;                           \
731         uint64_t                begin##tname;                           \
732                                                                         \
733         if (!timer##tname.initialized)                                  \
734         {                                                               \
735             timer##tname.initialized = 1;                               \
736             timer##tname.name = #tname;                                 \
737             pixman_timer_register (&timer##tname);                      \
738         }                                                               \
739                                                                         \
740         timer##tname.n_times++;                                         \
741         begin##tname = OIL_STAMP();
742
743 #define TIMER_END(tname)                                                \
744         timer##tname.total += OIL_STAMP() - begin##tname;               \
745     }
746
747 #endif /* PIXMAN_TIMING */
748
749 #endif /* PIXMAN_PRIVATE_H */