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