1 2 /* 3 * Copyright 2006 The Android Open Source Project 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 #ifndef SkPreConfig_DEFINED 11 #define SkPreConfig_DEFINED 12 13 #ifdef WEBKIT_VERSION_MIN_REQUIRED 14 #include "config.h" 15 #endif 16 17 ////////////////////////////////////////////////////////////////////// 18 19 #if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_PALM) && !defined(SK_BUILD_FOR_WINCE) && !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_SDL) && !defined(SK_BUILD_FOR_BREW) && !defined(SK_BUILD_FOR_NACL) 20 21 #ifdef __APPLE__ 22 #include "TargetConditionals.h" 23 #endif 24 25 #if defined(PALMOS_SDK_VERSION) 26 #define SK_BUILD_FOR_PALM 27 #elif defined(UNDER_CE) 28 #define SK_BUILD_FOR_WINCE 29 #elif defined(WIN32) 30 #define SK_BUILD_FOR_WIN32 31 #elif defined(__SYMBIAN32__) 32 #define SK_BUILD_FOR_WIN32 33 #elif defined(ANDROID_NDK) 34 #define SK_BUILD_FOR_ANDROID_NDK 35 #elif defined(ANDROID) 36 #define SK_BUILD_FOR_ANDROID 37 #elif defined(linux) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ 38 defined(__sun) || defined(__NetBSD__) || defined(__DragonFly__) || \ 39 defined(__GLIBC__) || defined(__GNU__) 40 #define SK_BUILD_FOR_UNIX 41 #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR 42 #define SK_BUILD_FOR_IOS 43 #else 44 #define SK_BUILD_FOR_MAC 45 #endif 46 47 #endif 48 49 /* Even if the user only defined the NDK variant we still need to build 50 * the default Android code. Therefore, when attempting to include/exclude 51 * something from the NDK variant check first that we are building for 52 * Android then check the status of the NDK define. 53 */ 54 #if defined(SK_BUILD_FOR_ANDROID_NDK) && !defined(SK_BUILD_FOR_ANDROID) 55 #define SK_BUILD_FOR_ANDROID 56 #endif 57 58 // USE_CHROMIUM_SKIA is defined when building Skia for the Chromium 59 // browser. 60 #if defined(USE_CHROMIUM_SKIA) 61 #define SK_BUILD_FOR_CHROMIUM 62 #endif 63 64 ////////////////////////////////////////////////////////////////////// 65 66 #if !defined(SK_DEBUG) && !defined(SK_RELEASE) 67 #ifdef NDEBUG 68 #define SK_RELEASE 69 #else 70 #define SK_DEBUG 71 #endif 72 #endif 73 74 #ifdef SK_BUILD_FOR_WIN32 75 #if !defined(SK_RESTRICT) 76 #define SK_RESTRICT __restrict 77 #endif 78 #if !defined(SK_WARN_UNUSED_RESULT) 79 #define SK_WARN_UNUSED_RESULT 80 #endif 81 #include "sk_stdint.h" 82 #endif 83 84 ////////////////////////////////////////////////////////////////////// 85 86 #if !defined(SK_RESTRICT) 87 #define SK_RESTRICT __restrict__ 88 #endif 89 90 #if !defined(SK_WARN_UNUSED_RESULT) 91 #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 92 #endif 93 94 ////////////////////////////////////////////////////////////////////// 95 96 #if !defined(SK_SCALAR_IS_FLOAT) && !defined(SK_SCALAR_IS_FIXED) 97 #define SK_SCALAR_IS_FLOAT 98 #endif 99 100 ////////////////////////////////////////////////////////////////////// 101 102 #if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) 103 #if defined (__ppc__) || defined(__ppc64__) 104 #define SK_CPU_BENDIAN 105 #else 106 #define SK_CPU_LENDIAN 107 #endif 108 #endif 109 110 ////////////////////////////////////////////////////////////////////// 111 112 /** 113 * SK_CPU_SSE_LEVEL 114 * 115 * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. 116 * On non-intel CPU this should be undefined. 117 */ 118 119 #define SK_CPU_SSE_LEVEL_SSE1 10 120 #define SK_CPU_SSE_LEVEL_SSE2 20 121 #define SK_CPU_SSE_LEVEL_SSE3 30 122 #define SK_CPU_SSE_LEVEL_SSSE3 31 123 124 // Are we in GCC? 125 #ifndef SK_CPU_SSE_LEVEL 126 #if defined(__SSE2__) 127 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 128 #elif defined(__SSE3__) 129 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 130 #elif defined(__SSSE3__) 131 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 132 #endif 133 #endif 134 135 // Are we in VisualStudio? 136 #ifndef SK_CPU_SSE_LEVEL 137 #if _M_IX86_FP == 1 138 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 139 #elif _M_IX86_FP >= 2 140 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 141 #endif 142 #endif 143 144 // 64bit intel guarantees at least SSE2 145 #if defined(__x86_64__) || defined(_WIN64) 146 #if !defined(SK_CPU_SSE_LEVEL) || (SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSE2) 147 #undef SK_CPU_SSE_LEVEL 148 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 149 #endif 150 #endif 151 152 ////////////////////////////////////////////////////////////////////// 153 // ARM defines 154 155 #if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) 156 #define SK_CPU_ARM 157 158 #if defined(__GNUC__) 159 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ 160 || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ 161 || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7) 162 #define SK_ARM_ARCH 7 163 #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ 164 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \ 165 || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \ 166 || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6) 167 #define SK_ARM_ARCH 6 168 #elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \ 169 || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \ 170 || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5) 171 #define SK_ARM_ARCH 5 172 #elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(_ARM_ARCH_4) 173 #define SK_ARM_ARCH 4 174 #else 175 #define SK_ARM_ARCH 3 176 #endif 177 178 #if defined(__thumb2__) && (SK_ARM_ARCH >= 6) \ 179 || !defined(__thumb__) && ((SK_ARM_ARCH > 5) || defined(__ARM_ARCH_5E__) \ 180 || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)) 181 #define SK_ARM_HAS_EDSP 182 #endif 183 #endif 184 #endif 185 186 ////////////////////////////////////////////////////////////////////// 187 188 /** 189 * THUMB is the only known config where we avoid small branches in 190 * favor of more complex math. 191 */ 192 #if !(defined(__arm__) && defined(__thumb__)) 193 #define SK_CPU_HAS_CONDITIONAL_INSTR 194 #endif 195 196 ////////////////////////////////////////////////////////////////////// 197 198 #if !defined(SKIA_IMPLEMENTATION) 199 #define SKIA_IMPLEMENTATION 0 200 #endif 201 202 #if defined(SKIA_DLL) 203 #if defined(WIN32) 204 #if SKIA_IMPLEMENTATION 205 #define SK_API __declspec(dllexport) 206 #else 207 #define SK_API __declspec(dllimport) 208 #endif 209 #else 210 #define SK_API __attribute__((visibility("default"))) 211 #endif 212 #else 213 #define SK_API 214 #endif 215 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 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 245 #endif 246 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 261