SkPostConfig.h 9.4 KB

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