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