SkPostConfig.h revision 62cf26f374975d55cb771cb3b6b482c9f222d1eb
1/* 2 * Copyright 2006 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8#ifndef SkPostConfig_DEFINED 9#define SkPostConfig_DEFINED 10 11#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE) 12# define SK_BUILD_FOR_WIN 13#endif 14 15#if defined(SK_DEBUG) && defined(SK_RELEASE) 16# error "cannot define both SK_DEBUG and SK_RELEASE" 17#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) 18# error "must define either SK_DEBUG or SK_RELEASE" 19#endif 20 21#if defined(SK_SUPPORT_UNITTEST) && !defined(SK_DEBUG) 22# error "can't have unittests without debug" 23#endif 24 25/** 26 * Matrix calculations may be float or double. 27 * The default is double, as that is faster given our impl uses doubles 28 * for intermediate calculations. 29 */ 30#if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT) 31# error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT" 32#elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT) 33# define SK_MSCALAR_IS_DOUBLE 34#endif 35 36#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) 37# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" 38#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) 39# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" 40#endif 41 42/** 43 * Ensure the port has defined all of SK_X32_SHIFT, or none of them. 44 */ 45#ifdef SK_A32_SHIFT 46# if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT) 47# error "all or none of the 32bit SHIFT amounts must be defined" 48# endif 49#else 50# if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT) 51# error "all or none of the 32bit SHIFT amounts must be defined" 52# endif 53#endif 54 55#if !defined(SK_HAS_COMPILER_FEATURE) 56# if defined(__has_feature) 57# define SK_HAS_COMPILER_FEATURE(x) __has_feature(x) 58# else 59# define SK_HAS_COMPILER_FEATURE(x) 0 60# endif 61#endif 62 63#if !defined(SK_ATTRIBUTE) 64# if defined(__clang__) || defined(__GNUC__) 65# define SK_ATTRIBUTE(attr) __attribute__((attr)) 66# else 67# define SK_ATTRIBUTE(attr) 68# endif 69#endif 70 71#if !defined(SK_SUPPORT_GPU) 72# define SK_SUPPORT_GPU 1 73#endif 74 75/** 76 * The clang static analyzer likes to know that when the program is not 77 * expected to continue (crash, assertion failure, etc). It will notice that 78 * some combination of parameters lead to a function call that does not return. 79 * It can then make appropriate assumptions about the parameters in code 80 * executed only if the non-returning function was *not* called. 81 */ 82#if !defined(SkNO_RETURN_HINT) 83# if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn) 84 static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn)); 85 static inline void SkNO_RETURN_HINT() {} 86# else 87# define SkNO_RETURN_HINT() do {} while (false) 88# endif 89#endif 90 91#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB) 92# error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB" 93#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB) 94# define SK_HAS_ZLIB 95#endif 96 97/////////////////////////////////////////////////////////////////////////////// 98 99#ifndef SkNEW 100# define SkNEW(type_name) (new type_name) 101# define SkNEW_ARGS(type_name, args) (new type_name args) 102# define SkNEW_ARRAY(type_name, count) (new type_name[(count)]) 103# define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name) 104# define SkNEW_PLACEMENT_ARGS(buf, type_name, args) (new (buf) type_name args) 105# define SkDELETE(obj) (delete (obj)) 106# define SkDELETE_ARRAY(array) (delete[] (array)) 107#endif 108 109#ifndef SK_CRASH 110# if 1 // set to 0 for infinite loop, which can help connecting gdb 111# define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false) 112# else 113# define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true) 114# endif 115#endif 116 117/////////////////////////////////////////////////////////////////////////////// 118 119/** 120 * SK_ENABLE_INST_COUNT controlls printing how many reference counted objects 121 * are still held on exit. 122 * Defaults to 1 in DEBUG and 0 in RELEASE. 123 */ 124#ifndef SK_ENABLE_INST_COUNT 125# ifdef SK_DEBUG 126// Only enabled for static builds, because instance counting relies on static 127// variables in functions defined in header files. 128# define SK_ENABLE_INST_COUNT !defined(SKIA_DLL) 129# else 130# define SK_ENABLE_INST_COUNT 0 131# endif 132#endif 133 134/////////////////////////////////////////////////////////////////////////////// 135 136#ifdef SK_BUILD_FOR_WIN 137# ifndef WIN32_LEAN_AND_MEAN 138# define WIN32_LEAN_AND_MEAN 139# define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 140# endif 141# ifndef NOMINMAX 142# define NOMINMAX 143# define NOMINMAX_WAS_LOCALLY_DEFINED 144# endif 145# 146# include <windows.h> 147# 148# ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 149# undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 150# undef WIN32_LEAN_AND_MEAN 151# endif 152# ifdef NOMINMAX_WAS_LOCALLY_DEFINED 153# undef NOMINMAX_WAS_LOCALLY_DEFINED 154# undef NOMINMAX 155# endif 156# 157# ifndef SK_DEBUGBREAK 158# define SK_DEBUGBREAK(p) do { if (!(p)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false) 159# endif 160# 161# ifndef SK_A32_SHIFT 162# define SK_A32_SHIFT 24 163# define SK_R32_SHIFT 16 164# define SK_G32_SHIFT 8 165# define SK_B32_SHIFT 0 166# endif 167# 168#else 169# ifndef SK_DEBUGBREAK 170# ifdef SK_DEBUG 171# include <stdio.h> 172# define SK_DEBUGBREAK(cond) do { if (cond) break; \ 173 SkDebugf("%s:%d: failed assertion \"%s\"\n", \ 174 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false) 175# else 176# define SK_DEBUGBREAK(cond) do { if (cond) break; SK_CRASH(); } while (false) 177# endif 178# endif 179#endif 180 181/** 182 * We check to see if the SHIFT value has already been defined. 183 * if not, we define it ourself to some default values. We default to OpenGL 184 * order (in memory: r,g,b,a) 185 */ 186#ifndef SK_A32_SHIFT 187# ifdef SK_CPU_BENDIAN 188# define SK_R32_SHIFT 24 189# define SK_G32_SHIFT 16 190# define SK_B32_SHIFT 8 191# define SK_A32_SHIFT 0 192# else 193# define SK_R32_SHIFT 0 194# define SK_G32_SHIFT 8 195# define SK_B32_SHIFT 16 196# define SK_A32_SHIFT 24 197# endif 198#endif 199 200/** 201 * SkColor has well defined shift values, but SkPMColor is configurable. This 202 * macro is a convenience that returns true if the shift values are equal while 203 * ignoring the machine's endianness. 204 */ 205#define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \ 206 (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0) 207 208/** 209 * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The 210 * relationship between the byte order and shift values depends on machine endianness. If the shift 211 * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little 212 * endian machine and the A channel on a big endian machine. Thus, given those shifts values, 213 * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and 214 * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine. 215 */ 216#ifdef SK_CPU_BENDIAN 217# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \ 218 (SK_ ## C3 ## 32_SHIFT == 0 && \ 219 SK_ ## C2 ## 32_SHIFT == 8 && \ 220 SK_ ## C1 ## 32_SHIFT == 16 && \ 221 SK_ ## C0 ## 32_SHIFT == 24) 222#else 223# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \ 224 (SK_ ## C0 ## 32_SHIFT == 0 && \ 225 SK_ ## C1 ## 32_SHIFT == 8 && \ 226 SK_ ## C2 ## 32_SHIFT == 16 && \ 227 SK_ ## C3 ## 32_SHIFT == 24) 228#endif 229 230////////////////////////////////////////////////////////////////////// 231 232// TODO: rebaseline as needed so we can remove this flag entirely. 233// - all platforms have int64_t now 234// - we have slightly different fixed math results because of this check 235// since we don't define this for linux/android 236#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) 237# ifndef SkLONGLONG 238# define SkLONGLONG int64_t 239# endif 240#endif 241 242////////////////////////////////////////////////////////////////////////////////////////////// 243#ifndef SK_BUILD_FOR_WINCE 244# include <string.h> 245# include <stdlib.h> 246#else 247# define _CMNINTRIN_DECLARE_ONLY 248# include "cmnintrin.h" 249#endif 250 251#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32 252# ifdef free 253# undef free 254# endif 255# include <crtdbg.h> 256# undef free 257# 258# ifdef SK_DEBUGx 259# if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus) 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 new[]( 268 size_t cb, 269 int nBlockUse, 270 const char * szFileName, 271 int nLine, 272 int foo 273 ); 274 void operator delete( 275 void *pUserData, 276 int, const char*, int, int 277 ); 278 void operator delete( 279 void *pUserData 280 ); 281 void operator delete[]( void * p ); 282# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0) 283# else 284# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) 285# endif 286# define new DEBUG_CLIENTBLOCK 287# else 288# define DEBUG_CLIENTBLOCK 289# endif 290#endif 291 292////////////////////////////////////////////////////////////////////// 293 294#ifndef SK_OVERRIDE 295# if defined(_MSC_VER) 296# define SK_OVERRIDE override 297# elif defined(__clang__) 298 // Using __attribute__((override)) on clang does not appear to always work. 299 // Clang defaults to C++03 and warns about using override. Squelch that. Intentionally no 300 // push/pop here so all users of SK_OVERRIDE ignore the warning too. This is like passing 301 // -Wno-c++11-extensions, except that GCC won't die (because it won't see this pragma). 302# pragma clang diagnostic ignored "-Wc++11-extensions" 303# 304# if __has_feature(cxx_override_control) 305# define SK_OVERRIDE override 306# elif defined(__has_extension) && __has_extension(cxx_override_control) 307# define SK_OVERRIDE override 308# endif 309# endif 310# ifndef SK_OVERRIDE 311# define SK_OVERRIDE 312# endif 313#endif 314 315////////////////////////////////////////////////////////////////////// 316 317#if !defined(SK_UNUSED) 318# define SK_UNUSED SK_ATTRIBUTE(unused) 319#endif 320 321#if !defined(SK_ATTR_DEPRECATED) 322 // FIXME: we ignore msg for now... 323# define SK_ATTR_DEPRECATED(msg) SK_ATTRIBUTE(deprecated) 324#endif 325 326#if !defined(SK_ATTR_EXTERNALLY_DEPRECATED) 327# if !defined(SK_INTERNAL) 328# define SK_ATTR_EXTERNALLY_DEPRECATED(msg) SK_ATTR_DEPRECATED(msg) 329# else 330# define SK_ATTR_EXTERNALLY_DEPRECATED(msg) 331# endif 332#endif 333 334/** 335 * If your judgment is better than the compiler's (i.e. you've profiled it), 336 * you can use SK_ALWAYS_INLINE to force inlining. E.g. 337 * inline void someMethod() { ... } // may not be inlined 338 * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined 339 */ 340#if !defined(SK_ALWAYS_INLINE) 341# if defined(SK_BUILD_FOR_WIN) 342# define SK_ALWAYS_INLINE __forceinline 343# else 344# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline 345# endif 346#endif 347 348////////////////////////////////////////////////////////////////////// 349 350#if defined(__clang__) || defined(__GNUC__) 351# define SK_PREFETCH(ptr) __builtin_prefetch(ptr) 352# define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1) 353#else 354# define SK_PREFETCH(ptr) 355# define SK_WRITE_PREFETCH(ptr) 356#endif 357 358////////////////////////////////////////////////////////////////////// 359 360#ifndef SK_PRINTF_LIKE 361# if defined(__clang__) || defined(__GNUC__) 362# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) 363# else 364# define SK_PRINTF_LIKE(A, B) 365# endif 366#endif 367 368////////////////////////////////////////////////////////////////////// 369 370#ifndef SK_SIZE_T_SPECIFIER 371# if defined(_MSC_VER) 372# define SK_SIZE_T_SPECIFIER "%Iu" 373# else 374# define SK_SIZE_T_SPECIFIER "%zu" 375# endif 376#endif 377 378////////////////////////////////////////////////////////////////////// 379 380#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 381# define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1 382#endif 383 384////////////////////////////////////////////////////////////////////// 385 386#ifndef SK_ATOMICS_PLATFORM_H 387# if defined(_MSC_VER) 388# define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_win.h" 389# elif defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) 390# define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_android.h" 391# else 392# define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_sync.h" 393# endif 394#endif 395 396#ifndef SK_MUTEX_PLATFORM_H 397# if defined(SK_BUILD_FOR_WIN) 398# define SK_MUTEX_PLATFORM_H "../../src/ports/SkMutex_win.h" 399# else 400# define SK_MUTEX_PLATFORM_H "../../src/ports/SkMutex_pthread.h" 401# endif 402#endif 403 404 405////////////////////////////////////////////////////////////////////// 406 407#if defined(SK_GAMMA_EXPONENT) && defined(SK_GAMMA_SRGB) 408# error "cannot define both SK_GAMMA_EXPONENT and SK_GAMMA_SRGB" 409#elif defined(SK_GAMMA_SRGB) 410# define SK_GAMMA_EXPONENT (0.0f) 411#elif !defined(SK_GAMMA_EXPONENT) 412# define SK_GAMMA_EXPONENT (2.2f) 413#endif 414 415#endif // SkPostConfig_DEFINED 416