SkPostConfig.h revision fffb2f1bda1982d451bc249743b8cc414995d6a8
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));
78            void SkNO_RETURN_HINT() {}
79        }
80    #else
81        #define SkNO_RETURN_HINT() do {} while (false)
82    #endif
83#endif
84
85#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB)
86    #error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB"
87#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB)
88    #define SK_HAS_ZLIB
89#endif
90
91///////////////////////////////////////////////////////////////////////////////
92
93#ifndef SkNEW
94    #define SkNEW(type_name)                new type_name
95    #define SkNEW_ARGS(type_name, args)     new type_name args
96    #define SkNEW_ARRAY(type_name, count)   new type_name[count]
97    #define SkDELETE(obj)                   delete obj
98    #define SkDELETE_ARRAY(array)           delete[] array
99#endif
100
101#ifndef SK_CRASH
102#if 1   // set to 0 for infinite loop, which can help connecting gdb
103    #define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
104#else
105    #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
106#endif
107#endif
108
109///////////////////////////////////////////////////////////////////////////////
110
111#if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT)
112    // if this is defined, we convert floats to 2scompliment ints for compares
113    #ifndef SK_SCALAR_SLOW_COMPARES
114        #define SK_SCALAR_SLOW_COMPARES
115    #endif
116    #ifndef SK_USE_FLOATBITS
117        #define SK_USE_FLOATBITS
118    #endif
119#endif
120
121#ifdef SK_BUILD_FOR_WIN
122    // we want lean_and_mean when we include windows.h
123    #ifndef WIN32_LEAN_AND_MEAN
124        #define WIN32_LEAN_AND_MEAN
125        #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
126    #endif
127
128    #include <windows.h>
129
130    #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
131        #undef WIN32_LEAN_AND_MEAN
132    #endif
133
134    #ifndef SK_DEBUGBREAK
135        #define SK_DEBUGBREAK(cond)     do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
136    #endif
137
138    #ifndef SK_A32_SHIFT
139        #define SK_A32_SHIFT 24
140        #define SK_R32_SHIFT 16
141        #define SK_G32_SHIFT 8
142        #define SK_B32_SHIFT 0
143    #endif
144
145#elif defined(SK_BUILD_FOR_MAC)
146    #ifndef SK_DEBUGBREAK
147        #define SK_DEBUGBREAK(cond)     do { if (!(cond)) SK_CRASH(); } while (false)
148    #endif
149#else
150    #ifdef SK_DEBUG
151        #include <stdio.h>
152        #ifndef SK_DEBUGBREAK
153            #define SK_DEBUGBREAK(cond) do { if (cond) break; \
154                SkDebugf("%s:%d: failed assertion \"%s\"\n", \
155                __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
156        #endif
157    #endif
158#endif
159
160/*
161 *  We check to see if the SHIFT value has already been defined.
162 *  if not, we define it ourself to some default values. We default to OpenGL
163 *  order (in memory: r,g,b,a)
164 */
165#ifndef SK_A32_SHIFT
166    #ifdef SK_CPU_BENDIAN
167        #define SK_R32_SHIFT    24
168        #define SK_G32_SHIFT    16
169        #define SK_B32_SHIFT    8
170        #define SK_A32_SHIFT    0
171    #else
172        #define SK_R32_SHIFT    0
173        #define SK_G32_SHIFT    8
174        #define SK_B32_SHIFT    16
175        #define SK_A32_SHIFT    24
176    #endif
177#endif
178
179//  stdlib macros
180
181#if 0
182#if !defined(strlen) && defined(SK_DEBUG)
183    extern size_t sk_strlen(const char*);
184    #define strlen(s)   sk_strlen(s)
185#endif
186#ifndef sk_strcpy
187    #define sk_strcpy(dst, src)     strcpy(dst, src)
188#endif
189#ifndef sk_strchr
190    #define sk_strchr(s, c)         strchr(s, c)
191#endif
192#ifndef sk_strrchr
193    #define sk_strrchr(s, c)        strrchr(s, c)
194#endif
195#ifndef sk_strcmp
196    #define sk_strcmp(s, t)         strcmp(s, t)
197#endif
198#ifndef sk_strncmp
199    #define sk_strncmp(s, t, n)     strncmp(s, t, n)
200#endif
201#ifndef sk_memcpy
202    #define sk_memcpy(dst, src, n)  memcpy(dst, src, n)
203#endif
204#ifndef memmove
205    #define memmove(dst, src, n)    memmove(dst, src, n)
206#endif
207#ifndef sk_memset
208    #define sk_memset(dst, val, n)  memset(dst, val, n)
209#endif
210#ifndef sk_memcmp
211    #define sk_memcmp(s, t, n)      memcmp(s, t, n)
212#endif
213
214#define sk_strequal(s, t)           (!sk_strcmp(s, t))
215#define sk_strnequal(s, t, n)       (!sk_strncmp(s, t, n))
216#endif
217
218//////////////////////////////////////////////////////////////////////
219
220#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
221    #ifndef SkLONGLONG
222        #ifdef SK_BUILD_FOR_WIN32
223            #define SkLONGLONG  __int64
224        #else
225            #define SkLONGLONG  long long
226        #endif
227    #endif
228#endif
229
230//////////////////////////////////////////////////////////////////////////////////////////////
231#ifndef SK_BUILD_FOR_WINCE
232#include <string.h>
233#include <stdlib.h>
234#else
235#define _CMNINTRIN_DECLARE_ONLY
236#include "cmnintrin.h"
237#endif
238
239#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
240//#define _CRTDBG_MAP_ALLOC
241#ifdef free
242#undef free
243#endif
244#include <crtdbg.h>
245#undef free
246
247#ifdef SK_DEBUGx
248#if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
249    void * operator new(
250        size_t cb,
251        int nBlockUse,
252        const char * szFileName,
253        int nLine,
254        int foo
255        );
256    void * operator new[](
257        size_t cb,
258        int nBlockUse,
259        const char * szFileName,
260        int nLine,
261        int foo
262        );
263    void operator delete(
264        void *pUserData,
265        int, const char*, int, int
266        );
267    void operator delete(
268        void *pUserData
269        );
270    void operator delete[]( void * p );
271    #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
272#else
273    #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)
274#endif
275    #define new DEBUG_CLIENTBLOCK
276#else
277#define DEBUG_CLIENTBLOCK
278#endif // _DEBUG
279
280
281#endif
282
283#endif
284
285//////////////////////////////////////////////////////////////////////
286
287#ifndef SK_OVERRIDE
288#if defined(_MSC_VER)
289#define SK_OVERRIDE override
290#elif defined(__clang__)
291// Some documentation suggests we should be using __attribute__((override)),
292// but it doesn't work.
293#define SK_OVERRIDE override
294#else
295// Linux GCC ignores "__attribute__((override))" and rejects "override".
296#define SK_OVERRIDE
297#endif
298#endif
299
300//////////////////////////////////////////////////////////////////////
301
302#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
303#define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
304#endif
305