SkPreConfig.h revision d01ec71f9c350ab73e24808a5d4da22a3c8fc515
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// Allows embedders that want to disable macros that take arguments to just 18// define that symbol to be one of these 19// 20#define SK_NOTHING_ARG1(arg1) 21#define SK_NOTHING_ARG2(arg1, arg2) 22#define SK_NOTHING_ARG3(arg1, arg2, arg3) 23 24////////////////////////////////////////////////////////////////////// 25 26#if !defined(SK_BUILD_FOR_ANDROID) && !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) 27 28 #ifdef __APPLE__ 29 #include "TargetConditionals.h" 30 #endif 31 32 #if defined(PALMOS_SDK_VERSION) 33 #define SK_BUILD_FOR_PALM 34 #elif defined(UNDER_CE) 35 #define SK_BUILD_FOR_WINCE 36 #elif defined(WIN32) 37 #define SK_BUILD_FOR_WIN32 38 #elif defined(__SYMBIAN32__) 39 #define SK_BUILD_FOR_WIN32 40 #elif defined(ANDROID) 41 #define SK_BUILD_FOR_ANDROID 42 #elif defined(linux) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ 43 defined(__sun) || defined(__NetBSD__) || defined(__DragonFly__) || \ 44 defined(__GLIBC__) || defined(__GNU__) 45 #define SK_BUILD_FOR_UNIX 46 #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR 47 #define SK_BUILD_FOR_IOS 48 #else 49 #define SK_BUILD_FOR_MAC 50 #endif 51 52#endif 53 54/* Even if the user only defined the framework variant we still need to build 55 * the default (NDK-compliant) Android code. Therefore, when attempting to 56 * include/exclude something from the framework variant check first that we are 57 * building for Android then check the status of the framework define. 58 */ 59#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_ANDROID) 60 #define SK_BUILD_FOR_ANDROID 61#endif 62 63////////////////////////////////////////////////////////////////////// 64 65#if !defined(SK_DEBUG) && !defined(SK_RELEASE) 66 #ifdef NDEBUG 67 #define SK_RELEASE 68 #else 69 #define SK_DEBUG 70 #endif 71#endif 72 73#ifdef SK_BUILD_FOR_WIN32 74 #if !defined(SK_RESTRICT) 75 #define SK_RESTRICT __restrict 76 #endif 77 #if !defined(SK_WARN_UNUSED_RESULT) 78 #define SK_WARN_UNUSED_RESULT 79 #endif 80#endif 81 82////////////////////////////////////////////////////////////////////// 83 84#if !defined(SK_RESTRICT) 85 #define SK_RESTRICT __restrict__ 86#endif 87 88#if !defined(SK_WARN_UNUSED_RESULT) 89 #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 90#endif 91 92////////////////////////////////////////////////////////////////////// 93 94#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) 95 #if defined(__sparc) || defined(__sparc__) || \ 96 defined(_POWER) || defined(__powerpc__) || \ 97 defined(__ppc__) || defined(__hppa) || \ 98 defined(__PPC__) || defined(__PPC64__) || \ 99 defined(_MIPSEB) || defined(__ARMEB__) || \ 100 defined(__s390__) || \ 101 (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ 102 (defined(__ia64) && defined(__BIG_ENDIAN__)) 103 #define SK_CPU_BENDIAN 104 #else 105 #define SK_CPU_LENDIAN 106 #endif 107#endif 108 109////////////////////////////////////////////////////////////////////// 110 111/** 112 * SK_CPU_SSE_LEVEL 113 * 114 * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. 115 * On non-intel CPU this should be undefined. 116 */ 117 118#define SK_CPU_SSE_LEVEL_SSE1 10 119#define SK_CPU_SSE_LEVEL_SSE2 20 120#define SK_CPU_SSE_LEVEL_SSE3 30 121#define SK_CPU_SSE_LEVEL_SSSE3 31 122 123// Are we in GCC? 124#ifndef SK_CPU_SSE_LEVEL 125 // These checks must be done in descending order to ensure we set the highest 126 // available SSE level. 127 #if defined(__SSSE3__) 128 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 129 #elif defined(__SSE3__) 130 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 131 #elif defined(__SSE2__) 132 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 133 #endif 134#endif 135 136// Are we in VisualStudio? 137#ifndef SK_CPU_SSE_LEVEL 138 // These checks must be done in descending order to ensure we set the highest 139 // available SSE level. 140 #if defined (_M_IX86_FP) 141 #if _M_IX86_FP >= 2 142 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 143 #elif _M_IX86_FP == 1 144 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 145 #endif 146 #endif 147#endif 148 149////////////////////////////////////////////////////////////////////// 150// ARM defines 151 152#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) 153 #define SK_CPU_ARM 154 155 #if defined(__GNUC__) 156 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \ 157 || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \ 158 || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7) 159 #define SK_ARM_ARCH 7 160 #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ 161 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \ 162 || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \ 163 || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6) 164 #define SK_ARM_ARCH 6 165 #elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \ 166 || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \ 167 || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5) 168 #define SK_ARM_ARCH 5 169 #elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(_ARM_ARCH_4) 170 #define SK_ARM_ARCH 4 171 #else 172 #define SK_ARM_ARCH 3 173 #endif 174 175 #if defined(__thumb2__) && (SK_ARM_ARCH >= 6) \ 176 || !defined(__thumb__) && ((SK_ARM_ARCH > 5) || defined(__ARM_ARCH_5E__) \ 177 || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__)) 178 #define SK_ARM_HAS_EDSP 179 #endif 180 #endif 181#endif 182 183// Disable ARM64 optimizations for iOS due to complications regarding gyp and iOS. 184#if defined(__aarch64__) && !defined(SK_BUILD_FOR_IOS) 185 #define SK_CPU_ARM64 186#endif 187 188////////////////////////////////////////////////////////////////////// 189 190#if !defined(SKIA_IMPLEMENTATION) 191 #define SKIA_IMPLEMENTATION 0 192#endif 193 194#if defined(SKIA_DLL) 195 #if defined(WIN32) 196 #if SKIA_IMPLEMENTATION 197 #define SK_API __declspec(dllexport) 198 #else 199 #define SK_API __declspec(dllimport) 200 #endif 201 #else 202 #define SK_API __attribute__((visibility("default"))) 203 #endif 204#else 205 #define SK_API 206#endif 207 208////////////////////////////////////////////////////////////////////// 209 210/** 211 * Use SK_PURE_FUNC as an attribute to indicate that a function's 212 * return value only depends on the value of its parameters. This 213 * can help the compiler optimize out successive calls. 214 * 215 * Usage: 216 * void function(int params) SK_PURE_FUNC; 217 */ 218#if defined(__GNUC__) 219# define SK_PURE_FUNC __attribute__((pure)) 220#else 221# define SK_PURE_FUNC /* nothing */ 222#endif 223 224////////////////////////////////////////////////////////////////////// 225 226/** 227 * SK_HAS_ATTRIBUTE(<name>) should return true iff the compiler 228 * supports __attribute__((<name>)). Mostly important because 229 * Clang doesn't support all of GCC attributes. 230 */ 231#if defined(__has_attribute) 232# define SK_HAS_ATTRIBUTE(x) __has_attribute(x) 233#elif defined(__GNUC__) 234# define SK_HAS_ATTRIBUTE(x) 1 235#else 236# define SK_HAS_ATTRIBUTE(x) 0 237#endif 238 239/** 240 * SK_ATTRIBUTE_OPTIMIZE_O1 can be used as a function attribute 241 * to specify individual optimization level of -O1, if the compiler 242 * supports it. 243 * 244 * NOTE: Clang/ARM (r161757) does not support the 'optimize' attribute. 245 */ 246#if SK_HAS_ATTRIBUTE(optimize) 247# define SK_ATTRIBUTE_OPTIMIZE_O1 __attribute__((optimize("O1"))) 248#else 249# define SK_ATTRIBUTE_OPTIMIZE_O1 /* nothing */ 250#endif 251 252#endif 253