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