reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame^] | 8 | // IWYU pragma: private, include "SkTypes.h" |
| 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkPreConfig_DEFINED |
| 11 | #define SkPreConfig_DEFINED |
| 12 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 13 | // Allows embedders that want to disable macros that take arguments to just |
| 14 | // define that symbol to be one of these |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 15 | #define SK_NOTHING_ARG1(arg1) |
| 16 | #define SK_NOTHING_ARG2(arg1, arg2) |
| 17 | #define SK_NOTHING_ARG3(arg1, arg2, arg3) |
| 18 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | ////////////////////////////////////////////////////////////////////// |
| 20 | |
bungeman | 3ac6b75 | 2015-07-29 13:37:27 -0700 | [diff] [blame] | 21 | #if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 22 | |
| 23 | #ifdef __APPLE__ |
| 24 | #include "TargetConditionals.h" |
| 25 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 26 | |
bungeman | 3ac6b75 | 2015-07-29 13:37:27 -0700 | [diff] [blame] | 27 | #if defined(WIN32) || defined(__SYMBIAN32__) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | #define SK_BUILD_FOR_WIN32 |
djsollen@google.com | 60abb07 | 2012-02-15 18:49:15 +0000 | [diff] [blame] | 29 | #elif defined(ANDROID) |
| 30 | #define SK_BUILD_FOR_ANDROID |
reed@google.com | ea6805d | 2011-11-30 20:44:25 +0000 | [diff] [blame] | 31 | #elif defined(linux) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ |
george@mozilla.com | 79c865a | 2012-07-25 18:52:56 +0000 | [diff] [blame] | 32 | defined(__sun) || defined(__NetBSD__) || defined(__DragonFly__) || \ |
| 33 | defined(__GLIBC__) || defined(__GNU__) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | #define SK_BUILD_FOR_UNIX |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 35 | #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR |
| 36 | #define SK_BUILD_FOR_IOS |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | #else |
| 38 | #define SK_BUILD_FOR_MAC |
| 39 | #endif |
| 40 | |
| 41 | #endif |
| 42 | |
commit-bot@chromium.org | 059a4c7 | 2013-03-13 12:48:26 +0000 | [diff] [blame] | 43 | /* Even if the user only defined the framework variant we still need to build |
| 44 | * the default (NDK-compliant) Android code. Therefore, when attempting to |
| 45 | * include/exclude something from the framework variant check first that we are |
| 46 | * building for Android then check the status of the framework define. |
djsollen@google.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame] | 47 | */ |
bsalomon@google.com | 530efc8 | 2013-03-13 13:38:30 +0000 | [diff] [blame] | 48 | #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_ANDROID) |
djsollen@google.com | 5862929 | 2011-11-03 13:08:29 +0000 | [diff] [blame] | 49 | #define SK_BUILD_FOR_ANDROID |
| 50 | #endif |
| 51 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | ////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | #if !defined(SK_DEBUG) && !defined(SK_RELEASE) |
| 55 | #ifdef NDEBUG |
| 56 | #define SK_RELEASE |
| 57 | #else |
| 58 | #define SK_DEBUG |
| 59 | #endif |
| 60 | #endif |
| 61 | |
reed@android.com | 63debae | 2009-12-16 17:25:43 +0000 | [diff] [blame] | 62 | #ifdef SK_BUILD_FOR_WIN32 |
tomhudson@google.com | 333d6cb | 2011-07-12 19:19:03 +0000 | [diff] [blame] | 63 | #if !defined(SK_RESTRICT) |
| 64 | #define SK_RESTRICT __restrict |
| 65 | #endif |
bungeman@google.com | 363a4c2 | 2012-04-09 22:33:11 +0000 | [diff] [blame] | 66 | #if !defined(SK_WARN_UNUSED_RESULT) |
| 67 | #define SK_WARN_UNUSED_RESULT |
| 68 | #endif |
reed@android.com | 63debae | 2009-12-16 17:25:43 +0000 | [diff] [blame] | 69 | #endif |
| 70 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 71 | ////////////////////////////////////////////////////////////////////// |
| 72 | |
reed@android.com | 5c80ea1 | 2009-01-08 17:49:50 +0000 | [diff] [blame] | 73 | #if !defined(SK_RESTRICT) |
| 74 | #define SK_RESTRICT __restrict__ |
| 75 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | |
bungeman@google.com | 363a4c2 | 2012-04-09 22:33:11 +0000 | [diff] [blame] | 77 | #if !defined(SK_WARN_UNUSED_RESULT) |
| 78 | #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
| 79 | #endif |
| 80 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 81 | ////////////////////////////////////////////////////////////////////// |
| 82 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 83 | #if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) |
commit-bot@chromium.org | 8ec45ce | 2014-04-03 16:38:01 +0000 | [diff] [blame] | 84 | #if defined(__sparc) || defined(__sparc__) || \ |
| 85 | defined(_POWER) || defined(__powerpc__) || \ |
| 86 | defined(__ppc__) || defined(__hppa) || \ |
| 87 | defined(__PPC__) || defined(__PPC64__) || \ |
| 88 | defined(_MIPSEB) || defined(__ARMEB__) || \ |
| 89 | defined(__s390__) || \ |
| 90 | (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ |
| 91 | (defined(__ia64) && defined(__BIG_ENDIAN__)) |
| 92 | #define SK_CPU_BENDIAN |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 93 | #else |
| 94 | #define SK_CPU_LENDIAN |
| 95 | #endif |
| 96 | #endif |
| 97 | |
| 98 | ////////////////////////////////////////////////////////////////////// |
| 99 | |
commit-bot@chromium.org | 4460e75 | 2014-04-09 16:50:55 +0000 | [diff] [blame] | 100 | #if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) |
| 101 | #define SK_CPU_X86 1 |
| 102 | #endif |
| 103 | |
reed@google.com | 4a2cb30 | 2012-07-02 14:36:37 +0000 | [diff] [blame] | 104 | /** |
reed@google.com | 126b436 | 2012-07-02 19:00:27 +0000 | [diff] [blame] | 105 | * SK_CPU_SSE_LEVEL |
| 106 | * |
reed@google.com | ab69788 | 2012-07-02 17:27:51 +0000 | [diff] [blame] | 107 | * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. |
| 108 | * On non-intel CPU this should be undefined. |
reed@google.com | 4a2cb30 | 2012-07-02 14:36:37 +0000 | [diff] [blame] | 109 | */ |
reed@google.com | 126b436 | 2012-07-02 19:00:27 +0000 | [diff] [blame] | 110 | |
reed@google.com | 00aad94 | 2012-07-09 13:02:35 +0000 | [diff] [blame] | 111 | #define SK_CPU_SSE_LEVEL_SSE1 10 |
reed@google.com | 8dbd572 | 2012-07-03 12:08:39 +0000 | [diff] [blame] | 112 | #define SK_CPU_SSE_LEVEL_SSE2 20 |
| 113 | #define SK_CPU_SSE_LEVEL_SSE3 30 |
| 114 | #define SK_CPU_SSE_LEVEL_SSSE3 31 |
commit-bot@chromium.org | ce4402c | 2014-05-12 14:16:19 +0000 | [diff] [blame] | 115 | #define SK_CPU_SSE_LEVEL_SSE41 41 |
| 116 | #define SK_CPU_SSE_LEVEL_SSE42 42 |
reed@google.com | ab69788 | 2012-07-02 17:27:51 +0000 | [diff] [blame] | 117 | |
reed@google.com | 126b436 | 2012-07-02 19:00:27 +0000 | [diff] [blame] | 118 | // Are we in GCC? |
reed@google.com | 4a2cb30 | 2012-07-02 14:36:37 +0000 | [diff] [blame] | 119 | #ifndef SK_CPU_SSE_LEVEL |
commit-bot@chromium.org | 88a9543 | 2014-02-25 18:14:08 +0000 | [diff] [blame] | 120 | // These checks must be done in descending order to ensure we set the highest |
| 121 | // available SSE level. |
commit-bot@chromium.org | ce4402c | 2014-05-12 14:16:19 +0000 | [diff] [blame] | 122 | #if defined(__SSE4_2__) |
| 123 | #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 |
| 124 | #elif defined(__SSE4_1__) |
| 125 | #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 |
| 126 | #elif defined(__SSSE3__) |
commit-bot@chromium.org | 88a9543 | 2014-02-25 18:14:08 +0000 | [diff] [blame] | 127 | #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 |
reed@google.com | ab69788 | 2012-07-02 17:27:51 +0000 | [diff] [blame] | 128 | #elif defined(__SSE3__) |
reed@google.com | 8dbd572 | 2012-07-03 12:08:39 +0000 | [diff] [blame] | 129 | #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 |
commit-bot@chromium.org | 88a9543 | 2014-02-25 18:14:08 +0000 | [diff] [blame] | 130 | #elif defined(__SSE2__) |
| 131 | #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 |
reed@google.com | 4a2cb30 | 2012-07-02 14:36:37 +0000 | [diff] [blame] | 132 | #endif |
| 133 | #endif |
| 134 | |
reed@google.com | 126b436 | 2012-07-02 19:00:27 +0000 | [diff] [blame] | 135 | // Are we in VisualStudio? |
| 136 | #ifndef SK_CPU_SSE_LEVEL |
commit-bot@chromium.org | 88a9543 | 2014-02-25 18:14:08 +0000 | [diff] [blame] | 137 | // These checks must be done in descending order to ensure we set the highest |
commit-bot@chromium.org | ce4402c | 2014-05-12 14:16:19 +0000 | [diff] [blame] | 138 | // available SSE level. 64-bit intel guarantees at least SSE2 support. |
| 139 | #if defined(_M_X64) || defined(_M_AMD64) |
| 140 | #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 |
| 141 | #elif defined (_M_IX86_FP) |
commit-bot@chromium.org | 88a9543 | 2014-02-25 18:14:08 +0000 | [diff] [blame] | 142 | #if _M_IX86_FP >= 2 |
commit-bot@chromium.org | 4736ed1 | 2014-02-06 16:26:08 +0000 | [diff] [blame] | 143 | #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 |
commit-bot@chromium.org | 88a9543 | 2014-02-25 18:14:08 +0000 | [diff] [blame] | 144 | #elif _M_IX86_FP == 1 |
| 145 | #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 |
commit-bot@chromium.org | 4736ed1 | 2014-02-06 16:26:08 +0000 | [diff] [blame] | 146 | #endif |
reed@google.com | 00aad94 | 2012-07-09 13:02:35 +0000 | [diff] [blame] | 147 | #endif |
| 148 | #endif |
| 149 | |
reed@google.com | 4a2cb30 | 2012-07-02 14:36:37 +0000 | [diff] [blame] | 150 | ////////////////////////////////////////////////////////////////////// |
caryclark@google.com | 867cbd8 | 2012-09-20 15:45:41 +0000 | [diff] [blame] | 151 | // ARM defines |
| 152 | |
commit-bot@chromium.org | d01ec71 | 2014-04-03 23:39:46 +0000 | [diff] [blame] | 153 | #if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) |
mtklein | 3a2682a | 2014-06-03 12:07:31 -0700 | [diff] [blame] | 154 | #define SK_CPU_ARM32 |
caryclark@google.com | 867cbd8 | 2012-09-20 15:45:41 +0000 | [diff] [blame] | 155 | |
| 156 | #if defined(__GNUC__) |
| 157 | #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ |
| 158 | || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ |
| 159 | || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7) |
| 160 | #define SK_ARM_ARCH 7 |
| 161 | #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ |
| 162 | || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \ |
| 163 | || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \ |
| 164 | || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6) |
| 165 | #define SK_ARM_ARCH 6 |
| 166 | #elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \ |
| 167 | || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \ |
| 168 | || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5) |
| 169 | #define SK_ARM_ARCH 5 |
| 170 | #elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(_ARM_ARCH_4) |
| 171 | #define SK_ARM_ARCH 4 |
| 172 | #else |
| 173 | #define SK_ARM_ARCH 3 |
| 174 | #endif |
| 175 | |
| 176 | #if defined(__thumb2__) && (SK_ARM_ARCH >= 6) \ |
| 177 | || !defined(__thumb__) && ((SK_ARM_ARCH > 5) || defined(__ARM_ARCH_5E__) \ |
| 178 | || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)) |
| 179 | #define SK_ARM_HAS_EDSP |
| 180 | #endif |
| 181 | #endif |
| 182 | #endif |
| 183 | |
commit-bot@chromium.org | d01ec71 | 2014-04-03 23:39:46 +0000 | [diff] [blame] | 184 | // Disable ARM64 optimizations for iOS due to complications regarding gyp and iOS. |
| 185 | #if defined(__aarch64__) && !defined(SK_BUILD_FOR_IOS) |
commit-bot@chromium.org | 6f2d4d4 | 2014-04-02 15:03:56 +0000 | [diff] [blame] | 186 | #define SK_CPU_ARM64 |
| 187 | #endif |
| 188 | |
mtklein | b79ff56 | 2015-03-20 09:25:26 -0700 | [diff] [blame] | 189 | // All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. |
mtklein | f3f9440 | 2015-04-17 14:02:40 -0700 | [diff] [blame] | 190 | // TODO: Why don't we want NEON on iOS? |
| 191 | #if !defined(SK_ARM_HAS_NEON) && !defined(SK_BUILD_FOR_IOS) && \ |
| 192 | (defined(SK_CPU_ARM64) || defined(__ARM_NEON__)) |
mtklein | b79ff56 | 2015-03-20 09:25:26 -0700 | [diff] [blame] | 193 | #define SK_ARM_HAS_NEON |
| 194 | #endif |
| 195 | |
caryclark@google.com | 867cbd8 | 2012-09-20 15:45:41 +0000 | [diff] [blame] | 196 | ////////////////////////////////////////////////////////////////////// |
reed@google.com | 4a2cb30 | 2012-07-02 14:36:37 +0000 | [diff] [blame] | 197 | |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 198 | #if !defined(SKIA_IMPLEMENTATION) |
| 199 | #define SKIA_IMPLEMENTATION 0 |
| 200 | #endif |
reed@google.com | c009111 | 2011-04-26 20:04:16 +0000 | [diff] [blame] | 201 | |
| 202 | #if defined(SKIA_DLL) |
| 203 | #if defined(WIN32) |
robertphillips@google.com | 866ff87 | 2012-11-20 01:40:45 +0000 | [diff] [blame] | 204 | #if SKIA_IMPLEMENTATION |
reed@google.com | c009111 | 2011-04-26 20:04:16 +0000 | [diff] [blame] | 205 | #define SK_API __declspec(dllexport) |
| 206 | #else |
| 207 | #define SK_API __declspec(dllimport) |
| 208 | #endif |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 209 | #else |
robertphillips@google.com | 866ff87 | 2012-11-20 01:40:45 +0000 | [diff] [blame] | 210 | #define SK_API __attribute__((visibility("default"))) |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 211 | #endif |
| 212 | #else |
| 213 | #define SK_API |
| 214 | #endif |
| 215 | |
digit@google.com | 157d944 | 2012-08-06 14:53:32 +0000 | [diff] [blame] | 216 | ////////////////////////////////////////////////////////////////////// |
| 217 | |
| 218 | /** |
| 219 | * Use SK_PURE_FUNC as an attribute to indicate that a function's |
| 220 | * return value only depends on the value of its parameters. This |
| 221 | * can help the compiler optimize out successive calls. |
| 222 | * |
| 223 | * Usage: |
| 224 | * void function(int params) SK_PURE_FUNC; |
| 225 | */ |
| 226 | #if defined(__GNUC__) |
| 227 | # define SK_PURE_FUNC __attribute__((pure)) |
| 228 | #else |
| 229 | # define SK_PURE_FUNC /* nothing */ |
| 230 | #endif |
| 231 | |
digit@google.com | 536079b | 2012-08-28 15:22:37 +0000 | [diff] [blame] | 232 | ////////////////////////////////////////////////////////////////////// |
| 233 | |
| 234 | /** |
| 235 | * SK_HAS_ATTRIBUTE(<name>) should return true iff the compiler |
| 236 | * supports __attribute__((<name>)). Mostly important because |
| 237 | * Clang doesn't support all of GCC attributes. |
| 238 | */ |
| 239 | #if defined(__has_attribute) |
| 240 | # define SK_HAS_ATTRIBUTE(x) __has_attribute(x) |
| 241 | #elif defined(__GNUC__) |
| 242 | # define SK_HAS_ATTRIBUTE(x) 1 |
| 243 | #else |
| 244 | # define SK_HAS_ATTRIBUTE(x) 0 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 245 | #endif |
| 246 | |
digit@google.com | 536079b | 2012-08-28 15:22:37 +0000 | [diff] [blame] | 247 | /** |
| 248 | * SK_ATTRIBUTE_OPTIMIZE_O1 can be used as a function attribute |
| 249 | * to specify individual optimization level of -O1, if the compiler |
| 250 | * supports it. |
| 251 | * |
| 252 | * NOTE: Clang/ARM (r161757) does not support the 'optimize' attribute. |
| 253 | */ |
| 254 | #if SK_HAS_ATTRIBUTE(optimize) |
| 255 | # define SK_ATTRIBUTE_OPTIMIZE_O1 __attribute__((optimize("O1"))) |
| 256 | #else |
| 257 | # define SK_ATTRIBUTE_OPTIMIZE_O1 /* nothing */ |
| 258 | #endif |
| 259 | |
| 260 | #endif |