• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2006 The Android Open Source Project
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 
10 #ifndef SkPostConfig_DEFINED
11 #define SkPostConfig_DEFINED
12 
13 #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
14     #define SK_BUILD_FOR_WIN
15 #endif
16 
17 #if defined(SK_DEBUG) && defined(SK_RELEASE)
18     #error "cannot define both SK_DEBUG and SK_RELEASE"
19 #elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
20     #error "must define either SK_DEBUG or SK_RELEASE"
21 #endif
22 
23 #if defined SK_SUPPORT_UNITTEST && !defined(SK_DEBUG)
24     #error "can't have unittests without debug"
25 #endif
26 
27 #if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT)
28     #error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT"
29 #elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT)
30     #ifdef SK_CAN_USE_FLOAT
31         #define SK_SCALAR_IS_FLOAT
32     #else
33         #define SK_SCALAR_IS_FIXED
34     #endif
35 #endif
36 
37 #if defined(SK_SCALAR_IS_FLOAT) && !defined(SK_CAN_USE_FLOAT)
38     #define SK_CAN_USE_FLOAT
39     // we do nothing in the else case: fixed-scalars can have floats or not
40 #endif
41 
42 #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
43     #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
44 #elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
45     #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
46 #endif
47 
48 // ensure the port has defined all of these, or none of them
49 #ifdef SK_A32_SHIFT
50     #if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
51         #error "all or none of the 32bit SHIFT amounts must be defined"
52     #endif
53 #else
54     #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
55         #error "all or none of the 32bit SHIFT amounts must be defined"
56     #endif
57 #endif
58 
59 #if !defined(SK_HAS_COMPILER_FEATURE)
60     #if defined(__has_feature)
61         #define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
62     #else
63         #define SK_HAS_COMPILER_FEATURE(x) 0
64     #endif
65 #endif
66 
67 /**
68  * The clang static analyzer likes to know that when the program is not
69  * expected to continue (crash, assertion failure, etc). It will notice that
70  * some combination of parameters lead to a function call that does not return.
71  * It can then make appropriate assumptions about the parameters in code
72  * executed only if the non-returning function was *not* called.
73  */
74 #if !defined(SkNO_RETURN_HINT)
75     #if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
76         namespace {
77             inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
SkNO_RETURN_HINT()78             void SkNO_RETURN_HINT() {}
79         }
80     #else
81         #define SkNO_RETURN_HINT() do {} while (false)
82     #endif
83 #endif
84 
85 ///////////////////////////////////////////////////////////////////////////////
86 
87 #ifndef SkNEW
88     #define SkNEW(type_name)                new type_name
89     #define SkNEW_ARGS(type_name, args)     new type_name args
90     #define SkNEW_ARRAY(type_name, count)   new type_name[count]
91     #define SkDELETE(obj)                   delete obj
92     #define SkDELETE_ARRAY(array)           delete[] array
93 #endif
94 
95 #ifndef SK_CRASH
96 #if 1   // set to 0 for infinite loop, which can help connecting gdb
97     #define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
98 #else
99     #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
100 #endif
101 #endif
102 
103 ///////////////////////////////////////////////////////////////////////////////
104 
105 #if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT)
106     // if this is defined, we convert floats to 2scompliment ints for compares
107     #ifndef SK_SCALAR_SLOW_COMPARES
108         #define SK_SCALAR_SLOW_COMPARES
109     #endif
110     #ifndef SK_USE_FLOATBITS
111         #define SK_USE_FLOATBITS
112     #endif
113 #endif
114 
115 #ifdef SK_BUILD_FOR_WIN
116     // we want lean_and_mean when we include windows.h
117     #ifndef WIN32_LEAN_AND_MEAN
118         #define WIN32_LEAN_AND_MEAN
119         #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
120     #endif
121 
122     #include <windows.h>
123 
124     #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
125         #undef WIN32_LEAN_AND_MEAN
126     #endif
127 
128     #ifndef SK_DEBUGBREAK
129         #define SK_DEBUGBREAK(cond)     do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
130     #endif
131 
132     #ifndef SK_A32_SHIFT
133         #define SK_A32_SHIFT 24
134         #define SK_R32_SHIFT 16
135         #define SK_G32_SHIFT 8
136         #define SK_B32_SHIFT 0
137     #endif
138 
139 #elif defined(SK_BUILD_FOR_MAC)
140     #ifndef SK_DEBUGBREAK
141         #define SK_DEBUGBREAK(cond)     do { if (!(cond)) SK_CRASH(); } while (false)
142     #endif
143 #else
144     #ifdef SK_DEBUG
145         #include <stdio.h>
146         #ifndef SK_DEBUGBREAK
147             #define SK_DEBUGBREAK(cond) do { if (cond) break; \
148                 SkDebugf("%s:%d: failed assertion \"%s\"\n", \
149                 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
150         #endif
151     #endif
152 #endif
153 
154 /*
155  *  We check to see if the SHIFT value has already been defined.
156  *  if not, we define it ourself to some default values. We default to OpenGL
157  *  order (in memory: r,g,b,a)
158  */
159 #ifndef SK_A32_SHIFT
160     #ifdef SK_CPU_BENDIAN
161         #define SK_R32_SHIFT    24
162         #define SK_G32_SHIFT    16
163         #define SK_B32_SHIFT    8
164         #define SK_A32_SHIFT    0
165     #else
166         #define SK_R32_SHIFT    0
167         #define SK_G32_SHIFT    8
168         #define SK_B32_SHIFT    16
169         #define SK_A32_SHIFT    24
170     #endif
171 #endif
172 
173 //  stdlib macros
174 
175 #if 0
176 #if !defined(strlen) && defined(SK_DEBUG)
177     extern size_t sk_strlen(const char*);
178     #define strlen(s)   sk_strlen(s)
179 #endif
180 #ifndef sk_strcpy
181     #define sk_strcpy(dst, src)     strcpy(dst, src)
182 #endif
183 #ifndef sk_strchr
184     #define sk_strchr(s, c)         strchr(s, c)
185 #endif
186 #ifndef sk_strrchr
187     #define sk_strrchr(s, c)        strrchr(s, c)
188 #endif
189 #ifndef sk_strcmp
190     #define sk_strcmp(s, t)         strcmp(s, t)
191 #endif
192 #ifndef sk_strncmp
193     #define sk_strncmp(s, t, n)     strncmp(s, t, n)
194 #endif
195 #ifndef sk_memcpy
196     #define sk_memcpy(dst, src, n)  memcpy(dst, src, n)
197 #endif
198 #ifndef memmove
199     #define memmove(dst, src, n)    memmove(dst, src, n)
200 #endif
201 #ifndef sk_memset
202     #define sk_memset(dst, val, n)  memset(dst, val, n)
203 #endif
204 #ifndef sk_memcmp
205     #define sk_memcmp(s, t, n)      memcmp(s, t, n)
206 #endif
207 
208 #define sk_strequal(s, t)           (!sk_strcmp(s, t))
209 #define sk_strnequal(s, t, n)       (!sk_strncmp(s, t, n))
210 #endif
211 
212 //////////////////////////////////////////////////////////////////////
213 
214 #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
215     #ifndef SkLONGLONG
216         #ifdef SK_BUILD_FOR_WIN32
217             #define SkLONGLONG  __int64
218         #else
219             #define SkLONGLONG  long long
220         #endif
221     #endif
222 #endif
223 
224 //////////////////////////////////////////////////////////////////////////////////////////////
225 #ifndef SK_BUILD_FOR_WINCE
226 #include <string.h>
227 #include <stdlib.h>
228 #else
229 #define _CMNINTRIN_DECLARE_ONLY
230 #include "cmnintrin.h"
231 #endif
232 
233 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
234 //#define _CRTDBG_MAP_ALLOC
235 #ifdef free
236 #undef free
237 #endif
238 #include <crtdbg.h>
239 #undef free
240 
241 #ifdef SK_DEBUGx
242 #if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
243     void * operator new(
244         size_t cb,
245         int nBlockUse,
246         const char * szFileName,
247         int nLine,
248         int foo
249         );
250     void * operator new[](
251         size_t cb,
252         int nBlockUse,
253         const char * szFileName,
254         int nLine,
255         int foo
256         );
257     void operator delete(
258         void *pUserData,
259         int, const char*, int, int
260         );
261     void operator delete(
262         void *pUserData
263         );
264     void operator delete[]( void * p );
265     #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
266 #else
267     #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)
268 #endif
269     #define new DEBUG_CLIENTBLOCK
270 #else
271 #define DEBUG_CLIENTBLOCK
272 #endif // _DEBUG
273 
274 
275 #endif
276 
277 #endif
278 
279 //////////////////////////////////////////////////////////////////////
280 
281 #ifndef SK_OVERRIDE
282 #if defined(_MSC_VER)
283 #define SK_OVERRIDE override
284 #elif defined(__clang__)
285 // Some documentation suggests we should be using __attribute__((override)),
286 // but it doesn't work.
287 #define SK_OVERRIDE override
288 #else
289 // Linux GCC ignores "__attribute__((override))" and rejects "override".
290 #define SK_OVERRIDE
291 #endif
292 #endif
293 
294 //////////////////////////////////////////////////////////////////////
295 
296 #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
297 #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
298 #endif
299