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