Move edge stepper macros into pixman-edge.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 #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 void
530 pixman_rasterize_edges_accessors (pixman_image_t *image,
531                                   pixman_edge_t *l,
532                                   pixman_edge_t *r,
533                                   pixman_fixed_t        t,
534                                   pixman_fixed_t        b);
535
536 pixman_bool_t
537 pixman_image_is_opaque(pixman_image_t *image);
538
539 pixman_bool_t
540 pixman_image_is_solid (pixman_image_t *image);
541
542 uint32_t
543 pixman_image_get_solid (pixman_image_t *image,
544                         pixman_format_code_t format);
545
546 pixman_bool_t
547 pixman_compute_composite_region32 (pixman_region32_t *  pRegion,
548                                    pixman_image_t *     pSrc,
549                                    pixman_image_t *     pMask,
550                                    pixman_image_t *     pDst,
551                                    int16_t              xSrc,
552                                    int16_t              ySrc,
553                                    int16_t              xMask,
554                                    int16_t              yMask,
555                                    int16_t              xDst,
556                                    int16_t              yDst,
557                                    uint16_t             width,
558                                    uint16_t             height);
559
560 /* Region Helpers */
561 pixman_bool_t pixman_region32_copy_from_region16 (pixman_region32_t *dst,
562                                                   pixman_region16_t *src);
563 pixman_bool_t pixman_region16_copy_from_region32 (pixman_region16_t *dst,
564                                                   pixman_region32_t *src);
565
566 #ifdef PIXMAN_TIMERS
567
568 /* Timing */
569 static inline uint64_t
570 oil_profile_stamp_rdtsc (void)
571 {
572     uint64_t ts;
573     __asm__ __volatile__("rdtsc\n" : "=A" (ts));
574     return ts;
575 }
576 #define OIL_STAMP oil_profile_stamp_rdtsc
577
578 typedef struct pixman_timer_t pixman_timer_t;
579
580 struct pixman_timer_t
581 {
582     int initialized;
583     const char *name;
584     uint64_t n_times;
585     uint64_t total;
586     pixman_timer_t *next;
587 };
588
589 extern int timer_defined;
590 void pixman_timer_register (pixman_timer_t *timer);
591
592 #define TIMER_BEGIN(tname)                                              \
593     {                                                                   \
594         static pixman_timer_t   timer##tname;                           \
595         uint64_t                begin##tname;                           \
596                                                                         \
597         if (!timer##tname.initialized)                                  \
598         {                                                               \
599             timer##tname.initialized = 1;                               \
600             timer##tname.name = #tname;                                 \
601             pixman_timer_register (&timer##tname);                      \
602         }                                                               \
603                                                                         \
604         timer##tname.n_times++;                                         \
605         begin##tname = OIL_STAMP();
606
607 #define TIMER_END(tname)                                                \
608         timer##tname.total += OIL_STAMP() - begin##tname;               \
609     }
610
611 #endif /* PIXMAN_TIMERS */
612
613 typedef struct pixman_implementation_t pixman_implementation_t;
614
615 typedef void (* pixman_combine_32_func_t) (pixman_implementation_t *    imp,
616                                            pixman_op_t                  op,
617                                            uint32_t *                   dest,
618                                            const uint32_t *             src,
619                                            const uint32_t *             mask,
620                                            int                          width);
621
622 typedef void (* pixman_combine_64_func_t) (pixman_implementation_t *    imp,
623                                            pixman_op_t                  op,
624                                            uint64_t *                   dest,
625                                            const uint64_t *             src,
626                                            const uint64_t *             mask,
627                                            int                          width);
628
629 typedef void (* pixman_composite_func_t)  (pixman_implementation_t *    imp,
630                                            pixman_op_t                  op,
631                                            pixman_image_t *             src,
632                                            pixman_image_t *             mask,
633                                            pixman_image_t *             dest,
634                                            int32_t                      src_x,
635                                            int32_t                      src_y,
636                                            int32_t                      mask_x,
637                                            int32_t                      mask_y,
638                                            int32_t                      dest_x,
639                                            int32_t                      dest_y,
640                                            int32_t                      width,
641                                            int32_t                      height);
642 typedef pixman_bool_t (* pixman_blt_func_t) (pixman_implementation_t *  imp,
643                                              uint32_t *                 src_bits,
644                                              uint32_t *                 dst_bits,
645                                              int                        src_stride,
646                                              int                        dst_stride,
647                                              int                        src_bpp,
648                                              int                        dst_bpp,
649                                              int                        src_x,
650                                              int                        src_y,
651                                              int                        dst_x,
652                                              int                        dst_y,
653                                              int                        width,
654                                              int                        height);
655 typedef pixman_bool_t (* pixman_fill_func_t) (pixman_implementation_t *imp,
656                                               uint32_t *bits,
657                                               int stride,
658                                               int bpp,
659                                               int x,
660                                               int y,
661                                               int width,
662                                               int height,
663                                               uint32_t xor);
664
665 void
666 _pixman_walk_composite_region (pixman_implementation_t *imp,
667                                pixman_op_t op,
668                                pixman_image_t * pSrc,
669                                pixman_image_t * pMask,
670                                pixman_image_t * pDst,
671                                int16_t xSrc,
672                                int16_t ySrc,
673                                int16_t xMask,
674                                int16_t yMask,
675                                int16_t xDst,
676                                int16_t yDst,
677                                uint16_t width,
678                                uint16_t height,
679                                pixman_composite_func_t compositeRect);
680
681 void _pixman_setup_combiner_functions_32 (pixman_implementation_t *imp);
682 void _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp);
683
684 /* These "formats" both have depth 0, so they
685  * will never clash with any real ones
686  */
687 #define PIXMAN_null             PIXMAN_FORMAT(0,0,0,0,0,0)
688 #define PIXMAN_solid            PIXMAN_FORMAT(0,1,0,0,0,0)
689
690 #define NEED_COMPONENT_ALPHA            (1 << 0)
691 #define NEED_PIXBUF                     (1 << 1)
692 #define NEED_SOLID_MASK                 (1 << 2)
693
694 typedef struct
695 {
696     pixman_op_t                 op;
697     pixman_format_code_t        src_format;
698     pixman_format_code_t        mask_format;
699     pixman_format_code_t        dest_format;
700     pixman_composite_func_t     func;
701     uint32_t                    flags;
702 } pixman_fast_path_t;
703
704 struct pixman_implementation_t
705 {
706     pixman_implementation_t *   toplevel;
707     pixman_implementation_t *   delegate;
708
709     pixman_composite_func_t     composite;
710     pixman_blt_func_t           blt;
711     pixman_fill_func_t          fill;
712     
713     pixman_combine_32_func_t    combine_32[PIXMAN_OP_LAST];
714     pixman_combine_32_func_t    combine_32_ca[PIXMAN_OP_LAST];
715     pixman_combine_64_func_t    combine_64[PIXMAN_OP_LAST];
716     pixman_combine_64_func_t    combine_64_ca[PIXMAN_OP_LAST];
717 };
718
719 pixman_implementation_t *
720 _pixman_implementation_create (pixman_implementation_t *delegate);
721
722 void
723 _pixman_implementation_combine_32 (pixman_implementation_t *    imp,
724                                    pixman_op_t                  op,
725                                    uint32_t *                   dest,
726                                    const uint32_t *             src,
727                                    const uint32_t *             mask,
728                                    int                          width);
729 void
730 _pixman_implementation_combine_64 (pixman_implementation_t *    imp,
731                                    pixman_op_t                  op,
732                                    uint64_t *                   dest,
733                                    const uint64_t *             src,
734                                    const uint64_t *             mask,
735                                    int                          width);
736 void
737 _pixman_implementation_combine_32_ca (pixman_implementation_t * imp,
738                                       pixman_op_t               op,
739                                       uint32_t *                dest,
740                                       const uint32_t *          src,
741                                       const uint32_t *          mask,
742                                       int                       width);
743 void
744 _pixman_implementation_combine_64_ca (pixman_implementation_t * imp,
745                                       pixman_op_t               op,
746                                       uint64_t *                dest,
747                                       const uint64_t *          src,
748                                       const uint64_t *          mask,
749                                       int                       width);
750 void
751 _pixman_implementation_composite (pixman_implementation_t *     imp,
752                                   pixman_op_t                   op,
753                                   pixman_image_t *              src,
754                                   pixman_image_t *              mask,
755                                   pixman_image_t *              dest,
756                                   int32_t                       src_x,
757                                   int32_t                       src_y,
758                                   int32_t                       mask_x,
759                                   int32_t                       mask_y,
760                                   int32_t                       dest_x,
761                                   int32_t                       dest_y,
762                                   int32_t                       width,
763                                   int32_t                       height);
764
765 pixman_bool_t
766 _pixman_implementation_blt (pixman_implementation_t *   imp,
767                             uint32_t *                  src_bits,
768                             uint32_t *                  dst_bits,
769                             int                         src_stride,
770                             int                         dst_stride,
771                             int                         src_bpp,
772                             int                         dst_bpp,
773                             int                         src_x,
774                             int                         src_y,
775                             int                         dst_x,
776                             int                         dst_y,
777                             int                         width,
778                             int                         height);
779 pixman_bool_t
780 _pixman_implementation_fill (pixman_implementation_t *   imp,
781                              uint32_t *bits,
782                              int stride,
783                              int bpp,
784                              int x,
785                              int y,
786                              int width,
787                              int height,
788                              uint32_t xor);
789     
790 /* Specific implementations */
791 pixman_implementation_t *
792 _pixman_implementation_create_general (void);
793 pixman_implementation_t *
794 _pixman_implementation_create_fast_path (void);
795 #ifdef USE_MMX
796 pixman_implementation_t *
797 _pixman_implementation_create_mmx (void);
798 #endif
799 #ifdef USE_SSE2
800 pixman_implementation_t *
801 _pixman_implementation_create_sse2 (void);
802 #endif
803 #ifdef USE_ARM_SIMD
804 pixman_implementation_t *
805 _pixman_implementation_create_arm_simd (void);
806 #endif
807 #ifdef USE_ARM_NEON
808 pixman_implementation_t *
809 _pixman_implementation_create_arm_neon (void);
810 #endif
811 #ifdef USE_VMX
812 pixman_implementation_t *
813 _pixman_implementation_create_vmx (void);
814 #endif
815
816 pixman_bool_t
817 _pixman_run_fast_path (const pixman_fast_path_t *paths,
818                        pixman_implementation_t *imp,
819                        pixman_op_t op,
820                        pixman_image_t *src,
821                        pixman_image_t *mask,
822                        pixman_image_t *dest,
823                        int32_t src_x,
824                        int32_t src_y,
825                        int32_t mask_x,
826                        int32_t mask_y,
827                        int32_t dest_x,
828                        int32_t dest_y,
829                        int32_t width,
830                        int32_t height);
831     
832 pixman_implementation_t *
833 _pixman_choose_implementation (void);
834
835 #endif /* PIXMAN_PRIVATE_H */