blob: fa65ee6d47015fa7750f29c58ee47e30f160f467 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
bungemand3ebb482015-08-05 13:57:49 -07008// IWYU pragma: private, include "SkTypes.h"
9
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkPostConfig_DEFINED
11#define SkPostConfig_DEFINED
12
bungemanf20488b2015-07-29 11:49:40 -070013#if defined(SK_BUILD_FOR_WIN32)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000014# define SK_BUILD_FOR_WIN
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#endif
16
17#if defined(SK_DEBUG) && defined(SK_RELEASE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000018# error "cannot define both SK_DEBUG and SK_RELEASE"
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000020# error "must define either SK_DEBUG or SK_RELEASE"
reed@android.com8a1c16f2008-12-17 15:59:43 +000021#endif
22
bungeman@google.com7fd1f502013-12-04 16:40:42 +000023#if defined(SK_SUPPORT_UNITTEST) && !defined(SK_DEBUG)
24# error "can't have unittests without debug"
reed@android.com8a1c16f2008-12-17 15:59:43 +000025#endif
26
bungeman@google.com7fd1f502013-12-04 16:40:42 +000027/**
28 * Matrix calculations may be float or double.
mtklein51958052015-06-09 15:06:22 -070029 * The default is float, as that's what Chromium's using.
bungeman@google.com7fd1f502013-12-04 16:40:42 +000030 */
vollick@chromium.org5596a692012-11-13 20:12:00 +000031#if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000032# error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT"
vollick@chromium.org5596a692012-11-13 20:12:00 +000033#elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT)
mtklein51958052015-06-09 15:06:22 -070034# define SK_MSCALAR_IS_FLOAT
vollick@chromium.org5596a692012-11-13 20:12:00 +000035#endif
36
reed@android.com8a1c16f2008-12-17 15:59:43 +000037#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000038# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
reed@android.com8a1c16f2008-12-17 15:59:43 +000039#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000040# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
reed@android.com8a1c16f2008-12-17 15:59:43 +000041#endif
42
bungeman@google.com7fd1f502013-12-04 16:40:42 +000043/**
44 * Ensure the port has defined all of SK_X32_SHIFT, or none of them.
45 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000046#ifdef SK_A32_SHIFT
bungeman@google.com7fd1f502013-12-04 16:40:42 +000047# if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
48# error "all or none of the 32bit SHIFT amounts must be defined"
49# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000050#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +000051# if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
52# error "all or none of the 32bit SHIFT amounts must be defined"
53# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000054#endif
55
bsalomon@google.com04423802011-11-23 21:25:35 +000056#if !defined(SK_HAS_COMPILER_FEATURE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000057# if defined(__has_feature)
58# define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
59# else
60# define SK_HAS_COMPILER_FEATURE(x) 0
61# endif
bsalomon@google.com04423802011-11-23 21:25:35 +000062#endif
63
bungeman@google.com5ebbbe52013-08-06 18:32:29 +000064#if !defined(SK_ATTRIBUTE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000065# if defined(__clang__) || defined(__GNUC__)
66# define SK_ATTRIBUTE(attr) __attribute__((attr))
67# else
68# define SK_ATTRIBUTE(attr)
69# endif
bungeman@google.com5ebbbe52013-08-06 18:32:29 +000070#endif
71
mtkleine7616142015-02-26 10:14:15 -080072// As usual, there are two ways to increase alignment... the MSVC way and the everyone-else way.
73#ifndef SK_STRUCT_ALIGN
74 #ifdef _MSC_VER
75 #define SK_STRUCT_ALIGN(N) __declspec(align(N))
76 #else
77 #define SK_STRUCT_ALIGN(N) __attribute__((aligned(N)))
78 #endif
79#endif
80
mtkleine5fb9c82016-07-07 08:12:09 -070081#if defined(_MSC_VER) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
82 #define SK_VECTORCALL __vectorcall
83#elif defined(SK_CPU_ARM32) && defined(SK_ARM_HAS_NEON)
84 #define SK_VECTORCALL __attribute__((pcs("aapcs-vfp")))
85#else
86 #define SK_VECTORCALL
87#endif
88
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000089#if !defined(SK_SUPPORT_GPU)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000090# define SK_SUPPORT_GPU 1
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000091#endif
92
bsalomon@google.com04423802011-11-23 21:25:35 +000093/**
94 * The clang static analyzer likes to know that when the program is not
95 * expected to continue (crash, assertion failure, etc). It will notice that
96 * some combination of parameters lead to a function call that does not return.
97 * It can then make appropriate assumptions about the parameters in code
98 * executed only if the non-returning function was *not* called.
99 */
100#if !defined(SkNO_RETURN_HINT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000101# if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
102 static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
103 static inline void SkNO_RETURN_HINT() {}
104# else
105# define SkNO_RETURN_HINT() do {} while (false)
106# endif
bsalomon@google.com04423802011-11-23 21:25:35 +0000107#endif
108
reed@android.com8a1c16f2008-12-17 15:59:43 +0000109///////////////////////////////////////////////////////////////////////////////
110
mdempsky106b1242015-09-22 06:10:35 -0700111// TODO(mdempsky): Move elsewhere as appropriate.
112#include <new>
reed@android.com8a1c16f2008-12-17 15:59:43 +0000113
reed@android.com8a1c16f2008-12-17 15:59:43 +0000114
115///////////////////////////////////////////////////////////////////////////////
116
reed@android.com8a1c16f2008-12-17 15:59:43 +0000117#ifdef SK_BUILD_FOR_WIN
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000118# ifndef SK_A32_SHIFT
119# define SK_A32_SHIFT 24
120# define SK_R32_SHIFT 16
121# define SK_G32_SHIFT 8
122# define SK_B32_SHIFT 0
123# endif
124#
mtklein3f73e8c2014-06-19 07:41:58 -0700125#endif
126
benjaminwagner58afee82015-11-18 13:14:14 -0800127#if defined(GOOGLE3)
benjaminwagner58afee82015-11-18 13:14:14 -0800128 void SkDebugfForDumpStackTrace(const char* data, void* unused);
djsollenf2b340f2016-01-29 08:51:04 -0800129 void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg);
130# define SK_DUMP_GOOGLE3_STACK() DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr)
131#else
132# define SK_DUMP_GOOGLE3_STACK()
benjaminwagner58afee82015-11-18 13:14:14 -0800133#endif
134
djsollenf2b340f2016-01-29 08:51:04 -0800135#ifndef SK_ABORT
bungeman1f790aa2016-07-20 09:49:10 -0700136# define SK_ABORT(message) \
djsollenf2b340f2016-01-29 08:51:04 -0800137 do { \
138 SkNO_RETURN_HINT(); \
bungeman1f790aa2016-07-20 09:49:10 -0700139 SkDebugf("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, message); \
djsollenf2b340f2016-01-29 08:51:04 -0800140 SK_DUMP_GOOGLE3_STACK(); \
141 sk_abort_no_print(); \
142 } while (false)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000143#endif
144
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000145/**
bsalomon@google.com27661182011-05-19 15:57:44 +0000146 * We check to see if the SHIFT value has already been defined.
147 * if not, we define it ourself to some default values. We default to OpenGL
148 * order (in memory: r,g,b,a)
149 */
150#ifndef SK_A32_SHIFT
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000151# ifdef SK_CPU_BENDIAN
152# define SK_R32_SHIFT 24
153# define SK_G32_SHIFT 16
154# define SK_B32_SHIFT 8
155# define SK_A32_SHIFT 0
156# else
157# define SK_R32_SHIFT 0
158# define SK_G32_SHIFT 8
159# define SK_B32_SHIFT 16
160# define SK_A32_SHIFT 24
161# endif
bsalomon@google.com27661182011-05-19 15:57:44 +0000162#endif
163
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000164/**
djsollen@google.com2b343cc2013-08-20 20:28:03 +0000165 * SkColor has well defined shift values, but SkPMColor is configurable. This
166 * macro is a convenience that returns true if the shift values are equal while
167 * ignoring the machine's endianness.
168 */
169#define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \
170 (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0)
171
172/**
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000173 * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The
174 * relationship between the byte order and shift values depends on machine endianness. If the shift
175 * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little
176 * endian machine and the A channel on a big endian machine. Thus, given those shifts values,
177 * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and
178 * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine.
179 */
180#ifdef SK_CPU_BENDIAN
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000181# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000182 (SK_ ## C3 ## 32_SHIFT == 0 && \
183 SK_ ## C2 ## 32_SHIFT == 8 && \
184 SK_ ## C1 ## 32_SHIFT == 16 && \
185 SK_ ## C0 ## 32_SHIFT == 24)
186#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000187# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000188 (SK_ ## C0 ## 32_SHIFT == 0 && \
189 SK_ ## C1 ## 32_SHIFT == 8 && \
190 SK_ ## C2 ## 32_SHIFT == 16 && \
191 SK_ ## C3 ## 32_SHIFT == 24)
192#endif
193
robertphillips@google.com0e6e8cc2013-08-15 13:43:23 +0000194//////////////////////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000195
196#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000197# ifdef free
198# undef free
199# endif
200# include <crtdbg.h>
201# undef free
202#
203# ifdef SK_DEBUGx
204# if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
205 void * operator new(
206 size_t cb,
207 int nBlockUse,
208 const char * szFileName,
209 int nLine,
210 int foo
211 );
212 void * operator new[](
213 size_t cb,
214 int nBlockUse,
215 const char * szFileName,
216 int nLine,
217 int foo
218 );
219 void operator delete(
220 void *pUserData,
221 int, const char*, int, int
222 );
223 void operator delete(
224 void *pUserData
225 );
226 void operator delete[]( void * p );
227# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
228# else
229# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
230# endif
231# define new DEBUG_CLIENTBLOCK
232# else
233# define DEBUG_CLIENTBLOCK
234# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000235#endif
236
tomhudson@google.com13413042011-10-03 16:01:10 +0000237//////////////////////////////////////////////////////////////////////
238
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000239#if !defined(SK_UNUSED)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000240# define SK_UNUSED SK_ATTRIBUTE(unused)
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000241#endif
242
reed@google.com44699382013-10-31 17:28:30 +0000243#if !defined(SK_ATTR_DEPRECATED)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000244 // FIXME: we ignore msg for now...
245# define SK_ATTR_DEPRECATED(msg) SK_ATTRIBUTE(deprecated)
reed@google.com44699382013-10-31 17:28:30 +0000246#endif
247
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000248#if !defined(SK_ATTR_EXTERNALLY_DEPRECATED)
249# if !defined(SK_INTERNAL)
250# define SK_ATTR_EXTERNALLY_DEPRECATED(msg) SK_ATTR_DEPRECATED(msg)
251# else
252# define SK_ATTR_EXTERNALLY_DEPRECATED(msg)
253# endif
254#endif
255
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000256/**
257 * If your judgment is better than the compiler's (i.e. you've profiled it),
258 * you can use SK_ALWAYS_INLINE to force inlining. E.g.
259 * inline void someMethod() { ... } // may not be inlined
260 * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined
261 */
mtklein@google.com1950d5f2013-11-22 16:56:22 +0000262#if !defined(SK_ALWAYS_INLINE)
263# if defined(SK_BUILD_FOR_WIN)
264# define SK_ALWAYS_INLINE __forceinline
265# else
266# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
267# endif
268#endif
269
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000270//////////////////////////////////////////////////////////////////////
271
mtklein6885a1e2015-10-27 13:06:47 -0700272#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
mtklein72815e92015-10-28 09:52:20 -0700273 #define SK_PREFETCH(ptr) _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0)
274 #define SK_WRITE_PREFETCH(ptr) _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0)
mtklein6885a1e2015-10-27 13:06:47 -0700275#elif defined(__GNUC__)
276 #define SK_PREFETCH(ptr) __builtin_prefetch(ptr)
277 #define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1)
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000278#else
mtklein6885a1e2015-10-27 13:06:47 -0700279 #define SK_PREFETCH(ptr)
280 #define SK_WRITE_PREFETCH(ptr)
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000281#endif
282
283//////////////////////////////////////////////////////////////////////
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000284
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000285#ifndef SK_PRINTF_LIKE
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000286# if defined(__clang__) || defined(__GNUC__)
287# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
288# else
289# define SK_PRINTF_LIKE(A, B)
290# endif
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000291#endif
292
293//////////////////////////////////////////////////////////////////////
294
295#ifndef SK_SIZE_T_SPECIFIER
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000296# if defined(_MSC_VER)
297# define SK_SIZE_T_SPECIFIER "%Iu"
298# else
299# define SK_SIZE_T_SPECIFIER "%zu"
300# endif
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000301#endif
302
303//////////////////////////////////////////////////////////////////////
304
caryclark@google.comd26147a2011-12-15 14:16:43 +0000305#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000306# define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
caryclark@google.comd26147a2011-12-15 14:16:43 +0000307#endif
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000308
bungeman@google.comd9947f62013-12-18 15:27:39 +0000309//////////////////////////////////////////////////////////////////////
310
derekf29dda802014-10-01 10:52:52 -0700311#ifndef SK_EGL
borenet48087572015-04-02 12:16:36 -0700312# if defined(SK_BUILD_FOR_ANDROID)
derekf29dda802014-10-01 10:52:52 -0700313# define SK_EGL 1
314# else
315# define SK_EGL 0
316# endif
317#endif
bungeman@google.com4770a3b2014-04-10 22:26:29 +0000318
319//////////////////////////////////////////////////////////////////////
320
mtklein8d7f5c32016-08-01 09:22:12 -0700321#if !defined(SK_GAMMA_EXPONENT)
322 #define SK_GAMMA_EXPONENT (0.0f) // SRGB
bungeman@google.com4770a3b2014-04-10 22:26:29 +0000323#endif
324
joshualitt3f655f32015-04-29 10:01:22 -0700325//////////////////////////////////////////////////////////////////////
326
327#ifndef GR_TEST_UTILS
328# define GR_TEST_UTILS 1
329#endif
330
ericrk369e9372016-02-05 15:32:36 -0800331//////////////////////////////////////////////////////////////////////
332
ericrk983294f2016-04-18 09:14:00 -0700333#if defined(SK_HISTOGRAM_ENUMERATION) && defined(SK_HISTOGRAM_BOOLEAN)
334# define SK_HISTOGRAMS_ENABLED 1
335#else
336# define SK_HISTOGRAMS_ENABLED 0
337#endif
338
ericrk369e9372016-02-05 15:32:36 -0800339#ifndef SK_HISTOGRAM_BOOLEAN
340# define SK_HISTOGRAM_BOOLEAN(name, value)
341#endif
342
343#ifndef SK_HISTOGRAM_ENUMERATION
344# define SK_HISTOGRAM_ENUMERATION(name, value, boundary_value)
345#endif
346
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000347#endif // SkPostConfig_DEFINED