Remove nonexistant function from header
[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
258 /* Even though the type of buffer is uint32_t *, the function
259  * actually expects a uint64_t *buffer.
260  */
261 void
262 _pixman_image_store_scanline_64 (bits_image_t *  image,
263                                  int             x,
264                                  int             y,
265                                  int             width,
266                                  const uint32_t *buffer);
267
268 pixman_image_t *
269 _pixman_image_allocate (void);
270
271 pixman_bool_t
272 _pixman_init_gradient (gradient_t *                  gradient,
273                        const pixman_gradient_stop_t *stops,
274                        int                           n_stops);
275 void
276 _pixman_image_reset_clip_region (pixman_image_t *image);
277
278 void
279 _pixman_image_validate (pixman_image_t *image);
280
281 pixman_bool_t
282 _pixman_image_is_opaque (pixman_image_t *image);
283
284 pixman_bool_t
285 _pixman_image_is_solid (pixman_image_t *image);
286
287 uint32_t
288 _pixman_image_get_solid (pixman_image_t *     image,
289                          pixman_format_code_t format);
290
291 #define PIXMAN_IMAGE_GET_LINE(image, x, y, type, out_stride, line, mul) \
292     do                                                                  \
293     {                                                                   \
294         uint32_t *__bits__;                                             \
295         int       __stride__;                                           \
296                                                                         \
297         __bits__ = image->bits.bits;                                    \
298         __stride__ = image->bits.rowstride;                             \
299         (out_stride) =                                                  \
300             __stride__ * (int) sizeof (uint32_t) / (int) sizeof (type); \
301         (line) =                                                        \
302             ((type *) __bits__) + (out_stride) * (y) + (mul) * (x);     \
303     } while (0)
304
305 /*
306  * Gradient walker
307  */
308 typedef struct
309 {
310     uint32_t                left_ag;
311     uint32_t                left_rb;
312     uint32_t                right_ag;
313     uint32_t                right_rb;
314     int32_t                 left_x;
315     int32_t                 right_x;
316     int32_t                 stepper;
317
318     pixman_gradient_stop_t *stops;
319     int                     num_stops;
320     unsigned int            spread;
321
322     int                     need_reset;
323 } pixman_gradient_walker_t;
324
325 void
326 _pixman_gradient_walker_init (pixman_gradient_walker_t *walker,
327                               gradient_t *              gradient,
328                               unsigned int              spread);
329
330 void
331 _pixman_gradient_walker_reset (pixman_gradient_walker_t *walker,
332                                pixman_fixed_32_32_t      pos);
333
334 uint32_t
335 _pixman_gradient_walker_pixel (pixman_gradient_walker_t *walker,
336                                pixman_fixed_32_32_t      x);
337
338 /*
339  * Edges
340  */
341
342 #define MAX_ALPHA(n)    ((1 << (n)) - 1)
343 #define N_Y_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n) / 2)) - 1)
344 #define N_X_FRAC(n)     ((n) == 1 ? 1 : (1 << ((n) / 2)) + 1)
345
346 #define STEP_Y_SMALL(n) (pixman_fixed_1 / N_Y_FRAC (n))
347 #define STEP_Y_BIG(n)   (pixman_fixed_1 - (N_Y_FRAC (n) - 1) * STEP_Y_SMALL (n))
348
349 #define Y_FRAC_FIRST(n) (STEP_Y_SMALL (n) / 2)
350 #define Y_FRAC_LAST(n)  (Y_FRAC_FIRST (n) + (N_Y_FRAC (n) - 1) * STEP_Y_SMALL (n))
351
352 #define STEP_X_SMALL(n) (pixman_fixed_1 / N_X_FRAC (n))
353 #define STEP_X_BIG(n)   (pixman_fixed_1 - (N_X_FRAC (n) - 1) * STEP_X_SMALL (n))
354
355 #define X_FRAC_FIRST(n) (STEP_X_SMALL (n) / 2)
356 #define X_FRAC_LAST(n)  (X_FRAC_FIRST (n) + (N_X_FRAC (n) - 1) * STEP_X_SMALL (n))
357
358 #define RENDER_SAMPLES_X(x, n)                                          \
359     ((n) == 1? 0 : (pixman_fixed_frac (x) +                             \
360                     X_FRAC_FIRST (n)) / STEP_X_SMALL (n))
361
362 void
363 pixman_rasterize_edges_accessors (pixman_image_t *image,
364                                   pixman_edge_t * l,
365                                   pixman_edge_t * r,
366                                   pixman_fixed_t  t,
367                                   pixman_fixed_t  b);
368
369 /*
370  * Implementations
371  */
372
373 typedef struct pixman_implementation_t pixman_implementation_t;
374
375 typedef void (*pixman_combine_32_func_t) (pixman_implementation_t *imp,
376                                           pixman_op_t              op,
377                                           uint32_t *               dest,
378                                           const uint32_t *         src,
379                                           const uint32_t *         mask,
380                                           int                      width);
381
382 typedef void (*pixman_combine_64_func_t) (pixman_implementation_t *imp,
383                                           pixman_op_t              op,
384                                           uint64_t *               dest,
385                                           const uint64_t *         src,
386                                           const uint64_t *         mask,
387                                           int                      width);
388
389 typedef void (*pixman_composite_func_t) (pixman_implementation_t *imp,
390                                          pixman_op_t              op,
391                                          pixman_image_t *         src,
392                                          pixman_image_t *         mask,
393                                          pixman_image_t *         dest,
394                                          int32_t                  src_x,
395                                          int32_t                  src_y,
396                                          int32_t                  mask_x,
397                                          int32_t                  mask_y,
398                                          int32_t                  dest_x,
399                                          int32_t                  dest_y,
400                                          int32_t                  width,
401                                          int32_t                  height);
402 typedef pixman_bool_t (*pixman_blt_func_t) (pixman_implementation_t *imp,
403                                             uint32_t *               src_bits,
404                                             uint32_t *               dst_bits,
405                                             int                      src_stride,
406                                             int                      dst_stride,
407                                             int                      src_bpp,
408                                             int                      dst_bpp,
409                                             int                      src_x,
410                                             int                      src_y,
411                                             int                      dst_x,
412                                             int                      dst_y,
413                                             int                      width,
414                                             int                      height);
415 typedef pixman_bool_t (*pixman_fill_func_t) (pixman_implementation_t *imp,
416                                              uint32_t *               bits,
417                                              int                      stride,
418                                              int                      bpp,
419                                              int                      x,
420                                              int                      y,
421                                              int                      width,
422                                              int                      height,
423                                              uint32_t                 xor);
424
425 void _pixman_setup_combiner_functions_32 (pixman_implementation_t *imp);
426 void _pixman_setup_combiner_functions_64 (pixman_implementation_t *imp);
427
428 struct pixman_implementation_t
429 {
430     pixman_implementation_t *toplevel;
431     pixman_implementation_t *delegate;
432
433     pixman_composite_func_t  composite;
434     pixman_blt_func_t        blt;
435     pixman_fill_func_t       fill;
436
437     pixman_combine_32_func_t combine_32[PIXMAN_N_OPERATORS];
438     pixman_combine_32_func_t combine_32_ca[PIXMAN_N_OPERATORS];
439     pixman_combine_64_func_t combine_64[PIXMAN_N_OPERATORS];
440     pixman_combine_64_func_t combine_64_ca[PIXMAN_N_OPERATORS];
441 };
442
443 pixman_implementation_t *
444 _pixman_implementation_create (pixman_implementation_t *delegate);
445
446 void
447 _pixman_implementation_combine_32 (pixman_implementation_t *imp,
448                                    pixman_op_t              op,
449                                    uint32_t *               dest,
450                                    const uint32_t *         src,
451                                    const uint32_t *         mask,
452                                    int                      width);
453 void
454 _pixman_implementation_combine_64 (pixman_implementation_t *imp,
455                                    pixman_op_t              op,
456                                    uint64_t *               dest,
457                                    const uint64_t *         src,
458                                    const uint64_t *         mask,
459                                    int                      width);
460 void
461 _pixman_implementation_combine_32_ca (pixman_implementation_t *imp,
462                                       pixman_op_t              op,
463                                       uint32_t *               dest,
464                                       const uint32_t *         src,
465                                       const uint32_t *         mask,
466                                       int                      width);
467 void
468 _pixman_implementation_combine_64_ca (pixman_implementation_t *imp,
469                                       pixman_op_t              op,
470                                       uint64_t *               dest,
471                                       const uint64_t *         src,
472                                       const uint64_t *         mask,
473                                       int                      width);
474 void
475 _pixman_implementation_composite (pixman_implementation_t *imp,
476                                   pixman_op_t              op,
477                                   pixman_image_t *         src,
478                                   pixman_image_t *         mask,
479                                   pixman_image_t *         dest,
480                                   int32_t                  src_x,
481                                   int32_t                  src_y,
482                                   int32_t                  mask_x,
483                                   int32_t                  mask_y,
484                                   int32_t                  dest_x,
485                                   int32_t                  dest_y,
486                                   int32_t                  width,
487                                   int32_t                  height);
488
489 pixman_bool_t
490 _pixman_implementation_blt (pixman_implementation_t *imp,
491                             uint32_t *               src_bits,
492                             uint32_t *               dst_bits,
493                             int                      src_stride,
494                             int                      dst_stride,
495                             int                      src_bpp,
496                             int                      dst_bpp,
497                             int                      src_x,
498                             int                      src_y,
499                             int                      dst_x,
500                             int                      dst_y,
501                             int                      width,
502                             int                      height);
503
504 pixman_bool_t
505 _pixman_implementation_fill (pixman_implementation_t *imp,
506                              uint32_t *               bits,
507                              int                      stride,
508                              int                      bpp,
509                              int                      x,
510                              int                      y,
511                              int                      width,
512                              int                      height,
513                              uint32_t                 xor);
514
515 /* Specific implementations */
516 pixman_implementation_t *
517 _pixman_implementation_create_general (void);
518
519 pixman_implementation_t *
520 _pixman_implementation_create_fast_path (void);
521
522 #ifdef USE_MMX
523 pixman_implementation_t *
524 _pixman_implementation_create_mmx (void);
525 #endif
526
527 #ifdef USE_SSE2
528 pixman_implementation_t *
529 _pixman_implementation_create_sse2 (void);
530 #endif
531
532 #ifdef USE_ARM_SIMD
533 pixman_implementation_t *
534 _pixman_implementation_create_arm_simd (void);
535 #endif
536
537 #ifdef USE_ARM_NEON
538 pixman_implementation_t *
539 _pixman_implementation_create_arm_neon (void);
540 #endif
541
542 #ifdef USE_VMX
543 pixman_implementation_t *
544 _pixman_implementation_create_vmx (void);
545 #endif
546
547 pixman_implementation_t *
548 _pixman_choose_implementation (void);
549
550
551
552 /*
553  * Utilities
554  */
555
556 /* These "formats" all have depth 0, so they
557  * will never clash with any real ones
558  */
559 #define PIXMAN_null             PIXMAN_FORMAT (0, 0, 0, 0, 0, 0)
560 #define PIXMAN_solid            PIXMAN_FORMAT (0, 1, 0, 0, 0, 0)
561 #define PIXMAN_a8r8g8b8_ca      PIXMAN_FORMAT (0, 2, 0, 0, 0, 0)
562 #define PIXMAN_a8b8g8r8_ca      PIXMAN_FORMAT (0, 3, 0, 0, 0, 0)
563 #define PIXMAN_pixbuf           PIXMAN_FORMAT (0, 4, 0, 0, 0, 0)
564 #define PIXMAN_rpixbuf          PIXMAN_FORMAT (0, 5, 0, 0, 0, 0)
565
566 typedef struct
567 {
568     pixman_op_t             op;
569     pixman_format_code_t    src_format;
570     pixman_format_code_t    mask_format;
571     pixman_format_code_t    dest_format;
572     pixman_composite_func_t func;
573 } pixman_fast_path_t;
574
575 /* Memory allocation helpers */
576 void *
577 pixman_malloc_ab (unsigned int n, unsigned int b);
578
579 void *
580 pixman_malloc_abc (unsigned int a, unsigned int b, unsigned int c);
581
582 pixman_bool_t
583 pixman_multiply_overflows_int (unsigned int a, unsigned int b);
584
585 pixman_bool_t
586 pixman_addition_overflows_int (unsigned int a, unsigned int b);
587
588 /* Compositing utilities */
589 pixman_bool_t
590 _pixman_run_fast_path (const pixman_fast_path_t *paths,
591                        pixman_implementation_t * imp,
592                        pixman_op_t               op,
593                        pixman_image_t *          src,
594                        pixman_image_t *          mask,
595                        pixman_image_t *          dest,
596                        int32_t                   src_x,
597                        int32_t                   src_y,
598                        int32_t                   mask_x,
599                        int32_t                   mask_y,
600                        int32_t                   dest_x,
601                        int32_t                   dest_y,
602                        int32_t                   width,
603                        int32_t                   height);
604
605 void
606 _pixman_walk_composite_region (pixman_implementation_t *imp,
607                                pixman_op_t              op,
608                                pixman_image_t *         src_image,
609                                pixman_image_t *         mask_image,
610                                pixman_image_t *         dst_image,
611                                int32_t                  src_x,
612                                int32_t                  src_y,
613                                int32_t                  mask_x,
614                                int32_t                  mask_y,
615                                int32_t                  dest_x,
616                                int32_t                  dest_y,
617                                int32_t                  width,
618                                int32_t                  height,
619                                pixman_composite_func_t  composite_rect);
620
621 void
622 pixman_expand (uint64_t *           dst,
623                const uint32_t *     src,
624                pixman_format_code_t format,
625                int                  width);
626
627 void
628 pixman_contract (uint32_t *      dst,
629                  const uint64_t *src,
630                  int             width);
631
632
633 /* Region Helpers */
634 pixman_bool_t
635 pixman_region32_copy_from_region16 (pixman_region32_t *dst,
636                                     pixman_region16_t *src);
637
638 pixman_bool_t
639 pixman_region16_copy_from_region32 (pixman_region16_t *dst,
640                                     pixman_region32_t *src);
641
642
643 /* Misc macros */
644
645 #ifndef FALSE
646 #   define FALSE 0
647 #endif
648
649 #ifndef TRUE
650 #   define TRUE 1
651 #endif
652
653 #ifndef MIN
654 #  define MIN(a, b) ((a < b) ? a : b)
655 #endif
656
657 #ifndef MAX
658 #  define MAX(a, b) ((a > b) ? a : b)
659 #endif
660
661 /* Integer division that rounds towards -infinity */
662 #define DIV(a, b)                                          \
663     ((((a) < 0) == ((b) < 0)) ? (a) / (b) :                \
664      ((a) - (b) + 1 - (((b) < 0) << 1)) / (b))
665
666 /* Modulus that produces the remainder wrt. DIV */
667 #define MOD(a, b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b))
668
669 #define CLIP(v, low, high) ((v) < (low) ? (low) : ((v) > (high) ? (high) : (v)))
670
671 /* Conversion between 8888 and 0565 */
672
673 #define CONVERT_8888_TO_0565(s)                                         \
674     ((((s) >> 3) & 0x001f) |                                            \
675      (((s) >> 5) & 0x07e0) |                                            \
676      (((s) >> 8) & 0xf800))
677
678 #define CONVERT_0565_TO_0888(s)                                         \
679     (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) |                       \
680      ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) |                   \
681      ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
682
683 #define PIXMAN_FORMAT_IS_WIDE(f)                                        \
684     (PIXMAN_FORMAT_A (f) > 8 ||                                         \
685      PIXMAN_FORMAT_R (f) > 8 ||                                         \
686      PIXMAN_FORMAT_G (f) > 8 ||                                         \
687      PIXMAN_FORMAT_B (f) > 8)
688
689 /*
690  * Various debugging code
691  */
692
693 #undef DEBUG
694 #define DEBUG 0
695
696 #if DEBUG
697
698 #define return_if_fail(expr)                                            \
699     do                                                                  \
700     {                                                                   \
701         if (!(expr))                                                    \
702         {                                                               \
703             fprintf (stderr, "In %s: %s failed\n", FUNC, # expr);       \
704             return;                                                     \
705         }                                                               \
706     }                                                                   \
707     while (0)
708
709 #define return_val_if_fail(expr, retval)                                \
710     do                                                                  \
711     {                                                                   \
712         if (!(expr))                                                    \
713         {                                                               \
714             fprintf (stderr, "In %s: %s failed\n", FUNC, # expr);       \
715             return (retval);                                            \
716         }                                                               \
717     }                                                                   \
718     while (0)
719
720 #else
721
722 #define return_if_fail(expr)                                            \
723     do                                                                  \
724     {                                                                   \
725         if (!(expr))                                                    \
726             return;                                                     \
727     }                                                                   \
728     while (0)
729
730 #define return_val_if_fail(expr, retval)                                \
731     do                                                                  \
732     {                                                                   \
733         if (!(expr))                                                    \
734             return (retval);                                            \
735     }                                                                   \
736     while (0)
737
738 #endif
739
740 /*
741  * Timers
742  */
743
744 #ifdef PIXMAN_TIMERS
745
746 static inline uint64_t
747 oil_profile_stamp_rdtsc (void)
748 {
749     uint64_t ts;
750
751     __asm__ __volatile__ ("rdtsc\n" : "=A" (ts));
752     return ts;
753 }
754
755 #define OIL_STAMP oil_profile_stamp_rdtsc
756
757 typedef struct pixman_timer_t pixman_timer_t;
758
759 struct pixman_timer_t
760 {
761     int             initialized;
762     const char *    name;
763     uint64_t        n_times;
764     uint64_t        total;
765     pixman_timer_t *next;
766 };
767
768 extern int timer_defined;
769
770 void pixman_timer_register (pixman_timer_t *timer);
771
772 #define TIMER_BEGIN(tname)                                              \
773     {                                                                   \
774         static pixman_timer_t timer ## tname;                           \
775         uint64_t              begin ## tname;                           \
776                                                                         \
777         if (!timer ## tname.initialized)                                \
778         {                                                               \
779             timer ## tname.initialized = 1;                             \
780             timer ## tname.name = # tname;                              \
781             pixman_timer_register (&timer ## tname);                    \
782         }                                                               \
783                                                                         \
784         timer ## tname.n_times++;                                       \
785         begin ## tname = OIL_STAMP ();
786
787 #define TIMER_END(tname)                                                \
788     timer ## tname.total += OIL_STAMP () - begin ## tname;              \
789     }
790
791 #endif /* PIXMAN_TIMERS */
792
793 #endif /* PIXMAN_PRIVATE_H */