blob: 86ad63ad6e82fb0947525683a694aa972a2d468a [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
robertphillips754f4e92014-09-18 13:52:08 -070039#if !defined(GR_GPU_STATS)
40#define GR_GPU_STATS 0
41#endif
42
reed@google.comac10a2d2010-12-22 21:39:39 +000043///////////////////////////////////////////////////////////////////////////////
44///////////////////////////////////////////////////////////////////////////////
45
commit-bot@chromium.org43823302013-09-25 20:57:51 +000046#if defined(SK_BUILD_FOR_WIN32)
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000047// VC8 doesn't support stdint.h, so we define those types here.
48typedef signed char int8_t;
49typedef unsigned char uint8_t;
50typedef short int16_t;
51typedef unsigned short uint16_t;
52typedef int int32_t;
53typedef unsigned uint32_t;
bsalomon@google.com4be283f2011-04-19 21:15:09 +000054typedef __int64 int64_t;
55typedef unsigned __int64 uint64_t;
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000056#else
reed@google.comac10a2d2010-12-22 21:39:39 +000057/*
bsalomon@google.com91826102011-03-21 19:51:57 +000058 * Include stdint.h with defines that trigger declaration of C99 limit/const
rmistry@google.comfbfcd562012-08-23 18:09:54 +000059 * macros here before anyone else has a chance to include stdint.h without
bsalomon@google.com91826102011-03-21 19:51:57 +000060 * these.
reed@google.comac10a2d2010-12-22 21:39:39 +000061 */
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000062#ifndef __STDC_LIMIT_MACROS
reed@google.comac10a2d2010-12-22 21:39:39 +000063#define __STDC_LIMIT_MACROS
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000064#endif
65#ifndef __STDC_CONSTANT_MACROS
reed@google.comac10a2d2010-12-22 21:39:39 +000066#define __STDC_CONSTANT_MACROS
senorblanco@chromium.orgf9a14552012-11-06 18:36:33 +000067#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000068#include <stdint.h>
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +000069#endif
reed@google.comac10a2d2010-12-22 21:39:39 +000070
71/*
bsalomon@google.com1c13c962011-02-14 16:51:21 +000072 * The "user config" file can be empty, and everything should work. It is
reed@google.comac10a2d2010-12-22 21:39:39 +000073 * meant to store a given platform/client's overrides of our guess-work.
74 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +000075 * A alternate user config file can be specified by defining
reed@google.comac10a2d2010-12-22 21:39:39 +000076 * GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h
77 *
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000078 * e.g. it can change the BUILD target or supply its own defines for anything
robertphillips@google.com4e5559a2013-10-30 17:04:16 +000079 * else (e.g. GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT)
reed@google.comac10a2d2010-12-22 21:39:39 +000080 */
81#if !defined(GR_USER_CONFIG_FILE)
82 #include "GrUserConfig.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +000083#else
reed@google.comac10a2d2010-12-22 21:39:39 +000084 #include GR_USER_CONFIG_FILE
85#endif
86
87
88///////////////////////////////////////////////////////////////////////////////
89///////////////////////////////////////////////////////////////////////////////
90// postconfig section:
91//
bsalomon@google.com91826102011-03-21 19:51:57 +000092
reed@google.comac10a2d2010-12-22 21:39:39 +000093// By now we must have a GR_..._BUILD symbol set to 1, and a decision about
94// debug -vs- release
95//
96
bungeman@google.comf85abda2012-03-22 17:56:29 +000097#define GrPrintf SkDebugf
reed@google.comac10a2d2010-12-22 21:39:39 +000098
99/**
100 * GR_STRING makes a string of X where X is expanded before conversion to a string
101 * if X itself contains macros.
102 */
103#define GR_STRING(X) GR_STRING_IMPL(X)
104#define GR_STRING_IMPL(X) #X
105
106/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000107 * GR_CONCAT concatenates X and Y where each is expanded before
reed@google.comac10a2d2010-12-22 21:39:39 +0000108 * contanenation if either contains macros.
109 */
110#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
111#define GR_CONCAT_IMPL(X,Y) X##Y
112
113/**
114 * Creates a string of the form "<filename>(<linenumber>) : "
115 */
116#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
117
118/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000119 * Compilers have different ways of issuing warnings. This macro
120 * attempts to abstract them, but may need to be specialized for your
reed@google.comac10a2d2010-12-22 21:39:39 +0000121 * particular compiler.
122 * To insert compiler warnings use "#pragma message GR_WARN(<string>)"
123 */
reed@google.comc9218432011-01-25 19:05:12 +0000124#if defined(_MSC_VER) && _MSC_VER
reed@google.comac10a2d2010-12-22 21:39:39 +0000125 #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
126#else//__GNUC__ - may need other defines for different compilers
127 #define GR_WARN(MSG) ("WARNING: " MSG)
128#endif
129
130/**
131 * GR_ALWAYSBREAK is an unconditional break in all builds.
132 */
133#if !defined(GR_ALWAYSBREAK)
commit-bot@chromium.org43823302013-09-25 20:57:51 +0000134 #if defined(SK_BUILD_FOR_WIN32)
bsalomon@google.com04423802011-11-23 21:25:35 +0000135 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000136 #else
reed@google.comac10a2d2010-12-22 21:39:39 +0000137 // TODO: do other platforms really not have continuable breakpoints?
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000138 // sign extend for 64bit architectures to be sure this is
reed@google.comac10a2d2010-12-22 21:39:39 +0000139 // in the high address range
bsalomon@google.com04423802011-11-23 21:25:35 +0000140 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000141 #endif
142#endif
143
144/**
145 * GR_DEBUGBREAK is an unconditional break in debug builds.
146 */
147#if !defined(GR_DEBUGBREAK)
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000148 #ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +0000149 #define GR_DEBUGBREAK GR_ALWAYSBREAK
150 #else
151 #define GR_DEBUGBREAK
152 #endif
153#endif
154
155/**
156 * GR_ALWAYSASSERT is an assertion in all builds.
157 */
158#if !defined(GR_ALWAYSASSERT)
159 #define GR_ALWAYSASSERT(COND) \
160 do { \
161 if (!(COND)) { \
162 GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
163 GR_ALWAYSBREAK; \
164 } \
165 } while (false)
166#endif
167
168/**
169 * GR_DEBUGASSERT is an assertion in debug builds only.
170 */
171#if !defined(GR_DEBUGASSERT)
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000172 #ifdef SK_DEBUG
reed@google.comac10a2d2010-12-22 21:39:39 +0000173 #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
174 #else
175 #define GR_DEBUGASSERT(COND)
176 #endif
177#endif
178
179/**
180 * Prettier forms of the above macros.
181 */
reed@google.comac10a2d2010-12-22 21:39:39 +0000182#define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
183
184/**
reed@google.comac10a2d2010-12-22 21:39:39 +0000185 * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
186 * it may print the message in the compiler log. Obviously, the condition must
187 * be evaluatable at compile time.
188 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000189// VS 2010 and GCC compiled with c++0x or gnu++0x support the new
reed@google.comac10a2d2010-12-22 21:39:39 +0000190// static_assert.
191#if !defined(GR_STATIC_ASSERT)
reed@google.comc9218432011-01-25 19:05:12 +0000192 #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__)
reed@google.comac10a2d2010-12-22 21:39:39 +0000193 #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
194 #else
195 template <bool> class GR_STATIC_ASSERT_FAILURE;
196 template <> class GR_STATIC_ASSERT_FAILURE<true> {};
197 #define GR_STATIC_ASSERT(CONDITION) \
198 enum {GR_CONCAT(X,__LINE__) = \
199 sizeof(GR_STATIC_ASSERT_FAILURE<CONDITION>)}
200 #endif
201#endif
202
reed@google.comac10a2d2010-12-22 21:39:39 +0000203/**
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000204 * GR_GEOM_BUFFER_MAP_THRESHOLD gives a threshold (in bytes) for when Gr should
205 * map a GrGeometryBuffer to update its contents. It will use map() if the
bsalomon@google.com96e96df2011-10-10 14:49:29 +0000206 * size of the updated region is greater than the threshold. Otherwise it will
207 * use updateData().
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000208 */
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +0000209#if !defined(GR_GEOM_BUFFER_MAP_THRESHOLD)
210 #define GR_GEOM_BUFFER_MAP_THRESHOLD (1 << 15)
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000211#endif
212
djsollen@google.com42041e62012-10-29 19:24:45 +0000213/**
robertphillips@google.com4e5559a2013-10-30 17:04:16 +0000214 * GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT gives a threshold (in megabytes) for the
djsollen@google.com42041e62012-10-29 19:24:45 +0000215 * maximum size of the texture cache in vram. The value is only a default and
216 * can be overridden at runtime.
217 */
robertphillips@google.com4e5559a2013-10-30 17:04:16 +0000218#if !defined(GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT)
219 #define GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT 96
220#endif
221
222/**
223 * GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT specifies the maximum number of
224 * textures the texture cache can hold in vram. The value is only a default and
225 * can be overridden at runtime.
226 */
227#if !defined(GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT)
228 #define GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT 2048
djsollen@google.com42041e62012-10-29 19:24:45 +0000229#endif
230
senorblanco@chromium.orge0d44ff2012-11-19 20:43:10 +0000231/**
sugoi@google.come3453cb2013-01-07 14:26:40 +0000232 * GR_STROKE_PATH_RENDERING controls whether or not the GrStrokePathRenderer can be selected
233 * as a path renderer. GrStrokePathRenderer is currently an experimental path renderer.
234 */
235#if !defined(GR_STROKE_PATH_RENDERING)
236 #define GR_STROKE_PATH_RENDERING 0
237#endif
238
georgeb62508b2014-08-12 18:00:47 -0700239/**
240 * GR_ALWAYS_ALLOCATE_ON_HEAP determines whether various temporary buffers created
241 * in the GPU backend are always allocated on the heap or are allowed to be
242 * allocated on the stack for smaller memory requests.
243 *
244 * This is only used for memory buffers that are created and then passed through to the
245 * 3D API (e.g. as texture or geometry data)
246 */
247#if !defined(GR_ALWAYS_ALLOCATE_ON_HEAP)
248 #define GR_ALWAYS_ALLOCATE_ON_HEAP 0
249#endif
250
reed@google.comac10a2d2010-12-22 21:39:39 +0000251#endif