michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkPostConfig_DEFINED michael@0: #define SkPostConfig_DEFINED michael@0: michael@0: #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE) michael@0: # define SK_BUILD_FOR_WIN michael@0: #endif michael@0: michael@0: #if defined(SK_DEBUG) && defined(SK_RELEASE) michael@0: # error "cannot define both SK_DEBUG and SK_RELEASE" michael@0: #elif !defined(SK_DEBUG) && !defined(SK_RELEASE) michael@0: # error "must define either SK_DEBUG or SK_RELEASE" michael@0: #endif michael@0: michael@0: #if defined(SK_SUPPORT_UNITTEST) && !defined(SK_DEBUG) michael@0: # error "can't have unittests without debug" michael@0: #endif michael@0: michael@0: /** michael@0: * Matrix calculations may be float or double. michael@0: * The default is double, as that is faster given our impl uses doubles michael@0: * for intermediate calculations. michael@0: */ michael@0: #if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT) michael@0: # error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT" michael@0: #elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT) michael@0: # define SK_MSCALAR_IS_DOUBLE michael@0: #endif michael@0: michael@0: #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) michael@0: # error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" michael@0: #elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) michael@0: # error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" michael@0: #endif michael@0: michael@0: /** michael@0: * Ensure the port has defined all of SK_X32_SHIFT, or none of them. michael@0: */ michael@0: #ifdef SK_A32_SHIFT michael@0: # if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT) michael@0: # error "all or none of the 32bit SHIFT amounts must be defined" michael@0: # endif michael@0: #else michael@0: # if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT) michael@0: # error "all or none of the 32bit SHIFT amounts must be defined" michael@0: # endif michael@0: #endif michael@0: michael@0: #if !defined(SK_HAS_COMPILER_FEATURE) michael@0: # if defined(__has_feature) michael@0: # define SK_HAS_COMPILER_FEATURE(x) __has_feature(x) michael@0: # else michael@0: # define SK_HAS_COMPILER_FEATURE(x) 0 michael@0: # endif michael@0: #endif michael@0: michael@0: #if !defined(SK_ATTRIBUTE) michael@0: # if defined(__clang__) || defined(__GNUC__) michael@0: # define SK_ATTRIBUTE(attr) __attribute__((attr)) michael@0: # else michael@0: # define SK_ATTRIBUTE(attr) michael@0: # endif michael@0: #endif michael@0: michael@0: #if !defined(SK_SUPPORT_GPU) michael@0: # define SK_SUPPORT_GPU 1 michael@0: #endif michael@0: michael@0: /** michael@0: * The clang static analyzer likes to know that when the program is not michael@0: * expected to continue (crash, assertion failure, etc). It will notice that michael@0: * some combination of parameters lead to a function call that does not return. michael@0: * It can then make appropriate assumptions about the parameters in code michael@0: * executed only if the non-returning function was *not* called. michael@0: */ michael@0: #if !defined(SkNO_RETURN_HINT) michael@0: # if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn) michael@0: static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn)); michael@0: static inline void SkNO_RETURN_HINT() {} michael@0: # else michael@0: # define SkNO_RETURN_HINT() do {} while (false) michael@0: # endif michael@0: #endif michael@0: michael@0: #if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB) michael@0: # error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB" michael@0: #elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB) michael@0: # define SK_HAS_ZLIB michael@0: #endif michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef SkNEW michael@0: # define SkNEW(type_name) (new type_name) michael@0: # define SkNEW_ARGS(type_name, args) (new type_name args) michael@0: # define SkNEW_ARRAY(type_name, count) (new type_name[(count)]) michael@0: # define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name) michael@0: # define SkNEW_PLACEMENT_ARGS(buf, type_name, args) (new (buf) type_name args) michael@0: # define SkDELETE(obj) (delete (obj)) michael@0: # define SkDELETE_ARRAY(array) (delete[] (array)) michael@0: #endif michael@0: michael@0: #ifndef SK_CRASH michael@0: # if 1 // set to 0 for infinite loop, which can help connecting gdb michael@0: # define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false) michael@0: # else michael@0: # define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true) michael@0: # endif michael@0: #endif michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: /** michael@0: * SK_ENABLE_INST_COUNT controlls printing how many reference counted objects michael@0: * are still held on exit. michael@0: * Defaults to 1 in DEBUG and 0 in RELEASE. michael@0: */ michael@0: #ifndef SK_ENABLE_INST_COUNT michael@0: # ifdef SK_DEBUG michael@0: // Only enabled for static builds, because instance counting relies on static michael@0: // variables in functions defined in header files. michael@0: # define SK_ENABLE_INST_COUNT !defined(SKIA_DLL) michael@0: # else michael@0: # define SK_ENABLE_INST_COUNT 0 michael@0: # endif michael@0: #endif michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifdef SK_BUILD_FOR_WIN michael@0: # ifndef WIN32_LEAN_AND_MEAN michael@0: # define WIN32_LEAN_AND_MEAN michael@0: # define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED michael@0: # endif michael@0: # ifndef NOMINMAX michael@0: # define NOMINMAX michael@0: # define NOMINMAX_WAS_LOCALLY_DEFINED michael@0: # endif michael@0: # michael@0: # include michael@0: # michael@0: # ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED michael@0: # undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED michael@0: # undef WIN32_LEAN_AND_MEAN michael@0: # endif michael@0: # ifdef NOMINMAX_WAS_LOCALLY_DEFINED michael@0: # undef NOMINMAX_WAS_LOCALLY_DEFINED michael@0: # undef NOMINMAX michael@0: # endif michael@0: # michael@0: # ifndef SK_DEBUGBREAK michael@0: # define SK_DEBUGBREAK(p) do { if (!(p)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false) michael@0: # endif michael@0: # michael@0: # ifndef SK_A32_SHIFT michael@0: # define SK_A32_SHIFT 24 michael@0: # define SK_R32_SHIFT 16 michael@0: # define SK_G32_SHIFT 8 michael@0: # define SK_B32_SHIFT 0 michael@0: # endif michael@0: # michael@0: #else michael@0: # ifdef SK_DEBUG michael@0: # include michael@0: # ifndef SK_DEBUGBREAK michael@0: # define SK_DEBUGBREAK(cond) do { if (cond) break; \ michael@0: SkDebugf("%s:%d: failed assertion \"%s\"\n", \ michael@0: __FILE__, __LINE__, #cond); SK_CRASH(); } while (false) michael@0: # endif michael@0: # endif michael@0: #endif michael@0: michael@0: /** michael@0: * We check to see if the SHIFT value has already been defined. michael@0: * if not, we define it ourself to some default values. We default to OpenGL michael@0: * order (in memory: r,g,b,a) michael@0: */ michael@0: #ifndef SK_A32_SHIFT michael@0: # ifdef SK_CPU_BENDIAN michael@0: # define SK_R32_SHIFT 24 michael@0: # define SK_G32_SHIFT 16 michael@0: # define SK_B32_SHIFT 8 michael@0: # define SK_A32_SHIFT 0 michael@0: # else michael@0: # define SK_R32_SHIFT 0 michael@0: # define SK_G32_SHIFT 8 michael@0: # define SK_B32_SHIFT 16 michael@0: # define SK_A32_SHIFT 24 michael@0: # endif michael@0: #endif michael@0: michael@0: /** michael@0: * SkColor has well defined shift values, but SkPMColor is configurable. This michael@0: * macro is a convenience that returns true if the shift values are equal while michael@0: * ignoring the machine's endianness. michael@0: */ michael@0: #define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \ michael@0: (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0) michael@0: michael@0: /** michael@0: * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The michael@0: * relationship between the byte order and shift values depends on machine endianness. If the shift michael@0: * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little michael@0: * endian machine and the A channel on a big endian machine. Thus, given those shifts values, michael@0: * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and michael@0: * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine. michael@0: */ michael@0: #ifdef SK_CPU_BENDIAN michael@0: # define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \ michael@0: (SK_ ## C3 ## 32_SHIFT == 0 && \ michael@0: SK_ ## C2 ## 32_SHIFT == 8 && \ michael@0: SK_ ## C1 ## 32_SHIFT == 16 && \ michael@0: SK_ ## C0 ## 32_SHIFT == 24) michael@0: #else michael@0: # define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \ michael@0: (SK_ ## C0 ## 32_SHIFT == 0 && \ michael@0: SK_ ## C1 ## 32_SHIFT == 8 && \ michael@0: SK_ ## C2 ## 32_SHIFT == 16 && \ michael@0: SK_ ## C3 ## 32_SHIFT == 24) michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: // TODO: rebaseline as needed so we can remove this flag entirely. michael@0: // - all platforms have int64_t now michael@0: // - we have slightly different fixed math results because of this check michael@0: // since we don't define this for linux/android michael@0: #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) michael@0: # ifndef SkLONGLONG michael@0: # define SkLONGLONG int64_t michael@0: # endif michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////////////////////// michael@0: #ifndef SK_BUILD_FOR_WINCE michael@0: # include michael@0: # include michael@0: #else michael@0: # define _CMNINTRIN_DECLARE_ONLY michael@0: # include "cmnintrin.h" michael@0: #endif michael@0: michael@0: #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32 michael@0: # ifdef free michael@0: # undef free michael@0: # endif michael@0: # include michael@0: # undef free michael@0: # michael@0: # ifdef SK_DEBUGx michael@0: # if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus) michael@0: void * operator new( michael@0: size_t cb, michael@0: int nBlockUse, michael@0: const char * szFileName, michael@0: int nLine, michael@0: int foo michael@0: ); michael@0: void * operator new[]( michael@0: size_t cb, michael@0: int nBlockUse, michael@0: const char * szFileName, michael@0: int nLine, michael@0: int foo michael@0: ); michael@0: void operator delete( michael@0: void *pUserData, michael@0: int, const char*, int, int michael@0: ); michael@0: void operator delete( michael@0: void *pUserData michael@0: ); michael@0: void operator delete[]( void * p ); michael@0: # define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0) michael@0: # else michael@0: # define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) michael@0: # endif michael@0: # define new DEBUG_CLIENTBLOCK michael@0: # else michael@0: # define DEBUG_CLIENTBLOCK michael@0: # endif michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef SK_OVERRIDE michael@0: # if defined(_MSC_VER) michael@0: # define SK_OVERRIDE override michael@0: # elif defined(__clang__) michael@0: // Using __attribute__((override)) on clang does not appear to always work. michael@0: // Clang defaults to C++03 and warns about using override. Squelch that. Intentionally no michael@0: // push/pop here so all users of SK_OVERRIDE ignore the warning too. This is like passing michael@0: // -Wno-c++11-extensions, except that GCC won't die (because it won't see this pragma). michael@0: # pragma clang diagnostic ignored "-Wc++11-extensions" michael@0: # michael@0: # if __has_feature(cxx_override_control) michael@0: # define SK_OVERRIDE override michael@0: # elif defined(__has_extension) && __has_extension(cxx_override_control) michael@0: # define SK_OVERRIDE override michael@0: # endif michael@0: # endif michael@0: # ifndef SK_OVERRIDE michael@0: # define SK_OVERRIDE michael@0: # endif michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: #if !defined(SK_UNUSED) michael@0: # define SK_UNUSED SK_ATTRIBUTE(unused) michael@0: #endif michael@0: michael@0: #if !defined(SK_ATTR_DEPRECATED) michael@0: // FIXME: we ignore msg for now... michael@0: # define SK_ATTR_DEPRECATED(msg) SK_ATTRIBUTE(deprecated) michael@0: #endif michael@0: michael@0: /** michael@0: * If your judgment is better than the compiler's (i.e. you've profiled it), michael@0: * you can use SK_ALWAYS_INLINE to force inlining. E.g. michael@0: * inline void someMethod() { ... } // may not be inlined michael@0: * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined michael@0: */ michael@0: #if !defined(SK_ALWAYS_INLINE) michael@0: # if defined(SK_BUILD_FOR_WIN) michael@0: # define SK_ALWAYS_INLINE __forceinline michael@0: # else michael@0: # define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline michael@0: # endif michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: #if defined(__clang__) || defined(__GNUC__) michael@0: # define SK_PREFETCH(ptr) __builtin_prefetch(ptr) michael@0: # define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1) michael@0: #else michael@0: # define SK_PREFETCH(ptr) michael@0: # define SK_WRITE_PREFETCH(ptr) michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef SK_PRINTF_LIKE michael@0: # if defined(__clang__) || defined(__GNUC__) michael@0: # define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) michael@0: # else michael@0: # define SK_PRINTF_LIKE(A, B) michael@0: # endif michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef SK_SIZE_T_SPECIFIER michael@0: # if defined(_MSC_VER) michael@0: # define SK_SIZE_T_SPECIFIER "%Iu" michael@0: # else michael@0: # define SK_SIZE_T_SPECIFIER "%zu" michael@0: # endif michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS michael@0: # define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1 michael@0: #endif michael@0: michael@0: ////////////////////////////////////////////////////////////////////// michael@0: michael@0: #ifndef SK_ATOMICS_PLATFORM_H michael@0: # if defined(_MSC_VER) michael@0: # define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_win.h" michael@0: # elif defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) michael@0: # define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_android.h" michael@0: # else michael@0: # define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_sync.h" michael@0: # endif michael@0: #endif michael@0: michael@0: #ifndef SK_MUTEX_PLATFORM_H michael@0: # if defined(SK_BUILD_FOR_WIN) michael@0: # define SK_MUTEX_PLATFORM_H "../../src/ports/SkMutex_win.h" michael@0: # else michael@0: # define SK_MUTEX_PLATFORM_H "../../src/ports/SkMutex_pthread.h" michael@0: # endif michael@0: #endif michael@0: michael@0: #endif // SkPostConfig_DEFINED