Various minor changes
[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 #include "pixman-compiler.h"
13
14 /*
15  * Images
16  */
17 typedef struct image_common image_common_t;
18 typedef struct source_image source_image_t;
19 typedef struct solid_fill solid_fill_t;
20 typedef struct gradient gradient_t;
21 typedef struct linear_gradient linear_gradient_t;
22 typedef struct horizontal_gradient horizontal_gradient_t;
23 typedef struct vertical_gradient vertical_gradient_t;
24 typedef struct conical_gradient conical_gradient_t;
25 typedef struct radial_gradient radial_gradient_t;
26 typedef struct bits_image bits_image_t;
27 typedef struct circle circle_t;
28
29 typedef void     (*fetchProc32)        (bits_image_t *pict,
30                                         int x, int y, int width,
31                                         uint32_t *buffer);
32 typedef uint32_t (*fetchPixelProc32)   (bits_image_t *pict,
33                                         int offset, int line);
34 typedef void     (*storeProc32)        (pixman_image_t *, uint32_t *bits,
35                                         const uint32_t *values,
36                                         int x, int width);
37 typedef void     (*fetchProc64)        (bits_image_t *pict,
38                                         int x, int y, int width,
39                                         uint64_t *buffer);
40 typedef uint64_t (*fetchPixelProc64)   (bits_image_t *pict,
41                                         int offset, int line);
42 typedef void     (*storeProc64)        (pixman_image_t *, uint32_t *bits,
43                                         const uint64_t *values,
44                                         int x, int width);
45 typedef void     (*fetch_pixels_32_t) (bits_image_t *image,
46                                        uint32_t *buffer, int n_pixels);
47 typedef void     (*fetch_pixels_64_t) (bits_image_t *image,
48                                        uint64_t *buffer, int n_pixels);
49 typedef void     (*scanStoreProc)     (bits_image_t *img,
50                                        int x, int y, int width,
51                                        uint32_t *buffer);
52 typedef void     (*scanFetchProc)     (pixman_image_t *,
53                                        int, int, int, uint32_t *,
54                                        uint32_t *, uint32_t);
55
56 typedef enum
57 {
58     BITS,
59     LINEAR,
60     CONICAL,
61     RADIAL,
62     SOLID
63 } image_type_t;
64
65 typedef enum
66 {
67     SOURCE_IMAGE_CLASS_UNKNOWN,
68     SOURCE_IMAGE_CLASS_HORIZONTAL,
69     SOURCE_IMAGE_CLASS_VERTICAL,
70 } source_pict_class_t;
71
72 typedef source_pict_class_t (* classify_func_t) (pixman_image_t *image,
73                                                  int             x,
74                                                  int             y,
75                                                  int             width,
76                                                  int             height);
77 typedef void (* property_changed_func_t)        (pixman_image_t *image);
78
79 struct image_common
80 {
81     image_type_t                type;
82     int32_t                     ref_count;
83     pixman_region32_t           clip_region;
84     pixman_bool_t               have_clip_region;   /* FALSE if there is no clip */
85     pixman_bool_t               client_clip;        /* Whether the source clip was
86                                                        set by a client */
87     pixman_bool_t               clip_sources;       /* Whether the clip applies when
88                                                      * the image is used as a source
89                                                      */
90     pixman_transform_t         *transform;
91     pixman_repeat_t             repeat;
92     pixman_filter_t             filter;
93     pixman_fixed_t             *filter_params;
94     int                         n_filter_params;
95     bits_image_t               *alpha_map;
96     int                         alpha_origin_x;
97     int                         alpha_origin_y;
98     pixman_bool_t               component_alpha;
99     pixman_read_memory_func_t   read_func;
100     pixman_write_memory_func_t  write_func;
101     classify_func_t             classify;
102     property_changed_func_t     property_changed;
103     scanFetchProc               get_scanline_32;
104     scanFetchProc               get_scanline_64;
105
106     pixman_image_destroy_func_t destroy_func;
107     void *                      destroy_data;
108 };
109
110 struct source_image
111 {
112     image_common_t      common;
113     source_pict_class_t class;
114 };
115
116 struct solid_fill
117 {
118     source_image_t      common;
119     uint32_t            color;          /* FIXME: shouldn't this be a pixman_color_t? */
120 };
121
122 struct gradient
123 {
124     source_image_t              common;
125     int                         n_stops;
126     pixman_gradient_stop_t *    stops;
127     int                         stop_range;
128     uint32_t *                  color_table;
129     int                         color_table_size;
130 };
131
132 struct linear_gradient
133 {
134     gradient_t                  common;
135     pixman_point_fixed_t        p1;
136     pixman_point_fixed_t        p2;
137 };
138
139 struct circle
140 {
141     pixman_fixed_t x;
142     pixman_fixed_t y;
143     pixman_fixed_t radius;
144 };
145
146 struct radial_gradient
147 {
148     gradient_t  common;
149
150     circle_t    c1;
151     circle_t    c2;
152     double      cdx;
153     double      cdy;
154     double      dr;
155     double      A;
156 };
157
158 struct conical_gradient
159 {
160     gradient_t                  common;
161     pixman_point_fixed_t        center;
162     pixman_fixed_t              angle;
163 };
164
165 struct bits_image
166 {
167     image_common_t              common;
168     pixman_format_code_t        format;
169     const pixman_indexed_t     *indexed;
170     int                         width;
171     int                         height;
172     uint32_t *                  bits;
173     uint32_t *                  free_me;
174     int                         rowstride; /* in number of uint32_t's */
175
176     /* Fetch raw pixels, with no regard for transformations, alpha map etc. */
177     fetch_pixels_32_t           fetch_pixels_raw_32;
178     fetch_pixels_64_t           fetch_pixels_raw_64;
179
180     /* Fetch raw scanlines, with no regard for transformations, alpha maps etc. */
181     fetchProc32                 fetch_scanline_raw_32;
182     fetchProc64                 fetch_scanline_raw_64;
183
184     /* Store scanlines with no regard for alpha maps */
185     storeProc32                 store_scanline_raw_32;
186     storeProc64                 store_scanline_raw_64;
187
188     /* Store a scanline, taking alpha maps into account */
189     scanStoreProc               store_scanline_32;
190     scanStoreProc               store_scanline_64;
191
192     /* Used for indirect access to the bits */
193     pixman_read_memory_func_t   read_func;
194     pixman_write_memory_func_t  write_func;
195 };
196
197 union pixman_image
198 {
199     image_type_t                type;
200     image_common_t              common;
201     bits_image_t                bits;
202     source_image_t              source;
203     gradient_t                  gradient;
204     linear_gradient_t           linear;
205     conical_gradient_t          conical;
206     radial_gradient_t           radial;
207     solid_fill_t                solid;
208 };
209
210
211 void
212 _pixman_bits_image_setup_raw_accessors (bits_image_t   *image);
213
214 void
215 _pixman_image_get_scanline_64_generic  (pixman_image_t *pict,
216                                         int             x,
217                                         int             y,
218                                         int             width,
219                                         uint64_t       *buffer,
220                                         uint64_t       *mask,
221                                         uint32_t        maskBits);
222
223 source_pict_class_t
224 _pixman_image_classify (pixman_image_t *image,
225                         int             x,
226                         int             y,
227                         int             width,
228                         int             height);
229
230 void
231 _pixman_image_get_scanline_32 (pixman_image_t *image, int x, int y, int width,
232                                uint32_t *buffer, uint32_t *mask,
233                                uint32_t mask_bits);
234
235 /* Even thought the type of buffer is uint32_t *, the function actually expects
236  * a uint64_t *buffer.
237  */
238 void
239 _pixman_image_get_scanline_64 (pixman_image_t *image, int x, int y, int width,
240                                uint32_t *buffer,
241                                uint32_t *unused, uint32_t unused2);
242
243 void
244 _pixman_image_store_scanline_32 (bits_image_t *image, int x, int y, int width,
245                                  uint32_t *buffer);
246 void
247 _pixman_image_fetch_pixels (bits_image_t *image, uint32_t *buffer,
248                             int n_pixels);
249
250 /* Even thought the type of buffer is uint32_t *, the function actually expects
251  * a uint64_t *buffer.
252  */
253 void
254 _pixman_image_store_scanline_64 (bits_image_t *image, int x, int y, int width,
255                                  uint32_t *buffer);
256
257 pixman_image_t *
258 _pixman_image_allocate (void);
259
260 pixman_bool_t
261 _pixman_init_gradient (gradient_t                   *gradient,
262                        const pixman_gradient_stop_t *stops,
263                        int                           n_stops);
264 void
265 _pixman_image_reset_clip_region (pixman_image_t *image);
266
267 pixman_bool_t
268 _pixman_image_is_opaque(pixman_image_t *image);
269
270 pixman_bool_t
271 _pixman_image_is_solid (pixman_image_t *image);
272
273 uint32_t
274 _pixman_image_get_solid (pixman_image_t *image,
275                         pixman_format_code_t format);
276
277 /*
278  * Gradient walker
279  */
280 typedef struct
281 {
282     uint32_t        left_ag;
283     uint32_t        left_rb;
284     uint32_t        right_ag;
285     uint32_t        right_rb;
286     int32_t       left_x;
287     int32_t       right_x;
288     int32_t       stepper;
289
290     pixman_gradient_stop_t      *stops;
291     int                      num_stops;
292     unsigned int             spread;
293
294     int           need_reset;
295 } pixman_gradient_walker_t;
296
297 void
298 _pixman_gradient_walker_init (pixman_gradient_walker_t  *walker,
299                               gradient_t      *gradient,
300                               unsigned int     spread);
301
302 void
303 _pixman_gradient_walker_reset (pixman_gradient_walker_t       *walker,
304                                pixman_fixed_32_32_t  pos);
305
306 uint32_t
307 _pixman_gradient_walker_pixel (pixman_gradient_walker_t       *walker,
308                                pixman_fixed_32_32_t  x);
309
310
311
312 #ifdef WORDS_BIGENDIAN
313 #define Fetch24(img, a)  ((unsigned long) (a) & 1 ?           \
314     ((READ(img, a) << 16) | READ(img, (uint16_t *) ((a)+1))) : \
315     ((READ(img, (uint16_t *) (a)) << 8) | READ(img, (a)+2)))
316 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
317     (WRITE(img, a, (uint8_t) ((v) >> 16)),                \
318      WRITE(img, (uint16_t *) ((a)+1), (uint16_t) (v))) :  \
319     (WRITE(img, (uint16_t *) (a), (uint16_t) ((v) >> 8)), \
320      WRITE(img, (a)+2, (uint8_t) (v))))
321 #else
322 #define Fetch24(img,a)  ((unsigned long) (a) & 1 ?                           \
323     (READ(img, a) | (READ(img, (uint16_t *) ((a)+1)) << 8)) : \
324     (READ(img, (uint16_t *) (a)) | (READ(img, (a)+2) << 16)))
325 #define Store24(img,a,v) ((unsigned long) (a) & 1 ? \
326     (WRITE(img, a, (uint8_t) (v)),                              \
327      WRITE(img, (uint16_t *) ((a)+1), (uint16_t) ((v) >> 8))) : \
328     (WRITE(img, (uint16_t *) (a), (uint16_t) (v)),              \
329      WRITE(img, (a)+2, (uint8_t) ((v) >> 16))))
330 #endif
331
332 #define FbIntMult(a,b,t) ( (t) = (a) * (b) + 0x80, ( ( ( (t)>>8 ) + (t) )>>8 ) )
333 #define FbIntDiv(a,b)    (((uint16_t) (a) * 255) / (b))
334
335 #define FbGet8(v,i)   ((uint16_t) (uint8_t) ((v) >> i))
336
337
338 #define cvt8888to0565(s)    ((((s) >> 3) & 0x001f) | \
339                              (((s) >> 5) & 0x07e0) | \
340                              (((s) >> 8) & 0xf800))
341 #define cvt0565to0888(s)    (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
342                              ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
343                              ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
344
345 /*
346  * There are two ways of handling alpha -- either as a single unified value or
347  * a separate value for each component, hence each macro must have two
348  * versions.  The unified alpha version has a 'U' at the end of the name,
349  * the component version has a 'C'.  Similarly, functions which deal with
350  * this difference will have two versions using the same convention.
351  */
352
353 #define FbOverU(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),(a),(t)) + FbGet8(x,i), \
354                             (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
355
356 #define FbOverC(x,y,i,a,t) ((t) = FbIntMult(FbGet8(y,i),FbGet8(a,i),(t)) + FbGet8(x,i), \
357                             (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
358
359 #define FbInU(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),(a),(t)) << (i))
360
361 #define FbInC(x,i,a,t) ((uint32_t) FbIntMult(FbGet8(x,i),FbGet8(a,i),(t)) << (i))
362
363 #define FbAdd(x,y,i,t)  ((t) = FbGet8(x,i) + FbGet8(y,i),               \
364                          (uint32_t) ((uint8_t) ((t) | (0 - ((t) >> 8)))) << (i))
365
366 #define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
367 #define div_65535(x) (((x) + 0x8000 + (((x) + 0x8000) >> 16)) >> 16)
368
369 #ifdef PIXMAN_FB_ACCESSORS
370
371 #define ACCESS(sym) sym##_accessors
372
373 #define READ(img, ptr)                                                  \
374     ((img)->common.read_func ((ptr), sizeof(*(ptr))))
375 #define WRITE(img, ptr,val)                                             \
376     ((img)->common.write_func ((ptr), (val), sizeof (*(ptr))))
377
378 #define MEMCPY_WRAPPED(img, dst, src, size)                             \
379     do {                                                                \
380         size_t _i;                                                      \
381         uint8_t *_dst = (uint8_t*)(dst), *_src = (uint8_t*)(src);       \
382         for(_i = 0; _i < size; _i++) {                                  \
383             WRITE((img), _dst +_i, READ((img), _src + _i));             \
384         }                                                               \
385     } while (0)
386
387 #define MEMSET_WRAPPED(img, dst, val, size)                             \
388     do {                                                                \
389         size_t _i;                                                      \
390         uint8_t *_dst = (uint8_t*)(dst);                                \
391         for(_i = 0; _i < (size_t) size; _i++) {                         \
392             WRITE((img), _dst +_i, (val));                              \
393         }                                                               \
394     } while (0)
395
396 #else
397
398 #define ACCESS(sym) sym
399
400 #define READ(img, ptr)          (*(ptr))
401 #define WRITE(img, ptr, val)    (*(ptr) = (val))
402 #define MEMCPY_WRAPPED(img, dst, src, size)                             \
403     memcpy(dst, src, size)
404 #define MEMSET_WRAPPED(img, dst, val, size)                             \
405     memset(dst, val, size)
406
407 #endif
408
409 #define fbComposeGetStart(pict,x,y,type,out_stride,line,mul) do {       \
410         uint32_t        *__bits__;                                      \
411         int             __stride__;                                     \
412                                                                         \
413         __bits__ = pict->bits.bits;                                     \
414         __stride__ = pict->bits.rowstride;                              \
415         (out_stride) = __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type);      \
416         (line) = ((type *) __bits__) +                                  \
417             (out_stride) * (y) + (mul) * (x);                           \
418     } while (0)
419
420
421 #define PIXMAN_FORMAT_16BPC(f)  (PIXMAN_FORMAT_A(f) > 8 || \
422                                  PIXMAN_FORMAT_R(f) > 8 || \
423                                  PIXMAN_FORMAT_G(f) > 8 || \
424                                  PIXMAN_FORMAT_B(f) > 8)
425 /*
426  * Edges
427  */
428
429 #define MAX_ALPHA(n)    ((1 << (n)) - 1)
430 #define N_Y_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
431 #define N_X_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n)/2)) + 1)
432
433 #define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC(n))
434 #define STEP_Y_BIG(n)   (pixman_fixed_1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
435
436 #define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
437 #define Y_FRAC_LAST(n)  (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
438
439 #define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC(n))
440 #define STEP_X_BIG(n)   (pixman_fixed_1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
441
442 #define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
443 #define X_FRAC_LAST(n)  (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
444
445 #define RenderSamplesX(x,n)     ((n) == 1 ? 0 : (pixman_fixed_frac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
446
447 void
448 pixman_rasterize_edges_accessors (pixman_image_t *image,
449                                   pixman_edge_t *l,
450                                   pixman_edge_t *r,
451                                   pixman_fixed_t        t,
452                                   pixman_fixed_t        b);
453
454 /*
455  * Implementations
456  */
457
458 typedef struct pixman_implementation_t pixman_implementation_t;
459
460 typedef void (* pixman_combine_32_func_t) (pixman_implementation_t *    imp,
461                                            pixman_op_t                  op,
462                                            uint32_t *                   dest,
463                                            const uint32_t *             src,
464                                            const uint32_t *             mask,
465                                            int                          width);
466
467 typedef void (* pixman_combine_64_func_t) (pixman_implementation_t *    imp,
468                                            pixman_op_t                  op,
469                                            uint64_t *                   dest,
470                                            const uint64_t *             src,
471                                            const uint64_t *             mask,
472                                            int                          width);
473
474 typedef void (* pixman_composite_func_t)  (pixman_implementation_t *    imp,
475                                            pixman_op_t                  op,
476                                            pixman_image_t *             src,
477                                            pixman_image_t *             mask,
478                                            pixman_image_t *             dest,
479                                            int32_t                      src_x,
480                                            int32_t                      src_y,
481                                            int32_t                      mask_x,
482                                            int32_t                      mask_y,
483                                            int32_t                      dest_x,
484                                            int32_t                      dest_y,
485                                            int32_t                      width,
486                                            int32_t                      height);
487 typedef pixman_bool_t (* pixman_blt_func_t) (pixman_implementation_t *  imp,
488                                              uint32_t *                 src_bits,
489                                              uint32_t *                 dst_bits,
490                                              int                        src_stride,
491                                              int                        dst_stride,
492                                              int                        src_bpp,
493                                              int                        dst_bpp,
494                                              int                        src_x,
495                                              int                        src_y,
496                                              int                        dst_x,
497                                              int                        dst_y,
498                                              int                        width,
499                                              int                        height);
500 typedef pixman_bool_t (* pixman_fill_func_t) (pixman_implementation_t *imp,
501                                               uint32_t *bits,
502                                               int stride,
503                                               int bpp,
504                                               int x,
505                                               int y,
506                                               int width,
507                                               int height,
508                                               uint32_t xor);
509
510 void _pixman_setup_combiner_functions_32 (pixman_implementation_t *imp);
511 void _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp);
512
513 struct pixman_implementation_t
514 {
515     pixman_implementation_t *   toplevel;
516     pixman_implementation_t *   delegate;
517
518     pixman_composite_func_t     composite;
519     pixman_blt_func_t           blt;
520     pixman_fill_func_t          fill;
521     
522     pixman_combine_32_func_t    combine_32[PIXMAN_OP_LAST];
523     pixman_combine_32_func_t    combine_32_ca[PIXMAN_OP_LAST];
524     pixman_combine_64_func_t    combine_64[PIXMAN_OP_LAST];
525     pixman_combine_64_func_t    combine_64_ca[PIXMAN_OP_LAST];
526 };
527
528 pixman_implementation_t *
529 _pixman_implementation_create (pixman_implementation_t *delegate);
530
531 void
532 _pixman_implementation_combine_32 (pixman_implementation_t *    imp,
533                                    pixman_op_t                  op,
534                                    uint32_t *                   dest,
535                                    const uint32_t *             src,
536                                    const uint32_t *             mask,
537                                    int                          width);
538 void
539 _pixman_implementation_combine_64 (pixman_implementation_t *    imp,
540                                    pixman_op_t                  op,
541                                    uint64_t *                   dest,
542                                    const uint64_t *             src,
543                                    const uint64_t *             mask,
544                                    int                          width);
545 void
546 _pixman_implementation_combine_32_ca (pixman_implementation_t * imp,
547                                       pixman_op_t               op,
548                                       uint32_t *                dest,
549                                       const uint32_t *          src,
550                                       const uint32_t *          mask,
551                                       int                       width);
552 void
553 _pixman_implementation_combine_64_ca (pixman_implementation_t * imp,
554                                       pixman_op_t               op,
555                                       uint64_t *                dest,
556                                       const uint64_t *          src,
557                                       const uint64_t *          mask,
558                                       int                       width);
559 void
560 _pixman_implementation_composite (pixman_implementation_t *     imp,
561                                   pixman_op_t                   op,
562                                   pixman_image_t *              src,
563                                   pixman_image_t *              mask,
564                                   pixman_image_t *              dest,
565                                   int32_t                       src_x,
566                                   int32_t                       src_y,
567                                   int32_t                       mask_x,
568                                   int32_t                       mask_y,
569                                   int32_t                       dest_x,
570                                   int32_t                       dest_y,
571                                   int32_t                       width,
572                                   int32_t                       height);
573
574 pixman_bool_t
575 _pixman_implementation_blt (pixman_implementation_t *   imp,
576                             uint32_t *                  src_bits,
577                             uint32_t *                  dst_bits,
578                             int                         src_stride,
579                             int                         dst_stride,
580                             int                         src_bpp,
581                             int                         dst_bpp,
582                             int                         src_x,
583                             int                         src_y,
584                             int                         dst_x,
585                             int                         dst_y,
586                             int                         width,
587                             int                         height);
588 pixman_bool_t
589 _pixman_implementation_fill (pixman_implementation_t *   imp,
590                              uint32_t *bits,
591                              int stride,
592                              int bpp,
593                              int x,
594                              int y,
595                              int width,
596                              int height,
597                              uint32_t xor);
598     
599 /* Specific implementations */
600 pixman_implementation_t *
601 _pixman_implementation_create_general (void);
602 pixman_implementation_t *
603 _pixman_implementation_create_fast_path (void);
604 #ifdef USE_MMX
605 pixman_implementation_t *
606 _pixman_implementation_create_mmx (void);
607 #endif
608 #ifdef USE_SSE2
609 pixman_implementation_t *
610 _pixman_implementation_create_sse2 (void);
611 #endif
612 #ifdef USE_ARM_SIMD
613 pixman_implementation_t *
614 _pixman_implementation_create_arm_simd (void);
615 #endif
616 #ifdef USE_ARM_NEON
617 pixman_implementation_t *
618 _pixman_implementation_create_arm_neon (void);
619 #endif
620 #ifdef USE_VMX
621 pixman_implementation_t *
622 _pixman_implementation_create_vmx (void);
623 #endif
624
625 pixman_implementation_t *
626 _pixman_choose_implementation (void);
627
628
629
630 /*
631  * Utilities
632  */
633
634 /* These "formats" both have depth 0, so they
635  * will never clash with any real ones
636  */
637 #define PIXMAN_null             PIXMAN_FORMAT(0,0,0,0,0,0)
638 #define PIXMAN_solid            PIXMAN_FORMAT(0,1,0,0,0,0)
639
640 #define NEED_COMPONENT_ALPHA            (1 << 0)
641 #define NEED_PIXBUF                     (1 << 1)
642 #define NEED_SOLID_MASK                 (1 << 2)
643
644 typedef struct
645 {
646     pixman_op_t                 op;
647     pixman_format_code_t        src_format;
648     pixman_format_code_t        mask_format;
649     pixman_format_code_t        dest_format;
650     pixman_composite_func_t     func;
651     uint32_t                    flags;
652 } pixman_fast_path_t;
653
654 /* Memory allocation helpers */
655 void *
656 pixman_malloc_ab (unsigned int n, unsigned int b);
657
658 void *
659 pixman_malloc_abc (unsigned int a, unsigned int b, unsigned int c);
660
661 pixman_bool_t
662 pixman_multiply_overflows_int (unsigned int a, unsigned int b);
663
664 pixman_bool_t
665 pixman_addition_overflows_int (unsigned int a, unsigned int b);
666
667 /* Compositing utilities */
668 pixman_bool_t
669 _pixman_run_fast_path (const pixman_fast_path_t *paths,
670                        pixman_implementation_t *imp,
671                        pixman_op_t op,
672                        pixman_image_t *src,
673                        pixman_image_t *mask,
674                        pixman_image_t *dest,
675                        int32_t src_x,
676                        int32_t src_y,
677                        int32_t mask_x,
678                        int32_t mask_y,
679                        int32_t dest_x,
680                        int32_t dest_y,
681                        int32_t width,
682                        int32_t height);
683     
684 void
685 _pixman_walk_composite_region (pixman_implementation_t *imp,
686                                pixman_op_t op,
687                                pixman_image_t * pSrc,
688                                pixman_image_t * pMask,
689                                pixman_image_t * pDst,
690                                int16_t xSrc,
691                                int16_t ySrc,
692                                int16_t xMask,
693                                int16_t yMask,
694                                int16_t xDst,
695                                int16_t yDst,
696                                uint16_t width,
697                                uint16_t height,
698                                pixman_composite_func_t compositeRect);
699
700 void
701 pixman_expand (uint64_t *dst, const uint32_t *src, pixman_format_code_t, int width);
702
703 void
704 pixman_contract (uint32_t *dst, const uint64_t *src, int width);
705
706
707 /* Region Helpers */
708 pixman_bool_t
709 pixman_region32_copy_from_region16 (pixman_region32_t *dst,
710                                     pixman_region16_t *src);
711
712 pixman_bool_t
713 pixman_region16_copy_from_region32 (pixman_region16_t *dst,
714                                     pixman_region32_t *src);
715
716
717 #ifndef FALSE
718 #   define FALSE 0
719 #endif
720
721 #ifndef TRUE
722 #   define TRUE 1
723 #endif
724
725 #ifndef MIN
726 #  define MIN(a,b) ((a < b)? a : b)
727 #endif
728
729 #ifndef MAX
730 #  define MAX(a,b) ((a > b)? a : b)
731 #endif
732
733 /* Integer division that rounds towards -infinity */
734 #define DIV(a,b) ((((a) < 0) == ((b) < 0)) ? (a) / (b) :                \
735                   ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
736
737 /* Modulus that produces the remainder wrt. DIV */
738 #define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
739
740 #define CLIP(v,low,high) ((v) < (low) ? (low) : ((v) > (high) ? (high) : (high)))
741
742
743 /*
744  * Various debugging code
745  */
746
747 #undef DEBUG
748 #define DEBUG 0
749
750 #if DEBUG
751
752 #define return_if_fail(expr)                                            \
753     do                                                                  \
754     {                                                                   \
755         if (!(expr))                                                    \
756         {                                                               \
757             fprintf(stderr, "In %s: %s failed\n", FUNC, #expr);         \
758             return;                                                     \
759         }                                                               \
760     }                                                                   \
761     while (0)
762
763 #define return_val_if_fail(expr, retval)                                \
764     do                                                                  \
765     {                                                                   \
766         if (!(expr))                                                    \
767         {                                                               \
768             fprintf(stderr, "In %s: %s failed\n", FUNC, #expr);         \
769             return (retval);                                            \
770         }                                                               \
771     }                                                                   \
772     while (0)
773
774 #else
775
776 #define return_if_fail(expr)                                            \
777     do                                                                  \
778     {                                                                   \
779         if (!(expr))                                                    \
780             return;                                                     \
781     }                                                                   \
782     while (0)
783
784 #define return_val_if_fail(expr, retval)                                \
785     do                                                                  \
786     {                                                                   \
787         if (!(expr))                                                    \
788             return (retval);                                            \
789     }                                                                   \
790     while (0)
791
792 #endif
793
794 /*
795  * Timers
796  */
797
798 #ifdef PIXMAN_TIMERS
799
800 static inline uint64_t
801 oil_profile_stamp_rdtsc (void)
802 {
803     uint64_t ts;
804     __asm__ __volatile__("rdtsc\n" : "=A" (ts));
805     return ts;
806 }
807 #define OIL_STAMP oil_profile_stamp_rdtsc
808
809 typedef struct pixman_timer_t pixman_timer_t;
810
811 struct pixman_timer_t
812 {
813     int initialized;
814     const char *name;
815     uint64_t n_times;
816     uint64_t total;
817     pixman_timer_t *next;
818 };
819
820 extern int timer_defined;
821 void pixman_timer_register (pixman_timer_t *timer);
822
823 #define TIMER_BEGIN(tname)                                              \
824     {                                                                   \
825         static pixman_timer_t   timer##tname;                           \
826         uint64_t                begin##tname;                           \
827                                                                         \
828         if (!timer##tname.initialized)                                  \
829         {                                                               \
830             timer##tname.initialized = 1;                               \
831             timer##tname.name = #tname;                                 \
832             pixman_timer_register (&timer##tname);                      \
833         }                                                               \
834                                                                         \
835         timer##tname.n_times++;                                         \
836         begin##tname = OIL_STAMP();
837
838 #define TIMER_END(tname)                                                \
839         timer##tname.total += OIL_STAMP() - begin##tname;               \
840     }
841
842 #endif /* PIXMAN_TIMERS */
843
844 #endif /* PIXMAN_PRIVATE_H */