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