• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 // IWYU pragma: private, include "SkTypes.h"
9 
10 #ifndef SkPreConfig_DEFINED
11 #define SkPreConfig_DEFINED
12 
13 // Allows embedders that want to disable macros that take arguments to just
14 // define that symbol to be one of these
15 #define SK_NOTHING_ARG1(arg1)
16 #define SK_NOTHING_ARG2(arg1, arg2)
17 #define SK_NOTHING_ARG3(arg1, arg2, arg3)
18 
19 //////////////////////////////////////////////////////////////////////
20 
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)
22 
23     #ifdef __APPLE__
24         #include "TargetConditionals.h"
25     #endif
26 
27     #if defined(_WIN32) || defined(__SYMBIAN32__)
28         #define SK_BUILD_FOR_WIN32
29     #elif defined(ANDROID) || defined(__ANDROID__)
30         #define SK_BUILD_FOR_ANDROID
31     #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \
32           defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \
33           defined(__DragonFly__) || defined(__Fuchsia__) || \
34           defined(__GLIBC__) || defined(__GNU__) || defined(__unix__)
35         #define SK_BUILD_FOR_UNIX
36     #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
37         #define SK_BUILD_FOR_IOS
38     #else
39         #define SK_BUILD_FOR_MAC
40     #endif
41 
42 #endif
43 
44 /* Even if the user only defined the framework variant we still need to build
45  * the default (NDK-compliant) Android code. Therefore, when attempting to
46  * include/exclude something from the framework variant check first that we are
47  * building for Android then check the status of the framework define.
48  */
49 #if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_ANDROID)
50     #define SK_BUILD_FOR_ANDROID
51 #endif
52 
53 //////////////////////////////////////////////////////////////////////
54 
55 #ifdef SK_BUILD_FOR_WIN32
56     #if !defined(SK_RESTRICT)
57         #define SK_RESTRICT __restrict
58     #endif
59     #if !defined(SK_WARN_UNUSED_RESULT)
60         #define SK_WARN_UNUSED_RESULT
61     #endif
62 #endif
63 
64 #if !defined(SK_RESTRICT)
65     #define SK_RESTRICT __restrict__
66 #endif
67 
68 #if !defined(SK_WARN_UNUSED_RESULT)
69     #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
70 #endif
71 
72 //////////////////////////////////////////////////////////////////////
73 
74 #if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN)
75     #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
76         #define SK_CPU_BENDIAN
77     #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
78         #define SK_CPU_LENDIAN
79     #elif defined(__sparc) || defined(__sparc__) || \
80       defined(_POWER) || defined(__powerpc__) || \
81       defined(__ppc__) || defined(__hppa) || \
82       defined(__PPC__) || defined(__PPC64__) || \
83       defined(_MIPSEB) || defined(__ARMEB__) || \
84       defined(__s390__) || \
85       (defined(__sh__) && defined(__BIG_ENDIAN__)) || \
86       (defined(__ia64) && defined(__BIG_ENDIAN__))
87          #define SK_CPU_BENDIAN
88     #else
89         #define SK_CPU_LENDIAN
90     #endif
91 #endif
92 
93 //////////////////////////////////////////////////////////////////////
94 
95 #if defined(__i386) || defined(_M_IX86) ||  defined(__x86_64__) || defined(_M_X64)
96   #define SK_CPU_X86 1
97 #endif
98 
99 /**
100  *  SK_CPU_SSE_LEVEL
101  *
102  *  If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level.
103  *  On non-intel CPU this should be undefined.
104  */
105 
106 #define SK_CPU_SSE_LEVEL_SSE1     10
107 #define SK_CPU_SSE_LEVEL_SSE2     20
108 #define SK_CPU_SSE_LEVEL_SSE3     30
109 #define SK_CPU_SSE_LEVEL_SSSE3    31
110 #define SK_CPU_SSE_LEVEL_SSE41    41
111 #define SK_CPU_SSE_LEVEL_SSE42    42
112 #define SK_CPU_SSE_LEVEL_AVX      51
113 #define SK_CPU_SSE_LEVEL_AVX2     52
114 
115 // When targetting iOS and using gyp to generate the build files, it is not
116 // possible to select files to build depending on the architecture (i.e. it
117 // is not possible to use hand optimized assembly implementation). In that
118 // configuration SK_BUILD_NO_OPTS is defined. Remove optimisation then.
119 #ifdef SK_BUILD_NO_OPTS
120     #define SK_CPU_SSE_LEVEL 0
121 #endif
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(__AVX2__)
128         #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_AVX2
129     #elif defined(__AVX__)
130         #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_AVX
131     #elif defined(__SSE4_2__)
132         #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE42
133     #elif defined(__SSE4_1__)
134         #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE41
135     #elif defined(__SSSE3__)
136         #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSSE3
137     #elif defined(__SSE3__)
138         #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE3
139     #elif defined(__SSE2__)
140         #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE2
141     #endif
142 #endif
143 
144 // Are we in VisualStudio?
145 #ifndef SK_CPU_SSE_LEVEL
146     // These checks must be done in descending order to ensure we set the highest
147     // available SSE level. 64-bit intel guarantees at least SSE2 support.
148     #if defined(__AVX2__)
149         #define SK_CPU_SSE_LEVEL        SK_CPU_SSE_LEVEL_AVX2
150     #elif defined(__AVX__)
151         #define SK_CPU_SSE_LEVEL        SK_CPU_SSE_LEVEL_AVX
152     #elif defined(_M_X64) || defined(_M_AMD64)
153         #define SK_CPU_SSE_LEVEL        SK_CPU_SSE_LEVEL_SSE2
154     #elif defined(_M_IX86_FP)
155         #if _M_IX86_FP >= 2
156             #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE2
157         #elif _M_IX86_FP == 1
158             #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE1
159         #endif
160     #endif
161 #endif
162 
163 //////////////////////////////////////////////////////////////////////
164 // ARM defines
165 
166 #if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR)
167     #define SK_CPU_ARM32
168 
169     #if defined(__GNUC__)
170         #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
171                 || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
172                 || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7)
173             #define SK_ARM_ARCH 7
174         #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
175                 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
176                 || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
177                 || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6)
178             #define SK_ARM_ARCH 6
179         #elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
180                 || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
181                 || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5)
182             #define SK_ARM_ARCH 5
183         #elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(_ARM_ARCH_4)
184             #define SK_ARM_ARCH 4
185         #else
186             #define SK_ARM_ARCH 3
187         #endif
188     #endif
189 #endif
190 
191 #if defined(__aarch64__) && !defined(SK_BUILD_NO_OPTS)
192     #define SK_CPU_ARM64
193 #endif
194 
195 // All 64-bit ARM chips have NEON.  Many 32-bit ARM chips do too.
196 #if !defined(SK_ARM_HAS_NEON) && !defined(SK_BUILD_NO_OPTS) && (defined(__ARM_NEON__) || defined(__ARM_NEON))
197     #define SK_ARM_HAS_NEON
198 #endif
199 
200 // Really this __APPLE__ check shouldn't be necessary, but it seems that Apple's Clang defines
201 // __ARM_FEATURE_CRC32 for -arch arm64, even though their chips don't support those instructions!
202 #if defined(__ARM_FEATURE_CRC32) && !defined(__APPLE__)
203     #define SK_ARM_HAS_CRC32
204 #endif
205 
206 //////////////////////////////////////////////////////////////////////
207 
208 #if !defined(SKIA_IMPLEMENTATION)
209     #define SKIA_IMPLEMENTATION 0
210 #endif
211 
212 #if !defined(SK_API)
213     #if defined(SKIA_DLL)
214         #if defined(_MSC_VER)
215             #if SKIA_IMPLEMENTATION
216                 #define SK_API __declspec(dllexport)
217             #else
218                 #define SK_API __declspec(dllimport)
219             #endif
220         #else
221             #define SK_API __attribute__((visibility("default")))
222         #endif
223     #else
224         #define SK_API
225     #endif
226 #endif
227 
228 //////////////////////////////////////////////////////////////////////
229 
230 /**
231  * Use SK_PURE_FUNC as an attribute to indicate that a function's
232  * return value only depends on the value of its parameters. This
233  * can help the compiler optimize out successive calls.
234  *
235  * Usage:
236  *      void  function(int params)  SK_PURE_FUNC;
237  */
238 #if defined(__GNUC__)
239 #  define  SK_PURE_FUNC  __attribute__((pure))
240 #else
241 #  define  SK_PURE_FUNC  /* nothing */
242 #endif
243 
244 //////////////////////////////////////////////////////////////////////
245 
246 /**
247  * SK_HAS_ATTRIBUTE(<name>) should return true iff the compiler
248  * supports __attribute__((<name>)). Mostly important because
249  * Clang doesn't support all of GCC attributes.
250  */
251 #if defined(__has_attribute)
252 #   define SK_HAS_ATTRIBUTE(x) __has_attribute(x)
253 #elif defined(__GNUC__)
254 #   define SK_HAS_ATTRIBUTE(x) 1
255 #else
256 #   define SK_HAS_ATTRIBUTE(x) 0
257 #endif
258 
259 /**
260  * SK_ATTRIBUTE_OPTIMIZE_O1 can be used as a function attribute
261  * to specify individual optimization level of -O1, if the compiler
262  * supports it.
263  *
264  * NOTE: Clang/ARM (r161757) does not support the 'optimize' attribute.
265  */
266 #if SK_HAS_ATTRIBUTE(optimize)
267 #   define SK_ATTRIBUTE_OPTIMIZE_O1 __attribute__((optimize("O1")))
268 #else
269 #   define SK_ATTRIBUTE_OPTIMIZE_O1 /* nothing */
270 #endif
271 
272 #endif
273