GrConfig.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2010 Google Inc.
  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. #ifndef GrConfig_DEFINED
  8. #define GrConfig_DEFINED
  9. #include "include/core/SkTypes.h"
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // preconfig section:
  12. //
  13. // All the work before including GrUserConfig.h should center around guessing
  14. // what platform we're on, and defining low-level symbols based on that.
  15. //
  16. // A build environment may have already defined symbols, so we first check
  17. // for that
  18. //
  19. // hack to ensure we know what sort of Apple platform we're on
  20. #if defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  21. #include <TargetConditionals.h>
  22. #endif
  23. /**
  24. * Gr defines are set to 0 or 1, rather than being undefined or defined
  25. */
  26. #if !defined(GR_CACHE_STATS)
  27. #if defined(SK_DEBUG) || defined(SK_DUMP_STATS)
  28. #define GR_CACHE_STATS 1
  29. #else
  30. #define GR_CACHE_STATS 0
  31. #endif
  32. #endif
  33. #if !defined(GR_GPU_STATS)
  34. #if defined(SK_DEBUG) || defined(SK_DUMP_STATS) || defined(GR_TEST_UTILS)
  35. #define GR_GPU_STATS 1
  36. #else
  37. #define GR_GPU_STATS 0
  38. #endif
  39. #endif
  40. ///////////////////////////////////////////////////////////////////////////////
  41. ///////////////////////////////////////////////////////////////////////////////
  42. /*
  43. * Include stdint.h with defines that trigger declaration of C99 limit/const
  44. * macros here before anyone else has a chance to include stdint.h without
  45. * these.
  46. */
  47. #ifndef __STDC_LIMIT_MACROS
  48. #define __STDC_LIMIT_MACROS
  49. #endif
  50. #ifndef __STDC_CONSTANT_MACROS
  51. #define __STDC_CONSTANT_MACROS
  52. #endif
  53. #include <stdint.h>
  54. ///////////////////////////////////////////////////////////////////////////////
  55. ///////////////////////////////////////////////////////////////////////////////
  56. // postconfig section:
  57. //
  58. /**
  59. * GR_STRING makes a string of X where X is expanded before conversion to a string
  60. * if X itself contains macros.
  61. */
  62. #define GR_STRING(X) GR_STRING_IMPL(X)
  63. #define GR_STRING_IMPL(X) #X
  64. /**
  65. * GR_CONCAT concatenates X and Y where each is expanded before
  66. * contanenation if either contains macros.
  67. */
  68. #define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
  69. #define GR_CONCAT_IMPL(X,Y) X##Y
  70. /**
  71. * Creates a string of the form "<filename>(<linenumber>) : "
  72. */
  73. #define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
  74. /**
  75. * Compilers have different ways of issuing warnings. This macro
  76. * attempts to abstract them, but may need to be specialized for your
  77. * particular compiler.
  78. * To insert compiler warnings use "#pragma message GR_WARN(<string>)"
  79. */
  80. #if defined(_MSC_VER)
  81. #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
  82. #else//__GNUC__ - may need other defines for different compilers
  83. #define GR_WARN(MSG) ("WARNING: " MSG)
  84. #endif
  85. /**
  86. * GR_ALWAYSBREAK is an unconditional break in all builds.
  87. */
  88. #if !defined(GR_ALWAYSBREAK)
  89. #if defined(SK_BUILD_FOR_WIN)
  90. #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); __debugbreak()
  91. #else
  92. // TODO: do other platforms really not have continuable breakpoints?
  93. // sign extend for 64bit architectures to be sure this is
  94. // in the high address range
  95. #define GR_ALWAYSBREAK SkNO_RETURN_HINT(); *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
  96. #endif
  97. #endif
  98. /**
  99. * GR_DEBUGBREAK is an unconditional break in debug builds.
  100. */
  101. #if !defined(GR_DEBUGBREAK)
  102. #ifdef SK_DEBUG
  103. #define GR_DEBUGBREAK GR_ALWAYSBREAK
  104. #else
  105. #define GR_DEBUGBREAK
  106. #endif
  107. #endif
  108. /**
  109. * GR_ALWAYSASSERT is an assertion in all builds.
  110. */
  111. #if !defined(GR_ALWAYSASSERT)
  112. #define GR_ALWAYSASSERT(COND) \
  113. do { \
  114. if (!(COND)) { \
  115. SkDebugf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
  116. GR_ALWAYSBREAK; \
  117. } \
  118. } while (false)
  119. #endif
  120. /**
  121. * GR_DEBUGASSERT is an assertion in debug builds only.
  122. */
  123. #if !defined(GR_DEBUGASSERT)
  124. #ifdef SK_DEBUG
  125. #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
  126. #else
  127. #define GR_DEBUGASSERT(COND)
  128. #endif
  129. #endif
  130. /**
  131. * Prettier forms of the above macros.
  132. */
  133. #define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
  134. /**
  135. * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
  136. * it may print the message in the compiler log. Obviously, the condition must
  137. * be evaluatable at compile time.
  138. */
  139. #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
  140. #endif