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 #elif defined(SK_BUILD_FOR_MAC) 113 #ifndef SK_DEBUGBREAK 114 #define SK_DEBUGBREAK(cond) do { if (!(cond)) SK_CRASH(); } while (false) 115 #endif 116 #else 117 #ifdef SK_DEBUG 118 #include <stdio.h> 119 #ifndef SK_DEBUGBREAK 120 #define SK_DEBUGBREAK(cond) do { if (cond) break; \ 121 SkDebugf("%s:%d: failed assertion \"%s\"\n", \ 122 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false) 123 #endif 124 #endif 125 #endif 126 127 // stdlib macros 128 129 #if 0 130 #if !defined(strlen) && defined(SK_DEBUG) 131 extern size_t sk_strlen(const char*); 132 #define strlen(s) sk_strlen(s) 133 #endif 134 #ifndef sk_strcpy 135 #define sk_strcpy(dst, src) strcpy(dst, src) 136 #endif 137 #ifndef sk_strchr 138 #define sk_strchr(s, c) strchr(s, c) 139 #endif 140 #ifndef sk_strrchr 141 #define sk_strrchr(s, c) strrchr(s, c) 142 #endif 143 #ifndef sk_strcmp 144 #define sk_strcmp(s, t) strcmp(s, t) 145 #endif 146 #ifndef sk_strncmp 147 #define sk_strncmp(s, t, n) strncmp(s, t, n) 148 #endif 149 #ifndef sk_memcpy 150 #define sk_memcpy(dst, src, n) memcpy(dst, src, n) 151 #endif 152 #ifndef memmove 153 #define memmove(dst, src, n) memmove(dst, src, n) 154 #endif 155 #ifndef sk_memset 156 #define sk_memset(dst, val, n) memset(dst, val, n) 157 #endif 158 #ifndef sk_memcmp 159 #define sk_memcmp(s, t, n) memcmp(s, t, n) 160 #endif 161 162 #define sk_strequal(s, t) (!sk_strcmp(s, t)) 163 #define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n)) 164 #endif 165 166 ////////////////////////////////////////////////////////////////////// 167 168 #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) 169 #ifndef SkLONGLONG 170 #ifdef SK_BUILD_FOR_WIN32 171 #define SkLONGLONG __int64 172 #else 173 #define SkLONGLONG long long 174 #endif 175 #endif 176 #endif 177 178 ////////////////////////////////////////////////////////////////////////////////////////////// 179 #ifndef SK_BUILD_FOR_WINCE 180 #include <string.h> 181 #include <stdlib.h> 182 #else 183 #define _CMNINTRIN_DECLARE_ONLY 184 #include "cmnintrin.h" 185 #endif 186 187 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32 188 //#define _CRTDBG_MAP_ALLOC 189 #ifdef free 190 #undef free 191 #endif 192 #include <crtdbg.h> 193 #undef free 194 195 #ifdef SK_DEBUGx 196 #if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus) 197 void * operator new( 198 size_t cb, 199 int nBlockUse, 200 const char * szFileName, 201 int nLine, 202 int foo 203 ); 204 void * operator new[]( 205 size_t cb, 206 int nBlockUse, 207 const char * szFileName, 208 int nLine, 209 int foo 210 ); 211 void operator delete( 212 void *pUserData, 213 int, const char*, int, int 214 ); 215 void operator delete( 216 void *pUserData 217 ); 218 void operator delete[]( void * p ); 219 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0) 220 #else 221 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) 222 #endif 223 #define new DEBUG_CLIENTBLOCK 224 #else 225 #define DEBUG_CLIENTBLOCK 226 #endif // _DEBUG 227 228 #endif 229 230 #endif 231 232