blob: 12fe87dafece995660e6187b009543d93652f3a8 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#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)
reed@google.com7886ad32012-06-11 21:21:26 +000030 #define SK_SCALAR_IS_FLOAT
reed@android.com8a1c16f2008-12-17 15:59:43 +000031#endif
32
vollick@chromium.org5596a692012-11-13 20:12:00 +000033#if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT)
34 #error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT"
35#elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT)
reed@google.com7d683352012-12-03 21:19:52 +000036 // default is double, as that is faster given our impl uses doubles
37 // for intermediate calculations.
38 #define SK_MSCALAR_IS_DOUBLE
vollick@chromium.org5596a692012-11-13 20:12:00 +000039#endif
40
reed@android.com8a1c16f2008-12-17 15:59:43 +000041#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
42 #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
43#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
44 #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
45#endif
46
47// ensure the port has defined all of these, or none of them
48#ifdef SK_A32_SHIFT
49 #if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
50 #error "all or none of the 32bit SHIFT amounts must be defined"
51 #endif
52#else
53 #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
54 #error "all or none of the 32bit SHIFT amounts must be defined"
55 #endif
56#endif
57
bsalomon@google.com04423802011-11-23 21:25:35 +000058#if !defined(SK_HAS_COMPILER_FEATURE)
59 #if defined(__has_feature)
60 #define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
61 #else
62 #define SK_HAS_COMPILER_FEATURE(x) 0
63 #endif
64#endif
65
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000066#if !defined(SK_SUPPORT_GPU)
67 #define SK_SUPPORT_GPU 1
68#endif
69
bsalomon@google.com04423802011-11-23 21:25:35 +000070/**
71 * The clang static analyzer likes to know that when the program is not
72 * expected to continue (crash, assertion failure, etc). It will notice that
73 * some combination of parameters lead to a function call that does not return.
74 * It can then make appropriate assumptions about the parameters in code
75 * executed only if the non-returning function was *not* called.
76 */
77#if !defined(SkNO_RETURN_HINT)
78 #if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
bsalomon@google.com3a52d682012-07-11 13:30:08 +000079 namespace {
80 inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
81 inline void SkNO_RETURN_HINT() {}
82 }
bsalomon@google.com04423802011-11-23 21:25:35 +000083 #else
84 #define SkNO_RETURN_HINT() do {} while (false)
85 #endif
86#endif
87
justinlin@google.comfffb2f12012-04-16 19:10:21 +000088#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB)
89 #error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB"
90#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB)
91 #define SK_HAS_ZLIB
92#endif
93
reed@android.com8a1c16f2008-12-17 15:59:43 +000094///////////////////////////////////////////////////////////////////////////////
95
96#ifndef SkNEW
97 #define SkNEW(type_name) new type_name
98 #define SkNEW_ARGS(type_name, args) new type_name args
99 #define SkNEW_ARRAY(type_name, count) new type_name[count]
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000100 #define SkNEW_PLACEMENT(buf, type_name) new (buf) type_name
101 #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \
102 new (buf) type_name args
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103 #define SkDELETE(obj) delete obj
104 #define SkDELETE_ARRAY(array) delete[] array
105#endif
106
107#ifndef SK_CRASH
108#if 1 // set to 0 for infinite loop, which can help connecting gdb
bsalomon@google.comb1277c92011-11-23 21:58:39 +0000109 #define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000110#else
bsalomon@google.comb1277c92011-11-23 21:58:39 +0000111 #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000112#endif
113#endif
114
115///////////////////////////////////////////////////////////////////////////////
116
117#if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT)
118 // if this is defined, we convert floats to 2scompliment ints for compares
119 #ifndef SK_SCALAR_SLOW_COMPARES
120 #define SK_SCALAR_SLOW_COMPARES
121 #endif
reed@android.com5c80ea12009-01-08 17:49:50 +0000122 #ifndef SK_USE_FLOATBITS
123 #define SK_USE_FLOATBITS
124 #endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000125#endif
126
127#ifdef SK_BUILD_FOR_WIN
reed@android.com16690af2009-04-06 16:09:53 +0000128 // we want lean_and_mean when we include windows.h
129 #ifndef WIN32_LEAN_AND_MEAN
130 #define WIN32_LEAN_AND_MEAN
131 #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
132 #endif
133
reed@android.com8a1c16f2008-12-17 15:59:43 +0000134 #include <windows.h>
reed@android.com16690af2009-04-06 16:09:53 +0000135
136 #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
137 #undef WIN32_LEAN_AND_MEAN
138 #endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000139
140 #ifndef SK_DEBUGBREAK
bsalomon@google.com04423802011-11-23 21:25:35 +0000141 #define SK_DEBUGBREAK(cond) do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000142 #endif
reed@android.comf2b98d62010-12-20 18:26:13 +0000143
144 #ifndef SK_A32_SHIFT
145 #define SK_A32_SHIFT 24
146 #define SK_R32_SHIFT 16
147 #define SK_G32_SHIFT 8
148 #define SK_B32_SHIFT 0
149 #endif
150
reed@android.com8a1c16f2008-12-17 15:59:43 +0000151#elif defined(SK_BUILD_FOR_MAC)
152 #ifndef SK_DEBUGBREAK
153 #define SK_DEBUGBREAK(cond) do { if (!(cond)) SK_CRASH(); } while (false)
154 #endif
155#else
156 #ifdef SK_DEBUG
157 #include <stdio.h>
158 #ifndef SK_DEBUGBREAK
159 #define SK_DEBUGBREAK(cond) do { if (cond) break; \
160 SkDebugf("%s:%d: failed assertion \"%s\"\n", \
161 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
162 #endif
163 #endif
164#endif
165
bsalomon@google.com27661182011-05-19 15:57:44 +0000166/*
167 * We check to see if the SHIFT value has already been defined.
168 * if not, we define it ourself to some default values. We default to OpenGL
169 * order (in memory: r,g,b,a)
170 */
171#ifndef SK_A32_SHIFT
172 #ifdef SK_CPU_BENDIAN
173 #define SK_R32_SHIFT 24
174 #define SK_G32_SHIFT 16
175 #define SK_B32_SHIFT 8
176 #define SK_A32_SHIFT 0
177 #else
178 #define SK_R32_SHIFT 0
179 #define SK_G32_SHIFT 8
180 #define SK_B32_SHIFT 16
181 #define SK_A32_SHIFT 24
182 #endif
183#endif
184
reed@android.com8a1c16f2008-12-17 15:59:43 +0000185// stdlib macros
186
187#if 0
188#if !defined(strlen) && defined(SK_DEBUG)
189 extern size_t sk_strlen(const char*);
190 #define strlen(s) sk_strlen(s)
191#endif
192#ifndef sk_strcpy
193 #define sk_strcpy(dst, src) strcpy(dst, src)
194#endif
195#ifndef sk_strchr
196 #define sk_strchr(s, c) strchr(s, c)
197#endif
198#ifndef sk_strrchr
199 #define sk_strrchr(s, c) strrchr(s, c)
200#endif
201#ifndef sk_strcmp
202 #define sk_strcmp(s, t) strcmp(s, t)
203#endif
204#ifndef sk_strncmp
205 #define sk_strncmp(s, t, n) strncmp(s, t, n)
206#endif
207#ifndef sk_memcpy
208 #define sk_memcpy(dst, src, n) memcpy(dst, src, n)
209#endif
210#ifndef memmove
211 #define memmove(dst, src, n) memmove(dst, src, n)
212#endif
213#ifndef sk_memset
214 #define sk_memset(dst, val, n) memset(dst, val, n)
215#endif
216#ifndef sk_memcmp
217 #define sk_memcmp(s, t, n) memcmp(s, t, n)
218#endif
219
220#define sk_strequal(s, t) (!sk_strcmp(s, t))
221#define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n))
222#endif
223
reed@android.com5c80ea12009-01-08 17:49:50 +0000224//////////////////////////////////////////////////////////////////////
225
226#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
227 #ifndef SkLONGLONG
228 #ifdef SK_BUILD_FOR_WIN32
229 #define SkLONGLONG __int64
230 #else
231 #define SkLONGLONG long long
232 #endif
233 #endif
234#endif
235
reed@android.com8a1c16f2008-12-17 15:59:43 +0000236//////////////////////////////////////////////////////////////////////////////////////////////
237#ifndef SK_BUILD_FOR_WINCE
238#include <string.h>
239#include <stdlib.h>
240#else
241#define _CMNINTRIN_DECLARE_ONLY
242#include "cmnintrin.h"
243#endif
244
245#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
246//#define _CRTDBG_MAP_ALLOC
247#ifdef free
248#undef free
249#endif
250#include <crtdbg.h>
251#undef free
252
253#ifdef SK_DEBUGx
254#if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
255 void * operator new(
256 size_t cb,
257 int nBlockUse,
258 const char * szFileName,
259 int nLine,
260 int foo
261 );
262 void * operator new[](
263 size_t cb,
264 int nBlockUse,
265 const char * szFileName,
266 int nLine,
267 int foo
268 );
269 void operator delete(
270 void *pUserData,
271 int, const char*, int, int
272 );
273 void operator delete(
274 void *pUserData
275 );
276 void operator delete[]( void * p );
277 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
278#else
279 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
280#endif
281 #define new DEBUG_CLIENTBLOCK
282#else
283#define DEBUG_CLIENTBLOCK
284#endif // _DEBUG
285
tomhudson@google.com13413042011-10-03 16:01:10 +0000286
reed@android.com8a1c16f2008-12-17 15:59:43 +0000287#endif
288
289#endif
290
tomhudson@google.com13413042011-10-03 16:01:10 +0000291//////////////////////////////////////////////////////////////////////
292
293#ifndef SK_OVERRIDE
george@mozilla.comece01002012-07-25 19:05:43 +0000294 #if defined(_MSC_VER)
295 #define SK_OVERRIDE override
caryclark@google.com867cbd82012-09-20 15:45:41 +0000296 #elif defined(__clang__) && !defined(SK_BUILD_FOR_IOS)
george@mozilla.comece01002012-07-25 19:05:43 +0000297 #if __has_feature(cxx_override_control)
298 // Some documentation suggests we should be using __attribute__((override)),
299 // but it doesn't work.
300 #define SK_OVERRIDE override
301 #elif defined(__has_extension)
302 #if __has_extension(cxx_override_control)
303 #define SK_OVERRIDE override
304 #endif
305 #endif
306 #else
307 // Linux GCC ignores "__attribute__((override))" and rejects "override".
308 #define SK_OVERRIDE
309 #endif
tomhudson@google.com13413042011-10-03 16:01:10 +0000310#endif
311
caryclark@google.comd26147a2011-12-15 14:16:43 +0000312//////////////////////////////////////////////////////////////////////
313
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000314#ifndef SK_PRINTF_LIKE
315#if defined(__clang__) || defined(__GNUC__)
316#define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
317#else
318#define SK_PRINTF_LIKE(A, B)
319#endif
320#endif
321
322//////////////////////////////////////////////////////////////////////
323
324#ifndef SK_SIZE_T_SPECIFIER
325#if defined(_MSC_VER)
326#define SK_SIZE_T_SPECIFIER "%Iu"
327#else
328#define SK_SIZE_T_SPECIFIER "%zu"
329#endif
330#endif
331
332//////////////////////////////////////////////////////////////////////
333
caryclark@google.comd26147a2011-12-15 14:16:43 +0000334#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
335#define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
336#endif