1 2/* 3 * Copyright 2010 Google Inc. 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 11#ifndef GrConfig_DEFINED 12#define GrConfig_DEFINED 13 14#include "SkTypes.h" 15 16/////////////////////////////////////////////////////////////////////////////// 17// preconfig section: 18// 19// All the work before including GrUserConfig.h should center around guessing 20// what platform we're on, and defining low-level symbols based on that. 21// 22// A build environment may have already defined symbols, so we first check 23// for that 24// 25 26// hack to ensure we know what sort of Apple platform we're on 27#if defined(__APPLE_CPP__) || defined(__APPLE_CC__) 28 #include <TargetConditionals.h> 29#endif 30 31/** 32 * Gr defines are set to 0 or 1, rather than being undefined or defined 33 */ 34 35#if !defined(GR_CACHE_STATS) 36 #define GR_CACHE_STATS 0 37#endif 38 39/////////////////////////////////////////////////////////////////////////////// 40/////////////////////////////////////////////////////////////////////////////// 41 42#if defined(SK_BUILD_FOR_WIN32) 43// VC8 doesn't support stdint.h, so we define those types here. 44typedef signed char int8_t; 45typedef unsigned char uint8_t; 46typedef short int16_t; 47typedef unsigned short uint16_t; 48typedef int int32_t; 49typedef unsigned uint32_t; 50typedef __int64 int64_t; 51typedef unsigned __int64 uint64_t; 52#else 53/* 54 * Include stdint.h with defines that trigger declaration of C99 limit/const 55 * macros here before anyone else has a chance to include stdint.h without 56 * these. 57 */ 58#ifndef __STDC_LIMIT_MACROS 59#define __STDC_LIMIT_MACROS 60#endif 61#ifndef __STDC_CONSTANT_MACROS 62#define __STDC_CONSTANT_MACROS 63#endif 64#include <stdint.h> 65#endif 66 67/* 68 * The "user config" file can be empty, and everything should work. It is 69 * meant to store a given platform/client's overrides of our guess-work. 70 * 71 * A alternate user config file can be specified by defining 72 * GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h 73 * 74 * e.g. it can change the BUILD target or supply its own defines for anything 75 * else (e.g. GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT) 76 */ 77#if !defined(GR_USER_CONFIG_FILE) 78 #include "GrUserConfig.h" 79#else 80 #include GR_USER_CONFIG_FILE 81#endif 82 83 84/////////////////////////////////////////////////////////////////////////////// 85/////////////////////////////////////////////////////////////////////////////// 86// postconfig section: 87// 88 89// By now we must have a GR_..._BUILD symbol set to 1, and a decision about 90// debug -vs- release 91// 92 93#define GrPrintf SkDebugf 94 95/** 96 * GR_STRING makes a string of X where X is expanded before conversion to a string 97 * if X itself contains macros. 98 */ 99#define GR_STRING(X) GR_STRING_IMPL(X) 100#define GR_STRING_IMPL(X) #X 101 102/** 103 * GR_CONCAT concatenates X and Y where each is expanded before 104 * contanenation if either contains macros. 105 */ 106#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y) 107#define GR_CONCAT_IMPL(X,Y) X##Y 108 109/** 110 * Creates a string of the form "<filename>(<linenumber>) : " 111 */ 112#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : " 113 114/** 115 * Compilers have different ways of issuing warnings. This macro 116 * attempts to abstract them, but may need to be specialized for your 117 * particular compiler. 118 * To insert compiler warnings use "#pragma message GR_WARN(<string>)" 119 */ 120#if defined(_MSC_VER) && _MSC_VER 121 #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG) 122#else//__GNUC__ - may need other defines for different compilers 123 #define GR_WARN(MSG) ("WARNING: " MSG) 124#endif 125 126/** 127 * GR_ALWAYSBREAK is an unconditional break in all builds. 128 */ 129#if !defined(GR_ALWAYSBREAK) 130 #if defined(SK_BUILD_FOR_WIN32) 131 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak() 132 #else 133 // TODO: do other platforms really not have continuable breakpoints? 134 // sign extend for 64bit architectures to be sure this is 135 // in the high address range 136 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0; 137 #endif 138#endif 139 140/** 141 * GR_DEBUGBREAK is an unconditional break in debug builds. 142 */ 143#if !defined(GR_DEBUGBREAK) 144 #ifdef SK_DEBUG 145 #define GR_DEBUGBREAK GR_ALWAYSBREAK 146 #else 147 #define GR_DEBUGBREAK 148 #endif 149#endif 150 151/** 152 * GR_ALWAYSASSERT is an assertion in all builds. 153 */ 154#if !defined(GR_ALWAYSASSERT) 155 #define GR_ALWAYSASSERT(COND) \ 156 do { \ 157 if (!(COND)) { \ 158 GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \ 159 GR_ALWAYSBREAK; \ 160 } \ 161 } while (false) 162#endif 163 164/** 165 * GR_DEBUGASSERT is an assertion in debug builds only. 166 */ 167#if !defined(GR_DEBUGASSERT) 168 #ifdef SK_DEBUG 169 #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND) 170 #else 171 #define GR_DEBUGASSERT(COND) 172 #endif 173#endif 174 175/** 176 * Prettier forms of the above macros. 177 */ 178#define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND) 179 180/** 181 * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform 182 * it may print the message in the compiler log. Obviously, the condition must 183 * be evaluatable at compile time. 184 */ 185// VS 2010 and GCC compiled with c++0x or gnu++0x support the new 186// static_assert. 187#if !defined(GR_STATIC_ASSERT) 188 #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__) 189 #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug") 190 #else 191 template <bool> class GR_STATIC_ASSERT_FAILURE; 192 template <> class GR_STATIC_ASSERT_FAILURE<true> {}; 193 #define GR_STATIC_ASSERT(CONDITION) \ 194 enum {GR_CONCAT(X,__LINE__) = \ 195 sizeof(GR_STATIC_ASSERT_FAILURE<CONDITION>)} 196 #endif 197#endif 198 199/** 200 * GR_GEOM_BUFFER_MAP_THRESHOLD gives a threshold (in bytes) for when Gr should 201 * map a GrGeometryBuffer to update its contents. It will use map() if the 202 * size of the updated region is greater than the threshold. Otherwise it will 203 * use updateData(). 204 */ 205#if !defined(GR_GEOM_BUFFER_MAP_THRESHOLD) 206 #define GR_GEOM_BUFFER_MAP_THRESHOLD (1 << 15) 207#endif 208 209/** 210 * GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT gives a threshold (in megabytes) for the 211 * maximum size of the texture cache in vram. The value is only a default and 212 * can be overridden at runtime. 213 */ 214#if !defined(GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT) 215 #define GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT 96 216#endif 217 218/** 219 * GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT specifies the maximum number of 220 * textures the texture cache can hold in vram. The value is only a default and 221 * can be overridden at runtime. 222 */ 223#if !defined(GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT) 224 #define GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT 2048 225#endif 226 227/** 228 * GR_STROKE_PATH_RENDERING controls whether or not the GrStrokePathRenderer can be selected 229 * as a path renderer. GrStrokePathRenderer is currently an experimental path renderer. 230 */ 231#if !defined(GR_STROKE_PATH_RENDERING) 232 #define GR_STROKE_PATH_RENDERING 0 233#endif 234 235#endif 236