• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 // IWYU pragma: private, include "SkTypes.h"
9 
10 #ifndef SkPostConfig_DEFINED
11 #define SkPostConfig_DEFINED
12 
13 #if !defined(SK_DEBUG) && !defined(SK_RELEASE)
14     #ifdef NDEBUG
15         #define SK_RELEASE
16     #else
17         #define SK_DEBUG
18     #endif
19 #endif
20 
21 #if defined(SK_DEBUG) && defined(SK_RELEASE)
22 #  error "cannot define both SK_DEBUG and SK_RELEASE"
23 #elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
24 #  error "must define either SK_DEBUG or SK_RELEASE"
25 #endif
26 
27 /**
28  * Matrix calculations may be float or double.
29  * The default is float, as that's what Chromium's using.
30  */
31 #if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT)
32 #  error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT"
33 #elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT)
34 #  define SK_MSCALAR_IS_FLOAT
35 #endif
36 
37 #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
38 #  error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
39 #elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
40 #  error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
41 #endif
42 
43 #if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN)
44     #error "The Skia team is not endian-savvy enough to support big-endian CPUs."
45     #error "If you still want to use Skia,"
46     #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN."
47 #endif
48 
49 #if !defined(SK_HAS_COMPILER_FEATURE)
50 #  if defined(__has_feature)
51 #    define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
52 #  else
53 #    define SK_HAS_COMPILER_FEATURE(x) 0
54 #  endif
55 #endif
56 
57 #if !defined(SK_ATTRIBUTE)
58 #  if defined(__clang__) || defined(__GNUC__)
59 #    define SK_ATTRIBUTE(attr) __attribute__((attr))
60 #  else
61 #    define SK_ATTRIBUTE(attr)
62 #  endif
63 #endif
64 
65 #if !defined(SK_SUPPORT_GPU)
66 #  define SK_SUPPORT_GPU 1
67 #endif
68 
69 /**
70  * If GPU is enabled but no GPU backends are enabled then enable GL by default.
71  * Traditionally clients have relied on Skia always building with the GL backend
72  * and opting in to additional backends. TODO: Require explicit opt in for GL.
73  */
74 #if SK_SUPPORT_GPU
75 #  if !defined(SK_GL) && !defined(SK_VULKAN) && !defined(SK_METAL)
76 #    define SK_GL
77 #  endif
78 #endif
79 
80 #if !defined(SK_SUPPORT_ATLAS_TEXT)
81 #  define SK_SUPPORT_ATLAS_TEXT 0
82 #elif SK_SUPPORT_ATLAS_TEXT && !SK_SUPPORT_GPU
83 #  error "SK_SUPPORT_ATLAS_TEXT requires SK_SUPPORT_GPU"
84 #endif
85 
86 /**
87  * The clang static analyzer likes to know that when the program is not
88  * expected to continue (crash, assertion failure, etc). It will notice that
89  * some combination of parameters lead to a function call that does not return.
90  * It can then make appropriate assumptions about the parameters in code
91  * executed only if the non-returning function was *not* called.
92  */
93 #if !defined(SkNO_RETURN_HINT)
94 #  if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
95      static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
SkNO_RETURN_HINT()96      static inline void SkNO_RETURN_HINT() {}
97 #  else
98 #    define SkNO_RETURN_HINT() do {} while (false)
99 #  endif
100 #endif
101 
102 #if !defined(SkUNREACHABLE)
103 #  if defined(_MSC_VER) && !defined(__clang__)
104 #    define SkUNREACHABLE __assume(false)
105 #  else
106 #    define SkUNREACHABLE __builtin_unreachable()
107 #  endif
108 #endif
109 
110 ///////////////////////////////////////////////////////////////////////////////
111 
112 #if defined(SK_BUILD_FOR_GOOGLE3)
113     void SkDebugfForDumpStackTrace(const char* data, void* unused);
114     void DumpStackTrace(int skip_count, void w(const char*, void*), void* arg);
115 #  define SK_DUMP_GOOGLE3_STACK() DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr)
116 #else
117 #  define SK_DUMP_GOOGLE3_STACK()
118 #endif
119 
120 #ifdef SK_BUILD_FOR_WIN
121 // permits visual studio to follow error back to source
122 #define SK_DUMP_LINE_FORMAT(message) \
123     SkDebugf("%s(%d): fatal error: \"%s\"\n", __FILE__, __LINE__, message)
124 #else
125 #define SK_DUMP_LINE_FORMAT(message) \
126     SkDebugf("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, message)
127 #endif
128 
129 #ifndef SK_ABORT
130 #  define SK_ABORT(message) \
131     do { \
132        SkNO_RETURN_HINT(); \
133        SK_DUMP_LINE_FORMAT(message); \
134        SK_DUMP_GOOGLE3_STACK(); \
135        sk_abort_no_print(); \
136        SkUNREACHABLE; \
137     } while (false)
138 #endif
139 
140 // If SK_R32_SHIFT is set, we'll use that to choose RGBA or BGRA.
141 // If not, we'll default to RGBA everywhere except BGRA on Windows.
142 #if defined(SK_R32_SHIFT)
143     static_assert(SK_R32_SHIFT == 0 || SK_R32_SHIFT == 16, "");
144 #elif defined(SK_BUILD_FOR_WIN)
145     #define SK_R32_SHIFT 16
146 #else
147     #define SK_R32_SHIFT 0
148 #endif
149 
150 #if defined(SK_B32_SHIFT)
151     static_assert(SK_B32_SHIFT == (16-SK_R32_SHIFT), "");
152 #else
153     #define SK_B32_SHIFT (16-SK_R32_SHIFT)
154 #endif
155 
156 #define SK_G32_SHIFT 8
157 #define SK_A32_SHIFT 24
158 
159 /**
160  * SkColor has well defined shift values, but SkPMColor is configurable. This
161  * macro is a convenience that returns true if the shift values are equal while
162  * ignoring the machine's endianness.
163  */
164 #define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \
165     (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0)
166 
167 /**
168  * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The
169  * relationship between the byte order and shift values depends on machine endianness. If the shift
170  * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little
171  * endian machine and the A channel on a big endian machine. Thus, given those shifts values,
172  * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and
173  * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine.
174  */
175 #ifdef SK_CPU_BENDIAN
176 #  define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3)     \
177         (SK_ ## C3 ## 32_SHIFT == 0  &&             \
178          SK_ ## C2 ## 32_SHIFT == 8  &&             \
179          SK_ ## C1 ## 32_SHIFT == 16 &&             \
180          SK_ ## C0 ## 32_SHIFT == 24)
181 #else
182 #  define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3)     \
183         (SK_ ## C0 ## 32_SHIFT == 0  &&             \
184          SK_ ## C1 ## 32_SHIFT == 8  &&             \
185          SK_ ## C2 ## 32_SHIFT == 16 &&             \
186          SK_ ## C3 ## 32_SHIFT == 24)
187 #endif
188 
189 //////////////////////////////////////////////////////////////////////////////////////////////
190 
191 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN
192     #ifdef free
193         #undef free
194     #endif
195     #include <crtdbg.h>
196     #undef free
197 #endif
198 
199 //////////////////////////////////////////////////////////////////////
200 
201 #if !defined(SK_UNUSED)
202 #  if !defined(__clang__) && defined(_MSC_VER)
203 #    define SK_UNUSED __pragma(warning(suppress:4189))
204 #  else
205 #    define SK_UNUSED SK_ATTRIBUTE(unused)
206 #  endif
207 #endif
208 
209 /**
210  * If your judgment is better than the compiler's (i.e. you've profiled it),
211  * you can use SK_ALWAYS_INLINE to force inlining. E.g.
212  *     inline void someMethod() { ... }             // may not be inlined
213  *     SK_ALWAYS_INLINE void someMethod() { ... }   // should always be inlined
214  */
215 #if !defined(SK_ALWAYS_INLINE)
216 #  if defined(SK_BUILD_FOR_WIN)
217 #    define SK_ALWAYS_INLINE __forceinline
218 #  else
219 #    define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
220 #  endif
221 #endif
222 
223 /**
224  * If your judgment is better than the compiler's (i.e. you've profiled it),
225  * you can use SK_NEVER_INLINE to prevent inlining.
226  */
227 #if !defined(SK_NEVER_INLINE)
228 #  if defined(SK_BUILD_FOR_WIN)
229 #    define SK_NEVER_INLINE __declspec(noinline)
230 #  else
231 #    define SK_NEVER_INLINE SK_ATTRIBUTE(noinline)
232 #  endif
233 #endif
234 
235 //////////////////////////////////////////////////////////////////////
236 
237 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
238     #define SK_PREFETCH(ptr)       _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0)
239     #define SK_WRITE_PREFETCH(ptr) _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0)
240 #elif defined(__GNUC__)
241     #define SK_PREFETCH(ptr)       __builtin_prefetch(ptr)
242     #define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1)
243 #else
244     #define SK_PREFETCH(ptr)
245     #define SK_WRITE_PREFETCH(ptr)
246 #endif
247 
248 //////////////////////////////////////////////////////////////////////
249 
250 #ifndef SK_PRINTF_LIKE
251 #  if defined(__clang__) || defined(__GNUC__)
252 #    define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
253 #  else
254 #    define SK_PRINTF_LIKE(A, B)
255 #  endif
256 #endif
257 
258 //////////////////////////////////////////////////////////////////////
259 
260 #ifndef SK_SIZE_T_SPECIFIER
261 #  if defined(_MSC_VER) && !defined(__clang__)
262 #    define SK_SIZE_T_SPECIFIER "%Iu"
263 #  else
264 #    define SK_SIZE_T_SPECIFIER "%zu"
265 #  endif
266 #endif
267 
268 //////////////////////////////////////////////////////////////////////
269 
270 #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
271     #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0
272 #endif
273 
274 //////////////////////////////////////////////////////////////////////
275 
276 #if !defined(SK_GAMMA_EXPONENT)
277     #define SK_GAMMA_EXPONENT (0.0f)  // SRGB
278 #endif
279 
280 //////////////////////////////////////////////////////////////////////
281 
282 #ifndef GR_TEST_UTILS
283 #  define GR_TEST_UTILS 0
284 #endif
285 
286 //////////////////////////////////////////////////////////////////////
287 
288 #if defined(SK_HISTOGRAM_ENUMERATION) && defined(SK_HISTOGRAM_BOOLEAN)
289 #  define SK_HISTOGRAMS_ENABLED 1
290 #else
291 #  define SK_HISTOGRAMS_ENABLED 0
292 #endif
293 
294 #ifndef SK_HISTOGRAM_BOOLEAN
295 #  define SK_HISTOGRAM_BOOLEAN(name, value)
296 #endif
297 
298 #ifndef SK_HISTOGRAM_ENUMERATION
299 #  define SK_HISTOGRAM_ENUMERATION(name, value, boundary_value)
300 #endif
301 
302 #ifndef SK_DISABLE_LEGACY_SHADERCONTEXT
303 #define SK_ENABLE_LEGACY_SHADERCONTEXT
304 #endif
305 
306 #endif // SkPostConfig_DEFINED
307