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