michael@0: michael@0: /* michael@0: * Copyright 2010 Google Inc. 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: michael@0: michael@0: #ifndef GrConfig_DEFINED michael@0: #define GrConfig_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: // preconfig section: michael@0: // michael@0: // All the work before including GrUserConfig.h should center around guessing michael@0: // what platform we're on, and defining low-level symbols based on that. michael@0: // michael@0: // A build environment may have already defined symbols, so we first check michael@0: // for that michael@0: // michael@0: michael@0: // hack to ensure we know what sort of Apple platform we're on michael@0: #if defined(__APPLE_CPP__) || defined(__APPLE_CC__) michael@0: #include michael@0: #endif michael@0: michael@0: /** michael@0: * Gr defines are set to 0 or 1, rather than being undefined or defined michael@0: */ michael@0: michael@0: #if !defined(GR_CACHE_STATS) michael@0: #define GR_CACHE_STATS 0 michael@0: #endif michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: #if defined(SK_BUILD_FOR_WIN32) michael@0: // VC8 doesn't support stdint.h, so we define those types here. michael@0: typedef signed char int8_t; michael@0: typedef unsigned char uint8_t; michael@0: typedef short int16_t; michael@0: typedef unsigned short uint16_t; michael@0: typedef int int32_t; michael@0: typedef unsigned uint32_t; michael@0: typedef __int64 int64_t; michael@0: typedef unsigned __int64 uint64_t; michael@0: #else michael@0: /* michael@0: * Include stdint.h with defines that trigger declaration of C99 limit/const michael@0: * macros here before anyone else has a chance to include stdint.h without michael@0: * these. michael@0: */ michael@0: #ifndef __STDC_LIMIT_MACROS michael@0: #define __STDC_LIMIT_MACROS michael@0: #endif michael@0: #ifndef __STDC_CONSTANT_MACROS michael@0: #define __STDC_CONSTANT_MACROS michael@0: #endif michael@0: #include michael@0: #endif michael@0: michael@0: /* michael@0: * The "user config" file can be empty, and everything should work. It is michael@0: * meant to store a given platform/client's overrides of our guess-work. michael@0: * michael@0: * A alternate user config file can be specified by defining michael@0: * GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h michael@0: * michael@0: * e.g. it can change the BUILD target or supply its own defines for anything michael@0: * else (e.g. GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT) michael@0: */ michael@0: #if !defined(GR_USER_CONFIG_FILE) michael@0: #include "GrUserConfig.h" michael@0: #else michael@0: #include GR_USER_CONFIG_FILE michael@0: #endif michael@0: michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: // postconfig section: michael@0: // michael@0: michael@0: // By now we must have a GR_..._BUILD symbol set to 1, and a decision about michael@0: // debug -vs- release michael@0: // michael@0: michael@0: #define GrPrintf SkDebugf michael@0: michael@0: /** michael@0: * GR_STRING makes a string of X where X is expanded before conversion to a string michael@0: * if X itself contains macros. michael@0: */ michael@0: #define GR_STRING(X) GR_STRING_IMPL(X) michael@0: #define GR_STRING_IMPL(X) #X michael@0: michael@0: /** michael@0: * GR_CONCAT concatenates X and Y where each is expanded before michael@0: * contanenation if either contains macros. michael@0: */ michael@0: #define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y) michael@0: #define GR_CONCAT_IMPL(X,Y) X##Y michael@0: michael@0: /** michael@0: * Creates a string of the form "() : " michael@0: */ michael@0: #define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : " michael@0: michael@0: /** michael@0: * Compilers have different ways of issuing warnings. This macro michael@0: * attempts to abstract them, but may need to be specialized for your michael@0: * particular compiler. michael@0: * To insert compiler warnings use "#pragma message GR_WARN()" michael@0: */ michael@0: #if defined(_MSC_VER) && _MSC_VER michael@0: #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG) michael@0: #else//__GNUC__ - may need other defines for different compilers michael@0: #define GR_WARN(MSG) ("WARNING: " MSG) michael@0: #endif michael@0: michael@0: /** michael@0: * GR_ALWAYSBREAK is an unconditional break in all builds. michael@0: */ michael@0: #if !defined(GR_ALWAYSBREAK) michael@0: #if defined(SK_BUILD_FOR_WIN32) michael@0: #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak() michael@0: #else michael@0: // TODO: do other platforms really not have continuable breakpoints? michael@0: // sign extend for 64bit architectures to be sure this is michael@0: // in the high address range michael@0: #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0; michael@0: #endif michael@0: #endif michael@0: michael@0: /** michael@0: * GR_DEBUGBREAK is an unconditional break in debug builds. michael@0: */ michael@0: #if !defined(GR_DEBUGBREAK) michael@0: #ifdef SK_DEBUG michael@0: #define GR_DEBUGBREAK GR_ALWAYSBREAK michael@0: #else michael@0: #define GR_DEBUGBREAK michael@0: #endif michael@0: #endif michael@0: michael@0: /** michael@0: * GR_ALWAYSASSERT is an assertion in all builds. michael@0: */ michael@0: #if !defined(GR_ALWAYSASSERT) michael@0: #define GR_ALWAYSASSERT(COND) \ michael@0: do { \ michael@0: if (!(COND)) { \ michael@0: GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \ michael@0: GR_ALWAYSBREAK; \ michael@0: } \ michael@0: } while (false) michael@0: #endif michael@0: michael@0: /** michael@0: * GR_DEBUGASSERT is an assertion in debug builds only. michael@0: */ michael@0: #if !defined(GR_DEBUGASSERT) michael@0: #ifdef SK_DEBUG michael@0: #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND) michael@0: #else michael@0: #define GR_DEBUGASSERT(COND) michael@0: #endif michael@0: #endif michael@0: michael@0: /** michael@0: * Prettier forms of the above macros. michael@0: */ michael@0: #define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND) michael@0: michael@0: /** michael@0: * Crash from unrecoverable condition, optionally with a message. The debug variants only michael@0: * crash in a debug build. The message versions print the message regardless of release vs debug. michael@0: */ michael@0: inline void GrCrash() { GrAlwaysAssert(false); } michael@0: inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); } michael@0: inline void GrDebugCrash() { SkASSERT(false); } michael@0: inline void GrDebugCrash(const char* msg) { GrPrintf(msg); SkASSERT(false); } michael@0: michael@0: /** michael@0: * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform michael@0: * it may print the message in the compiler log. Obviously, the condition must michael@0: * be evaluatable at compile time. michael@0: */ michael@0: // VS 2010 and GCC compiled with c++0x or gnu++0x support the new michael@0: // static_assert. michael@0: #if !defined(GR_STATIC_ASSERT) michael@0: #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__) michael@0: #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug") michael@0: #else michael@0: template class GR_STATIC_ASSERT_FAILURE; michael@0: template <> class GR_STATIC_ASSERT_FAILURE {}; michael@0: #define GR_STATIC_ASSERT(CONDITION) \ michael@0: enum {GR_CONCAT(X,__LINE__) = \ michael@0: sizeof(GR_STATIC_ASSERT_FAILURE)} michael@0: #endif michael@0: #endif michael@0: michael@0: /** michael@0: * GR_GEOM_BUFFER_LOCK_THRESHOLD gives a threshold (in bytes) for when Gr should michael@0: * lock a GrGeometryBuffer to update its contents. It will use lock() if the michael@0: * size of the updated region is greater than the threshold. Otherwise it will michael@0: * use updateData(). michael@0: */ michael@0: #if !defined(GR_GEOM_BUFFER_LOCK_THRESHOLD) michael@0: #define GR_GEOM_BUFFER_LOCK_THRESHOLD (1 << 15) michael@0: #endif michael@0: michael@0: /** michael@0: * GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT gives a threshold (in megabytes) for the michael@0: * maximum size of the texture cache in vram. The value is only a default and michael@0: * can be overridden at runtime. michael@0: */ michael@0: #if !defined(GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT) michael@0: #define GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT 96 michael@0: #endif michael@0: michael@0: /** michael@0: * GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT specifies the maximum number of michael@0: * textures the texture cache can hold in vram. The value is only a default and michael@0: * can be overridden at runtime. michael@0: */ michael@0: #if !defined(GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT) michael@0: #define GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT 2048 michael@0: #endif michael@0: michael@0: /** michael@0: * GR_STROKE_PATH_RENDERING controls whether or not the GrStrokePathRenderer can be selected michael@0: * as a path renderer. GrStrokePathRenderer is currently an experimental path renderer. michael@0: */ michael@0: #if !defined(GR_STROKE_PATH_RENDERING) michael@0: #define GR_STROKE_PATH_RENDERING 0 michael@0: #endif michael@0: michael@0: #endif