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