Tizen 2.0 Release
[framework/graphics/cairo.git] / src / cairo-time-private.h
1 /* cairo - a vector graphics library with display and print output
2  *
3  * Copyright (C) 2011 Andrea Canciani
4  *
5  * Permission to use, copy, modify, distribute, and sell this software
6  * and its documentation for any purpose is hereby granted without
7  * fee, provided that the above copyright notice appear in all copies
8  * and that both that copyright notice and this permission notice
9  * appear in supporting documentation, and that the name of the
10  * copyright holders not be used in advertising or publicity
11  * pertaining to distribution of the software without specific,
12  * written prior permission. The copyright holders make no
13  * representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied
15  * warranty.
16  *
17  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
23  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24  * SOFTWARE.
25  *
26  * Authors: Andrea Canciani <ranma42@gmail.com>
27  *
28  */
29
30 #ifndef CAIRO_TIME_PRIVATE_H
31 #define CAIRO_TIME_PRIVATE_H
32
33 #include "cairo-compiler-private.h"
34 #include "cairo-wideint-private.h"
35
36 /* Make the base type signed for easier arithmetic */
37 typedef cairo_int64_t cairo_time_t;
38
39 #define _cairo_time_add _cairo_int64_add
40 #define _cairo_time_sub _cairo_int64_sub
41 #define _cairo_time_gt  _cairo_int64_gt
42 #define _cairo_time_lt  _cairo_int64_lt
43
44 #define _cairo_time_to_double   _cairo_int64_to_double
45 #define _cairo_time_from_double _cairo_double_to_int64
46
47 cairo_private int
48 _cairo_time_cmp (const void *a,
49                  const void *b);
50
51 cairo_private double
52 _cairo_time_to_s (cairo_time_t t);
53
54 cairo_private cairo_time_t
55 _cairo_time_from_s (double t);
56
57 cairo_private cairo_time_t
58 _cairo_time_get (void);
59
60 static cairo_always_inline cairo_time_t
61 _cairo_time_get_delta (cairo_time_t t)
62 {
63     cairo_time_t now;
64
65     now = _cairo_time_get ();
66
67     return _cairo_time_sub (now, t);
68 }
69
70 static cairo_always_inline double
71 _cairo_time_to_ns (cairo_time_t t)
72 {
73     return 1.e9 * _cairo_time_to_s (t);
74 }
75
76 static cairo_always_inline cairo_time_t
77 _cairo_time_max (cairo_time_t a, cairo_time_t b)
78 {
79     if (_cairo_int64_gt (a, b))
80         return a;
81     else
82         return b;
83 }
84
85 static cairo_always_inline cairo_time_t
86 _cairo_time_min (cairo_time_t a, cairo_time_t b)
87 {
88     if (_cairo_int64_lt (a, b))
89         return a;
90     else
91         return b;
92 }
93
94 #endif