SkPostConfig.h revision 22f0761d7879c108d305cb0d6cc0242ad29e780f
1ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner
2ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner/*
3ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner * Copyright 2006 The Android Open Source Project
4ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner *
5ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner * Use of this source code is governed by a BSD-style license that can be
6ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner * found in the LICENSE file.
7ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner */
8ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner
9ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner
10ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#ifndef SkPostConfig_DEFINED
11ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#define SkPostConfig_DEFINED
12ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner
13ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
14ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner    #define SK_BUILD_FOR_WIN
15ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#endif
16ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner
17ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#if defined(SK_DEBUG) && defined(SK_RELEASE)
18ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner    #error "cannot define both SK_DEBUG and SK_RELEASE"
19ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
20ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner    #error "must define either SK_DEBUG or SK_RELEASE"
21ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#endif
22ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner
23ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#if defined SK_SUPPORT_UNITTEST && !defined(SK_DEBUG)
24ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner    #error "can't have unittests without debug"
25ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#endif
26ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner
27ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT)
28ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner    #error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT"
29ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT)
30ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner    #define SK_SCALAR_IS_FLOAT
31ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#endif
32ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner
33ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
34ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner    #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
35ef457d2a39ce5f164b1b95c10181e4a99f620a19David 'Digit' Turner#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
36    #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
37#endif
38
39// ensure the port has defined all of these, or none of them
40#ifdef SK_A32_SHIFT
41    #if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
42        #error "all or none of the 32bit SHIFT amounts must be defined"
43    #endif
44#else
45    #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
46        #error "all or none of the 32bit SHIFT amounts must be defined"
47    #endif
48#endif
49
50#if !defined(SK_HAS_COMPILER_FEATURE)
51    #if defined(__has_feature)
52        #define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
53    #else
54        #define SK_HAS_COMPILER_FEATURE(x) 0
55    #endif
56#endif
57
58/**
59 * The clang static analyzer likes to know that when the program is not
60 * expected to continue (crash, assertion failure, etc). It will notice that
61 * some combination of parameters lead to a function call that does not return.
62 * It can then make appropriate assumptions about the parameters in code
63 * executed only if the non-returning function was *not* called.
64 */
65#if !defined(SkNO_RETURN_HINT)
66    #if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
67        // If we make this a static clang will complain that it isn't called in
68        // any file that has no asserts.
69        void SkNoReturnHint() __attribute__((analyzer_noreturn));
70        #define SkNO_RETURN_HINT() SkNoReturnHint()
71    #else
72        #define SkNO_RETURN_HINT() do {} while (false)
73    #endif
74#endif
75
76#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB)
77    #error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB"
78#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB)
79    #define SK_HAS_ZLIB
80#endif
81
82///////////////////////////////////////////////////////////////////////////////
83
84#ifndef SkNEW
85    #define SkNEW(type_name)                new type_name
86    #define SkNEW_ARGS(type_name, args)     new type_name args
87    #define SkNEW_ARRAY(type_name, count)   new type_name[count]
88    #define SkNEW_PLACEMENT(buf, type_name) new (buf) type_name
89    #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \
90                                            new (buf) type_name args
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_PRINTF_LIKE
297#if defined(__clang__) || defined(__GNUC__)
298#define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
299#else
300#define SK_PRINTF_LIKE(A, B)
301#endif
302#endif
303
304//////////////////////////////////////////////////////////////////////
305
306#ifndef SK_SIZE_T_SPECIFIER
307#if defined(_MSC_VER)
308#define SK_SIZE_T_SPECIFIER "%Iu"
309#else
310#define SK_SIZE_T_SPECIFIER "%zu"
311#endif
312#endif
313
314//////////////////////////////////////////////////////////////////////
315
316#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
317#define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
318#endif
319