GrConfig.h 4.9 KB

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