blob: fc464c5038bad993262e90522df3464533613674 [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
robertphillips@google.com59552022012-08-31 13:07:37 +000035#if !defined(GR_CACHE_STATS)
36 #define GR_CACHE_STATS 0
37#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000038
reed@google.comac10a2d2010-12-22 21:39:39 +000039///////////////////////////////////////////////////////////////////////////////
40///////////////////////////////////////////////////////////////////////////////
41
commit-bot@chromium.org43823302013-09-25 20:57:51 +000042#if defined(SK_BUILD_FOR_WIN32)
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000043// VC8 doesn't support stdint.h, so we define those types here.
44typedef signed char int8_t;
45typedef unsigned char uint8_t;
46typedef short int16_t;
47typedef unsigned short uint16_t;
48typedef int int32_t;
49typedef unsigned uint32_t;
bsalomon@google.com4be283f2011-04-19 21:15:09 +000050typedef __int64 int64_t;
51typedef unsigned __int64 uint64_t;
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000052#else
reed@google.comac10a2d2010-12-22 21:39:39 +000053/*
bsalomon@google.com91826102011-03-21 19:51:57 +000054 * Include stdint.h with defines that trigger declaration of C99 limit/const
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055 * macros here before anyone else has a chance to include stdint.h without
bsalomon@google.com91826102011-03-21 19:51:57 +000056 * these.
reed@google.comac10a2d2010-12-22 21:39:39 +000057 */
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000058#ifndef __STDC_LIMIT_MACROS
reed@google.comac10a2d2010-12-22 21:39:39 +000059#define __STDC_LIMIT_MACROS
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000060#endif
61#ifndef __STDC_CONSTANT_MACROS
reed@google.comac10a2d2010-12-22 21:39:39 +000062#define __STDC_CONSTANT_MACROS
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000063#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000064#include <stdint.h>
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000065#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000066
67/*
bsalomon@google.com1c13c962011-02-14 16:51:21 +000068 * The "user config" file can be empty, and everything should work. It is
reed@google.comac10a2d2010-12-22 21:39:39 +000069 * meant to store a given platform/client's overrides of our guess-work.
70 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +000071 * A alternate user config file can be specified by defining
reed@google.comac10a2d2010-12-22 21:39:39 +000072 * GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h
73 *
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000074 * e.g. it can change the BUILD target or supply its own defines for anything
robertphillips@google.com4e5559a2013-10-30 17:04:16 +000075 * else (e.g. GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT)
reed@google.comac10a2d2010-12-22 21:39:39 +000076 */
77#if !defined(GR_USER_CONFIG_FILE)
78 #include "GrUserConfig.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +000079#else
reed@google.comac10a2d2010-12-22 21:39:39 +000080 #include GR_USER_CONFIG_FILE
81#endif
82
83
84///////////////////////////////////////////////////////////////////////////////
85///////////////////////////////////////////////////////////////////////////////
86// postconfig section:
87//
bsalomon@google.com91826102011-03-21 19:51:57 +000088
reed@google.comac10a2d2010-12-22 21:39:39 +000089// By now we must have a GR_..._BUILD symbol set to 1, and a decision about
90// debug -vs- release
91//
92
bungeman@google.comf85abda2012-03-22 17:56:29 +000093#define GrPrintf SkDebugf
reed@google.comac10a2d2010-12-22 21:39:39 +000094
95/**
96 * GR_STRING makes a string of X where X is expanded before conversion to a string
97 * if X itself contains macros.
98 */
99#define GR_STRING(X) GR_STRING_IMPL(X)
100#define GR_STRING_IMPL(X) #X
101
102/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000103 * GR_CONCAT concatenates X and Y where each is expanded before
reed@google.comac10a2d2010-12-22 21:39:39 +0000104 * contanenation if either contains macros.
105 */
106#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
107#define GR_CONCAT_IMPL(X,Y) X##Y
108
109/**
110 * Creates a string of the form "<filename>(<linenumber>) : "
111 */
112#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
113
114/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000115 * Compilers have different ways of issuing warnings. This macro
116 * attempts to abstract them, but may need to be specialized for your
reed@google.comac10a2d2010-12-22 21:39:39 +0000117 * particular compiler.
118 * To insert compiler warnings use "#pragma message GR_WARN(<string>)"
119 */
reed@google.comc9218432011-01-25 19:05:12 +0000120#if defined(_MSC_VER) && _MSC_VER
reed@google.comac10a2d2010-12-22 21:39:39 +0000121 #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
122#else//__GNUC__ - may need other defines for different compilers
123 #define GR_WARN(MSG) ("WARNING: " MSG)
124#endif
125
126/**
127 * GR_ALWAYSBREAK is an unconditional break in all builds.
128 */
129#if !defined(GR_ALWAYSBREAK)
commit-bot@chromium.org43823302013-09-25 20:57:51 +0000130 #if defined(SK_BUILD_FOR_WIN32)
bsalomon@google.com04423802011-11-23 21:25:35 +0000131 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000132 #else
reed@google.comac10a2d2010-12-22 21:39:39 +0000133 // TODO: do other platforms really not have continuable breakpoints?
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000134 // sign extend for 64bit architectures to be sure this is
reed@google.comac10a2d2010-12-22 21:39:39 +0000135 // in the high address range
bsalomon@google.com04423802011-11-23 21:25:35 +0000136 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000137 #endif
138#endif
139
140/**
141 * GR_DEBUGBREAK is an unconditional break in debug builds.
142 */
143#if !defined(GR_DEBUGBREAK)
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000144 #ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +0000145 #define GR_DEBUGBREAK GR_ALWAYSBREAK
146 #else
147 #define GR_DEBUGBREAK
148 #endif
149#endif
150
151/**
152 * GR_ALWAYSASSERT is an assertion in all builds.
153 */
154#if !defined(GR_ALWAYSASSERT)
155 #define GR_ALWAYSASSERT(COND) \
156 do { \
157 if (!(COND)) { \
158 GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
159 GR_ALWAYSBREAK; \
160 } \
161 } while (false)
162#endif
163
164/**
165 * GR_DEBUGASSERT is an assertion in debug builds only.
166 */
167#if !defined(GR_DEBUGASSERT)
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000168 #ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +0000169 #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
170 #else
171 #define GR_DEBUGASSERT(COND)
172 #endif
173#endif
174
175/**
176 * Prettier forms of the above macros.
177 */
reed@google.comac10a2d2010-12-22 21:39:39 +0000178#define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
179
180/**
commit-bot@chromium.org8d47ddc2013-05-09 14:55:46 +0000181 * Crash from unrecoverable condition, optionally with a message. The debug variants only
182 * crash in a debug build. The message versions print the message regardless of release vs debug.
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000183 */
184inline void GrCrash() { GrAlwaysAssert(false); }
185inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); }
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000186inline void GrDebugCrash() { SkASSERT(false); }
187inline void GrDebugCrash(const char* msg) { GrPrintf(msg); SkASSERT(false); }
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000188
189/**
reed@google.comac10a2d2010-12-22 21:39:39 +0000190 * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
191 * it may print the message in the compiler log. Obviously, the condition must
192 * be evaluatable at compile time.
193 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000194// VS 2010 and GCC compiled with c++0x or gnu++0x support the new
reed@google.comac10a2d2010-12-22 21:39:39 +0000195// static_assert.
196#if !defined(GR_STATIC_ASSERT)
reed@google.comc9218432011-01-25 19:05:12 +0000197 #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__)
reed@google.comac10a2d2010-12-22 21:39:39 +0000198 #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
199 #else
200 template <bool> class GR_STATIC_ASSERT_FAILURE;
201 template <> class GR_STATIC_ASSERT_FAILURE<true> {};
202 #define GR_STATIC_ASSERT(CONDITION) \
203 enum {GR_CONCAT(X,__LINE__) = \
204 sizeof(GR_STATIC_ASSERT_FAILURE<CONDITION>)}
205 #endif
206#endif
207
reed@google.comac10a2d2010-12-22 21:39:39 +0000208/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000209 * GR_GEOM_BUFFER_LOCK_THRESHOLD gives a threshold (in bytes) for when Gr should
bsalomon@google.com96e96df2011-10-10 14:49:29 +0000210 * lock a GrGeometryBuffer to update its contents. It will use lock() if the
211 * size of the updated region is greater than the threshold. Otherwise it will
212 * use updateData().
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000213 */
214#if !defined(GR_GEOM_BUFFER_LOCK_THRESHOLD)
215 #define GR_GEOM_BUFFER_LOCK_THRESHOLD (1 << 15)
216#endif
217
djsollen@google.com42041e62012-10-29 19:24:45 +0000218/**
robertphillips@google.com4e5559a2013-10-30 17:04:16 +0000219 * GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT gives a threshold (in megabytes) for the
djsollen@google.com42041e62012-10-29 19:24:45 +0000220 * maximum size of the texture cache in vram. The value is only a default and
221 * can be overridden at runtime.
222 */
robertphillips@google.com4e5559a2013-10-30 17:04:16 +0000223#if !defined(GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT)
224 #define GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT 96
225#endif
226
227/**
228 * GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT specifies the maximum number of
229 * textures the texture cache can hold in vram. The value is only a default and
230 * can be overridden at runtime.
231 */
232#if !defined(GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT)
233 #define GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT 2048
djsollen@google.com42041e62012-10-29 19:24:45 +0000234#endif
235
senorblanco@chromium.orge0d44ff2012-11-19 20:43:10 +0000236/**
sugoi@google.come3453cb2013-01-07 14:26:40 +0000237 * GR_STROKE_PATH_RENDERING controls whether or not the GrStrokePathRenderer can be selected
238 * as a path renderer. GrStrokePathRenderer is currently an experimental path renderer.
239 */
240#if !defined(GR_STROKE_PATH_RENDERING)
241 #define GR_STROKE_PATH_RENDERING 0
242#endif
243
reed@google.comac10a2d2010-12-22 21:39:39 +0000244#endif