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