blob: 0d904ea51c2de76422fb81d2a5d6a2992d62ffbd [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
bungeman@google.com7fd1f502013-12-04 16:40:42 +000025/**
26 * Matrix calculations may be float or double.
27 * The default is double, as that is faster given our impl uses doubles
28 * for intermediate calculations.
29 */
vollick@chromium.org5596a692012-11-13 20:12:00 +000030#if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000031# error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT"
vollick@chromium.org5596a692012-11-13 20:12:00 +000032#elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000033# define SK_MSCALAR_IS_DOUBLE
vollick@chromium.org5596a692012-11-13 20:12:00 +000034#endif
35
reed@android.com8a1c16f2008-12-17 15:59:43 +000036#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000037# error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
reed@android.com8a1c16f2008-12-17 15:59:43 +000038#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000039# error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
reed@android.com8a1c16f2008-12-17 15:59:43 +000040#endif
41
bungeman@google.com7fd1f502013-12-04 16:40:42 +000042/**
43 * Ensure the port has defined all of SK_X32_SHIFT, or none of them.
44 */
reed@android.com8a1c16f2008-12-17 15:59:43 +000045#ifdef SK_A32_SHIFT
bungeman@google.com7fd1f502013-12-04 16:40:42 +000046# if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
47# error "all or none of the 32bit SHIFT amounts must be defined"
48# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000049#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +000050# if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
51# error "all or none of the 32bit SHIFT amounts must be defined"
52# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000053#endif
54
bsalomon@google.com04423802011-11-23 21:25:35 +000055#if !defined(SK_HAS_COMPILER_FEATURE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000056# if defined(__has_feature)
57# define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
58# else
59# define SK_HAS_COMPILER_FEATURE(x) 0
60# endif
bsalomon@google.com04423802011-11-23 21:25:35 +000061#endif
62
bungeman@google.com5ebbbe52013-08-06 18:32:29 +000063#if !defined(SK_ATTRIBUTE)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000064# if defined(__clang__) || defined(__GNUC__)
65# define SK_ATTRIBUTE(attr) __attribute__((attr))
66# else
67# define SK_ATTRIBUTE(attr)
68# endif
bungeman@google.com5ebbbe52013-08-06 18:32:29 +000069#endif
70
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000071#if !defined(SK_SUPPORT_GPU)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000072# define SK_SUPPORT_GPU 1
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000073#endif
74
bsalomon@google.com04423802011-11-23 21:25:35 +000075/**
76 * The clang static analyzer likes to know that when the program is not
77 * expected to continue (crash, assertion failure, etc). It will notice that
78 * some combination of parameters lead to a function call that does not return.
79 * It can then make appropriate assumptions about the parameters in code
80 * executed only if the non-returning function was *not* called.
81 */
82#if !defined(SkNO_RETURN_HINT)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000083# if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
84 static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
85 static inline void SkNO_RETURN_HINT() {}
86# else
87# define SkNO_RETURN_HINT() do {} while (false)
88# endif
bsalomon@google.com04423802011-11-23 21:25:35 +000089#endif
90
justinlin@google.comfffb2f12012-04-16 19:10:21 +000091#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000092# error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB"
justinlin@google.comfffb2f12012-04-16 19:10:21 +000093#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB)
bungeman@google.com7fd1f502013-12-04 16:40:42 +000094# define SK_HAS_ZLIB
justinlin@google.comfffb2f12012-04-16 19:10:21 +000095#endif
96
reed@android.com8a1c16f2008-12-17 15:59:43 +000097///////////////////////////////////////////////////////////////////////////////
98
99#ifndef SkNEW
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000100# define SkNEW(type_name) (new type_name)
101# define SkNEW_ARGS(type_name, args) (new type_name args)
102# define SkNEW_ARRAY(type_name, count) (new type_name[(count)])
103# define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name)
104# define SkNEW_PLACEMENT_ARGS(buf, type_name, args) (new (buf) type_name args)
105# define SkDELETE(obj) (delete (obj))
106# define SkDELETE_ARRAY(array) (delete[] (array))
reed@android.com8a1c16f2008-12-17 15:59:43 +0000107#endif
108
109#ifndef SK_CRASH
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000110# 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
reed@android.com8a1c16f2008-12-17 15:59:43 +0000115#endif
116
117///////////////////////////////////////////////////////////////////////////////
118
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000119/**
120 * SK_ENABLE_INST_COUNT controlls printing how many reference counted objects
121 * are still held on exit.
122 * Defaults to 1 in DEBUG and 0 in RELEASE.
robertphillips@google.com38869512013-12-12 14:24:20 +0000123 * FIXME: currently always 0, since it fails if multiple threads run at once
124 * (see skbug.com/1219 ).
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000125 */
bsalomon@google.com4e230682013-01-15 20:37:04 +0000126#ifndef SK_ENABLE_INST_COUNT
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000127# ifdef SK_DEBUG
robertphillips@google.com38869512013-12-12 14:24:20 +0000128# define SK_ENABLE_INST_COUNT 0
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000129# else
130# define SK_ENABLE_INST_COUNT 0
131# endif
bsalomon@google.com4e230682013-01-15 20:37:04 +0000132#endif
133
134///////////////////////////////////////////////////////////////////////////////
135
reed@android.com8a1c16f2008-12-17 15:59:43 +0000136#ifdef SK_BUILD_FOR_WIN
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000137# ifndef WIN32_LEAN_AND_MEAN
138# define WIN32_LEAN_AND_MEAN
139# define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
140# endif
141# ifndef NOMINMAX
142# define NOMINMAX
143# define NOMINMAX_WAS_LOCALLY_DEFINED
144# endif
145#
146# include <windows.h>
147#
148# ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
149# undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
150# undef WIN32_LEAN_AND_MEAN
151# endif
152# ifdef NOMINMAX_WAS_LOCALLY_DEFINED
153# undef NOMINMAX_WAS_LOCALLY_DEFINED
154# undef NOMINMAX
155# endif
156#
157# ifndef SK_DEBUGBREAK
158# define SK_DEBUGBREAK(p) do { if (!(p)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
159# endif
160#
161# ifndef SK_A32_SHIFT
162# define SK_A32_SHIFT 24
163# define SK_R32_SHIFT 16
164# define SK_G32_SHIFT 8
165# define SK_B32_SHIFT 0
166# endif
167#
reed@android.com8a1c16f2008-12-17 15:59:43 +0000168#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000169# ifdef SK_DEBUG
170# include <stdio.h>
171# ifndef SK_DEBUGBREAK
172# define SK_DEBUGBREAK(cond) do { if (cond) break; \
reed@android.com8a1c16f2008-12-17 15:59:43 +0000173 SkDebugf("%s:%d: failed assertion \"%s\"\n", \
174 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000175# endif
176# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000177#endif
178
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000179/**
bsalomon@google.com27661182011-05-19 15:57:44 +0000180 * We check to see if the SHIFT value has already been defined.
181 * if not, we define it ourself to some default values. We default to OpenGL
182 * order (in memory: r,g,b,a)
183 */
184#ifndef SK_A32_SHIFT
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000185# ifdef SK_CPU_BENDIAN
186# define SK_R32_SHIFT 24
187# define SK_G32_SHIFT 16
188# define SK_B32_SHIFT 8
189# define SK_A32_SHIFT 0
190# else
191# define SK_R32_SHIFT 0
192# define SK_G32_SHIFT 8
193# define SK_B32_SHIFT 16
194# define SK_A32_SHIFT 24
195# endif
bsalomon@google.com27661182011-05-19 15:57:44 +0000196#endif
197
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000198/**
djsollen@google.com2b343cc2013-08-20 20:28:03 +0000199 * SkColor has well defined shift values, but SkPMColor is configurable. This
200 * macro is a convenience that returns true if the shift values are equal while
201 * ignoring the machine's endianness.
202 */
203#define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \
204 (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0)
205
206/**
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000207 * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The
208 * relationship between the byte order and shift values depends on machine endianness. If the shift
209 * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little
210 * endian machine and the A channel on a big endian machine. Thus, given those shifts values,
211 * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and
212 * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine.
213 */
214#ifdef SK_CPU_BENDIAN
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000215# define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000216 (SK_ ## C3 ## 32_SHIFT == 0 && \
217 SK_ ## C2 ## 32_SHIFT == 8 && \
218 SK_ ## C1 ## 32_SHIFT == 16 && \
219 SK_ ## C0 ## 32_SHIFT == 24)
220#else
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_ ## C0 ## 32_SHIFT == 0 && \
223 SK_ ## C1 ## 32_SHIFT == 8 && \
224 SK_ ## C2 ## 32_SHIFT == 16 && \
225 SK_ ## C3 ## 32_SHIFT == 24)
226#endif
227
reed@android.com5c80ea12009-01-08 17:49:50 +0000228//////////////////////////////////////////////////////////////////////
229
robertphillips@google.com0e6e8cc2013-08-15 13:43:23 +0000230#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000231# ifndef SkLONGLONG
232# ifdef SK_BUILD_FOR_WIN32
233# define SkLONGLONG __int64
234# else
235# define SkLONGLONG long long
236# endif
237# endif
robertphillips@google.com0e6e8cc2013-08-15 13:43:23 +0000238#endif
239
240//////////////////////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000241#ifndef SK_BUILD_FOR_WINCE
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000242# include <string.h>
243# include <stdlib.h>
reed@android.com8a1c16f2008-12-17 15:59:43 +0000244#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000245# define _CMNINTRIN_DECLARE_ONLY
246# include "cmnintrin.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000247#endif
248
249#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000250# ifdef free
251# undef free
252# endif
253# include <crtdbg.h>
254# undef free
255#
256# ifdef SK_DEBUGx
257# if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
258 void * operator new(
259 size_t cb,
260 int nBlockUse,
261 const char * szFileName,
262 int nLine,
263 int foo
264 );
265 void * operator new[](
266 size_t cb,
267 int nBlockUse,
268 const char * szFileName,
269 int nLine,
270 int foo
271 );
272 void operator delete(
273 void *pUserData,
274 int, const char*, int, int
275 );
276 void operator delete(
277 void *pUserData
278 );
279 void operator delete[]( void * p );
280# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
281# else
282# define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
283# endif
284# define new DEBUG_CLIENTBLOCK
285# else
286# define DEBUG_CLIENTBLOCK
287# endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000288#endif
289
tomhudson@google.com13413042011-10-03 16:01:10 +0000290//////////////////////////////////////////////////////////////////////
291
292#ifndef SK_OVERRIDE
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000293# if defined(_MSC_VER)
294# define SK_OVERRIDE override
295# elif defined(__clang__)
296 // Using __attribute__((override)) on clang does not appear to always work.
297 // Clang defaults to C++03 and warns about using override. Squelch that. Intentionally no
298 // push/pop here so all users of SK_OVERRIDE ignore the warning too. This is like passing
299 // -Wno-c++11-extensions, except that GCC won't die (because it won't see this pragma).
300# pragma clang diagnostic ignored "-Wc++11-extensions"
301#
302# if __has_feature(cxx_override_control)
303# define SK_OVERRIDE override
304# elif defined(__has_extension) && __has_extension(cxx_override_control)
305# define SK_OVERRIDE override
306# endif
307# endif
308# ifndef SK_OVERRIDE
309# define SK_OVERRIDE
310# endif
tomhudson@google.com13413042011-10-03 16:01:10 +0000311#endif
312
caryclark@google.comd26147a2011-12-15 14:16:43 +0000313//////////////////////////////////////////////////////////////////////
314
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000315#if !defined(SK_UNUSED)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000316# define SK_UNUSED SK_ATTRIBUTE(unused)
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000317#endif
318
reed@google.com44699382013-10-31 17:28:30 +0000319#if !defined(SK_ATTR_DEPRECATED)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000320 // FIXME: we ignore msg for now...
321# define SK_ATTR_DEPRECATED(msg) SK_ATTRIBUTE(deprecated)
reed@google.com44699382013-10-31 17:28:30 +0000322#endif
323
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000324/**
325 * If your judgment is better than the compiler's (i.e. you've profiled it),
326 * you can use SK_ALWAYS_INLINE to force inlining. E.g.
327 * inline void someMethod() { ... } // may not be inlined
328 * SK_ALWAYS_INLINE void someMethod() { ... } // should always be inlined
329 */
mtklein@google.com1950d5f2013-11-22 16:56:22 +0000330#if !defined(SK_ALWAYS_INLINE)
331# if defined(SK_BUILD_FOR_WIN)
332# define SK_ALWAYS_INLINE __forceinline
333# else
334# define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
335# endif
336#endif
337
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000338//////////////////////////////////////////////////////////////////////
339
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000340#if defined(__clang__) || defined(__GNUC__)
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000341# define SK_PREFETCH(ptr) __builtin_prefetch(ptr)
342# define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1)
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000343#else
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000344# define SK_PREFETCH(ptr)
345# define SK_WRITE_PREFETCH(ptr)
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000346#endif
347
348//////////////////////////////////////////////////////////////////////
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000349
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000350#ifndef SK_PRINTF_LIKE
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000351# if defined(__clang__) || defined(__GNUC__)
352# define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
353# else
354# define SK_PRINTF_LIKE(A, B)
355# endif
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000356#endif
357
358//////////////////////////////////////////////////////////////////////
359
360#ifndef SK_SIZE_T_SPECIFIER
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000361# if defined(_MSC_VER)
362# define SK_SIZE_T_SPECIFIER "%Iu"
363# else
364# define SK_SIZE_T_SPECIFIER "%zu"
365# endif
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000366#endif
367
368//////////////////////////////////////////////////////////////////////
369
caryclark@google.comd26147a2011-12-15 14:16:43 +0000370#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000371# define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
caryclark@google.comd26147a2011-12-15 14:16:43 +0000372#endif
bungeman@google.com7fd1f502013-12-04 16:40:42 +0000373
374#endif // SkPostConfig_DEFINED