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 /* 136 * We check to see if the SHIFT value has already been defined. 137 * if not, we define it ourself to some default values. We default to OpenGL 138 * order (in memory: r,g,b,a) 139 */ 140 #ifndef SK_A32_SHIFT 141 #ifdef SK_CPU_BENDIAN 142 #define SK_R32_SHIFT 24 143 #define SK_G32_SHIFT 16 144 #define SK_B32_SHIFT 8 145 #define SK_A32_SHIFT 0 146 #else 147 #define SK_R32_SHIFT 0 148 #define SK_G32_SHIFT 8 149 #define SK_B32_SHIFT 16 150 #define SK_A32_SHIFT 24 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