blob: 2aa4d822e07fd50b9f8dd94687da090b98073c24 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkPreConfig_DEFINED
11#define SkPreConfig_DEFINED
12
reed@android.comf2b98d62010-12-20 18:26:13 +000013#ifdef WEBKIT_VERSION_MIN_REQUIRED
14 #include "config.h"
15#endif
16
reed@google.com44699382013-10-31 17:28:30 +000017// 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
reed@android.com8a1c16f2008-12-17 15:59:43 +000024//////////////////////////////////////////////////////////////////////
25
commit-bot@chromium.org059a4c72013-03-13 12:48:26 +000026#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)
reed@android.comf2b98d62010-12-20 18:26:13 +000027
28 #ifdef __APPLE__
29 #include "TargetConditionals.h"
30 #endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000031
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
djsollen@google.com60abb072012-02-15 18:49:15 +000040 #elif defined(ANDROID)
41 #define SK_BUILD_FOR_ANDROID
reed@google.comea6805d2011-11-30 20:44:25 +000042 #elif defined(linux) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
george@mozilla.com79c865a2012-07-25 18:52:56 +000043 defined(__sun) || defined(__NetBSD__) || defined(__DragonFly__) || \
44 defined(__GLIBC__) || defined(__GNU__)
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 #define SK_BUILD_FOR_UNIX
reed@android.comf2b98d62010-12-20 18:26:13 +000046 #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
47 #define SK_BUILD_FOR_IOS
reed@android.com8a1c16f2008-12-17 15:59:43 +000048 #else
49 #define SK_BUILD_FOR_MAC
50 #endif
51
52#endif
53
commit-bot@chromium.org059a4c72013-03-13 12:48:26 +000054/* 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.
djsollen@google.com58629292011-11-03 13:08:29 +000058 */
bsalomon@google.com530efc82013-03-13 13:38:30 +000059#if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_ANDROID)
djsollen@google.com58629292011-11-03 13:08:29 +000060 #define SK_BUILD_FOR_ANDROID
61#endif
62
reed@android.com8a1c16f2008-12-17 15:59:43 +000063//////////////////////////////////////////////////////////////////////
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
reed@android.com63debae2009-12-16 17:25:43 +000073#ifdef SK_BUILD_FOR_WIN32
tomhudson@google.com333d6cb2011-07-12 19:19:03 +000074 #if !defined(SK_RESTRICT)
75 #define SK_RESTRICT __restrict
76 #endif
bungeman@google.com363a4c22012-04-09 22:33:11 +000077 #if !defined(SK_WARN_UNUSED_RESULT)
78 #define SK_WARN_UNUSED_RESULT
79 #endif
reed@android.com63debae2009-12-16 17:25:43 +000080#endif
81
reed@android.com8a1c16f2008-12-17 15:59:43 +000082//////////////////////////////////////////////////////////////////////
83
reed@android.com5c80ea12009-01-08 17:49:50 +000084#if !defined(SK_RESTRICT)
85 #define SK_RESTRICT __restrict__
86#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000087
bungeman@google.com363a4c22012-04-09 22:33:11 +000088#if !defined(SK_WARN_UNUSED_RESULT)
89 #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
90#endif
91
reed@android.com8a1c16f2008-12-17 15:59:43 +000092//////////////////////////////////////////////////////////////////////
93
reed@android.com8a1c16f2008-12-17 15:59:43 +000094#if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN)
george@mozilla.comaa2d3512013-08-06 20:16:34 +000095 #if defined (__ppc__) || defined(__PPC__) || defined(__ppc64__) \
96 || defined(__PPC64__)
reed@android.com8a1c16f2008-12-17 15:59:43 +000097 #define SK_CPU_BENDIAN
98 #else
99 #define SK_CPU_LENDIAN
100 #endif
101#endif
102
103//////////////////////////////////////////////////////////////////////
104
reed@google.com4a2cb302012-07-02 14:36:37 +0000105/**
reed@google.com126b4362012-07-02 19:00:27 +0000106 * SK_CPU_SSE_LEVEL
107 *
reed@google.comab697882012-07-02 17:27:51 +0000108 * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level.
109 * On non-intel CPU this should be undefined.
reed@google.com4a2cb302012-07-02 14:36:37 +0000110 */
reed@google.com126b4362012-07-02 19:00:27 +0000111
reed@google.com00aad942012-07-09 13:02:35 +0000112#define SK_CPU_SSE_LEVEL_SSE1 10
reed@google.com8dbd5722012-07-03 12:08:39 +0000113#define SK_CPU_SSE_LEVEL_SSE2 20
114#define SK_CPU_SSE_LEVEL_SSE3 30
115#define SK_CPU_SSE_LEVEL_SSSE3 31
reed@google.comab697882012-07-02 17:27:51 +0000116
reed@google.com126b4362012-07-02 19:00:27 +0000117// Are we in GCC?
reed@google.com4a2cb302012-07-02 14:36:37 +0000118#ifndef SK_CPU_SSE_LEVEL
reed@google.com00aad942012-07-09 13:02:35 +0000119 #if defined(__SSE2__)
reed@google.com8dbd5722012-07-03 12:08:39 +0000120 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
reed@google.comab697882012-07-02 17:27:51 +0000121 #elif defined(__SSE3__)
reed@google.com8dbd5722012-07-03 12:08:39 +0000122 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3
reed@google.com00aad942012-07-09 13:02:35 +0000123 #elif defined(__SSSE3__)
reed@google.com8dbd5722012-07-03 12:08:39 +0000124 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3
reed@google.com4a2cb302012-07-02 14:36:37 +0000125 #endif
126#endif
127
reed@google.com126b4362012-07-02 19:00:27 +0000128// Are we in VisualStudio?
129#ifndef SK_CPU_SSE_LEVEL
reed@google.com00aad942012-07-09 13:02:35 +0000130 #if _M_IX86_FP == 1
131 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1
132 #elif _M_IX86_FP >= 2
133 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
134 #endif
135#endif
136
137// 64bit intel guarantees at least SSE2
138#if defined(__x86_64__) || defined(_WIN64)
139 #if !defined(SK_CPU_SSE_LEVEL) || (SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSE2)
140 #undef SK_CPU_SSE_LEVEL
reed@google.com8dbd5722012-07-03 12:08:39 +0000141 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
reed@google.com126b4362012-07-02 19:00:27 +0000142 #endif
143#endif
144
reed@google.com4a2cb302012-07-02 14:36:37 +0000145//////////////////////////////////////////////////////////////////////
caryclark@google.com867cbd82012-09-20 15:45:41 +0000146// ARM defines
147
148#if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR)
149 #define SK_CPU_ARM
150
151 #if defined(__GNUC__)
152 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
153 || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
154 || defined(__ARM_ARCH_7EM__) || defined(_ARM_ARCH_7)
155 #define SK_ARM_ARCH 7
156 #elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
157 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
158 || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
159 || defined(__ARM_ARCH_6M__) || defined(_ARM_ARCH_6)
160 #define SK_ARM_ARCH 6
161 #elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
162 || defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
163 || defined(__ARM_ARCH_5TEJ__) || defined(_ARM_ARCH_5)
164 #define SK_ARM_ARCH 5
165 #elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || defined(_ARM_ARCH_4)
166 #define SK_ARM_ARCH 4
167 #else
168 #define SK_ARM_ARCH 3
169 #endif
170
171 #if defined(__thumb2__) && (SK_ARM_ARCH >= 6) \
172 || !defined(__thumb__) && ((SK_ARM_ARCH > 5) || defined(__ARM_ARCH_5E__) \
173 || defined(__ARM_ARCH_5TE__) || defined(__ARM_ARCH_5TEJ__))
174 #define SK_ARM_HAS_EDSP
175 #endif
176 #endif
177#endif
178
179//////////////////////////////////////////////////////////////////////
reed@google.com4a2cb302012-07-02 14:36:37 +0000180
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +0000181#if !defined(SKIA_IMPLEMENTATION)
182 #define SKIA_IMPLEMENTATION 0
183#endif
reed@google.comc0091112011-04-26 20:04:16 +0000184
185#if defined(SKIA_DLL)
186 #if defined(WIN32)
robertphillips@google.com866ff872012-11-20 01:40:45 +0000187 #if SKIA_IMPLEMENTATION
reed@google.comc0091112011-04-26 20:04:16 +0000188 #define SK_API __declspec(dllexport)
189 #else
190 #define SK_API __declspec(dllimport)
191 #endif
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +0000192 #else
robertphillips@google.com866ff872012-11-20 01:40:45 +0000193 #define SK_API __attribute__((visibility("default")))
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +0000194 #endif
195#else
196 #define SK_API
197#endif
198
digit@google.com157d9442012-08-06 14:53:32 +0000199//////////////////////////////////////////////////////////////////////
200
201/**
202 * Use SK_PURE_FUNC as an attribute to indicate that a function's
203 * return value only depends on the value of its parameters. This
204 * can help the compiler optimize out successive calls.
205 *
206 * Usage:
207 * void function(int params) SK_PURE_FUNC;
208 */
209#if defined(__GNUC__)
210# define SK_PURE_FUNC __attribute__((pure))
211#else
212# define SK_PURE_FUNC /* nothing */
213#endif
214
digit@google.com536079b2012-08-28 15:22:37 +0000215//////////////////////////////////////////////////////////////////////
216
217/**
218 * SK_HAS_ATTRIBUTE(<name>) should return true iff the compiler
219 * supports __attribute__((<name>)). Mostly important because
220 * Clang doesn't support all of GCC attributes.
221 */
222#if defined(__has_attribute)
223# define SK_HAS_ATTRIBUTE(x) __has_attribute(x)
224#elif defined(__GNUC__)
225# define SK_HAS_ATTRIBUTE(x) 1
226#else
227# define SK_HAS_ATTRIBUTE(x) 0
reed@android.com8a1c16f2008-12-17 15:59:43 +0000228#endif
229
digit@google.com536079b2012-08-28 15:22:37 +0000230/**
231 * SK_ATTRIBUTE_OPTIMIZE_O1 can be used as a function attribute
232 * to specify individual optimization level of -O1, if the compiler
233 * supports it.
234 *
235 * NOTE: Clang/ARM (r161757) does not support the 'optimize' attribute.
236 */
237#if SK_HAS_ATTRIBUTE(optimize)
238# define SK_ATTRIBUTE_OPTIMIZE_O1 __attribute__((optimize("O1")))
239#else
240# define SK_ATTRIBUTE_OPTIMIZE_O1 /* nothing */
241#endif
242
243#endif