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