blob: c61c34e193b4082e32245136af20a912c47735b3 [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.comc9218432011-01-25 19:05:12 +000088// we need both GR_DEBUG and GR_RELEASE to be defined as 0 or 1
89//
90#ifndef GR_DEBUG
91 #ifdef GR_RELEASE
92 #define GR_DEBUG !GR_RELEASE
reed@google.comac10a2d2010-12-22 21:39:39 +000093 #else
reed@google.comc9218432011-01-25 19:05:12 +000094 #ifdef NDEBUG
95 #define GR_DEBUG 0
96 #else
97 #define GR_DEBUG 1
98 #endif
reed@google.comac10a2d2010-12-22 21:39:39 +000099 #endif
reed@google.comc9218432011-01-25 19:05:12 +0000100#endif
101
102#ifndef GR_RELEASE
reed@google.comac10a2d2010-12-22 21:39:39 +0000103 #define GR_RELEASE !GR_DEBUG
104#endif
105
reed@google.comc9218432011-01-25 19:05:12 +0000106#if GR_DEBUG == GR_RELEASE
reed@google.com8752ad72011-01-26 04:55:57 +0000107 #error "GR_DEBUG and GR_RELEASE must not be the same"
reed@google.comc9218432011-01-25 19:05:12 +0000108#endif
109
reed@google.comac10a2d2010-12-22 21:39:39 +0000110///////////////////////////////////////////////////////////////////////////////
111///////////////////////////////////////////////////////////////////////////////
112
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000113#if GR_WIN32_BUILD
114// VC8 doesn't support stdint.h, so we define those types here.
115typedef signed char int8_t;
116typedef unsigned char uint8_t;
117typedef short int16_t;
118typedef unsigned short uint16_t;
119typedef int int32_t;
120typedef unsigned uint32_t;
bsalomon@google.com4be283f2011-04-19 21:15:09 +0000121typedef __int64 int64_t;
122typedef unsigned __int64 uint64_t;
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000123#else
reed@google.comac10a2d2010-12-22 21:39:39 +0000124/*
bsalomon@google.com91826102011-03-21 19:51:57 +0000125 * Include stdint.h with defines that trigger declaration of C99 limit/const
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000126 * macros here before anyone else has a chance to include stdint.h without
bsalomon@google.com91826102011-03-21 19:51:57 +0000127 * these.
reed@google.comac10a2d2010-12-22 21:39:39 +0000128 */
129#define __STDC_LIMIT_MACROS
130#define __STDC_CONSTANT_MACROS
131#include <stdint.h>
senorblanco@chromium.org9d18b782011-03-28 20:47:09 +0000132#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000133
134/*
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000135 * The "user config" file can be empty, and everything should work. It is
reed@google.comac10a2d2010-12-22 21:39:39 +0000136 * meant to store a given platform/client's overrides of our guess-work.
137 *
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000138 * A alternate user config file can be specified by defining
reed@google.comac10a2d2010-12-22 21:39:39 +0000139 * GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h
140 *
141 * e.g. it can specify GR_DEBUG/GR_RELEASE as it please, change the BUILD
142 * target, or supply its own defines for anything else (e.g. GR_SCALAR)
143 */
144#if !defined(GR_USER_CONFIG_FILE)
145 #include "GrUserConfig.h"
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000146#else
reed@google.comac10a2d2010-12-22 21:39:39 +0000147 #include GR_USER_CONFIG_FILE
148#endif
149
150
151///////////////////////////////////////////////////////////////////////////////
152///////////////////////////////////////////////////////////////////////////////
153// postconfig section:
154//
bsalomon@google.com91826102011-03-21 19:51:57 +0000155
156// GR_IMPLEMENTATION should be define to 1 when building Gr and 0 when including
157// it in another dependent build. The Gr makefile/ide-project should define this
158// to 1.
159#if !defined(GR_IMPLEMENTATION)
160 #define GR_IMPLEMENTATION 0
161#endif
162
163// If Gr is built as a shared library then GR_DLL should be defined to 1 (both
164// when building Gr and when including its headers in dependent builds). Only
165// currently supported minimally for Chrome's Win32 Multi-DLL build (TODO:
166// correctly exort all of the public API correctly and support shared lib on
167// other platforms).
168#if !defined(GR_DLL)
169 #define GR_DLL 0
170#endif
171
bsalomon@google.com48ba56d2011-04-26 17:59:32 +0000172#if GR_DLL
173 #if GR_WIN32_BUILD
174 #if GR_IMPLEMENTATION
175 #define GR_API __declspec(dllexport)
176 #else
177 #define GR_API __declspec(dllimport)
178 #endif
bsalomon@google.com91826102011-03-21 19:51:57 +0000179 #else
bsalomon@google.com48ba56d2011-04-26 17:59:32 +0000180 #define GR_API __attribute__((visibility("default")))
bsalomon@google.com91826102011-03-21 19:51:57 +0000181 #endif
182#else
183 #define GR_API
184#endif
185
reed@google.comac10a2d2010-12-22 21:39:39 +0000186// By now we must have a GR_..._BUILD symbol set to 1, and a decision about
187// debug -vs- release
188//
189
bungeman@google.comf85abda2012-03-22 17:56:29 +0000190#define GrPrintf SkDebugf
reed@google.comac10a2d2010-12-22 21:39:39 +0000191
192/**
193 * GR_STRING makes a string of X where X is expanded before conversion to a string
194 * if X itself contains macros.
195 */
196#define GR_STRING(X) GR_STRING_IMPL(X)
197#define GR_STRING_IMPL(X) #X
198
199/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000200 * GR_CONCAT concatenates X and Y where each is expanded before
reed@google.comac10a2d2010-12-22 21:39:39 +0000201 * contanenation if either contains macros.
202 */
203#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
204#define GR_CONCAT_IMPL(X,Y) X##Y
205
206/**
207 * Creates a string of the form "<filename>(<linenumber>) : "
208 */
209#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
210
211/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000212 * Compilers have different ways of issuing warnings. This macro
213 * attempts to abstract them, but may need to be specialized for your
reed@google.comac10a2d2010-12-22 21:39:39 +0000214 * particular compiler.
215 * To insert compiler warnings use "#pragma message GR_WARN(<string>)"
216 */
reed@google.comc9218432011-01-25 19:05:12 +0000217#if defined(_MSC_VER) && _MSC_VER
reed@google.comac10a2d2010-12-22 21:39:39 +0000218 #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
219#else//__GNUC__ - may need other defines for different compilers
220 #define GR_WARN(MSG) ("WARNING: " MSG)
221#endif
222
223/**
224 * GR_ALWAYSBREAK is an unconditional break in all builds.
225 */
226#if !defined(GR_ALWAYSBREAK)
227 #if GR_WIN32_BUILD
bsalomon@google.com04423802011-11-23 21:25:35 +0000228 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000229 #else
reed@google.comac10a2d2010-12-22 21:39:39 +0000230 // TODO: do other platforms really not have continuable breakpoints?
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000231 // sign extend for 64bit architectures to be sure this is
reed@google.comac10a2d2010-12-22 21:39:39 +0000232 // in the high address range
bsalomon@google.com04423802011-11-23 21:25:35 +0000233 #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000234 #endif
235#endif
236
237/**
238 * GR_DEBUGBREAK is an unconditional break in debug builds.
239 */
240#if !defined(GR_DEBUGBREAK)
241 #if GR_DEBUG
242 #define GR_DEBUGBREAK GR_ALWAYSBREAK
243 #else
244 #define GR_DEBUGBREAK
245 #endif
246#endif
247
248/**
249 * GR_ALWAYSASSERT is an assertion in all builds.
250 */
251#if !defined(GR_ALWAYSASSERT)
252 #define GR_ALWAYSASSERT(COND) \
253 do { \
254 if (!(COND)) { \
255 GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
256 GR_ALWAYSBREAK; \
257 } \
258 } while (false)
259#endif
260
261/**
262 * GR_DEBUGASSERT is an assertion in debug builds only.
263 */
264#if !defined(GR_DEBUGASSERT)
265 #if GR_DEBUG
266 #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
267 #else
268 #define GR_DEBUGASSERT(COND)
269 #endif
270#endif
271
272/**
273 * Prettier forms of the above macros.
274 */
275#define GrAssert(COND) GR_DEBUGASSERT(COND)
276#define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
277
278/**
bsalomon@google.com6f7fbc92011-02-01 19:12:40 +0000279 * Crash from unrecoverable condition, optionally with a message.
280 */
281inline void GrCrash() { GrAlwaysAssert(false); }
282inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); }
283
284/**
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000285 * GR_DEBUGCODE compiles the code X in debug builds only
reed@google.comac10a2d2010-12-22 21:39:39 +0000286 */
287#if !defined(GR_DEBUGCODE)
288 #if GR_DEBUG
289 #define GR_DEBUGCODE(X) X
290 #else
291 #define GR_DEBUGCODE(X)
292 #endif
293#endif
294
295/**
296 * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
297 * it may print the message in the compiler log. Obviously, the condition must
298 * be evaluatable at compile time.
299 */
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000300// VS 2010 and GCC compiled with c++0x or gnu++0x support the new
reed@google.comac10a2d2010-12-22 21:39:39 +0000301// static_assert.
302#if !defined(GR_STATIC_ASSERT)
reed@google.comc9218432011-01-25 19:05:12 +0000303 #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__)
reed@google.comac10a2d2010-12-22 21:39:39 +0000304 #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
305 #else
306 template <bool> class GR_STATIC_ASSERT_FAILURE;
307 template <> class GR_STATIC_ASSERT_FAILURE<true> {};
308 #define GR_STATIC_ASSERT(CONDITION) \
309 enum {GR_CONCAT(X,__LINE__) = \
310 sizeof(GR_STATIC_ASSERT_FAILURE<CONDITION>)}
311 #endif
312#endif
313
314#if !defined(GR_SCALAR_IS_FLOAT)
315 #define GR_SCALAR_IS_FLOAT 0
316#endif
317#if !defined(GR_SCALAR_IS_FIXED)
318 #define GR_SCALAR_IS_FIXED 0
319#endif
320
321#if !defined(GR_TEXT_SCALAR_TYPE_IS_USHORT)
322 #define GR_TEXT_SCALAR_TYPE_IS_USHORT 0
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000323#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000324#if !defined(GR_TEXT_SCALAR_TYPE_IS_FLOAT)
325 #define GR_TEXT_SCALAR_TYPE_IS_FLOAT 0
326#endif
327#if !defined(GR_TEXT_SCALAR_TYPE_IS_FIXED)
328 #define GR_TEXT_SCALAR_TYPE_IS_FIXED 0
329#endif
330
331#ifndef GR_DUMP_TEXTURE_UPLOAD
332 #define GR_DUMP_TEXTURE_UPLOAD 0
333#endif
334
335/**
bsalomon@google.comd16983b2011-02-02 22:42:20 +0000336 * GR_STATIC_RECT_VB controls whether rects are drawn by issuing a vertex
337 * for each corner or using a static vb that is positioned by modifying the
338 * view / texture matrix.
339 */
bsalomon@google.com43333232011-02-02 19:24:54 +0000340#if !defined(GR_STATIC_RECT_VB)
341 #define GR_STATIC_RECT_VB 0
342#endif
343
bsalomon@google.comd16983b2011-02-02 22:42:20 +0000344/**
bsalomon@google.com1d4edd32012-08-16 18:36:06 +0000345 * GR_DISABLE_DRAW_BUFFERING prevents GrContext from queueing draws in a
346 * GrInOrderDrawBuffer.
347 */
348#if !defined(GR_DISABLE_DRAW_BUFFERING)
349 #define GR_DISABLE_DRAW_BUFFERING 0
350#endif
351
352/**
bsalomon@google.comd16983b2011-02-02 22:42:20 +0000353 * GR_AGGRESSIVE_SHADER_OPTS controls how aggressively shaders are optimized
354 * for special cases. On systems where program changes are expensive this
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000355 * may not be advantageous. Consecutive draws may no longer use the same
bsalomon@google.comd16983b2011-02-02 22:42:20 +0000356 * program.
357 */
358#if !defined(GR_AGGRESSIVE_SHADER_OPTS)
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +0000359 #define GR_AGGRESSIVE_SHADER_OPTS 1
bsalomon@google.comd16983b2011-02-02 22:42:20 +0000360#endif
361
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000362/**
363 * GR_GEOM_BUFFER_LOCK_THRESHOLD gives a threshold (in bytes) for when Gr should
bsalomon@google.com96e96df2011-10-10 14:49:29 +0000364 * lock a GrGeometryBuffer to update its contents. It will use lock() if the
365 * size of the updated region is greater than the threshold. Otherwise it will
366 * use updateData().
bsalomon@google.com1c13c962011-02-14 16:51:21 +0000367 */
368#if !defined(GR_GEOM_BUFFER_LOCK_THRESHOLD)
369 #define GR_GEOM_BUFFER_LOCK_THRESHOLD (1 << 15)
370#endif
371
reed@google.comac10a2d2010-12-22 21:39:39 +0000372///////////////////////////////////////////////////////////////////////////////
373// tail section:
374//
375// Now we just assert if we are missing some required define, or if we detect
376// and inconsistent combination of defines
377//
378
379
380/**
381 * Only one build target macro should be 1 and the rest should be 0.
382 */
383#define GR_BUILD_SUM (GR_WIN32_BUILD + GR_MAC_BUILD + GR_IOS_BUILD + GR_ANDROID_BUILD + GR_LINUX_BUILD + GR_QNX_BUILD)
384#if 0 == GR_BUILD_SUM
385 #error "Missing a GR_BUILD define"
386#elif 1 != GR_BUILD_SUM
387 #error "More than one GR_BUILD defined"
388#endif
389
390
391#if !GR_SCALAR_IS_FLOAT && !GR_SCALAR_IS_FIXED
392 #undef GR_SCALAR_IS_FLOAT
393 #define GR_SCALAR_IS_FLOAT 1
394 #pragma message GR_WARN("Scalar type not defined, defaulting to float")
395#endif
396
397#if !GR_TEXT_SCALAR_IS_FLOAT && \
398 !GR_TEXT_SCALAR_IS_FIXED && \
399 !GR_TEXT_SCALAR_IS_USHORT
400 #undef GR_TEXT_SCALAR_IS_FLOAT
401 #define GR_TEXT_SCALAR_IS_FLOAT 1
402 #pragma message GR_WARN("Text scalar type not defined, defaulting to float")
403#endif
404
405#if 0
406#if GR_WIN32_BUILD
407// #pragma message GR_WARN("GR_WIN32_BUILD")
408#endif
409#if GR_MAC_BUILD
410// #pragma message GR_WARN("GR_MAC_BUILD")
411#endif
412#if GR_IOS_BUILD
413// #pragma message GR_WARN("GR_IOS_BUILD")
414#endif
415#if GR_ANDROID_BUILD
416// #pragma message GR_WARN("GR_ANDROID_BUILD")
417#endif
418#if GR_LINUX_BUILD
419// #pragma message GR_WARN("GR_LINUX_BUILD")
420#endif
421#if GR_QNX_BUILD
422// #pragma message GR_WARN("GR_QNX_BUILD")
423#endif
424#endif
425
426#endif
427