blob: 8e65f51b25f46be7e13b0ff10c0f91d7b6ef3d83 [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)
bsalomon24234fe2014-10-24 09:34:41 -070036 #ifdef SK_DEVELOPER
37 #define GR_CACHE_STATS 1
38 #else
39 #define GR_CACHE_STATS 0
40 #endif
robertphillips@google.com59552022012-08-31 13:07:37 +000041#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000042
robertphillips754f4e92014-09-18 13:52:08 -070043#if !defined(GR_GPU_STATS)
bsalomon24234fe2014-10-24 09:34:41 -070044 #ifdef SK_DEVELOPER
45 #define GR_GPU_STATS 1
46 #else
47 #define GR_GPU_STATS 0
48 #endif
robertphillips754f4e92014-09-18 13:52:08 -070049#endif
50
reed@google.comac10a2d2010-12-22 21:39:39 +000051///////////////////////////////////////////////////////////////////////////////
52///////////////////////////////////////////////////////////////////////////////
53
commit-bot@chromium.org43823302013-09-25 20:57:51 +000054#if defined(SK_BUILD_FOR_WIN32)
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000055// VC8 doesn't support stdint.h, so we define those types here.
56typedef signed char int8_t;
57typedef unsigned char uint8_t;
58typedef short int16_t;
59typedef unsigned short uint16_t;
60typedef int int32_t;
61typedef unsigned uint32_t;
bsalomon@google.com4be283f2011-04-19 21:15:09 +000062typedef __int64 int64_t;
63typedef unsigned __int64 uint64_t;
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000064#else
reed@google.comac10a2d2010-12-22 21:39:39 +000065/*
bsalomon@google.com91826102011-03-21 19:51:57 +000066 * Include stdint.h with defines that trigger declaration of C99 limit/const
rmistry@google.comfbfcd562012-08-23 18:09:54 +000067 * macros here before anyone else has a chance to include stdint.h without
bsalomon@google.com91826102011-03-21 19:51:57 +000068 * these.
reed@google.comac10a2d2010-12-22 21:39:39 +000069 */
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000070#ifndef __STDC_LIMIT_MACROS
reed@google.comac10a2d2010-12-22 21:39:39 +000071#define __STDC_LIMIT_MACROS
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000072#endif
73#ifndef __STDC_CONSTANT_MACROS
reed@google.comac10a2d2010-12-22 21:39:39 +000074#define __STDC_CONSTANT_MACROS
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000075#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000076#include <stdint.h>
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000077#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000078
79/*
bsalomon@google.com1c13c962011-02-14 16:51:21 +000080 * The "user config" file can be empty, and everything should work. It is
reed@google.comac10a2d2010-12-22 21:39:39 +000081 * meant to store a given platform/client's overrides of our guess-work.
82 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +000083 * A alternate user config file can be specified by defining
reed@google.comac10a2d2010-12-22 21:39:39 +000084 * GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h
85 *
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000086 * e.g. it can change the BUILD target or supply its own defines for anything
robertphillips@google.com4e5559a2013-10-30 17:04:16 +000087 * else (e.g. GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT)
reed@google.comac10a2d2010-12-22 21:39:39 +000088 */
89#if !defined(GR_USER_CONFIG_FILE)
90 #include "GrUserConfig.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +000091#else
reed@google.comac10a2d2010-12-22 21:39:39 +000092 #include GR_USER_CONFIG_FILE
93#endif
94
95
96///////////////////////////////////////////////////////////////////////////////
97///////////////////////////////////////////////////////////////////////////////
98// postconfig section:
99//
bsalomon@google.com91826102011-03-21 19:51:57 +0000100
reed@google.comac10a2d2010-12-22 21:39:39 +0000101// By now we must have a GR_..._BUILD symbol set to 1, and a decision about
102// debug -vs- release
103//
104
bungeman@google.comf85abda2012-03-22 17:56:29 +0000105#define GrPrintf SkDebugf
reed@google.comac10a2d2010-12-22 21:39:39 +0000106
107/**
108 * GR_STRING makes a string of X where X is expanded before conversion to a string
109 * if X itself contains macros.
110 */
111#define GR_STRING(X) GR_STRING_IMPL(X)
112#define GR_STRING_IMPL(X) #X
113
114/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000115 * GR_CONCAT concatenates X and Y where each is expanded before
reed@google.comac10a2d2010-12-22 21:39:39 +0000116 * contanenation if either contains macros.
117 */
118#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
119#define GR_CONCAT_IMPL(X,Y) X##Y
120
121/**
122 * Creates a string of the form "<filename>(<linenumber>) : "
123 */
124#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
125
126/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000127 * Compilers have different ways of issuing warnings. This macro
128 * attempts to abstract them, but may need to be specialized for your
reed@google.comac10a2d2010-12-22 21:39:39 +0000129 * particular compiler.
130 * To insert compiler warnings use "#pragma message GR_WARN(<string>)"
131 */
reed@google.comc9218432011-01-25 19:05:12 +0000132#if defined(_MSC_VER) && _MSC_VER
reed@google.comac10a2d2010-12-22 21:39:39 +0000133 #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
134#else//__GNUC__ - may need other defines for different compilers
135 #define GR_WARN(MSG) ("WARNING: " MSG)
136#endif
137
138/**
139 * GR_ALWAYSBREAK is an unconditional break in all builds.
140 */
141#if !defined(GR_ALWAYSBREAK)
commit-bot@chromium.org43823302013-09-25 20:57:51 +0000142 #if defined(SK_BUILD_FOR_WIN32)
bsalomon@google.com04423802011-11-23 21:25:35 +0000143 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000144 #else
reed@google.comac10a2d2010-12-22 21:39:39 +0000145 // TODO: do other platforms really not have continuable breakpoints?
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000146 // sign extend for 64bit architectures to be sure this is
reed@google.comac10a2d2010-12-22 21:39:39 +0000147 // in the high address range
bsalomon@google.com04423802011-11-23 21:25:35 +0000148 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000149 #endif
150#endif
151
152/**
153 * GR_DEBUGBREAK is an unconditional break in debug builds.
154 */
155#if !defined(GR_DEBUGBREAK)
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000156 #ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +0000157 #define GR_DEBUGBREAK GR_ALWAYSBREAK
158 #else
159 #define GR_DEBUGBREAK
160 #endif
161#endif
162
163/**
164 * GR_ALWAYSASSERT is an assertion in all builds.
165 */
166#if !defined(GR_ALWAYSASSERT)
167 #define GR_ALWAYSASSERT(COND) \
168 do { \
169 if (!(COND)) { \
170 GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
171 GR_ALWAYSBREAK; \
172 } \
173 } while (false)
174#endif
175
176/**
177 * GR_DEBUGASSERT is an assertion in debug builds only.
178 */
179#if !defined(GR_DEBUGASSERT)
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000180 #ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +0000181 #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
182 #else
183 #define GR_DEBUGASSERT(COND)
184 #endif
185#endif
186
187/**
188 * Prettier forms of the above macros.
189 */
reed@google.comac10a2d2010-12-22 21:39:39 +0000190#define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
191
192/**
reed@google.comac10a2d2010-12-22 21:39:39 +0000193 * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
194 * it may print the message in the compiler log. Obviously, the condition must
195 * be evaluatable at compile time.
196 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000197// VS 2010 and GCC compiled with c++0x or gnu++0x support the new
reed@google.comac10a2d2010-12-22 21:39:39 +0000198// static_assert.
199#if !defined(GR_STATIC_ASSERT)
reed@google.comc9218432011-01-25 19:05:12 +0000200 #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__)
reed@google.comac10a2d2010-12-22 21:39:39 +0000201 #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
202 #else
203 template <bool> class GR_STATIC_ASSERT_FAILURE;
204 template <> class GR_STATIC_ASSERT_FAILURE<true> {};
205 #define GR_STATIC_ASSERT(CONDITION) \
206 enum {GR_CONCAT(X,__LINE__) = \
207 sizeof(GR_STATIC_ASSERT_FAILURE<CONDITION>)}
208 #endif
209#endif
210
reed@google.comac10a2d2010-12-22 21:39:39 +0000211/**
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000212 * GR_GEOM_BUFFER_MAP_THRESHOLD gives a threshold (in bytes) for when Gr should
213 * map a GrGeometryBuffer to update its contents. It will use map() if the
bsalomon@google.com96e96df2011-10-10 14:49:29 +0000214 * size of the updated region is greater than the threshold. Otherwise it will
215 * use updateData().
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000216 */
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000217#if !defined(GR_GEOM_BUFFER_MAP_THRESHOLD)
218 #define GR_GEOM_BUFFER_MAP_THRESHOLD (1 << 15)
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000219#endif
220
djsollen@google.com42041e62012-10-29 19:24:45 +0000221/**
robertphillips@google.com4e5559a2013-10-30 17:04:16 +0000222 * GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT gives a threshold (in megabytes) for the
djsollen@google.com42041e62012-10-29 19:24:45 +0000223 * maximum size of the texture cache in vram. The value is only a default and
224 * can be overridden at runtime.
225 */
robertphillips@google.com4e5559a2013-10-30 17:04:16 +0000226#if !defined(GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT)
227 #define GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT 96
228#endif
229
230/**
231 * GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT specifies the maximum number of
232 * textures the texture cache can hold in vram. The value is only a default and
233 * can be overridden at runtime.
234 */
235#if !defined(GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT)
236 #define GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT 2048
djsollen@google.com42041e62012-10-29 19:24:45 +0000237#endif
238
senorblanco@chromium.orge0d44ff2012-11-19 20:43:10 +0000239/**
sugoi@google.come3453cb2013-01-07 14:26:40 +0000240 * GR_STROKE_PATH_RENDERING controls whether or not the GrStrokePathRenderer can be selected
241 * as a path renderer. GrStrokePathRenderer is currently an experimental path renderer.
242 */
243#if !defined(GR_STROKE_PATH_RENDERING)
244 #define GR_STROKE_PATH_RENDERING 0
245#endif
246
georgeb62508b2014-08-12 18:00:47 -0700247/**
248 * GR_ALWAYS_ALLOCATE_ON_HEAP determines whether various temporary buffers created
249 * in the GPU backend are always allocated on the heap or are allowed to be
250 * allocated on the stack for smaller memory requests.
251 *
252 * This is only used for memory buffers that are created and then passed through to the
253 * 3D API (e.g. as texture or geometry data)
254 */
255#if !defined(GR_ALWAYS_ALLOCATE_ON_HEAP)
256 #define GR_ALWAYS_ALLOCATE_ON_HEAP 0
257#endif
258
reed@google.comac10a2d2010-12-22 21:39:39 +0000259#endif