SkPostConfig.h revision 05ea1810a231b1f699c98a0b6272e08a4c93b06b
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef SkPostConfig_DEFINED
18#define SkPostConfig_DEFINED
19
20#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
21    #define SK_BUILD_FOR_WIN
22#endif
23
24#if defined(SK_DEBUG) && defined(SK_RELEASE)
25    #error "cannot define both SK_DEBUG and SK_RELEASE"
26#elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
27    #error "must define either SK_DEBUG or SK_RELEASE"
28#endif
29
30#if defined SK_SUPPORT_UNITTEST && !defined(SK_DEBUG)
31    #error "can't have unittests without debug"
32#endif
33
34#if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT)
35    #error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT"
36#elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT)
37    #ifdef SK_CAN_USE_FLOAT
38        #define SK_SCALAR_IS_FLOAT
39    #else
40        #define SK_SCALAR_IS_FIXED
41    #endif
42#endif
43
44#if defined(SK_SCALAR_IS_FLOAT) && !defined(SK_CAN_USE_FLOAT)
45    #define SK_CAN_USE_FLOAT
46    // we do nothing in the else case: fixed-scalars can have floats or not
47#endif
48
49#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
50    #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
51#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
52    #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
53#endif
54
55// ensure the port has defined all of these, or none of them
56#ifdef SK_A32_SHIFT
57    #if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
58        #error "all or none of the 32bit SHIFT amounts must be defined"
59    #endif
60#else
61    #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
62        #error "all or none of the 32bit SHIFT amounts must be defined"
63    #endif
64#endif
65
66/*
67 *  We check to see if the SHIFT value has already been defined.
68 *  if not, we define it ourself to some default values. We default to OpenGL
69 *  order (in memory: r,g,b,a)
70 */
71#ifndef SK_A32_SHIFT
72    #ifdef SK_CPU_BENDIAN
73        #define SK_R32_SHIFT    24
74        #define SK_G32_SHIFT    16
75        #define SK_B32_SHIFT    8
76        #define SK_A32_SHIFT    0
77    #else
78        #define SK_R32_SHIFT    0
79        #define SK_G32_SHIFT    8
80        #define SK_B32_SHIFT    16
81        #define SK_A32_SHIFT    24
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() *(int *)(uintptr_t)0xbbadbeef = 0
98#else
99    #define SK_CRASH()  do {} 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)) __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//  stdlib macros
155
156#if 0
157#if !defined(strlen) && defined(SK_DEBUG)
158    extern size_t sk_strlen(const char*);
159    #define strlen(s)   sk_strlen(s)
160#endif
161#ifndef sk_strcpy
162    #define sk_strcpy(dst, src)     strcpy(dst, src)
163#endif
164#ifndef sk_strchr
165    #define sk_strchr(s, c)         strchr(s, c)
166#endif
167#ifndef sk_strrchr
168    #define sk_strrchr(s, c)        strrchr(s, c)
169#endif
170#ifndef sk_strcmp
171    #define sk_strcmp(s, t)         strcmp(s, t)
172#endif
173#ifndef sk_strncmp
174    #define sk_strncmp(s, t, n)     strncmp(s, t, n)
175#endif
176#ifndef sk_memcpy
177    #define sk_memcpy(dst, src, n)  memcpy(dst, src, n)
178#endif
179#ifndef memmove
180    #define memmove(dst, src, n)    memmove(dst, src, n)
181#endif
182#ifndef sk_memset
183    #define sk_memset(dst, val, n)  memset(dst, val, n)
184#endif
185#ifndef sk_memcmp
186    #define sk_memcmp(s, t, n)      memcmp(s, t, n)
187#endif
188
189#define sk_strequal(s, t)           (!sk_strcmp(s, t))
190#define sk_strnequal(s, t, n)       (!sk_strncmp(s, t, n))
191#endif
192
193//////////////////////////////////////////////////////////////////////
194
195#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
196    #ifndef SkLONGLONG
197        #ifdef SK_BUILD_FOR_WIN32
198            #define SkLONGLONG  __int64
199        #else
200            #define SkLONGLONG  long long
201        #endif
202    #endif
203#endif
204
205//////////////////////////////////////////////////////////////////////////////////////////////
206#ifndef SK_BUILD_FOR_WINCE
207#include <string.h>
208#include <stdlib.h>
209#else
210#define _CMNINTRIN_DECLARE_ONLY
211#include "cmnintrin.h"
212#endif
213
214#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
215//#define _CRTDBG_MAP_ALLOC
216#ifdef free
217#undef free
218#endif
219#include <crtdbg.h>
220#undef free
221
222#ifdef SK_DEBUGx
223#if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
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 new[](
232        size_t cb,
233        int nBlockUse,
234        const char * szFileName,
235        int nLine,
236        int foo
237        );
238    void operator delete(
239        void *pUserData,
240        int, const char*, int, int
241        );
242    void operator delete(
243        void *pUserData
244        );
245    void operator delete[]( void * p );
246    #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
247#else
248    #define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)
249#endif
250    #define new DEBUG_CLIENTBLOCK
251#else
252#define DEBUG_CLIENTBLOCK
253#endif // _DEBUG
254
255#endif
256
257#endif
258
259