blob: 02b8b8b30541a7ce72cefcfa38bbb8f7dfbc2e74 [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
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000081#if !defined(SK_SUPPORT_GPU)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000082# define SK_SUPPORT_GPU 1
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000083#endif
84
bsalomon@google.com04423802011-11-23 21:25:35 +000085/**
86 * The clang static analyzer likes to know that when the program is not
87 * expected to continue (crash, assertion failure, etc). It will notice that
88 * some combination of parameters lead to a function call that does not return.
89 * It can then make appropriate assumptions about the parameters in code
90 * executed only if the non-returning function was *not* called.
91 */
92#if !defined(SkNO_RETURN_HINT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000093# if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
94 static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
95 static inline void SkNO_RETURN_HINT() {}
96# else
97# define SkNO_RETURN_HINT() do {} while (false)
98# endif
bsalomon@google.com04423802011-11-23 21:25:35 +000099#endif
100
reed@android.com8a1c16f2008-12-17 15:59:43 +0000101///////////////////////////////////////////////////////////////////////////////
102
mdempsky106b1242015-09-22 06:10:35 -0700103// TODO(mdempsky): Move elsewhere as appropriate.
104#include <new>
reed@android.com8a1c16f2008-12-17 15:59:43 +0000105
106#ifndef SK_CRASH
mtklein3f73e8c2014-06-19 07:41:58 -0700107# ifdef SK_BUILD_FOR_WIN
108# define SK_CRASH() __debugbreak()
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000109# else
mtklein3f73e8c2014-06-19 07:41:58 -0700110# if 1 // set to 0 for infinite loop, which can help connecting gdb
111# define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
112# else
113# define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
114# endif
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000115# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000116#endif
117
118///////////////////////////////////////////////////////////////////////////////
119
reed@android.com8a1c16f2008-12-17 15:59:43 +0000120#ifdef SK_BUILD_FOR_WIN
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000121# ifndef WIN32_LEAN_AND_MEAN
122# define WIN32_LEAN_AND_MEAN
123# define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
124# endif
125# ifndef NOMINMAX
126# define NOMINMAX
127# define NOMINMAX_WAS_LOCALLY_DEFINED
128# endif
129#
130# include <windows.h>
131#
132# ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
133# undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
134# undef WIN32_LEAN_AND_MEAN
135# endif
136# ifdef NOMINMAX_WAS_LOCALLY_DEFINED
137# undef NOMINMAX_WAS_LOCALLY_DEFINED
138# undef NOMINMAX
139# endif
140#
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000141# ifndef SK_A32_SHIFT
142# define SK_A32_SHIFT 24
143# define SK_R32_SHIFT 16
144# define SK_G32_SHIFT 8
145# define SK_B32_SHIFT 0
146# endif
147#
mtklein3f73e8c2014-06-19 07:41:58 -0700148#endif
149
150#ifndef SK_ALWAYSBREAK
benjaminwagner8a3760f2015-10-29 13:40:27 -0700151# if defined(GOOGLE3)
152 void DebugWriteToStderr(const char*, void*);
153 void DumpStackTrace(int skip_count, void w(const char*, void*),
154 void* arg);
155# define SK_ALWAYSBREAK(cond) do { \
156 if (cond) break; \
157 SkNO_RETURN_HINT(); \
158 SkDebugf("%s:%d: failed assertion \"%s\"\n", __FILE__, __LINE__, #cond); \
159 DumpStackTrace(0, DebugWriteToStderr, nullptr); \
160 SK_CRASH(); \
161 } while (false)
162# elif defined(SK_DEBUG)
mtklein3f73e8c2014-06-19 07:41:58 -0700163# define SK_ALWAYSBREAK(cond) do { \
164 if (cond) break; \
165 SkNO_RETURN_HINT(); \
166 SkDebugf("%s:%d: failed assertion \"%s\"\n", __FILE__, __LINE__, #cond); \
167 SK_CRASH(); \
168 } while (false)
169# else
170# define SK_ALWAYSBREAK(cond) do { if (cond) break; SK_CRASH(); } while (false)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000171# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000172#endif
173
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000174/**
bsalomon@google.com27661182011-05-19 15:57:44 +0000175 * We check to see if the SHIFT value has already been defined.
176 * if not, we define it ourself to some default values. We default to OpenGL
177 * order (in memory: r,g,b,a)
178 */
179#ifndef SK_A32_SHIFT
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000180# ifdef SK_CPU_BENDIAN
181# define SK_R32_SHIFT 24
182# define SK_G32_SHIFT 16
183# define SK_B32_SHIFT 8
184# define SK_A32_SHIFT 0
185# else
186# define SK_R32_SHIFT 0
187# define SK_G32_SHIFT 8
188# define SK_B32_SHIFT 16
189# define SK_A32_SHIFT 24
190# endif
bsalomon@google.com27661182011-05-19 15:57:44 +0000191#endif
192
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000193/**
djsollen@google.com2b343cc2013-08-20 20:28:03 +0000194 * SkColor has well defined shift values, but SkPMColor is configurable. This
195 * macro is a convenience that returns true if the shift values are equal while
196 * ignoring the machine's endianness.
197 */
198#define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \
199 (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0)
200
201/**
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000202 * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The
203 * relationship between the byte order and shift values depends on machine endianness. If the shift
204 * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little
205 * endian machine and the A channel on a big endian machine. Thus, given those shifts values,
206 * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and
207 * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine.
208 */
209#ifdef SK_CPU_BENDIAN
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000210# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000211 (SK_ ## C3 ## 32_SHIFT == 0 && \
212 SK_ ## C2 ## 32_SHIFT == 8 && \
213 SK_ ## C1 ## 32_SHIFT == 16 && \
214 SK_ ## C0 ## 32_SHIFT == 24)
215#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000216# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000217 (SK_ ## C0 ## 32_SHIFT == 0 && \
218 SK_ ## C1 ## 32_SHIFT == 8 && \
219 SK_ ## C2 ## 32_SHIFT == 16 && \
220 SK_ ## C3 ## 32_SHIFT == 24)
221#endif
222
robertphillips@google.com0e6e8cc2013-08-15 13:43:23 +0000223//////////////////////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000224
225#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000226# ifdef free
227# undef free
228# endif
229# include <crtdbg.h>
230# undef free
231#
232# ifdef SK_DEBUGx
233# if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
234 void * operator new(
235 size_t cb,
236 int nBlockUse,
237 const char * szFileName,
238 int nLine,
239 int foo
240 );
241 void * operator new[](
242 size_t cb,
243 int nBlockUse,
244 const char * szFileName,
245 int nLine,
246 int foo
247 );
248 void operator delete(
249 void *pUserData,
250 int, const char*, int, int
251 );
252 void operator delete(
253 void *pUserData
254 );
255 void operator delete[]( void * p );
256# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
257# else
258# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
259# endif
260# define new DEBUG_CLIENTBLOCK
261# else
262# define DEBUG_CLIENTBLOCK
263# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000264#endif
265
tomhudson@google.com13413042011-10-03 16:01:10 +0000266//////////////////////////////////////////////////////////////////////
267
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000268#if !defined(SK_UNUSED)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000269# define SK_UNUSED SK_ATTRIBUTE(unused)
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000270#endif
271
reed@google.com44699382013-10-31 17:28:30 +0000272#if !defined(SK_ATTR_DEPRECATED)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000273 // FIXME: we ignore msg for now...
274# define SK_ATTR_DEPRECATED(msg) SK_ATTRIBUTE(deprecated)
reed@google.com44699382013-10-31 17:28:30 +0000275#endif
276
commit-bot@chromium.orgd70fa202014-04-24 21:51:58 +0000277#if !defined(SK_ATTR_EXTERNALLY_DEPRECATED)
278# if !defined(SK_INTERNAL)
279# define SK_ATTR_EXTERNALLY_DEPRECATED(msg) SK_ATTR_DEPRECATED(msg)
280# else
281# define SK_ATTR_EXTERNALLY_DEPRECATED(msg)
282# endif
283#endif
284
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000285/**
286 * If your judgment is better than the compiler's (i.e. you've profiled it),
287 * you can use SK_ALWAYS_INLINE to force inlining. E.g.
288 * inline void someMethod() { ... } // may not be inlined
289 * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined
290 */
mtklein@google.com1950d5f2013-11-22 16:56:22 +0000291#if !defined(SK_ALWAYS_INLINE)
292# if defined(SK_BUILD_FOR_WIN)
293# define SK_ALWAYS_INLINE __forceinline
294# else
295# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
296# endif
297#endif
298
mtkleincd1930d2015-07-21 12:39:57 -0700299#if defined(SK_BUILD_FOR_WIN)
300 #define SK_VECTORCALL __vectorcall
301#elif defined(SK_CPU_ARM32)
302 #define SK_VECTORCALL __attribute__((pcs("aapcs-vfp")))
303#else
304 #define SK_VECTORCALL
305#endif
306
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000307//////////////////////////////////////////////////////////////////////
308
mtklein6885a1e2015-10-27 13:06:47 -0700309#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
mtklein72815e92015-10-28 09:52:20 -0700310 #define SK_PREFETCH(ptr) _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0)
311 #define SK_WRITE_PREFETCH(ptr) _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0)
mtklein6885a1e2015-10-27 13:06:47 -0700312#elif defined(__GNUC__)
313 #define SK_PREFETCH(ptr) __builtin_prefetch(ptr)
314 #define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1)
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000315#else
mtklein6885a1e2015-10-27 13:06:47 -0700316 #define SK_PREFETCH(ptr)
317 #define SK_WRITE_PREFETCH(ptr)
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000318#endif
319
320//////////////////////////////////////////////////////////////////////
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000321
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000322#ifndef SK_PRINTF_LIKE
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000323# if defined(__clang__) || defined(__GNUC__)
324# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
325# else
326# define SK_PRINTF_LIKE(A, B)
327# endif
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000328#endif
329
330//////////////////////////////////////////////////////////////////////
331
332#ifndef SK_SIZE_T_SPECIFIER
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000333# if defined(_MSC_VER)
334# define SK_SIZE_T_SPECIFIER "%Iu"
335# else
336# define SK_SIZE_T_SPECIFIER "%zu"
337# endif
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000338#endif
339
340//////////////////////////////////////////////////////////////////////
341
caryclark@google.comd26147a2011-12-15 14:16:43 +0000342#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000343# define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
caryclark@google.comd26147a2011-12-15 14:16:43 +0000344#endif
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000345
bungeman@google.comd9947f62013-12-18 15:27:39 +0000346//////////////////////////////////////////////////////////////////////
347
derekf29dda802014-10-01 10:52:52 -0700348#ifndef SK_EGL
borenet48087572015-04-02 12:16:36 -0700349# if defined(SK_BUILD_FOR_ANDROID)
derekf29dda802014-10-01 10:52:52 -0700350# define SK_EGL 1
351# else
352# define SK_EGL 0
353# endif
354#endif
bungeman@google.com4770a3b2014-04-10 22:26:29 +0000355
356//////////////////////////////////////////////////////////////////////
357
358#if defined(SK_GAMMA_EXPONENT) && defined(SK_GAMMA_SRGB)
359# error "cannot define both SK_GAMMA_EXPONENT and SK_GAMMA_SRGB"
360#elif defined(SK_GAMMA_SRGB)
361# define SK_GAMMA_EXPONENT (0.0f)
362#elif !defined(SK_GAMMA_EXPONENT)
363# define SK_GAMMA_EXPONENT (2.2f)
364#endif
365
joshualitt3f655f32015-04-29 10:01:22 -0700366//////////////////////////////////////////////////////////////////////
367
368#ifndef GR_TEST_UTILS
369# define GR_TEST_UTILS 1
370#endif
371
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000372#endif // SkPostConfig_DEFINED