blob: 63637e5c503df5f16f9aa1a3329c0f1bae077a3b [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 SkPostConfig_DEFINED
11#define SkPostConfig_DEFINED
12
13#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
14 #define SK_BUILD_FOR_WIN
15#endif
16
17#if defined(SK_DEBUG) && defined(SK_RELEASE)
18 #error "cannot define both SK_DEBUG and SK_RELEASE"
19#elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
20 #error "must define either SK_DEBUG or SK_RELEASE"
21#endif
22
23#if defined SK_SUPPORT_UNITTEST && !defined(SK_DEBUG)
24 #error "can't have unittests without debug"
25#endif
26
27#if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT)
28 #error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT"
29#elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT)
reed@google.com7886ad32012-06-11 21:21:26 +000030 #define SK_SCALAR_IS_FLOAT
reed@android.com8a1c16f2008-12-17 15:59:43 +000031#endif
32
vollick@chromium.org5596a692012-11-13 20:12:00 +000033#if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT)
34 #error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT"
35#elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT)
reed@google.com7d683352012-12-03 21:19:52 +000036 // default is double, as that is faster given our impl uses doubles
37 // for intermediate calculations.
38 #define SK_MSCALAR_IS_DOUBLE
vollick@chromium.org5596a692012-11-13 20:12:00 +000039#endif
40
reed@android.com8a1c16f2008-12-17 15:59:43 +000041#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
42 #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
43#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
44 #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
45#endif
46
47// ensure the port has defined all of these, or none of them
48#ifdef SK_A32_SHIFT
49 #if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
50 #error "all or none of the 32bit SHIFT amounts must be defined"
51 #endif
52#else
53 #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
54 #error "all or none of the 32bit SHIFT amounts must be defined"
55 #endif
56#endif
57
bsalomon@google.com04423802011-11-23 21:25:35 +000058#if !defined(SK_HAS_COMPILER_FEATURE)
59 #if defined(__has_feature)
60 #define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
61 #else
62 #define SK_HAS_COMPILER_FEATURE(x) 0
63 #endif
64#endif
65
bungeman@google.com5ebbbe52013-08-06 18:32:29 +000066#if !defined(SK_ATTRIBUTE)
67 #if defined(__clang__) || defined(__GNUC__)
68 #define SK_ATTRIBUTE(attr) __attribute__((attr))
69 #else
70 #define SK_ATTRIBUTE(attr)
71 #endif
72#endif
73
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000074#if !defined(SK_SUPPORT_GPU)
75 #define SK_SUPPORT_GPU 1
76#endif
77
bsalomon@google.com04423802011-11-23 21:25:35 +000078/**
79 * The clang static analyzer likes to know that when the program is not
80 * expected to continue (crash, assertion failure, etc). It will notice that
81 * some combination of parameters lead to a function call that does not return.
82 * It can then make appropriate assumptions about the parameters in code
83 * executed only if the non-returning function was *not* called.
84 */
85#if !defined(SkNO_RETURN_HINT)
86 #if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
bsalomon@google.com672d5c22013-01-02 20:33:18 +000087 static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
88 static inline void SkNO_RETURN_HINT() {}
bsalomon@google.com04423802011-11-23 21:25:35 +000089 #else
90 #define SkNO_RETURN_HINT() do {} while (false)
91 #endif
92#endif
93
justinlin@google.comfffb2f12012-04-16 19:10:21 +000094#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB)
95 #error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB"
96#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB)
97 #define SK_HAS_ZLIB
98#endif
99
reed@android.com8a1c16f2008-12-17 15:59:43 +0000100///////////////////////////////////////////////////////////////////////////////
101
102#ifndef SkNEW
bsalomon@google.com0ac6af42013-01-16 15:16:18 +0000103 #define SkNEW(type_name) (new type_name)
104 #define SkNEW_ARGS(type_name, args) (new type_name args)
105 #define SkNEW_ARRAY(type_name, count) (new type_name[(count)])
106 #define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name)
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000107 #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \
bsalomon@google.com0ac6af42013-01-16 15:16:18 +0000108 (new (buf) type_name args)
109 #define SkDELETE(obj) (delete (obj))
110 #define SkDELETE_ARRAY(array) (delete[] (array))
reed@android.com8a1c16f2008-12-17 15:59:43 +0000111#endif
112
113#ifndef SK_CRASH
114#if 1 // set to 0 for infinite loop, which can help connecting gdb
bsalomon@google.comb1277c92011-11-23 21:58:39 +0000115 #define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000116#else
bsalomon@google.comb1277c92011-11-23 21:58:39 +0000117 #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000118#endif
119#endif
120
121///////////////////////////////////////////////////////////////////////////////
122
bsalomon@google.com4e230682013-01-15 20:37:04 +0000123// SK_ENABLE_INST_COUNT defaults to 1 in DEBUG and 0 in RELEASE
124#ifndef SK_ENABLE_INST_COUNT
125 #ifdef SK_DEBUG
caryclark@google.com7abfa492013-04-12 11:59:41 +0000126 // FIXME: fails if multiple threads run at once (see skbug.com/1219 )
127 #define SK_ENABLE_INST_COUNT 0
bsalomon@google.com4e230682013-01-15 20:37:04 +0000128 #else
129 #define SK_ENABLE_INST_COUNT 0
130 #endif
131#endif
132
133///////////////////////////////////////////////////////////////////////////////
134
reed@android.com8a1c16f2008-12-17 15:59:43 +0000135#if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT)
136 // if this is defined, we convert floats to 2scompliment ints for compares
137 #ifndef SK_SCALAR_SLOW_COMPARES
138 #define SK_SCALAR_SLOW_COMPARES
139 #endif
reed@android.com5c80ea12009-01-08 17:49:50 +0000140 #ifndef SK_USE_FLOATBITS
141 #define SK_USE_FLOATBITS
142 #endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000143#endif
144
145#ifdef SK_BUILD_FOR_WIN
reed@android.com16690af2009-04-06 16:09:53 +0000146 // we want lean_and_mean when we include windows.h
147 #ifndef WIN32_LEAN_AND_MEAN
148 #define WIN32_LEAN_AND_MEAN
149 #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
150 #endif
bsalomon@google.comf3f2d162013-07-31 18:52:31 +0000151 #ifndef NOMINMAX
152 #define NOMINMAX
153 #define NOMINMAX_WAS_LOCALLY_DEFINED
154 #endif
reed@android.com16690af2009-04-06 16:09:53 +0000155
reed@android.com8a1c16f2008-12-17 15:59:43 +0000156 #include <windows.h>
reed@android.com16690af2009-04-06 16:09:53 +0000157
158 #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
bsalomon@google.comf3f2d162013-07-31 18:52:31 +0000159 #undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
reed@android.com16690af2009-04-06 16:09:53 +0000160 #undef WIN32_LEAN_AND_MEAN
161 #endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000162
bsalomon@google.comf3f2d162013-07-31 18:52:31 +0000163 #ifdef NOMINMAX_WAS_LOCALLY_DEFINED
164 #undef NOMINMAX_WAS_LOCALLY_DEFINED
165 #undef NOMINMAX
166 #endif
167
reed@android.com8a1c16f2008-12-17 15:59:43 +0000168 #ifndef SK_DEBUGBREAK
bsalomon@google.com04423802011-11-23 21:25:35 +0000169 #define SK_DEBUGBREAK(cond) do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
reed@android.com8a1c16f2008-12-17 15:59:43 +0000170 #endif
reed@android.comf2b98d62010-12-20 18:26:13 +0000171
172 #ifndef SK_A32_SHIFT
173 #define SK_A32_SHIFT 24
174 #define SK_R32_SHIFT 16
175 #define SK_G32_SHIFT 8
176 #define SK_B32_SHIFT 0
177 #endif
178
reed@android.com8a1c16f2008-12-17 15:59:43 +0000179#else
180 #ifdef SK_DEBUG
181 #include <stdio.h>
182 #ifndef SK_DEBUGBREAK
183 #define SK_DEBUGBREAK(cond) do { if (cond) break; \
184 SkDebugf("%s:%d: failed assertion \"%s\"\n", \
185 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
186 #endif
187 #endif
188#endif
189
bsalomon@google.com27661182011-05-19 15:57:44 +0000190/*
191 * We check to see if the SHIFT value has already been defined.
192 * if not, we define it ourself to some default values. We default to OpenGL
193 * order (in memory: r,g,b,a)
194 */
195#ifndef SK_A32_SHIFT
196 #ifdef SK_CPU_BENDIAN
197 #define SK_R32_SHIFT 24
198 #define SK_G32_SHIFT 16
199 #define SK_B32_SHIFT 8
200 #define SK_A32_SHIFT 0
201 #else
202 #define SK_R32_SHIFT 0
203 #define SK_G32_SHIFT 8
204 #define SK_B32_SHIFT 16
205 #define SK_A32_SHIFT 24
206 #endif
207#endif
208
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000209/**
djsollen@google.com2b343cc2013-08-20 20:28:03 +0000210 * SkColor has well defined shift values, but SkPMColor is configurable. This
211 * macro is a convenience that returns true if the shift values are equal while
212 * ignoring the machine's endianness.
213 */
214#define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \
215 (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0)
216
217/**
commit-bot@chromium.orge4657ed2013-03-19 14:16:31 +0000218 * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The
219 * relationship between the byte order and shift values depends on machine endianness. If the shift
220 * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little
221 * endian machine and the A channel on a big endian machine. Thus, given those shifts values,
222 * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and
223 * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine.
224 */
225#ifdef SK_CPU_BENDIAN
226 #define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
227 (SK_ ## C3 ## 32_SHIFT == 0 && \
228 SK_ ## C2 ## 32_SHIFT == 8 && \
229 SK_ ## C1 ## 32_SHIFT == 16 && \
230 SK_ ## C0 ## 32_SHIFT == 24)
231#else
232 #define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
233 (SK_ ## C0 ## 32_SHIFT == 0 && \
234 SK_ ## C1 ## 32_SHIFT == 8 && \
235 SK_ ## C2 ## 32_SHIFT == 16 && \
236 SK_ ## C3 ## 32_SHIFT == 24)
237#endif
238
reed@android.com8a1c16f2008-12-17 15:59:43 +0000239// stdlib macros
240
241#if 0
242#if !defined(strlen) && defined(SK_DEBUG)
243 extern size_t sk_strlen(const char*);
244 #define strlen(s) sk_strlen(s)
245#endif
246#ifndef sk_strcpy
247 #define sk_strcpy(dst, src) strcpy(dst, src)
248#endif
249#ifndef sk_strchr
250 #define sk_strchr(s, c) strchr(s, c)
251#endif
252#ifndef sk_strrchr
253 #define sk_strrchr(s, c) strrchr(s, c)
254#endif
255#ifndef sk_strcmp
256 #define sk_strcmp(s, t) strcmp(s, t)
257#endif
258#ifndef sk_strncmp
259 #define sk_strncmp(s, t, n) strncmp(s, t, n)
260#endif
261#ifndef sk_memcpy
262 #define sk_memcpy(dst, src, n) memcpy(dst, src, n)
263#endif
264#ifndef memmove
265 #define memmove(dst, src, n) memmove(dst, src, n)
266#endif
267#ifndef sk_memset
268 #define sk_memset(dst, val, n) memset(dst, val, n)
269#endif
270#ifndef sk_memcmp
271 #define sk_memcmp(s, t, n) memcmp(s, t, n)
272#endif
273
274#define sk_strequal(s, t) (!sk_strcmp(s, t))
275#define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n))
276#endif
277
reed@android.com5c80ea12009-01-08 17:49:50 +0000278//////////////////////////////////////////////////////////////////////
279
robertphillips@google.com0e6e8cc2013-08-15 13:43:23 +0000280#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
281 #ifndef SkLONGLONG
282 #ifdef SK_BUILD_FOR_WIN32
283 #define SkLONGLONG __int64
284 #else
285 #define SkLONGLONG long long
286 #endif
287 #endif
288#endif
289
290//////////////////////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000291#ifndef SK_BUILD_FOR_WINCE
292#include <string.h>
293#include <stdlib.h>
294#else
295#define _CMNINTRIN_DECLARE_ONLY
296#include "cmnintrin.h"
297#endif
298
299#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
300//#define _CRTDBG_MAP_ALLOC
301#ifdef free
302#undef free
303#endif
304#include <crtdbg.h>
305#undef free
306
307#ifdef SK_DEBUGx
308#if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
309 void * operator new(
310 size_t cb,
311 int nBlockUse,
312 const char * szFileName,
313 int nLine,
314 int foo
315 );
316 void * operator new[](
317 size_t cb,
318 int nBlockUse,
319 const char * szFileName,
320 int nLine,
321 int foo
322 );
323 void operator delete(
324 void *pUserData,
325 int, const char*, int, int
326 );
327 void operator delete(
328 void *pUserData
329 );
330 void operator delete[]( void * p );
331 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
332#else
333 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
334#endif
335 #define new DEBUG_CLIENTBLOCK
336#else
337#define DEBUG_CLIENTBLOCK
338#endif // _DEBUG
339
tomhudson@google.com13413042011-10-03 16:01:10 +0000340
reed@android.com8a1c16f2008-12-17 15:59:43 +0000341#endif
342
343#endif
344
tomhudson@google.com13413042011-10-03 16:01:10 +0000345//////////////////////////////////////////////////////////////////////
346
347#ifndef SK_OVERRIDE
george@mozilla.comece01002012-07-25 19:05:43 +0000348 #if defined(_MSC_VER)
349 #define SK_OVERRIDE override
commit-bot@chromium.orge63c46c2013-07-03 08:39:46 +0000350 #elif defined(__clang__)
commit-bot@chromium.orgaa2c2ff2013-04-22 14:39:06 +0000351 // Clang defaults to C++03 and warns about using override. Squelch that. Intentionally no
352 // push/pop here so all users of SK_OVERRIDE ignore the warning too. This is like passing
353 // -Wno-c++11-extensions, except that GCC won't die (because it won't see this pragma).
354 #pragma clang diagnostic ignored "-Wc++11-extensions"
355
george@mozilla.comece01002012-07-25 19:05:43 +0000356 #if __has_feature(cxx_override_control)
357 // Some documentation suggests we should be using __attribute__((override)),
358 // but it doesn't work.
359 #define SK_OVERRIDE override
360 #elif defined(__has_extension)
361 #if __has_extension(cxx_override_control)
362 #define SK_OVERRIDE override
363 #endif
364 #endif
george@mozilla.com2d952672013-08-06 18:35:00 +0000365 #endif
366 #ifndef SK_OVERRIDE
george@mozilla.comece01002012-07-25 19:05:43 +0000367 #define SK_OVERRIDE
368 #endif
tomhudson@google.com13413042011-10-03 16:01:10 +0000369#endif
370
caryclark@google.comd26147a2011-12-15 14:16:43 +0000371//////////////////////////////////////////////////////////////////////
372
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000373#if !defined(SK_UNUSED)
374 #define SK_UNUSED SK_ATTRIBUTE(unused)
375#endif
376
reed@google.com44699382013-10-31 17:28:30 +0000377#if !defined(SK_ATTR_DEPRECATED)
378 // we ignore msg for now...
robertphillips@google.comd2f79482013-10-31 22:42:33 +0000379 #define SK_ATTR_DEPRECATED(msg) //SK_ATTRIBUTE(deprecated)
reed@google.com44699382013-10-31 17:28:30 +0000380#endif
381
bungeman@google.com5ebbbe52013-08-06 18:32:29 +0000382//////////////////////////////////////////////////////////////////////
383
commit-bot@chromium.orgfedf13d2013-11-05 15:03:26 +0000384#if defined(__clang__) || defined(__GNUC__)
385#define SK_PREFETCH(ptr) __builtin_prefetch(ptr)
386#define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1)
387#else
388#define SK_PREFETCH(ptr)
389#define SK_WRITE_PREFETCH(ptr)
390#endif
391
392//////////////////////////////////////////////////////////////////////
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000393#ifndef SK_PRINTF_LIKE
394#if defined(__clang__) || defined(__GNUC__)
395#define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
396#else
397#define SK_PRINTF_LIKE(A, B)
398#endif
399#endif
400
401//////////////////////////////////////////////////////////////////////
402
403#ifndef SK_SIZE_T_SPECIFIER
404#if defined(_MSC_VER)
405#define SK_SIZE_T_SPECIFIER "%Iu"
406#else
407#define SK_SIZE_T_SPECIFIER "%zu"
408#endif
409#endif
410
411//////////////////////////////////////////////////////////////////////
412
caryclark@google.comd26147a2011-12-15 14:16:43 +0000413#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
414#define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
415#endif