SkPostConfig.h revision 867cbd8bc29371a360194aed648c4d43307b0639
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_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) 34 #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" 35#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) 36 #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" 37#endif 38 39// ensure the port has defined all of these, or none of them 40#ifdef SK_A32_SHIFT 41 #if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT) 42 #error "all or none of the 32bit SHIFT amounts must be defined" 43 #endif 44#else 45 #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT) 46 #error "all or none of the 32bit SHIFT amounts must be defined" 47 #endif 48#endif 49 50#if !defined(SK_HAS_COMPILER_FEATURE) 51 #if defined(__has_feature) 52 #define SK_HAS_COMPILER_FEATURE(x) __has_feature(x) 53 #else 54 #define SK_HAS_COMPILER_FEATURE(x) 0 55 #endif 56#endif 57 58#if !defined(SK_SUPPORT_GPU) 59 #define SK_SUPPORT_GPU 1 60#endif 61 62/** 63 * The clang static analyzer likes to know that when the program is not 64 * expected to continue (crash, assertion failure, etc). It will notice that 65 * some combination of parameters lead to a function call that does not return. 66 * It can then make appropriate assumptions about the parameters in code 67 * executed only if the non-returning function was *not* called. 68 */ 69#if !defined(SkNO_RETURN_HINT) 70 #if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn) 71 namespace { 72 inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn)); 73 inline void SkNO_RETURN_HINT() {} 74 } 75 #else 76 #define SkNO_RETURN_HINT() do {} while (false) 77 #endif 78#endif 79 80#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB) 81 #error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB" 82#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB) 83 #define SK_HAS_ZLIB 84#endif 85 86/////////////////////////////////////////////////////////////////////////////// 87 88#ifndef SkNEW 89 #define SkNEW(type_name) new type_name 90 #define SkNEW_ARGS(type_name, args) new type_name args 91 #define SkNEW_ARRAY(type_name, count) new type_name[count] 92 #define SkNEW_PLACEMENT(buf, type_name) new (buf) type_name 93 #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \ 94 new (buf) type_name args 95 #define SkDELETE(obj) delete obj 96 #define SkDELETE_ARRAY(array) delete[] array 97#endif 98 99#ifndef SK_CRASH 100#if 1 // set to 0 for infinite loop, which can help connecting gdb 101 #define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false) 102#else 103 #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true) 104#endif 105#endif 106 107/////////////////////////////////////////////////////////////////////////////// 108 109#if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT) 110 // if this is defined, we convert floats to 2scompliment ints for compares 111 #ifndef SK_SCALAR_SLOW_COMPARES 112 #define SK_SCALAR_SLOW_COMPARES 113 #endif 114 #ifndef SK_USE_FLOATBITS 115 #define SK_USE_FLOATBITS 116 #endif 117#endif 118 119#ifdef SK_BUILD_FOR_WIN 120 // we want lean_and_mean when we include windows.h 121 #ifndef WIN32_LEAN_AND_MEAN 122 #define WIN32_LEAN_AND_MEAN 123 #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 124 #endif 125 126 #include <windows.h> 127 128 #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 129 #undef WIN32_LEAN_AND_MEAN 130 #endif 131 132 #ifndef SK_DEBUGBREAK 133 #define SK_DEBUGBREAK(cond) do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false) 134 #endif 135 136 #ifndef SK_A32_SHIFT 137 #define SK_A32_SHIFT 24 138 #define SK_R32_SHIFT 16 139 #define SK_G32_SHIFT 8 140 #define SK_B32_SHIFT 0 141 #endif 142 143#elif defined(SK_BUILD_FOR_MAC) 144 #ifndef SK_DEBUGBREAK 145 #define SK_DEBUGBREAK(cond) do { if (!(cond)) SK_CRASH(); } while (false) 146 #endif 147#else 148 #ifdef SK_DEBUG 149 #include <stdio.h> 150 #ifndef SK_DEBUGBREAK 151 #define SK_DEBUGBREAK(cond) do { if (cond) break; \ 152 SkDebugf("%s:%d: failed assertion \"%s\"\n", \ 153 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false) 154 #endif 155 #endif 156#endif 157 158/* 159 * We check to see if the SHIFT value has already been defined. 160 * if not, we define it ourself to some default values. We default to OpenGL 161 * order (in memory: r,g,b,a) 162 */ 163#ifndef SK_A32_SHIFT 164 #ifdef SK_CPU_BENDIAN 165 #define SK_R32_SHIFT 24 166 #define SK_G32_SHIFT 16 167 #define SK_B32_SHIFT 8 168 #define SK_A32_SHIFT 0 169 #else 170 #define SK_R32_SHIFT 0 171 #define SK_G32_SHIFT 8 172 #define SK_B32_SHIFT 16 173 #define SK_A32_SHIFT 24 174 #endif 175#endif 176 177// stdlib macros 178 179#if 0 180#if !defined(strlen) && defined(SK_DEBUG) 181 extern size_t sk_strlen(const char*); 182 #define strlen(s) sk_strlen(s) 183#endif 184#ifndef sk_strcpy 185 #define sk_strcpy(dst, src) strcpy(dst, src) 186#endif 187#ifndef sk_strchr 188 #define sk_strchr(s, c) strchr(s, c) 189#endif 190#ifndef sk_strrchr 191 #define sk_strrchr(s, c) strrchr(s, c) 192#endif 193#ifndef sk_strcmp 194 #define sk_strcmp(s, t) strcmp(s, t) 195#endif 196#ifndef sk_strncmp 197 #define sk_strncmp(s, t, n) strncmp(s, t, n) 198#endif 199#ifndef sk_memcpy 200 #define sk_memcpy(dst, src, n) memcpy(dst, src, n) 201#endif 202#ifndef memmove 203 #define memmove(dst, src, n) memmove(dst, src, n) 204#endif 205#ifndef sk_memset 206 #define sk_memset(dst, val, n) memset(dst, val, n) 207#endif 208#ifndef sk_memcmp 209 #define sk_memcmp(s, t, n) memcmp(s, t, n) 210#endif 211 212#define sk_strequal(s, t) (!sk_strcmp(s, t)) 213#define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n)) 214#endif 215 216////////////////////////////////////////////////////////////////////// 217 218#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) 219 #ifndef SkLONGLONG 220 #ifdef SK_BUILD_FOR_WIN32 221 #define SkLONGLONG __int64 222 #else 223 #define SkLONGLONG long long 224 #endif 225 #endif 226#endif 227 228////////////////////////////////////////////////////////////////////////////////////////////// 229#ifndef SK_BUILD_FOR_WINCE 230#include <string.h> 231#include <stdlib.h> 232#else 233#define _CMNINTRIN_DECLARE_ONLY 234#include "cmnintrin.h" 235#endif 236 237#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32 238//#define _CRTDBG_MAP_ALLOC 239#ifdef free 240#undef free 241#endif 242#include <crtdbg.h> 243#undef free 244 245#ifdef SK_DEBUGx 246#if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus) 247 void * operator new( 248 size_t cb, 249 int nBlockUse, 250 const char * szFileName, 251 int nLine, 252 int foo 253 ); 254 void * operator new[]( 255 size_t cb, 256 int nBlockUse, 257 const char * szFileName, 258 int nLine, 259 int foo 260 ); 261 void operator delete( 262 void *pUserData, 263 int, const char*, int, int 264 ); 265 void operator delete( 266 void *pUserData 267 ); 268 void operator delete[]( void * p ); 269 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0) 270#else 271 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) 272#endif 273 #define new DEBUG_CLIENTBLOCK 274#else 275#define DEBUG_CLIENTBLOCK 276#endif // _DEBUG 277 278 279#endif 280 281#endif 282 283////////////////////////////////////////////////////////////////////// 284 285#ifndef SK_OVERRIDE 286 #if defined(_MSC_VER) 287 #define SK_OVERRIDE override 288 #elif defined(__clang__) && !defined(SK_BUILD_FOR_IOS) 289 #if __has_feature(cxx_override_control) 290 // Some documentation suggests we should be using __attribute__((override)), 291 // but it doesn't work. 292 #define SK_OVERRIDE override 293 #elif defined(__has_extension) 294 #if __has_extension(cxx_override_control) 295 #define SK_OVERRIDE override 296 #endif 297 #endif 298 #else 299 // Linux GCC ignores "__attribute__((override))" and rejects "override". 300 #define SK_OVERRIDE 301 #endif 302#endif 303 304////////////////////////////////////////////////////////////////////// 305 306#ifndef SK_PRINTF_LIKE 307#if defined(__clang__) || defined(__GNUC__) 308#define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) 309#else 310#define SK_PRINTF_LIKE(A, B) 311#endif 312#endif 313 314////////////////////////////////////////////////////////////////////// 315 316#ifndef SK_SIZE_T_SPECIFIER 317#if defined(_MSC_VER) 318#define SK_SIZE_T_SPECIFIER "%Iu" 319#else 320#define SK_SIZE_T_SPECIFIER "%zu" 321#endif 322#endif 323 324////////////////////////////////////////////////////////////////////// 325 326#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 327#define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1 328#endif 329