SkPreConfig.h revision e3fa811657ecf4ab694d026752a81080c6b10611
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)
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(__GLIBC__) || defined(__GNU__) || \
34          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#if !defined(SK_DEBUG) && !defined(SK_RELEASE)
56    #ifdef NDEBUG
57        #define SK_RELEASE
58    #else
59        #define SK_DEBUG
60    #endif
61#endif
62
63#ifdef SK_BUILD_FOR_WIN32
64    #if !defined(SK_RESTRICT)
65        #define SK_RESTRICT __restrict
66    #endif
67    #if !defined(SK_WARN_UNUSED_RESULT)
68        #define SK_WARN_UNUSED_RESULT
69    #endif
70#endif
71
72//////////////////////////////////////////////////////////////////////
73
74#if !defined(SK_RESTRICT)
75    #define SK_RESTRICT __restrict__
76#endif
77
78#if !defined(SK_WARN_UNUSED_RESULT)
79    #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
80#endif
81
82//////////////////////////////////////////////////////////////////////
83
84#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN)
85    #if defined(__sparc) || defined(__sparc__) || \
86      defined(_POWER) || defined(__powerpc__) || \
87      defined(__ppc__) || defined(__hppa) || \
88      defined(__PPC__) || defined(__PPC64__) || \
89      defined(_MIPSEB) || defined(__ARMEB__) || \
90      defined(__s390__) || \
91      (defined(__sh__) && defined(__BIG_ENDIAN__)) || \
92      (defined(__ia64) && defined(__BIG_ENDIAN__))
93         #define SK_CPU_BENDIAN
94    #else
95        #define SK_CPU_LENDIAN
96    #endif
97#endif
98
99//////////////////////////////////////////////////////////////////////
100
101#if defined(__i386) || defined(_M_IX86) ||  defined(__x86_64__) || defined(_M_X64)
102  #define SK_CPU_X86 1
103#endif
104
105/**
106 *  SK_CPU_SSE_LEVEL
107 *
108 *  If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level.
109 *  On non-intel CPU this should be undefined.
110 */
111
112#define SK_CPU_SSE_LEVEL_SSE1     10
113#define SK_CPU_SSE_LEVEL_SSE2     20
114#define SK_CPU_SSE_LEVEL_SSE3     30
115#define SK_CPU_SSE_LEVEL_SSSE3    31
116#define SK_CPU_SSE_LEVEL_SSE41    41
117#define SK_CPU_SSE_LEVEL_SSE42    42
118#define SK_CPU_SSE_LEVEL_AVX      51
119#define SK_CPU_SSE_LEVEL_AVX2     52
120
121// When targetting iOS and using gyp to generate the build files, it is not
122// possible to select files to build depending on the architecture (i.e. it
123// is not possible to use hand optimized assembly implementation). In that
124// configuration SK_BUILD_NO_OPTS is defined. Remove optimisation then.
125#ifdef SK_BUILD_NO_OPTS
126    #define SK_CPU_SSE_LEVEL 0
127#endif
128
129// Are we in GCC?
130#ifndef SK_CPU_SSE_LEVEL
131    // These checks must be done in descending order to ensure we set the highest
132    // available SSE level.
133    #if defined(__AVX2__)
134        #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_AVX2
135    #elif defined(__AVX__)
136        #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_AVX
137    #elif defined(__SSE4_2__)
138        #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE42
139    #elif defined(__SSE4_1__)
140        #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE41
141    #elif defined(__SSSE3__)
142        #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSSE3
143    #elif defined(__SSE3__)
144        #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE3
145    #elif defined(__SSE2__)
146        #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE2
147    #endif
148#endif
149
150// Are we in VisualStudio?
151#ifndef SK_CPU_SSE_LEVEL
152    // These checks must be done in descending order to ensure we set the highest
153    // available SSE level. 64-bit intel guarantees at least SSE2 support.
154    #if defined(__AVX2__)
155        #define SK_CPU_SSE_LEVEL        SK_CPU_SSE_LEVEL_AVX2
156    #elif defined(__AVX__)
157        #define SK_CPU_SSE_LEVEL        SK_CPU_SSE_LEVEL_AVX
158    #elif defined(_M_X64) || defined(_M_AMD64)
159        #define SK_CPU_SSE_LEVEL        SK_CPU_SSE_LEVEL_SSE2
160    #elif defined(_M_IX86_FP)
161        #if _M_IX86_FP >= 2
162            #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE2
163        #elif _M_IX86_FP == 1
164            #define SK_CPU_SSE_LEVEL    SK_CPU_SSE_LEVEL_SSE1
165        #endif
166    #endif
167#endif
168
169//////////////////////////////////////////////////////////////////////
170// ARM defines
171
172#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR)
173    #define SK_CPU_ARM32
174
175    #if defined(__GNUC__)
176        #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
177                || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
178                || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7)
179            #define SK_ARM_ARCH 7
180        #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
181                || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
182                || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
183                || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6)
184            #define SK_ARM_ARCH 6
185        #elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
186                || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
187                || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5)
188            #define SK_ARM_ARCH 5
189        #elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(_ARM_ARCH_4)
190            #define SK_ARM_ARCH 4
191        #else
192            #define SK_ARM_ARCH 3
193        #endif
194    #endif
195#endif
196
197#if defined(__aarch64__) && !defined(SK_BUILD_NO_OPTS)
198    #define SK_CPU_ARM64
199#endif
200
201// All 64-bit ARM chips have NEON.  Many 32-bit ARM chips do too.
202#if !defined(SK_ARM_HAS_NEON) && !defined(SK_BUILD_NO_OPTS) && (defined(__ARM_NEON__) || defined(__ARM_NEON))
203    #define SK_ARM_HAS_NEON
204#endif
205
206//////////////////////////////////////////////////////////////////////
207
208#if !defined(SKIA_IMPLEMENTATION)
209    #define SKIA_IMPLEMENTATION 0
210#endif
211
212#if defined(SKIA_DLL)
213    #if defined(WIN32)
214        #if SKIA_IMPLEMENTATION
215            #define SK_API __declspec(dllexport)
216        #else
217            #define SK_API __declspec(dllimport)
218        #endif
219    #else
220        #define SK_API __attribute__((visibility("default")))
221    #endif
222#else
223    #define SK_API
224#endif
225
226//////////////////////////////////////////////////////////////////////
227
228/**
229 * Use SK_PURE_FUNC as an attribute to indicate that a function's
230 * return value only depends on the value of its parameters. This
231 * can help the compiler optimize out successive calls.
232 *
233 * Usage:
234 *      void  function(int params)  SK_PURE_FUNC;
235 */
236#if defined(__GNUC__)
237#  define  SK_PURE_FUNC  __attribute__((pure))
238#else
239#  define  SK_PURE_FUNC  /* nothing */
240#endif
241
242//////////////////////////////////////////////////////////////////////
243
244/**
245 * SK_HAS_ATTRIBUTE(<name>) should return true iff the compiler
246 * supports __attribute__((<name>)). Mostly important because
247 * Clang doesn't support all of GCC attributes.
248 */
249#if defined(__has_attribute)
250#   define SK_HAS_ATTRIBUTE(x) __has_attribute(x)
251#elif defined(__GNUC__)
252#   define SK_HAS_ATTRIBUTE(x) 1
253#else
254#   define SK_HAS_ATTRIBUTE(x) 0
255#endif
256
257/**
258 * SK_ATTRIBUTE_OPTIMIZE_O1 can be used as a function attribute
259 * to specify individual optimization level of -O1, if the compiler
260 * supports it.
261 *
262 * NOTE: Clang/ARM (r161757) does not support the 'optimize' attribute.
263 */
264#if SK_HAS_ATTRIBUTE(optimize)
265#   define SK_ATTRIBUTE_OPTIMIZE_O1 __attribute__((optimize("O1")))
266#else
267#   define SK_ATTRIBUTE_OPTIMIZE_O1 /* nothing */
268#endif
269
270#endif
271