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