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 #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) 37 #define GR_CACHE_STATS 1 38 #else 39 #define GR_CACHE_STATS 0 40 #endif 41 #endif 42 43 #if !defined(GR_GPU_STATS) 44 #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) 45 #define GR_GPU_STATS 1 46 #else 47 #define GR_GPU_STATS 0 48 #endif 49 #endif 50 51 /////////////////////////////////////////////////////////////////////////////// 52 /////////////////////////////////////////////////////////////////////////////// 53 54 #if defined(SK_BUILD_FOR_WIN32) 55 // VC8 doesn't support stdint.h, so we define those types here. 56 typedef signed char int8_t; 57 typedef unsigned char uint8_t; 58 typedef short int16_t; 59 typedef unsigned short uint16_t; 60 typedef int int32_t; 61 typedef unsigned uint32_t; 62 typedef __int64 int64_t; 63 typedef unsigned __int64 uint64_t; 64 #else 65 /* 66 * Include stdint.h with defines that trigger declaration of C99 limit/const 67 * macros here before anyone else has a chance to include stdint.h without 68 * these. 69 */ 70 #ifndef __STDC_LIMIT_MACROS 71 #define __STDC_LIMIT_MACROS 72 #endif 73 #ifndef __STDC_CONSTANT_MACROS 74 #define __STDC_CONSTANT_MACROS 75 #endif 76 #include <stdint.h> 77 #endif 78 79 /////////////////////////////////////////////////////////////////////////////// 80 /////////////////////////////////////////////////////////////////////////////// 81 // postconfig section: 82 // 83 84 /** 85 * GR_STRING makes a string of X where X is expanded before conversion to a string 86 * if X itself contains macros. 87 */ 88 #define GR_STRING(X) GR_STRING_IMPL(X) 89 #define GR_STRING_IMPL(X) #X 90 91 /** 92 * GR_CONCAT concatenates X and Y where each is expanded before 93 * contanenation if either contains macros. 94 */ 95 #define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y) 96 #define GR_CONCAT_IMPL(X,Y) X##Y 97 98 /** 99 * Creates a string of the form "<filename>(<linenumber>) : " 100 */ 101 #define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : " 102 103 /** 104 * Compilers have different ways of issuing warnings. This macro 105 * attempts to abstract them, but may need to be specialized for your 106 * particular compiler. 107 * To insert compiler warnings use "#pragma message GR_WARN(<string>)" 108 */ 109 #if defined(_MSC_VER) 110 #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG) 111 #else//__GNUC__ - may need other defines for different compilers 112 #define GR_WARN(MSG) ("WARNING: " MSG) 113 #endif 114 115 /** 116 * GR_ALWAYSBREAK is an unconditional break in all builds. 117 */ 118 #if !defined(GR_ALWAYSBREAK) 119 #if defined(SK_BUILD_FOR_WIN32) 120 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak() 121 #else 122 // TODO: do other platforms really not have continuable breakpoints? 123 // sign extend for 64bit architectures to be sure this is 124 // in the high address range 125 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0; 126 #endif 127 #endif 128 129 /** 130 * GR_DEBUGBREAK is an unconditional break in debug builds. 131 */ 132 #if !defined(GR_DEBUGBREAK) 133 #ifdef SK_DEBUG 134 #define GR_DEBUGBREAK GR_ALWAYSBREAK 135 #else 136 #define GR_DEBUGBREAK 137 #endif 138 #endif 139 140 /** 141 * GR_ALWAYSASSERT is an assertion in all builds. 142 */ 143 #if !defined(GR_ALWAYSASSERT) 144 #define GR_ALWAYSASSERT(COND) \ 145 do { \ 146 if (!(COND)) { \ 147 SkDebugf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \ 148 GR_ALWAYSBREAK; \ 149 } \ 150 } while (false) 151 #endif 152 153 /** 154 * GR_DEBUGASSERT is an assertion in debug builds only. 155 */ 156 #if !defined(GR_DEBUGASSERT) 157 #ifdef SK_DEBUG 158 #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND) 159 #else 160 #define GR_DEBUGASSERT(COND) 161 #endif 162 #endif 163 164 /** 165 * Prettier forms of the above macros. 166 */ 167 #define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND) 168 169 /** 170 * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform 171 * it may print the message in the compiler log. Obviously, the condition must 172 * be evaluatable at compile time. 173 */ 174 #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug") 175 176 #endif 177