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