/include/core/SkPostConfig.h

https://github.com/Jib-BAOSP/platform_external_skia · C Header · 258 lines · 197 code · 31 blank · 30 comment · 25 complexity · b066ae101060dd92b1487bf23d6c1e23 MD5 · raw file

  1. /*
  2. * Copyright (C) 2006 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SkPostConfig_DEFINED
  17. #define SkPostConfig_DEFINED
  18. #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
  19. #define SK_BUILD_FOR_WIN
  20. #endif
  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. #if defined SK_SUPPORT_UNITTEST && !defined(SK_DEBUG)
  27. #error "can't have unittests without debug"
  28. #endif
  29. #if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT)
  30. #error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT"
  31. #elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT)
  32. #ifdef SK_CAN_USE_FLOAT
  33. #define SK_SCALAR_IS_FLOAT
  34. #else
  35. #define SK_SCALAR_IS_FIXED
  36. #endif
  37. #endif
  38. #if defined(SK_SCALAR_IS_FLOAT) && !defined(SK_CAN_USE_FLOAT)
  39. #define SK_CAN_USE_FLOAT
  40. // we do nothing in the else case: fixed-scalars can have floats or not
  41. #endif
  42. #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
  43. #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
  44. #elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
  45. #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
  46. #endif
  47. // ensure the port has defined all of these, or none of them
  48. #ifdef SK_A32_SHIFT
  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. #else
  53. #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
  54. #error "all or none of the 32bit SHIFT amounts must be defined"
  55. #endif
  56. #endif
  57. ///////////////////////////////////////////////////////////////////////////////
  58. #ifndef SkNEW
  59. #define SkNEW(type_name) new type_name
  60. #define SkNEW_ARGS(type_name, args) new type_name args
  61. #define SkNEW_ARRAY(type_name, count) new type_name[count]
  62. #define SkDELETE(obj) delete obj
  63. #define SkDELETE_ARRAY(array) delete[] array
  64. #endif
  65. #ifndef SK_CRASH
  66. #if 1 // set to 0 for infinite loop, which can help connecting gdb
  67. #define SK_CRASH() *(int *)(uintptr_t)0xbbadbeef = 0
  68. #else
  69. #define SK_CRASH() do {} while (true)
  70. #endif
  71. #endif
  72. ///////////////////////////////////////////////////////////////////////////////
  73. #if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT)
  74. // if this is defined, we convert floats to 2scompliment ints for compares
  75. #ifndef SK_SCALAR_SLOW_COMPARES
  76. #define SK_SCALAR_SLOW_COMPARES
  77. #endif
  78. #ifndef SK_USE_FLOATBITS
  79. #define SK_USE_FLOATBITS
  80. #endif
  81. #endif
  82. #ifdef SK_BUILD_FOR_WIN
  83. // we want lean_and_mean when we include windows.h
  84. #ifndef WIN32_LEAN_AND_MEAN
  85. #define WIN32_LEAN_AND_MEAN
  86. #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
  87. #endif
  88. #include <windows.h>
  89. #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
  90. #undef WIN32_LEAN_AND_MEAN
  91. #endif
  92. #ifndef SK_DEBUGBREAK
  93. #define SK_DEBUGBREAK(cond) do { if (!(cond)) __debugbreak(); } while (false)
  94. #endif
  95. #ifndef SK_A32_SHIFT
  96. #define SK_A32_SHIFT 24
  97. #define SK_R32_SHIFT 16
  98. #define SK_G32_SHIFT 8
  99. #define SK_B32_SHIFT 0
  100. #endif
  101. #elif defined(SK_BUILD_FOR_MAC)
  102. #ifndef SK_DEBUGBREAK
  103. #define SK_DEBUGBREAK(cond) do { if (!(cond)) SK_CRASH(); } while (false)
  104. #endif
  105. #else
  106. #ifdef SK_DEBUG
  107. #include <stdio.h>
  108. #ifndef SK_DEBUGBREAK
  109. #define SK_DEBUGBREAK(cond) do { if (cond) break; \
  110. SkDebugf("%s:%d: failed assertion \"%s\"\n", \
  111. __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
  112. #endif
  113. #endif
  114. #endif
  115. /*
  116. * We check to see if the SHIFT value has already been defined.
  117. * if not, we define it ourself to some default values. We default to OpenGL
  118. * order (in memory: r,g,b,a)
  119. */
  120. #ifndef SK_A32_SHIFT
  121. #ifdef SK_CPU_BENDIAN
  122. #define SK_R32_SHIFT 24
  123. #define SK_G32_SHIFT 16
  124. #define SK_B32_SHIFT 8
  125. #define SK_A32_SHIFT 0
  126. #else
  127. #define SK_R32_SHIFT 0
  128. #define SK_G32_SHIFT 8
  129. #define SK_B32_SHIFT 16
  130. #define SK_A32_SHIFT 24
  131. #endif
  132. #endif
  133. // stdlib macros
  134. #if 0
  135. #if !defined(strlen) && defined(SK_DEBUG)
  136. extern size_t sk_strlen(const char*);
  137. #define strlen(s) sk_strlen(s)
  138. #endif
  139. #ifndef sk_strcpy
  140. #define sk_strcpy(dst, src) strcpy(dst, src)
  141. #endif
  142. #ifndef sk_strchr
  143. #define sk_strchr(s, c) strchr(s, c)
  144. #endif
  145. #ifndef sk_strrchr
  146. #define sk_strrchr(s, c) strrchr(s, c)
  147. #endif
  148. #ifndef sk_strcmp
  149. #define sk_strcmp(s, t) strcmp(s, t)
  150. #endif
  151. #ifndef sk_strncmp
  152. #define sk_strncmp(s, t, n) strncmp(s, t, n)
  153. #endif
  154. #ifndef sk_memcpy
  155. #define sk_memcpy(dst, src, n) memcpy(dst, src, n)
  156. #endif
  157. #ifndef memmove
  158. #define memmove(dst, src, n) memmove(dst, src, n)
  159. #endif
  160. #ifndef sk_memset
  161. #define sk_memset(dst, val, n) memset(dst, val, n)
  162. #endif
  163. #ifndef sk_memcmp
  164. #define sk_memcmp(s, t, n) memcmp(s, t, n)
  165. #endif
  166. #define sk_strequal(s, t) (!sk_strcmp(s, t))
  167. #define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n))
  168. #endif
  169. //////////////////////////////////////////////////////////////////////
  170. #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
  171. #ifndef SkLONGLONG
  172. #ifdef SK_BUILD_FOR_WIN32
  173. #define SkLONGLONG __int64
  174. #else
  175. #define SkLONGLONG long long
  176. #endif
  177. #endif
  178. #endif
  179. //////////////////////////////////////////////////////////////////////////////////////////////
  180. #ifndef SK_BUILD_FOR_WINCE
  181. #include <string.h>
  182. #include <stdlib.h>
  183. #else
  184. #define _CMNINTRIN_DECLARE_ONLY
  185. #include "cmnintrin.h"
  186. #endif
  187. #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
  188. //#define _CRTDBG_MAP_ALLOC
  189. #ifdef free
  190. #undef free
  191. #endif
  192. #include <crtdbg.h>
  193. #undef free
  194. #ifdef SK_DEBUGx
  195. #if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
  196. void * operator new(
  197. size_t cb,
  198. int nBlockUse,
  199. const char * szFileName,
  200. int nLine,
  201. int foo
  202. );
  203. void * operator new[](
  204. size_t cb,
  205. int nBlockUse,
  206. const char * szFileName,
  207. int nLine,
  208. int foo
  209. );
  210. void operator delete(
  211. void *pUserData,
  212. int, const char*, int, int
  213. );
  214. void operator delete(
  215. void *pUserData
  216. );
  217. void operator delete[]( void * p );
  218. #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
  219. #else
  220. #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
  221. #endif
  222. #define new DEBUG_CLIENTBLOCK
  223. #else
  224. #define DEBUG_CLIENTBLOCK
  225. #endif // _DEBUG
  226. #endif
  227. #endif