blob: e3fa1a44e908752ab51dadb4234c0197ced6256b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@google.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
reed@google.comac10a2d2010-12-22 21:39:39 +000011#ifndef GrConfig_DEFINED
12#define GrConfig_DEFINED
13
robertphillips@google.com59552022012-08-31 13:07:37 +000014#include "SkTypes.h"
15
reed@google.comac10a2d2010-12-22 21:39:39 +000016///////////////////////////////////////////////////////////////////////////////
17// preconfig section:
18//
19// All the work before including GrUserConfig.h should center around guessing
20// what platform we're on, and defining low-level symbols based on that.
21//
22// A build environment may have already defined symbols, so we first check
23// for that
24//
25
26// hack to ensure we know what sort of Apple platform we're on
27#if defined(__APPLE_CPP__) || defined(__APPLE_CC__)
28 #include <TargetConditionals.h>
29#endif
30
31/**
32 * Gr defines are set to 0 or 1, rather than being undefined or defined
33 */
34
35#if !defined(GR_ANDROID_BUILD)
36 #define GR_ANDROID_BUILD 0
37#endif
38#if !defined(GR_IOS_BUILD)
39 #define GR_IOS_BUILD 0
40#endif
41#if !defined(GR_LINUX_BUILD)
42 #define GR_LINUX_BUILD 0
43#endif
44#if !defined(GR_MAC_BUILD)
45 #define GR_MAC_BUILD 0
46#endif
47#if !defined(GR_WIN32_BUILD)
48 #define GR_WIN32_BUILD 0
49#endif
50#if !defined(GR_QNX_BUILD)
51 #define GR_QNX_BUILD 0
52#endif
robertphillips@google.com59552022012-08-31 13:07:37 +000053#if !defined(GR_CACHE_STATS)
54 #define GR_CACHE_STATS 0
55#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000056
57/**
58 * If no build target has been defined, attempt to infer.
59 */
60#if !GR_ANDROID_BUILD && !GR_IOS_BUILD && !GR_LINUX_BUILD && !GR_MAC_BUILD && !GR_WIN32_BUILD && !GR_QNX_BUILD
61 #if defined(_WIN32)
62 #undef GR_WIN32_BUILD
63 #define GR_WIN32_BUILD 1
64// #error "WIN"
65 #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
66 #undef GR_IOS_BUILD
67 #define GR_IOS_BUILD 1
68// #error "IOS"
djsollen@google.com56c69772011-11-08 19:00:26 +000069 #elif defined(SK_BUILD_FOR_ANDROID)
reed@google.comac10a2d2010-12-22 21:39:39 +000070 #undef GR_ANDROID_BUILD
71 #define GR_ANDROID_BUILD 1
72// #error "ANDROID"
73 #elif TARGET_OS_MAC
74 #undef GR_MAC_BUILD
75 #define GR_MAC_BUILD 1
76// #error "MAC"
77 #elif TARGET_OS_QNX || defined(__QNXNTO__)
78 #undef GR_QNX_BUILD
79 #define GR_QNX_BUILD 1
80// #error "QNX"
81 #else
82 #undef GR_LINUX_BUILD
83 #define GR_LINUX_BUILD 1
84// #error "LINUX"
bsalomon@google.com1c13c962011-02-14 16:51:21 +000085 #endif
reed@google.comac10a2d2010-12-22 21:39:39 +000086#endif
87
reed@google.comac10a2d2010-12-22 21:39:39 +000088///////////////////////////////////////////////////////////////////////////////
89///////////////////////////////////////////////////////////////////////////////
90
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000091#if GR_WIN32_BUILD
92// VC8 doesn't support stdint.h, so we define those types here.
93typedef signed char int8_t;
94typedef unsigned char uint8_t;
95typedef short int16_t;
96typedef unsigned short uint16_t;
97typedef int int32_t;
98typedef unsigned uint32_t;
bsalomon@google.com4be283f2011-04-19 21:15:09 +000099typedef __int64 int64_t;
100typedef unsigned __int64 uint64_t;
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000101#else
reed@google.comac10a2d2010-12-22 21:39:39 +0000102/*
bsalomon@google.com91826102011-03-21 19:51:57 +0000103 * Include stdint.h with defines that trigger declaration of C99 limit/const
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000104 * macros here before anyone else has a chance to include stdint.h without
bsalomon@google.com91826102011-03-21 19:51:57 +0000105 * these.
reed@google.comac10a2d2010-12-22 21:39:39 +0000106 */
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +0000107#ifndef __STDC_LIMIT_MACROS
reed@google.comac10a2d2010-12-22 21:39:39 +0000108#define __STDC_LIMIT_MACROS
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +0000109#endif
110#ifndef __STDC_CONSTANT_MACROS
reed@google.comac10a2d2010-12-22 21:39:39 +0000111#define __STDC_CONSTANT_MACROS
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +0000112#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000113#include <stdint.h>
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000114#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000115
116/*
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000117 * The "user config" file can be empty, and everything should work. It is
reed@google.comac10a2d2010-12-22 21:39:39 +0000118 * meant to store a given platform/client's overrides of our guess-work.
119 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000120 * A alternate user config file can be specified by defining
reed@google.comac10a2d2010-12-22 21:39:39 +0000121 * GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h
122 *
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000123 * e.g. it can change the BUILD target or supply its own defines for anything
124 * else (e.g. GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT)
reed@google.comac10a2d2010-12-22 21:39:39 +0000125 */
126#if !defined(GR_USER_CONFIG_FILE)
127 #include "GrUserConfig.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000128#else
reed@google.comac10a2d2010-12-22 21:39:39 +0000129 #include GR_USER_CONFIG_FILE
130#endif
131
132
133///////////////////////////////////////////////////////////////////////////////
134///////////////////////////////////////////////////////////////////////////////
135// postconfig section:
136//
bsalomon@google.com91826102011-03-21 19:51:57 +0000137
reed@google.comac10a2d2010-12-22 21:39:39 +0000138// By now we must have a GR_..._BUILD symbol set to 1, and a decision about
139// debug -vs- release
140//
141
bungeman@google.comf85abda2012-03-22 17:56:29 +0000142#define GrPrintf SkDebugf
reed@google.comac10a2d2010-12-22 21:39:39 +0000143
144/**
145 * GR_STRING makes a string of X where X is expanded before conversion to a string
146 * if X itself contains macros.
147 */
148#define GR_STRING(X) GR_STRING_IMPL(X)
149#define GR_STRING_IMPL(X) #X
150
151/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000152 * GR_CONCAT concatenates X and Y where each is expanded before
reed@google.comac10a2d2010-12-22 21:39:39 +0000153 * contanenation if either contains macros.
154 */
155#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
156#define GR_CONCAT_IMPL(X,Y) X##Y
157
158/**
159 * Creates a string of the form "<filename>(<linenumber>) : "
160 */
161#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
162
163/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000164 * Compilers have different ways of issuing warnings. This macro
165 * attempts to abstract them, but may need to be specialized for your
reed@google.comac10a2d2010-12-22 21:39:39 +0000166 * particular compiler.
167 * To insert compiler warnings use "#pragma message GR_WARN(<string>)"
168 */
reed@google.comc9218432011-01-25 19:05:12 +0000169#if defined(_MSC_VER) && _MSC_VER
reed@google.comac10a2d2010-12-22 21:39:39 +0000170 #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
171#else//__GNUC__ - may need other defines for different compilers
172 #define GR_WARN(MSG) ("WARNING: " MSG)
173#endif
174
175/**
176 * GR_ALWAYSBREAK is an unconditional break in all builds.
177 */
178#if !defined(GR_ALWAYSBREAK)
179 #if GR_WIN32_BUILD
bsalomon@google.com04423802011-11-23 21:25:35 +0000180 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000181 #else
reed@google.comac10a2d2010-12-22 21:39:39 +0000182 // TODO: do other platforms really not have continuable breakpoints?
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000183 // sign extend for 64bit architectures to be sure this is
reed@google.comac10a2d2010-12-22 21:39:39 +0000184 // in the high address range
bsalomon@google.com04423802011-11-23 21:25:35 +0000185 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000186 #endif
187#endif
188
189/**
190 * GR_DEBUGBREAK is an unconditional break in debug builds.
191 */
192#if !defined(GR_DEBUGBREAK)
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000193 #ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +0000194 #define GR_DEBUGBREAK GR_ALWAYSBREAK
195 #else
196 #define GR_DEBUGBREAK
197 #endif
198#endif
199
200/**
201 * GR_ALWAYSASSERT is an assertion in all builds.
202 */
203#if !defined(GR_ALWAYSASSERT)
204 #define GR_ALWAYSASSERT(COND) \
205 do { \
206 if (!(COND)) { \
207 GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
208 GR_ALWAYSBREAK; \
209 } \
210 } while (false)
211#endif
212
213/**
214 * GR_DEBUGASSERT is an assertion in debug builds only.
215 */
216#if !defined(GR_DEBUGASSERT)
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000217 #ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +0000218 #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
219 #else
220 #define GR_DEBUGASSERT(COND)
221 #endif
222#endif
223
224/**
225 * Prettier forms of the above macros.
226 */
reed@google.comac10a2d2010-12-22 21:39:39 +0000227#define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
228
229/**
commit-bot@chromium.org8d47ddc2013-05-09 14:55:46 +0000230 * Crash from unrecoverable condition, optionally with a message. The debug variants only
231 * crash in a debug build. The message versions print the message regardless of release vs debug.
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000232 */
233inline void GrCrash() { GrAlwaysAssert(false); }
234inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000235inline void GrDebugCrash() { SkASSERT(false); }
236inline void GrDebugCrash(const char* msg) { GrPrintf(msg); SkASSERT(false); }
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000237
238/**
reed@google.comac10a2d2010-12-22 21:39:39 +0000239 * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
240 * it may print the message in the compiler log. Obviously, the condition must
241 * be evaluatable at compile time.
242 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000243// VS 2010 and GCC compiled with c++0x or gnu++0x support the new
reed@google.comac10a2d2010-12-22 21:39:39 +0000244// static_assert.
245#if !defined(GR_STATIC_ASSERT)
reed@google.comc9218432011-01-25 19:05:12 +0000246 #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__)
reed@google.comac10a2d2010-12-22 21:39:39 +0000247 #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
248 #else
249 template <bool> class GR_STATIC_ASSERT_FAILURE;
250 template <> class GR_STATIC_ASSERT_FAILURE<true> {};
251 #define GR_STATIC_ASSERT(CONDITION) \
252 enum {GR_CONCAT(X,__LINE__) = \
253 sizeof(GR_STATIC_ASSERT_FAILURE<CONDITION>)}
254 #endif
255#endif
256
reed@google.comac10a2d2010-12-22 21:39:39 +0000257/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000258 * GR_GEOM_BUFFER_LOCK_THRESHOLD gives a threshold (in bytes) for when Gr should
bsalomon@google.com96e96df2011-10-10 14:49:29 +0000259 * lock a GrGeometryBuffer to update its contents. It will use lock() if the
260 * size of the updated region is greater than the threshold. Otherwise it will
261 * use updateData().
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000262 */
263#if !defined(GR_GEOM_BUFFER_LOCK_THRESHOLD)
264 #define GR_GEOM_BUFFER_LOCK_THRESHOLD (1 << 15)
265#endif
266
djsollen@google.com42041e62012-10-29 19:24:45 +0000267/**
268 * GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT gives a threshold (in megabytes) for the
269 * maximum size of the texture cache in vram. The value is only a default and
270 * can be overridden at runtime.
271 */
272#if !defined(GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT)
273 #define GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT 96
274#endif
275
senorblanco@chromium.orge0d44ff2012-11-19 20:43:10 +0000276/**
sugoi@google.come3453cb2013-01-07 14:26:40 +0000277 * GR_STROKE_PATH_RENDERING controls whether or not the GrStrokePathRenderer can be selected
278 * as a path renderer. GrStrokePathRenderer is currently an experimental path renderer.
279 */
280#if !defined(GR_STROKE_PATH_RENDERING)
281 #define GR_STROKE_PATH_RENDERING 0
282#endif
283
reed@google.comac10a2d2010-12-22 21:39:39 +0000284///////////////////////////////////////////////////////////////////////////////
285// tail section:
286//
287// Now we just assert if we are missing some required define, or if we detect
288// and inconsistent combination of defines
289//
290
291
292/**
293 * Only one build target macro should be 1 and the rest should be 0.
294 */
295#define GR_BUILD_SUM (GR_WIN32_BUILD + GR_MAC_BUILD + GR_IOS_BUILD + GR_ANDROID_BUILD + GR_LINUX_BUILD + GR_QNX_BUILD)
296#if 0 == GR_BUILD_SUM
297 #error "Missing a GR_BUILD define"
298#elif 1 != GR_BUILD_SUM
299 #error "More than one GR_BUILD defined"
300#endif
301
reed@google.comac10a2d2010-12-22 21:39:39 +0000302#if 0
303#if GR_WIN32_BUILD
304// #pragma message GR_WARN("GR_WIN32_BUILD")
305#endif
306#if GR_MAC_BUILD
307// #pragma message GR_WARN("GR_MAC_BUILD")
308#endif
309#if GR_IOS_BUILD
310// #pragma message GR_WARN("GR_IOS_BUILD")
311#endif
312#if GR_ANDROID_BUILD
313// #pragma message GR_WARN("GR_ANDROID_BUILD")
314#endif
315#if GR_LINUX_BUILD
316// #pragma message GR_WARN("GR_LINUX_BUILD")
317#endif
318#if GR_QNX_BUILD
319// #pragma message GR_WARN("GR_QNX_BUILD")
320#endif
321#endif
322
323#endif