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