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