Fix scale issues
[profile/ivi/org.tizen.video-player.git] / src / hb-private.h
1 /*
2  * Copyright (C) 2007,2008,2009  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Red Hat Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_PRIVATE_H
28 #define HB_PRIVATE_H
29
30 #if HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include "hb-common.h"
35
36 #include <stdlib.h>
37 #include <string.h>
38 #include <assert.h>
39
40 /* We only use these two for debug output.  However, the debug code is
41  * always seen by the compiler (and optimized out in non-debug builds.
42  * If including these becomes a problem, we can start thinking about
43  * someway around that. */
44 #include <stdio.h>
45 #include <errno.h>
46
47
48 /* Essentials */
49
50 #ifndef NULL
51 # define NULL ((void *) 0)
52 #endif
53
54 #undef FALSE
55 #define FALSE 0
56
57 #undef TRUE
58 #define TRUE 1
59
60
61 /* Basics */
62
63 #undef MIN
64 #define MIN(a,b) ((a) < (b) ? (a) : (b))
65
66 #undef MAX
67 #define MAX(a,b) ((a) > (b) ? (a) : (b))
68
69 #undef  ARRAY_LENGTH
70 #define ARRAY_LENGTH(__array) ((signed int) (sizeof (__array) / sizeof (__array[0])))
71
72 #define HB_STMT_START do
73 #define HB_STMT_END   while (0)
74
75 #define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
76 #define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond))
77 #define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond))
78
79
80 /* Misc */
81
82
83 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
84 #define _HB_BOOLEAN_EXPR(expr) ((expr) ? 1 : 0)
85 #define likely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 1))
86 #define unlikely(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 0))
87 #else
88 #define likely(expr) (expr)
89 #define unlikely(expr) (expr)
90 #endif
91
92 #ifndef __GNUC__
93 #undef __attribute__
94 #define __attribute__(x)
95 #endif
96
97 #if __GNUC__ >= 3
98 #define HB_PURE_FUNC    __attribute__((pure))
99 #define HB_CONST_FUNC   __attribute__((const))
100 #else
101 #define HB_PURE_FUNC
102 #define HB_CONST_FUNC
103 #endif
104 #if __GNUC__ >= 4
105 #define HB_UNUSED       __attribute__((unused))
106 #else
107 #define HB_UNUSED
108 #endif
109
110 #ifndef HB_INTERNAL
111 # define HB_INTERNAL __attribute__((__visibility__("hidden")))
112 #endif
113
114
115 #if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER)
116 #define snprintf _snprintf
117 #endif
118
119 #ifdef _MSC_VER
120 #undef inline
121 #define inline __inline
122 #endif
123
124 #ifdef __STRICT_ANSI__
125 #undef inline
126 #define inline __inline__
127 #endif
128
129
130 #if __GNUC__ >= 3
131 #define HB_FUNC __PRETTY_FUNCTION__
132 #elif defined(_MSC_VER)
133 #define HB_FUNC __FUNCSIG__
134 #else
135 #define HB_FUNC __func__
136 #endif
137
138
139 /* Return the number of 1 bits in mask.
140  *
141  * GCC 3.4 supports a "population count" builtin, which on many targets is
142  * implemented with a single instruction. There is a fallback definition
143  * in libgcc in case a target does not have one, which should be just as
144  * good as the open-coded solution below, (which is "HACKMEM 169").
145  */
146 static inline HB_CONST_FUNC unsigned int
147 _hb_popcount32 (uint32_t mask)
148 {
149 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
150     return __builtin_popcount (mask);
151 #else
152     register uint32_t y;
153
154     y = (mask >> 1) &033333333333;
155     y = mask - y - ((y >>1) & 033333333333);
156     return (((y + (y >> 3)) & 030707070707) % 077);
157 #endif
158 }
159
160
161 /* We need external help for these */
162
163 #ifdef HAVE_GLIB
164
165 #include <glib.h>
166
167 typedef int hb_atomic_int_t;
168 #define hb_atomic_int_fetch_and_add(AI, V)      g_atomic_int_exchange_and_add (&(AI), V)
169 #define hb_atomic_int_get(AI)                   g_atomic_int_get (&(AI))
170 #define hb_atomic_int_set(AI, V)                g_atomic_int_set (&(AI), V)
171
172 typedef GStaticMutex hb_mutex_t;
173 #define HB_MUTEX_INIT                   G_STATIC_MUTEX_INIT
174 #define hb_mutex_init(M)                g_static_mutex_init (&M)
175 #define hb_mutex_lock(M)                g_static_mutex_lock (&M)
176 #define hb_mutex_trylock(M)             g_static_mutex_trylock (&M)
177 #define hb_mutex_unlock(M)              g_static_mutex_unlock (&M)
178
179 #else
180
181 #ifdef _MSC_VER
182 #pragma message(__LOC__"Could not find any system to define platform macros, library will NOT be thread-safe")
183 #else
184 #warning "Could not find any system to define platform macros, library will NOT be thread-safe"
185 #endif
186
187 typedef int hb_atomic_int_t;
188 #define hb_atomic_int_fetch_and_add(AI, V)      ((AI) += (V), (AI) - (V))
189 #define hb_atomic_int_get(AI)                   (AI)
190 #define hb_atomic_int_set(AI, V)                HB_STMT_START { (AI) = (V); } HB_STMT_END
191
192 typedef int hb_mutex_t;
193 #define HB_MUTEX_INIT                           0
194 #define hb_mutex_init(M)                        HB_STMT_START { (M) = 0; } HB_STMT_END
195 #define hb_mutex_lock(M)                        HB_STMT_START { (M) = 1; } HB_STMT_END
196 #define hb_mutex_trylock(M)                     ((M) = 1, 1)
197 #define hb_mutex_unlock(M)                      HB_STMT_START { (M) = 0; } HB_STMT_END
198
199 #endif
200
201
202 /* Big-endian handling */
203
204 #define hb_be_uint16(v)         ((uint16_t) ((((const uint8_t *)&(v))[0] << 8) + (((const uint8_t *)&(v))[1])))
205
206 #define hb_be_uint16_put(v,V)   HB_STMT_START { v[0] = (V>>8); v[1] = (V); } HB_STMT_END
207 #define hb_be_uint16_get(v)     (uint16_t) ((v[0] << 8) + v[1])
208 #define hb_be_uint16_cmp(a,b)   (a[0] == b[0] && a[1] == b[1])
209
210 #define hb_be_uint32_put(v,V)   HB_STMT_START { v[0] = (V>>24); v[1] = (V>>16); v[2] = (V>>8); v[3] = (V); } HB_STMT_END
211 #define hb_be_uint32_get(v)     (uint32_t) ((v[0] << 24) + (v[1] << 16) + (v[2] << 8) + v[3])
212 #define hb_be_uint32_cmp(a,b)   (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3])
213
214
215 /* Debug */
216
217 #ifndef HB_DEBUG
218 #define HB_DEBUG 0
219 #endif
220
221 static inline hb_bool_t /* always returns TRUE */
222 _hb_trace (const char *what,
223            const char *function,
224            const void *obj,
225            unsigned int depth,
226            unsigned int max_depth)
227 {
228   if (depth < max_depth)
229     fprintf (stderr, "%s(%p) %-*d-> %s\n", what, obj, depth, depth, function);
230   return TRUE;
231 }
232
233
234 #include "hb-object-private.h"
235
236 #endif /* HB_PRIVATE_H */