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 #define SK_SCALAR_IS_FLOAT 31 #endif 32 33 #if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT) 34 #error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT" 35 #elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT) 36 // default is double, as that is faster given our impl uses doubles 37 // for intermediate calculations. 38 #define SK_MSCALAR_IS_DOUBLE 39 #endif 40 41 #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) 42 #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" 43 #elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) 44 #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" 45 #endif 46 47 // ensure the port has defined all of these, or none of them 48 #ifdef SK_A32_SHIFT 49 #if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT) 50 #error "all or none of the 32bit SHIFT amounts must be defined" 51 #endif 52 #else 53 #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT) 54 #error "all or none of the 32bit SHIFT amounts must be defined" 55 #endif 56 #endif 57 58 #if !defined(SK_HAS_COMPILER_FEATURE) 59 #if defined(__has_feature) 60 #define SK_HAS_COMPILER_FEATURE(x) __has_feature(x) 61 #else 62 #define SK_HAS_COMPILER_FEATURE(x) 0 63 #endif 64 #endif 65 66 #if !defined(SK_ATTRIBUTE) 67 #if defined(__clang__) || defined(__GNUC__) 68 #define SK_ATTRIBUTE(attr) __attribute__((attr)) 69 #else 70 #define SK_ATTRIBUTE(attr) 71 #endif 72 #endif 73 74 #if !defined(SK_SUPPORT_GPU) 75 #define SK_SUPPORT_GPU 1 76 #endif 77 78 /** 79 * The clang static analyzer likes to know that when the program is not 80 * expected to continue (crash, assertion failure, etc). It will notice that 81 * some combination of parameters lead to a function call that does not return. 82 * It can then make appropriate assumptions about the parameters in code 83 * executed only if the non-returning function was *not* called. 84 */ 85 #if !defined(SkNO_RETURN_HINT) 86 #if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn) 87 static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn)); 88 static inline void SkNO_RETURN_HINT() {} 89 #else 90 #define SkNO_RETURN_HINT() do {} while (false) 91 #endif 92 #endif 93 94 #if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB) 95 #error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB" 96 #elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB) 97 #define SK_HAS_ZLIB 98 #endif 99 100 /////////////////////////////////////////////////////////////////////////////// 101 102 #ifndef SkNEW 103 #define SkNEW(type_name) (new type_name) 104 #define SkNEW_ARGS(type_name, args) (new type_name args) 105 #define SkNEW_ARRAY(type_name, count) (new type_name[(count)]) 106 #define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name) 107 #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \ 108 (new (buf) type_name args) 109 #define SkDELETE(obj) (delete (obj)) 110 #define SkDELETE_ARRAY(array) (delete[] (array)) 111 #endif 112 113 #ifndef SK_CRASH 114 #if 1 // set to 0 for infinite loop, which can help connecting gdb 115 #define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false) 116 #else 117 #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true) 118 #endif 119 #endif 120 121 /////////////////////////////////////////////////////////////////////////////// 122 123 // SK_ENABLE_INST_COUNT defaults to 1 in DEBUG and 0 in RELEASE 124 #ifndef SK_ENABLE_INST_COUNT 125 #ifdef SK_DEBUG 126 // FIXME: fails if multiple threads run at once (see skbug.com/1219 ) 127 #define SK_ENABLE_INST_COUNT 0 128 #else 129 #define SK_ENABLE_INST_COUNT 0 130 #endif 131 #endif 132 133 /////////////////////////////////////////////////////////////////////////////// 134 135 #if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT) 136 // if this is defined, we convert floats to 2scompliment ints for compares 137 #ifndef SK_SCALAR_SLOW_COMPARES 138 #define SK_SCALAR_SLOW_COMPARES 139 #endif 140 #ifndef SK_USE_FLOATBITS 141 #define SK_USE_FLOATBITS 142 #endif 143 #endif 144 145 #ifdef SK_BUILD_FOR_WIN 146 // we want lean_and_mean when we include windows.h 147 #ifndef WIN32_LEAN_AND_MEAN 148 #define WIN32_LEAN_AND_MEAN 149 #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 150 #endif 151 #ifndef NOMINMAX 152 #define NOMINMAX 153 #define NOMINMAX_WAS_LOCALLY_DEFINED 154 #endif 155 156 #include <windows.h> 157 158 #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 159 #undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 160 #undef WIN32_LEAN_AND_MEAN 161 #endif 162 163 #ifdef NOMINMAX_WAS_LOCALLY_DEFINED 164 #undef NOMINMAX_WAS_LOCALLY_DEFINED 165 #undef NOMINMAX 166 #endif 167 168 #ifndef SK_DEBUGBREAK 169 #define SK_DEBUGBREAK(cond) do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false) 170 #endif 171 172 #ifndef SK_A32_SHIFT 173 #define SK_A32_SHIFT 24 174 #define SK_R32_SHIFT 16 175 #define SK_G32_SHIFT 8 176 #define SK_B32_SHIFT 0 177 #endif 178 179 #else 180 #ifdef SK_DEBUG 181 #include <stdio.h> 182 #ifndef SK_DEBUGBREAK 183 #define SK_DEBUGBREAK(cond) do { if (cond) break; \ 184 SkDebugf("%s:%d: failed assertion \"%s\"\n", \ 185 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false) 186 #endif 187 #endif 188 #endif 189 190 /* 191 * We check to see if the SHIFT value has already been defined. 192 * if not, we define it ourself to some default values. We default to OpenGL 193 * order (in memory: r,g,b,a) 194 */ 195 #ifndef SK_A32_SHIFT 196 #ifdef SK_CPU_BENDIAN 197 #define SK_R32_SHIFT 24 198 #define SK_G32_SHIFT 16 199 #define SK_B32_SHIFT 8 200 #define SK_A32_SHIFT 0 201 #else 202 #define SK_R32_SHIFT 0 203 #define SK_G32_SHIFT 8 204 #define SK_B32_SHIFT 16 205 #define SK_A32_SHIFT 24 206 #endif 207 #endif 208 209 /** 210 * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The 211 * relationship between the byte order and shift values depends on machine endianness. If the shift 212 * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little 213 * endian machine and the A channel on a big endian machine. Thus, given those shifts values, 214 * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and 215 * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine. 216 */ 217 #ifdef SK_CPU_BENDIAN 218 #define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \ 219 (SK_ ## C3 ## 32_SHIFT == 0 && \ 220 SK_ ## C2 ## 32_SHIFT == 8 && \ 221 SK_ ## C1 ## 32_SHIFT == 16 && \ 222 SK_ ## C0 ## 32_SHIFT == 24) 223 #else 224 #define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \ 225 (SK_ ## C0 ## 32_SHIFT == 0 && \ 226 SK_ ## C1 ## 32_SHIFT == 8 && \ 227 SK_ ## C2 ## 32_SHIFT == 16 && \ 228 SK_ ## C3 ## 32_SHIFT == 24) 229 #endif 230 231 // stdlib macros 232 233 #if 0 234 #if !defined(strlen) && defined(SK_DEBUG) 235 extern size_t sk_strlen(const char*); 236 #define strlen(s) sk_strlen(s) 237 #endif 238 #ifndef sk_strcpy 239 #define sk_strcpy(dst, src) strcpy(dst, src) 240 #endif 241 #ifndef sk_strchr 242 #define sk_strchr(s, c) strchr(s, c) 243 #endif 244 #ifndef sk_strrchr 245 #define sk_strrchr(s, c) strrchr(s, c) 246 #endif 247 #ifndef sk_strcmp 248 #define sk_strcmp(s, t) strcmp(s, t) 249 #endif 250 #ifndef sk_strncmp 251 #define sk_strncmp(s, t, n) strncmp(s, t, n) 252 #endif 253 #ifndef sk_memcpy 254 #define sk_memcpy(dst, src, n) memcpy(dst, src, n) 255 #endif 256 #ifndef memmove 257 #define memmove(dst, src, n) memmove(dst, src, n) 258 #endif 259 #ifndef sk_memset 260 #define sk_memset(dst, val, n) memset(dst, val, n) 261 #endif 262 #ifndef sk_memcmp 263 #define sk_memcmp(s, t, n) memcmp(s, t, n) 264 #endif 265 266 #define sk_strequal(s, t) (!sk_strcmp(s, t)) 267 #define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n)) 268 #endif 269 270 ////////////////////////////////////////////////////////////////////// 271 272 #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) 273 #ifndef SkLONGLONG 274 #ifdef SK_BUILD_FOR_WIN32 275 #define SkLONGLONG __int64 276 #else 277 #define SkLONGLONG long long 278 #endif 279 #endif 280 #endif 281 282 ////////////////////////////////////////////////////////////////////////////////////////////// 283 #ifndef SK_BUILD_FOR_WINCE 284 #include <string.h> 285 #include <stdlib.h> 286 #else 287 #define _CMNINTRIN_DECLARE_ONLY 288 #include "cmnintrin.h" 289 #endif 290 291 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32 292 //#define _CRTDBG_MAP_ALLOC 293 #ifdef free 294 #undef free 295 #endif 296 #include <crtdbg.h> 297 #undef free 298 299 #ifdef SK_DEBUGx 300 #if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus) 301 void * operator new( 302 size_t cb, 303 int nBlockUse, 304 const char * szFileName, 305 int nLine, 306 int foo 307 ); 308 void * operator new[]( 309 size_t cb, 310 int nBlockUse, 311 const char * szFileName, 312 int nLine, 313 int foo 314 ); 315 void operator delete( 316 void *pUserData, 317 int, const char*, int, int 318 ); 319 void operator delete( 320 void *pUserData 321 ); 322 void operator delete[]( void * p ); 323 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0) 324 #else 325 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) 326 #endif 327 #define new DEBUG_CLIENTBLOCK 328 #else 329 #define DEBUG_CLIENTBLOCK 330 #endif // _DEBUG 331 332 333 #endif 334 335 #endif 336 337 ////////////////////////////////////////////////////////////////////// 338 339 #ifndef SK_OVERRIDE 340 #if defined(_MSC_VER) 341 #define SK_OVERRIDE override 342 #elif defined(__clang__) 343 // Clang defaults to C++03 and warns about using override. Squelch that. Intentionally no 344 // push/pop here so all users of SK_OVERRIDE ignore the warning too. This is like passing 345 // -Wno-c++11-extensions, except that GCC won't die (because it won't see this pragma). 346 #pragma clang diagnostic ignored "-Wc++11-extensions" 347 348 #if __has_feature(cxx_override_control) 349 // Some documentation suggests we should be using __attribute__((override)), 350 // but it doesn't work. 351 #define SK_OVERRIDE override 352 #elif defined(__has_extension) 353 #if __has_extension(cxx_override_control) 354 #define SK_OVERRIDE override 355 #endif 356 #endif 357 #endif 358 #ifndef SK_OVERRIDE 359 #define SK_OVERRIDE 360 #endif 361 #endif 362 363 ////////////////////////////////////////////////////////////////////// 364 365 #if !defined(SK_UNUSED) 366 #define SK_UNUSED SK_ATTRIBUTE(unused) 367 #endif 368 369 ////////////////////////////////////////////////////////////////////// 370 371 #ifndef SK_PRINTF_LIKE 372 #if defined(__clang__) || defined(__GNUC__) 373 #define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) 374 #else 375 #define SK_PRINTF_LIKE(A, B) 376 #endif 377 #endif 378 379 ////////////////////////////////////////////////////////////////////// 380 381 #ifndef SK_SIZE_T_SPECIFIER 382 #if defined(_MSC_VER) 383 #define SK_SIZE_T_SPECIFIER "%Iu" 384 #else 385 #define SK_SIZE_T_SPECIFIER "%zu" 386 #endif 387 #endif 388 389 ////////////////////////////////////////////////////////////////////// 390 391 #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 392 #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1 393 #endif 394