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