epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrConfig_DEFINED |
| 12 | #define GrConfig_DEFINED |
| 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame^] | 14 | #include "include/core/SkTypes.h" |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 15 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 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 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 35 | #if !defined(GR_CACHE_STATS) |
djsollen | efe46d2 | 2016-04-29 06:41:35 -0700 | [diff] [blame] | 36 | #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) |
bsalomon | 24234fe | 2014-10-24 09:34:41 -0700 | [diff] [blame] | 37 | #define GR_CACHE_STATS 1 |
| 38 | #else |
| 39 | #define GR_CACHE_STATS 0 |
| 40 | #endif |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 41 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 43 | #if !defined(GR_GPU_STATS) |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 44 | #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || defined(GR_TEST_UTILS) |
bsalomon | 24234fe | 2014-10-24 09:34:41 -0700 | [diff] [blame] | 45 | #define GR_GPU_STATS 1 |
| 46 | #else |
| 47 | #define GR_GPU_STATS 0 |
| 48 | #endif |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 49 | #endif |
| 50 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 51 | /////////////////////////////////////////////////////////////////////////////// |
| 52 | /////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | /* |
bsalomon@google.com | 9182610 | 2011-03-21 19:51:57 +0000 | [diff] [blame] | 55 | * Include stdint.h with defines that trigger declaration of C99 limit/const |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 56 | * macros here before anyone else has a chance to include stdint.h without |
bsalomon@google.com | 9182610 | 2011-03-21 19:51:57 +0000 | [diff] [blame] | 57 | * these. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 58 | */ |
senorblanco@chromium.org | f9a1455 | 2012-11-06 18:36:33 +0000 | [diff] [blame] | 59 | #ifndef __STDC_LIMIT_MACROS |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 60 | #define __STDC_LIMIT_MACROS |
senorblanco@chromium.org | f9a1455 | 2012-11-06 18:36:33 +0000 | [diff] [blame] | 61 | #endif |
| 62 | #ifndef __STDC_CONSTANT_MACROS |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 63 | #define __STDC_CONSTANT_MACROS |
senorblanco@chromium.org | f9a1455 | 2012-11-06 18:36:33 +0000 | [diff] [blame] | 64 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 65 | #include <stdint.h> |
| 66 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 67 | /////////////////////////////////////////////////////////////////////////////// |
| 68 | /////////////////////////////////////////////////////////////////////////////// |
| 69 | // postconfig section: |
| 70 | // |
bsalomon@google.com | 9182610 | 2011-03-21 19:51:57 +0000 | [diff] [blame] | 71 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 72 | /** |
| 73 | * GR_STRING makes a string of X where X is expanded before conversion to a string |
| 74 | * if X itself contains macros. |
| 75 | */ |
| 76 | #define GR_STRING(X) GR_STRING_IMPL(X) |
| 77 | #define GR_STRING_IMPL(X) #X |
| 78 | |
| 79 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 80 | * GR_CONCAT concatenates X and Y where each is expanded before |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 81 | * contanenation if either contains macros. |
| 82 | */ |
| 83 | #define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y) |
| 84 | #define GR_CONCAT_IMPL(X,Y) X##Y |
| 85 | |
| 86 | /** |
| 87 | * Creates a string of the form "<filename>(<linenumber>) : " |
| 88 | */ |
| 89 | #define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : " |
| 90 | |
| 91 | /** |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 92 | * Compilers have different ways of issuing warnings. This macro |
| 93 | * attempts to abstract them, but may need to be specialized for your |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | * particular compiler. |
| 95 | * To insert compiler warnings use "#pragma message GR_WARN(<string>)" |
| 96 | */ |
bungeman | d7dc76f | 2016-03-10 11:14:40 -0800 | [diff] [blame] | 97 | #if defined(_MSC_VER) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 98 | #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG) |
| 99 | #else//__GNUC__ - may need other defines for different compilers |
| 100 | #define GR_WARN(MSG) ("WARNING: " MSG) |
| 101 | #endif |
| 102 | |
| 103 | /** |
| 104 | * GR_ALWAYSBREAK is an unconditional break in all builds. |
| 105 | */ |
| 106 | #if !defined(GR_ALWAYSBREAK) |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 107 | #if defined(SK_BUILD_FOR_WIN) |
bsalomon@google.com | 0442380 | 2011-11-23 21:25:35 +0000 | [diff] [blame] | 108 | #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak() |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 109 | #else |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 110 | // TODO: do other platforms really not have continuable breakpoints? |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 111 | // sign extend for 64bit architectures to be sure this is |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 112 | // in the high address range |
bsalomon@google.com | 0442380 | 2011-11-23 21:25:35 +0000 | [diff] [blame] | 113 | #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 114 | #endif |
| 115 | #endif |
| 116 | |
| 117 | /** |
| 118 | * GR_DEBUGBREAK is an unconditional break in debug builds. |
| 119 | */ |
| 120 | #if !defined(GR_DEBUGBREAK) |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 121 | #ifdef SK_DEBUG |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 122 | #define GR_DEBUGBREAK GR_ALWAYSBREAK |
| 123 | #else |
| 124 | #define GR_DEBUGBREAK |
| 125 | #endif |
| 126 | #endif |
| 127 | |
| 128 | /** |
| 129 | * GR_ALWAYSASSERT is an assertion in all builds. |
| 130 | */ |
| 131 | #if !defined(GR_ALWAYSASSERT) |
| 132 | #define GR_ALWAYSASSERT(COND) \ |
| 133 | do { \ |
| 134 | if (!(COND)) { \ |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 135 | SkDebugf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \ |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 136 | GR_ALWAYSBREAK; \ |
| 137 | } \ |
| 138 | } while (false) |
| 139 | #endif |
| 140 | |
| 141 | /** |
| 142 | * GR_DEBUGASSERT is an assertion in debug builds only. |
| 143 | */ |
| 144 | #if !defined(GR_DEBUGASSERT) |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 145 | #ifdef SK_DEBUG |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 146 | #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND) |
| 147 | #else |
| 148 | #define GR_DEBUGASSERT(COND) |
| 149 | #endif |
| 150 | #endif |
| 151 | |
| 152 | /** |
| 153 | * Prettier forms of the above macros. |
| 154 | */ |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 155 | #define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND) |
| 156 | |
| 157 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 158 | * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform |
| 159 | * it may print the message in the compiler log. Obviously, the condition must |
| 160 | * be evaluatable at compile time. |
| 161 | */ |
bungeman | d7dc76f | 2016-03-10 11:14:40 -0800 | [diff] [blame] | 162 | #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug") |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 163 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 164 | #endif |