blob: 395ece89f1fe813ba3989beefe80ad32c212088a [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
8#ifndef SkPostConfig_DEFINED
9#define SkPostConfig_DEFINED
10
11#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000012# define SK_BUILD_FOR_WIN
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#endif
14
15#if defined(SK_DEBUG) && defined(SK_RELEASE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000016# error "cannot define both SK_DEBUG and SK_RELEASE"
reed@android.com8a1c16f2008-12-17 15:59:43 +000017#elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000018# error "must define either SK_DEBUG or SK_RELEASE"
reed@android.com8a1c16f2008-12-17 15:59:43 +000019#endif
20
bungeman@google.com7fd1f502013-12-04 16:40:42 +000021#if defined(SK_SUPPORT_UNITTEST) && !defined(SK_DEBUG)
22# error "can't have unittests without debug"
reed@android.com8a1c16f2008-12-17 15:59:43 +000023#endif
24
25#if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000026# error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT"
reed@android.com8a1c16f2008-12-17 15:59:43 +000027#elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000028# define SK_SCALAR_IS_FLOAT
reed@android.com8a1c16f2008-12-17 15:59:43 +000029#endif
30
bungeman@google.com7fd1f502013-12-04 16:40:42 +000031/**
32 * Matrix calculations may be float or double.
33 * The default is double, as that is faster given our impl uses doubles
34 * for intermediate calculations.
35 */
vollick@chromium.org5596a692012-11-13 20:12:00 +000036#if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000037# error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT"
vollick@chromium.org5596a692012-11-13 20:12:00 +000038#elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000039# define SK_MSCALAR_IS_DOUBLE
vollick@chromium.org5596a692012-11-13 20:12:00 +000040#endif
41
reed@android.com8a1c16f2008-12-17 15:59:43 +000042#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000043# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
reed@android.com8a1c16f2008-12-17 15:59:43 +000044#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000045# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
reed@android.com8a1c16f2008-12-17 15:59:43 +000046#endif
47
bungeman@google.com7fd1f502013-12-04 16:40:42 +000048/**
49 * Ensure the port has defined all of SK_X32_SHIFT, or none of them.
50 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000051#ifdef SK_A32_SHIFT
bungeman@google.com7fd1f502013-12-04 16:40:42 +000052# if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
53# error "all or none of the 32bit SHIFT amounts must be defined"
54# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000055#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +000056# if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
57# error "all or none of the 32bit SHIFT amounts must be defined"
58# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000059#endif
60
bsalomon@google.com04423802011-11-23 21:25:35 +000061#if !defined(SK_HAS_COMPILER_FEATURE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000062# if defined(__has_feature)
63# define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
64# else
65# define SK_HAS_COMPILER_FEATURE(x) 0
66# endif
bsalomon@google.com04423802011-11-23 21:25:35 +000067#endif
68
bungeman@google.com5ebbbe52013-08-06 18:32:29 +000069#if !defined(SK_ATTRIBUTE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000070# if defined(__clang__) || defined(__GNUC__)
71# define SK_ATTRIBUTE(attr) __attribute__((attr))
72# else
73# define SK_ATTRIBUTE(attr)
74# endif
bungeman@google.com5ebbbe52013-08-06 18:32:29 +000075#endif
76
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000077#if !defined(SK_SUPPORT_GPU)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000078# define SK_SUPPORT_GPU 1
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000079#endif
80
bsalomon@google.com04423802011-11-23 21:25:35 +000081/**
82 * The clang static analyzer likes to know that when the program is not
83 * expected to continue (crash, assertion failure, etc). It will notice that
84 * some combination of parameters lead to a function call that does not return.
85 * It can then make appropriate assumptions about the parameters in code
86 * executed only if the non-returning function was *not* called.
87 */
88#if !defined(SkNO_RETURN_HINT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000089# if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
90 static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
91 static inline void SkNO_RETURN_HINT() {}
92# else
93# define SkNO_RETURN_HINT() do {} while (false)
94# endif
bsalomon@google.com04423802011-11-23 21:25:35 +000095#endif
96
justinlin@google.comfffb2f12012-04-16 19:10:21 +000097#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000098# error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB"
justinlin@google.comfffb2f12012-04-16 19:10:21 +000099#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000100# define SK_HAS_ZLIB
justinlin@google.comfffb2f12012-04-16 19:10:21 +0000101#endif
102
reed@android.com8a1c16f2008-12-17 15:59:43 +0000103///////////////////////////////////////////////////////////////////////////////
104
105#ifndef SkNEW
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000106# define SkNEW(type_name) (new type_name)
107# define SkNEW_ARGS(type_name, args) (new type_name args)
108# define SkNEW_ARRAY(type_name, count) (new type_name[(count)])
109# define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name)
110# define SkNEW_PLACEMENT_ARGS(buf, type_name, args) (new (buf) type_name args)
111# define SkDELETE(obj) (delete (obj))
112# define SkDELETE_ARRAY(array) (delete[] (array))
reed@android.com8a1c16f2008-12-17 15:59:43 +0000113#endif
114
115#ifndef SK_CRASH
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000116# if 1 // set to 0 for infinite loop, which can help connecting gdb
117# define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
118# else
119# define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
120# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000121#endif
122
123///////////////////////////////////////////////////////////////////////////////
124
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000125/**
126 * SK_ENABLE_INST_COUNT controlls printing how many reference counted objects
127 * are still held on exit.
128 * Defaults to 1 in DEBUG and 0 in RELEASE.
robertphillips@google.com38869512013-12-12 14:24:20 +0000129 * FIXME: currently always 0, since it fails if multiple threads run at once
130 * (see skbug.com/1219 ).
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000131 */
bsalomon@google.com4e230682013-01-15 20:37:04 +0000132#ifndef SK_ENABLE_INST_COUNT
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000133# ifdef SK_DEBUG
robertphillips@google.com38869512013-12-12 14:24:20 +0000134# define SK_ENABLE_INST_COUNT 0
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000135# else
136# define SK_ENABLE_INST_COUNT 0
137# endif
bsalomon@google.com4e230682013-01-15 20:37:04 +0000138#endif
139
140///////////////////////////////////////////////////////////////////////////////
141
reed@android.com8a1c16f2008-12-17 15:59:43 +0000142#ifdef SK_BUILD_FOR_WIN
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000143# ifndef WIN32_LEAN_AND_MEAN
144# define WIN32_LEAN_AND_MEAN
145# define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
146# endif
147# ifndef NOMINMAX
148# define NOMINMAX
149# define NOMINMAX_WAS_LOCALLY_DEFINED
150# endif
151#
152# include <windows.h>
153#
154# ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
155# undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
156# undef WIN32_LEAN_AND_MEAN
157# endif
158# ifdef NOMINMAX_WAS_LOCALLY_DEFINED
159# undef NOMINMAX_WAS_LOCALLY_DEFINED
160# undef NOMINMAX
161# endif
162#
163# ifndef SK_DEBUGBREAK
164# define SK_DEBUGBREAK(p) do { if (!(p)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
165# endif
166#
167# ifndef SK_A32_SHIFT
168# define SK_A32_SHIFT 24
169# define SK_R32_SHIFT 16
170# define SK_G32_SHIFT 8
171# define SK_B32_SHIFT 0
172# endif
173#
reed@android.com8a1c16f2008-12-17 15:59:43 +0000174#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000175# ifdef SK_DEBUG
176# include <stdio.h>
177# ifndef SK_DEBUGBREAK
178# define SK_DEBUGBREAK(cond) do { if (cond) break; \
reed@android.com8a1c16f2008-12-17 15:59:43 +0000179 SkDebugf("%s:%d: failed assertion \"%s\"\n", \
180 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000181# endif
182# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000183#endif
184
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000185/**
bsalomon@google.com27661182011-05-19 15:57:44 +0000186 * We check to see if the SHIFT value has already been defined.
187 * if not, we define it ourself to some default values. We default to OpenGL
188 * order (in memory: r,g,b,a)
189 */
190#ifndef SK_A32_SHIFT
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000191# ifdef SK_CPU_BENDIAN
192# define SK_R32_SHIFT 24
193# define SK_G32_SHIFT 16
194# define SK_B32_SHIFT 8
195# define SK_A32_SHIFT 0
196# else
197# define SK_R32_SHIFT 0
198# define SK_G32_SHIFT 8
199# define SK_B32_SHIFT 16
200# define SK_A32_SHIFT 24
201# endif
bsalomon@google.com27661182011-05-19 15:57:44 +0000202#endif
203
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000204/**
djsollen@google.com2b343cc2013-08-20 20:28:03 +0000205 * SkColor has well defined shift values, but SkPMColor is configurable. This
206 * macro is a convenience that returns true if the shift values are equal while
207 * ignoring the machine's endianness.
208 */
209#define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \
210 (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0)
211
212/**
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000213 * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The
214 * relationship between the byte order and shift values depends on machine endianness. If the shift
215 * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little
216 * endian machine and the A channel on a big endian machine. Thus, given those shifts values,
217 * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and
218 * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine.
219 */
220#ifdef SK_CPU_BENDIAN
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000221# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000222 (SK_ ## C3 ## 32_SHIFT == 0 && \
223 SK_ ## C2 ## 32_SHIFT == 8 && \
224 SK_ ## C1 ## 32_SHIFT == 16 && \
225 SK_ ## C0 ## 32_SHIFT == 24)
226#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000227# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000228 (SK_ ## C0 ## 32_SHIFT == 0 && \
229 SK_ ## C1 ## 32_SHIFT == 8 && \
230 SK_ ## C2 ## 32_SHIFT == 16 && \
231 SK_ ## C3 ## 32_SHIFT == 24)
232#endif
233
reed@android.com5c80ea12009-01-08 17:49:50 +0000234//////////////////////////////////////////////////////////////////////
235
robertphillips@google.com0e6e8cc2013-08-15 13:43:23 +0000236#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000237# ifndef SkLONGLONG
238# ifdef SK_BUILD_FOR_WIN32
239# define SkLONGLONG __int64
240# else
241# define SkLONGLONG long long
242# endif
243# endif
robertphillips@google.com0e6e8cc2013-08-15 13:43:23 +0000244#endif
245
246//////////////////////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000247#ifndef SK_BUILD_FOR_WINCE
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000248# include <string.h>
249# include <stdlib.h>
reed@android.com8a1c16f2008-12-17 15:59:43 +0000250#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000251# define _CMNINTRIN_DECLARE_ONLY
252# include "cmnintrin.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000253#endif
254
255#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000256# ifdef free
257# undef free
258# endif
259# include <crtdbg.h>
260# undef free
261#
262# ifdef SK_DEBUGx
263# if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
264 void * operator new(
265 size_t cb,
266 int nBlockUse,
267 const char * szFileName,
268 int nLine,
269 int foo
270 );
271 void * operator new[](
272 size_t cb,
273 int nBlockUse,
274 const char * szFileName,
275 int nLine,
276 int foo
277 );
278 void operator delete(
279 void *pUserData,
280 int, const char*, int, int
281 );
282 void operator delete(
283 void *pUserData
284 );
285 void operator delete[]( void * p );
286# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
287# else
288# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
289# endif
290# define new DEBUG_CLIENTBLOCK
291# else
292# define DEBUG_CLIENTBLOCK
293# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000294#endif
295
tomhudson@google.com13413042011-10-03 16:01:10 +0000296//////////////////////////////////////////////////////////////////////
297
298#ifndef SK_OVERRIDE
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000299# if defined(_MSC_VER)
300# define SK_OVERRIDE override
301# elif defined(__clang__)
302 // Using __attribute__((override)) on clang does not appear to always work.
303 // Clang defaults to C++03 and warns about using override. Squelch that. Intentionally no
304 // push/pop here so all users of SK_OVERRIDE ignore the warning too. This is like passing
305 // -Wno-c++11-extensions, except that GCC won't die (because it won't see this pragma).
306# pragma clang diagnostic ignored "-Wc++11-extensions"
307#
308# if __has_feature(cxx_override_control)
309# define SK_OVERRIDE override
310# elif defined(__has_extension) && __has_extension(cxx_override_control)
311# define SK_OVERRIDE override
312# endif
313# endif
314# ifndef SK_OVERRIDE
315# define SK_OVERRIDE
316# endif
tomhudson@google.com13413042011-10-03 16:01:10 +0000317#endif
318
caryclark@google.comd26147a2011-12-15 14:16:43 +0000319//////////////////////////////////////////////////////////////////////
320
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000321#if !defined(SK_UNUSED)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000322# define SK_UNUSED SK_ATTRIBUTE(unused)
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000323#endif
324
reed@google.com44699382013-10-31 17:28:30 +0000325#if !defined(SK_ATTR_DEPRECATED)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000326 // FIXME: we ignore msg for now...
327# define SK_ATTR_DEPRECATED(msg) SK_ATTRIBUTE(deprecated)
reed@google.com44699382013-10-31 17:28:30 +0000328#endif
329
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000330/**
331 * If your judgment is better than the compiler's (i.e. you've profiled it),
332 * you can use SK_ALWAYS_INLINE to force inlining. E.g.
333 * inline void someMethod() { ... } // may not be inlined
334 * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined
335 */
mtklein@google.com1950d5f2013-11-22 16:56:22 +0000336#if !defined(SK_ALWAYS_INLINE)
337# if defined(SK_BUILD_FOR_WIN)
338# define SK_ALWAYS_INLINE __forceinline
339# else
340# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
341# endif
342#endif
343
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000344//////////////////////////////////////////////////////////////////////
345
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000346#if defined(__clang__) || defined(__GNUC__)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000347# define SK_PREFETCH(ptr) __builtin_prefetch(ptr)
348# define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1)
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000349#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000350# define SK_PREFETCH(ptr)
351# define SK_WRITE_PREFETCH(ptr)
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000352#endif
353
354//////////////////////////////////////////////////////////////////////
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000355
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000356#ifndef SK_PRINTF_LIKE
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000357# if defined(__clang__) || defined(__GNUC__)
358# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
359# else
360# define SK_PRINTF_LIKE(A, B)
361# endif
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000362#endif
363
364//////////////////////////////////////////////////////////////////////
365
366#ifndef SK_SIZE_T_SPECIFIER
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000367# if defined(_MSC_VER)
368# define SK_SIZE_T_SPECIFIER "%Iu"
369# else
370# define SK_SIZE_T_SPECIFIER "%zu"
371# endif
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000372#endif
373
374//////////////////////////////////////////////////////////////////////
375
caryclark@google.comd26147a2011-12-15 14:16:43 +0000376#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000377# define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
caryclark@google.comd26147a2011-12-15 14:16:43 +0000378#endif
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000379
380#endif // SkPostConfig_DEFINED