• 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 "include/core/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 #define SK_DUMP_STATS // open dump
36 #if !defined(GR_CACHE_STATS)
37   #if defined(SK_DEBUG) || defined(SK_DUMP_STATS)
38       #define GR_CACHE_STATS  1
39   #else
40       #define GR_CACHE_STATS  0
41   #endif
42 #endif
43 
44 #if !defined(GR_GPU_STATS)
45   #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || defined(GR_TEST_UTILS)
46       #define GR_GPU_STATS    1
47   #else
48       #define GR_GPU_STATS    0
49   #endif
50 #endif
51 
52 ///////////////////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////////////////
54 
55 /*
56  *  Include stdint.h with defines that trigger declaration of C99 limit/const
57  *  macros here before anyone else has a chance to include stdint.h without
58  *  these.
59  */
60 #ifndef __STDC_LIMIT_MACROS
61 #define __STDC_LIMIT_MACROS
62 #endif
63 #ifndef __STDC_CONSTANT_MACROS
64 #define __STDC_CONSTANT_MACROS
65 #endif
66 #include <stdint.h>
67 
68 ///////////////////////////////////////////////////////////////////////////////
69 ///////////////////////////////////////////////////////////////////////////////
70 // postconfig section:
71 //
72 
73 /**
74  *  GR_STRING makes a string of X where X is expanded before conversion to a string
75  *  if X itself contains macros.
76  */
77 #define GR_STRING(X) GR_STRING_IMPL(X)
78 #define GR_STRING_IMPL(X) #X
79 
80 /**
81  *  GR_CONCAT concatenates X and Y  where each is expanded before
82  *  contanenation if either contains macros.
83  */
84 #define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
85 #define GR_CONCAT_IMPL(X,Y) X##Y
86 
87 /**
88  *  Creates a string of the form "<filename>(<linenumber>) : "
89  */
90 #define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
91 
92 /**
93  *  Compilers have different ways of issuing warnings. This macro
94  *  attempts to abstract them, but may need to be specialized for your
95  *  particular compiler.
96  *  To insert compiler warnings use "#pragma message GR_WARN(<string>)"
97  */
98 #if defined(_MSC_VER)
99     #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
100 #else//__GNUC__ - may need other defines for different compilers
101     #define GR_WARN(MSG) ("WARNING: " MSG)
102 #endif
103 
104 /**
105  *  GR_ALWAYSBREAK is an unconditional break in all builds.
106  */
107 #if !defined(GR_ALWAYSBREAK)
108     #if     defined(SK_BUILD_FOR_WIN)
109         #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
110     #else
111         // TODO: do other platforms really not have continuable breakpoints?
112         // sign extend for 64bit architectures to be sure this is
113         // in the high address range
114         #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
115     #endif
116 #endif
117 
118 /**
119  *  GR_DEBUGBREAK is an unconditional break in debug builds.
120  */
121 #if !defined(GR_DEBUGBREAK)
122     #ifdef SK_DEBUG
123         #define GR_DEBUGBREAK GR_ALWAYSBREAK
124     #else
125         #define GR_DEBUGBREAK
126     #endif
127 #endif
128 
129 /**
130  *  GR_ALWAYSASSERT is an assertion in all builds.
131  */
132 #if !defined(GR_ALWAYSASSERT)
133     #define GR_ALWAYSASSERT(COND)                                        \
134         do {                                                             \
135             if (!(COND)) {                                               \
136                 SkDebugf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
137                 GR_ALWAYSBREAK;                                          \
138             }                                                            \
139         } while (false)
140 #endif
141 
142 /**
143  *  GR_DEBUGASSERT is an assertion in debug builds only.
144  */
145 #if !defined(GR_DEBUGASSERT)
146     #ifdef SK_DEBUG
147         #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
148     #else
149         #define GR_DEBUGASSERT(COND)
150     #endif
151 #endif
152 
153 /**
154  *  Prettier forms of the above macros.
155  */
156 #define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
157 
158 /**
159  *  GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
160  *  it may print the message in the compiler log. Obviously, the condition must
161  *  be evaluatable at compile time.
162  */
163 #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
164 
165 #endif
166