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