SkPostConfig.h 9.4 KB

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