• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * 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.
7  */
8 
9 
10 
11 #ifndef GrConfig_DEFINED
12 #define GrConfig_DEFINED
13 
14 #include "SkTypes.h"
15 
16 ///////////////////////////////////////////////////////////////////////////////
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
53 #if !defined(GR_CACHE_STATS)
54     #define GR_CACHE_STATS      0
55 #endif
56 
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"
69     #elif defined(SK_BUILD_FOR_ANDROID)
70         #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"
85     #endif
86 #endif
87 
88 // 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
93     #else
94         #ifdef NDEBUG
95             #define GR_DEBUG    0
96         #else
97             #define GR_DEBUG    1
98         #endif
99     #endif
100 #endif
101 
102 #ifndef GR_RELEASE
103     #define GR_RELEASE  !GR_DEBUG
104 #endif
105 
106 #if GR_DEBUG == GR_RELEASE
107     #error "GR_DEBUG and GR_RELEASE must not be the same"
108 #endif
109 
110 ///////////////////////////////////////////////////////////////////////////////
111 ///////////////////////////////////////////////////////////////////////////////
112 
113 #if GR_WIN32_BUILD
114 // VC8 doesn't support stdint.h, so we define those types here.
115 typedef signed char int8_t;
116 typedef unsigned char uint8_t;
117 typedef short int16_t;
118 typedef unsigned short uint16_t;
119 typedef int int32_t;
120 typedef unsigned uint32_t;
121 typedef __int64 int64_t;
122 typedef unsigned __int64 uint64_t;
123 #else
124 /*
125  *  Include stdint.h with defines that trigger declaration of C99 limit/const
126  *  macros here before anyone else has a chance to include stdint.h without
127  *  these.
128  */
129 #ifndef __STDC_LIMIT_MACROS
130 #define __STDC_LIMIT_MACROS
131 #endif
132 #ifndef __STDC_CONSTANT_MACROS
133 #define __STDC_CONSTANT_MACROS
134 #endif
135 #include <stdint.h>
136 #endif
137 
138 /*
139  *  The "user config" file can be empty, and everything should work. It is
140  *  meant to store a given platform/client's overrides of our guess-work.
141  *
142  *  A alternate user config file can be specified by defining
143  *  GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h
144  *
145  *  e.g. it can specify GR_DEBUG/GR_RELEASE as it please, change the BUILD
146  *  target, or supply its own defines for anything else (e.g. GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT)
147  */
148 #if !defined(GR_USER_CONFIG_FILE)
149     #include "GrUserConfig.h"
150 #else
151     #include GR_USER_CONFIG_FILE
152 #endif
153 
154 
155 ///////////////////////////////////////////////////////////////////////////////
156 ///////////////////////////////////////////////////////////////////////////////
157 // postconfig section:
158 //
159 
160 // GR_IMPLEMENTATION should be define to 1 when building Gr and 0 when including
161 // it in another dependent build. The Gr makefile/ide-project should define this
162 // to 1.
163 #if !defined(GR_IMPLEMENTATION)
164     #define GR_IMPLEMENTATION 0
165 #endif
166 
167 // If Gr is built as a shared library then GR_DLL should be defined to 1 (both
168 // when building Gr and when including its headers in dependent builds). Only
169 // currently supported minimally for Chrome's Win32 Multi-DLL build (TODO:
170 // correctly exort all of the public API correctly and support shared lib on
171 // other platforms).
172 #if !defined(GR_DLL)
173     #define GR_DLL 0
174 #endif
175 
176 #if GR_DLL
177     #if GR_WIN32_BUILD
178         #if GR_IMPLEMENTATION
179             #define GR_API __declspec(dllexport)
180         #else
181             #define GR_API __declspec(dllimport)
182         #endif
183     #else
184         #define GR_API __attribute__((visibility("default")))
185     #endif
186 #else
187     #define GR_API
188 #endif
189 
190 // By now we must have a GR_..._BUILD symbol set to 1, and a decision about
191 // debug -vs- release
192 //
193 
194 #define GrPrintf SkDebugf
195 
196 /**
197  *  GR_STRING makes a string of X where X is expanded before conversion to a string
198  *  if X itself contains macros.
199  */
200 #define GR_STRING(X) GR_STRING_IMPL(X)
201 #define GR_STRING_IMPL(X) #X
202 
203 /**
204  *  GR_CONCAT concatenates X and Y  where each is expanded before
205  *  contanenation if either contains macros.
206  */
207 #define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
208 #define GR_CONCAT_IMPL(X,Y) X##Y
209 
210 /**
211  *  Creates a string of the form "<filename>(<linenumber>) : "
212  */
213 #define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
214 
215 /**
216  *  Compilers have different ways of issuing warnings. This macro
217  *  attempts to abstract them, but may need to be specialized for your
218  *  particular compiler.
219  *  To insert compiler warnings use "#pragma message GR_WARN(<string>)"
220  */
221 #if defined(_MSC_VER) && _MSC_VER
222     #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
223 #else//__GNUC__ - may need other defines for different compilers
224     #define GR_WARN(MSG) ("WARNING: " MSG)
225 #endif
226 
227 /**
228  *  GR_ALWAYSBREAK is an unconditional break in all builds.
229  */
230 #if !defined(GR_ALWAYSBREAK)
231     #if     GR_WIN32_BUILD
232         #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
233     #else
234         // TODO: do other platforms really not have continuable breakpoints?
235         // sign extend for 64bit architectures to be sure this is
236         // in the high address range
237         #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
238     #endif
239 #endif
240 
241 /**
242  *  GR_DEBUGBREAK is an unconditional break in debug builds.
243  */
244 #if !defined(GR_DEBUGBREAK)
245     #if GR_DEBUG
246         #define GR_DEBUGBREAK GR_ALWAYSBREAK
247     #else
248         #define GR_DEBUGBREAK
249     #endif
250 #endif
251 
252 /**
253  *  GR_ALWAYSASSERT is an assertion in all builds.
254  */
255 #if !defined(GR_ALWAYSASSERT)
256     #define GR_ALWAYSASSERT(COND)                                        \
257         do {                                                             \
258             if (!(COND)) {                                               \
259                 GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
260                 GR_ALWAYSBREAK;                                          \
261             }                                                            \
262         } while (false)
263 #endif
264 
265 /**
266  *  GR_DEBUGASSERT is an assertion in debug builds only.
267  */
268 #if !defined(GR_DEBUGASSERT)
269     #if GR_DEBUG
270         #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
271     #else
272         #define GR_DEBUGASSERT(COND)
273     #endif
274 #endif
275 
276 /**
277  *  Prettier forms of the above macros.
278  */
279 #define GrAssert(COND) GR_DEBUGASSERT(COND)
280 #define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
281 
282 /**
283  * Crash from unrecoverable condition, optionally with a message.
284  */
GrCrash()285 inline void GrCrash() { GrAlwaysAssert(false); }
GrCrash(const char * msg)286 inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); }
287 
288 /**
289  *  GR_DEBUGCODE compiles the code X in debug builds only
290  */
291 #if !defined(GR_DEBUGCODE)
292     #if GR_DEBUG
293         #define GR_DEBUGCODE(X) X
294     #else
295         #define GR_DEBUGCODE(X)
296     #endif
297 #endif
298 
299 /**
300  *  GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
301  *  it may print the message in the compiler log. Obviously, the condition must
302  *  be evaluatable at compile time.
303  */
304 // VS 2010 and GCC compiled with c++0x or gnu++0x support the new
305 // static_assert.
306 #if !defined(GR_STATIC_ASSERT)
307     #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__)
308         #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
309     #else
310         template <bool> class GR_STATIC_ASSERT_FAILURE;
311         template <> class GR_STATIC_ASSERT_FAILURE<true> {};
312         #define GR_STATIC_ASSERT(CONDITION) \
313             enum {GR_CONCAT(X,__LINE__) = \
314             sizeof(GR_STATIC_ASSERT_FAILURE<CONDITION>)}
315     #endif
316 #endif
317 
318 #if !defined(GR_TEXT_SCALAR_TYPE_IS_USHORT)
319     #define GR_TEXT_SCALAR_TYPE_IS_USHORT  0
320 #endif
321 #if !defined(GR_TEXT_SCALAR_TYPE_IS_FLOAT)
322     #define GR_TEXT_SCALAR_TYPE_IS_FLOAT   0
323 #endif
324 #if !defined(GR_TEXT_SCALAR_TYPE_IS_FIXED)
325     #define GR_TEXT_SCALAR_TYPE_IS_FIXED   0
326 #endif
327 
328 #ifndef GR_DUMP_TEXTURE_UPLOAD
329     #define GR_DUMP_TEXTURE_UPLOAD  0
330 #endif
331 
332 /**
333  *  GR_STATIC_RECT_VB controls whether rects are drawn by issuing a vertex
334  *  for each corner or using a static vb that is positioned by modifying the
335  *  view / texture matrix.
336  */
337 #if !defined(GR_STATIC_RECT_VB)
338     #define GR_STATIC_RECT_VB 0
339 #endif
340 
341 /**
342  *  GR_DISABLE_DRAW_BUFFERING prevents GrContext from queueing draws in a
343  *  GrInOrderDrawBuffer.
344  */
345 #if !defined(GR_DISABLE_DRAW_BUFFERING)
346     #define GR_DISABLE_DRAW_BUFFERING 0
347 #endif
348 
349 /**
350  *  GR_AGGRESSIVE_SHADER_OPTS controls how aggressively shaders are optimized
351  *  for special cases. On systems where program changes are expensive this
352  *  may not be advantageous. Consecutive draws may no longer use the same
353  *  program.
354  */
355 #if !defined(GR_AGGRESSIVE_SHADER_OPTS)
356     #define GR_AGGRESSIVE_SHADER_OPTS 1
357 #endif
358 
359 /**
360  * GR_GEOM_BUFFER_LOCK_THRESHOLD gives a threshold (in bytes) for when Gr should
361  * lock a GrGeometryBuffer to update its contents. It will use lock() if the
362  * size of the updated region is greater than the threshold. Otherwise it will
363  * use updateData().
364  */
365 #if !defined(GR_GEOM_BUFFER_LOCK_THRESHOLD)
366     #define GR_GEOM_BUFFER_LOCK_THRESHOLD (1 << 15)
367 #endif
368 
369 /**
370  * GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT gives a threshold (in megabytes) for the
371  * maximum size of the texture cache in vram. The value is only a default and
372  * can be overridden at runtime.
373  */
374 #if !defined(GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT)
375     #define GR_DEFAULT_TEXTURE_CACHE_MB_LIMIT 96
376 #endif
377 
378 /**
379  * GR_USE_NEW_GL_SHADER_SOURCE_SIGNATURE is for compatibility with the new version
380  * of the OpenGLES2.0 headers from Khronos.  glShaderSource now takes a const char * const *,
381  * instead of a const char **.
382  */
383 #if !defined(GR_USE_NEW_GL_SHADER_SOURCE_SIGNATURE)
384     #define GR_USE_NEW_GL_SHADER_SOURCE_SIGNATURE 0
385 #endif
386 
387 /**
388  * GR_STROKE_PATH_RENDERING controls whether or not the GrStrokePathRenderer can be selected
389  * as a path renderer. GrStrokePathRenderer is currently an experimental path renderer.
390  */
391 #if !defined(GR_STROKE_PATH_RENDERING)
392     #define GR_STROKE_PATH_RENDERING                 0
393 #endif
394 
395 ///////////////////////////////////////////////////////////////////////////////
396 // tail section:
397 //
398 // Now we just assert if we are missing some required define, or if we detect
399 // and inconsistent combination of defines
400 //
401 
402 
403 /**
404  *  Only one build target macro should be 1 and the rest should be 0.
405  */
406 #define GR_BUILD_SUM    (GR_WIN32_BUILD + GR_MAC_BUILD + GR_IOS_BUILD + GR_ANDROID_BUILD + GR_LINUX_BUILD + GR_QNX_BUILD)
407 #if 0 == GR_BUILD_SUM
408     #error "Missing a GR_BUILD define"
409 #elif 1 != GR_BUILD_SUM
410     #error "More than one GR_BUILD defined"
411 #endif
412 
413 
414 #if !GR_TEXT_SCALAR_IS_FLOAT && \
415     !GR_TEXT_SCALAR_IS_FIXED && \
416     !GR_TEXT_SCALAR_IS_USHORT
417     #undef  GR_TEXT_SCALAR_IS_FLOAT
418     #define GR_TEXT_SCALAR_IS_FLOAT         1
419     #pragma message GR_WARN("Text scalar type not defined, defaulting to float")
420 #endif
421 
422 #if 0
423 #if GR_WIN32_BUILD
424 //    #pragma message GR_WARN("GR_WIN32_BUILD")
425 #endif
426 #if GR_MAC_BUILD
427 //    #pragma message GR_WARN("GR_MAC_BUILD")
428 #endif
429 #if GR_IOS_BUILD
430 //    #pragma message GR_WARN("GR_IOS_BUILD")
431 #endif
432 #if GR_ANDROID_BUILD
433 //    #pragma message GR_WARN("GR_ANDROID_BUILD")
434 #endif
435 #if GR_LINUX_BUILD
436 //    #pragma message GR_WARN("GR_LINUX_BUILD")
437 #endif
438 #if GR_QNX_BUILD
439 //    #pragma message GR_WARN("GR_QNX_BUILD")
440 #endif
441 #endif
442 
443 #endif
444