epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #ifndef SkPostConfig_DEFINED |
| 11 | #define SkPostConfig_DEFINED |
| 12 | |
| 13 | #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE) |
| 14 | #define SK_BUILD_FOR_WIN |
| 15 | #endif |
| 16 | |
| 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 | #if defined SK_SUPPORT_UNITTEST && !defined(SK_DEBUG) |
| 24 | #error "can't have unittests without debug" |
| 25 | #endif |
| 26 | |
| 27 | #if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT) |
| 28 | #error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT" |
| 29 | #elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT) |
reed@google.com | 7886ad3 | 2012-06-11 21:21:26 +0000 | [diff] [blame] | 30 | #define SK_SCALAR_IS_FLOAT |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
vollick@chromium.org | 5596a69 | 2012-11-13 20:12:00 +0000 | [diff] [blame] | 33 | #if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT) |
| 34 | #error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT" |
| 35 | #elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT) |
reed@google.com | 7d68335 | 2012-12-03 21:19:52 +0000 | [diff] [blame^] | 36 | // default is double, as that is faster given our impl uses doubles |
| 37 | // for intermediate calculations. |
| 38 | #define SK_MSCALAR_IS_DOUBLE |
vollick@chromium.org | 5596a69 | 2012-11-13 20:12:00 +0000 | [diff] [blame] | 39 | #endif |
| 40 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 41 | #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) |
| 42 | #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" |
| 43 | #elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) |
| 44 | #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" |
| 45 | #endif |
| 46 | |
| 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 | |
bsalomon@google.com | 0442380 | 2011-11-23 21:25:35 +0000 | [diff] [blame] | 58 | #if !defined(SK_HAS_COMPILER_FEATURE) |
| 59 | #if defined(__has_feature) |
| 60 | #define SK_HAS_COMPILER_FEATURE(x) __has_feature(x) |
| 61 | #else |
| 62 | #define SK_HAS_COMPILER_FEATURE(x) 0 |
| 63 | #endif |
| 64 | #endif |
| 65 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 66 | #if !defined(SK_SUPPORT_GPU) |
| 67 | #define SK_SUPPORT_GPU 1 |
| 68 | #endif |
| 69 | |
bsalomon@google.com | 0442380 | 2011-11-23 21:25:35 +0000 | [diff] [blame] | 70 | /** |
| 71 | * The clang static analyzer likes to know that when the program is not |
| 72 | * expected to continue (crash, assertion failure, etc). It will notice that |
| 73 | * some combination of parameters lead to a function call that does not return. |
| 74 | * It can then make appropriate assumptions about the parameters in code |
| 75 | * executed only if the non-returning function was *not* called. |
| 76 | */ |
| 77 | #if !defined(SkNO_RETURN_HINT) |
| 78 | #if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn) |
bsalomon@google.com | 3a52d68 | 2012-07-11 13:30:08 +0000 | [diff] [blame] | 79 | namespace { |
| 80 | inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn)); |
| 81 | inline void SkNO_RETURN_HINT() {} |
| 82 | } |
bsalomon@google.com | 0442380 | 2011-11-23 21:25:35 +0000 | [diff] [blame] | 83 | #else |
| 84 | #define SkNO_RETURN_HINT() do {} while (false) |
| 85 | #endif |
| 86 | #endif |
| 87 | |
justinlin@google.com | fffb2f1 | 2012-04-16 19:10:21 +0000 | [diff] [blame] | 88 | #if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB) |
| 89 | #error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB" |
| 90 | #elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB) |
| 91 | #define SK_HAS_ZLIB |
| 92 | #endif |
| 93 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 94 | /////////////////////////////////////////////////////////////////////////////// |
| 95 | |
| 96 | #ifndef SkNEW |
| 97 | #define SkNEW(type_name) new type_name |
| 98 | #define SkNEW_ARGS(type_name, args) new type_name args |
| 99 | #define SkNEW_ARRAY(type_name, count) new type_name[count] |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 100 | #define SkNEW_PLACEMENT(buf, type_name) new (buf) type_name |
| 101 | #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \ |
| 102 | new (buf) type_name args |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | #define SkDELETE(obj) delete obj |
| 104 | #define SkDELETE_ARRAY(array) delete[] array |
| 105 | #endif |
| 106 | |
| 107 | #ifndef SK_CRASH |
| 108 | #if 1 // set to 0 for infinite loop, which can help connecting gdb |
bsalomon@google.com | b1277c9 | 2011-11-23 21:58:39 +0000 | [diff] [blame] | 109 | #define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 110 | #else |
bsalomon@google.com | b1277c9 | 2011-11-23 21:58:39 +0000 | [diff] [blame] | 111 | #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 112 | #endif |
| 113 | #endif |
| 114 | |
| 115 | /////////////////////////////////////////////////////////////////////////////// |
| 116 | |
| 117 | #if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT) |
| 118 | // if this is defined, we convert floats to 2scompliment ints for compares |
| 119 | #ifndef SK_SCALAR_SLOW_COMPARES |
| 120 | #define SK_SCALAR_SLOW_COMPARES |
| 121 | #endif |
reed@android.com | 5c80ea1 | 2009-01-08 17:49:50 +0000 | [diff] [blame] | 122 | #ifndef SK_USE_FLOATBITS |
| 123 | #define SK_USE_FLOATBITS |
| 124 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 125 | #endif |
| 126 | |
| 127 | #ifdef SK_BUILD_FOR_WIN |
reed@android.com | 16690af | 2009-04-06 16:09:53 +0000 | [diff] [blame] | 128 | // we want lean_and_mean when we include windows.h |
| 129 | #ifndef WIN32_LEAN_AND_MEAN |
| 130 | #define WIN32_LEAN_AND_MEAN |
| 131 | #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED |
| 132 | #endif |
| 133 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 134 | #include <windows.h> |
reed@android.com | 16690af | 2009-04-06 16:09:53 +0000 | [diff] [blame] | 135 | |
| 136 | #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED |
| 137 | #undef WIN32_LEAN_AND_MEAN |
| 138 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 139 | |
| 140 | #ifndef SK_DEBUGBREAK |
bsalomon@google.com | 0442380 | 2011-11-23 21:25:35 +0000 | [diff] [blame] | 141 | #define SK_DEBUGBREAK(cond) do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 142 | #endif |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 143 | |
| 144 | #ifndef SK_A32_SHIFT |
| 145 | #define SK_A32_SHIFT 24 |
| 146 | #define SK_R32_SHIFT 16 |
| 147 | #define SK_G32_SHIFT 8 |
| 148 | #define SK_B32_SHIFT 0 |
| 149 | #endif |
| 150 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 151 | #elif defined(SK_BUILD_FOR_MAC) |
| 152 | #ifndef SK_DEBUGBREAK |
| 153 | #define SK_DEBUGBREAK(cond) do { if (!(cond)) SK_CRASH(); } while (false) |
| 154 | #endif |
| 155 | #else |
| 156 | #ifdef SK_DEBUG |
| 157 | #include <stdio.h> |
| 158 | #ifndef SK_DEBUGBREAK |
| 159 | #define SK_DEBUGBREAK(cond) do { if (cond) break; \ |
| 160 | SkDebugf("%s:%d: failed assertion \"%s\"\n", \ |
| 161 | __FILE__, __LINE__, #cond); SK_CRASH(); } while (false) |
| 162 | #endif |
| 163 | #endif |
| 164 | #endif |
| 165 | |
bsalomon@google.com | 2766118 | 2011-05-19 15:57:44 +0000 | [diff] [blame] | 166 | /* |
| 167 | * We check to see if the SHIFT value has already been defined. |
| 168 | * if not, we define it ourself to some default values. We default to OpenGL |
| 169 | * order (in memory: r,g,b,a) |
| 170 | */ |
| 171 | #ifndef SK_A32_SHIFT |
| 172 | #ifdef SK_CPU_BENDIAN |
| 173 | #define SK_R32_SHIFT 24 |
| 174 | #define SK_G32_SHIFT 16 |
| 175 | #define SK_B32_SHIFT 8 |
| 176 | #define SK_A32_SHIFT 0 |
| 177 | #else |
| 178 | #define SK_R32_SHIFT 0 |
| 179 | #define SK_G32_SHIFT 8 |
| 180 | #define SK_B32_SHIFT 16 |
| 181 | #define SK_A32_SHIFT 24 |
| 182 | #endif |
| 183 | #endif |
| 184 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 185 | // stdlib macros |
| 186 | |
| 187 | #if 0 |
| 188 | #if !defined(strlen) && defined(SK_DEBUG) |
| 189 | extern size_t sk_strlen(const char*); |
| 190 | #define strlen(s) sk_strlen(s) |
| 191 | #endif |
| 192 | #ifndef sk_strcpy |
| 193 | #define sk_strcpy(dst, src) strcpy(dst, src) |
| 194 | #endif |
| 195 | #ifndef sk_strchr |
| 196 | #define sk_strchr(s, c) strchr(s, c) |
| 197 | #endif |
| 198 | #ifndef sk_strrchr |
| 199 | #define sk_strrchr(s, c) strrchr(s, c) |
| 200 | #endif |
| 201 | #ifndef sk_strcmp |
| 202 | #define sk_strcmp(s, t) strcmp(s, t) |
| 203 | #endif |
| 204 | #ifndef sk_strncmp |
| 205 | #define sk_strncmp(s, t, n) strncmp(s, t, n) |
| 206 | #endif |
| 207 | #ifndef sk_memcpy |
| 208 | #define sk_memcpy(dst, src, n) memcpy(dst, src, n) |
| 209 | #endif |
| 210 | #ifndef memmove |
| 211 | #define memmove(dst, src, n) memmove(dst, src, n) |
| 212 | #endif |
| 213 | #ifndef sk_memset |
| 214 | #define sk_memset(dst, val, n) memset(dst, val, n) |
| 215 | #endif |
| 216 | #ifndef sk_memcmp |
| 217 | #define sk_memcmp(s, t, n) memcmp(s, t, n) |
| 218 | #endif |
| 219 | |
| 220 | #define sk_strequal(s, t) (!sk_strcmp(s, t)) |
| 221 | #define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n)) |
| 222 | #endif |
| 223 | |
reed@android.com | 5c80ea1 | 2009-01-08 17:49:50 +0000 | [diff] [blame] | 224 | ////////////////////////////////////////////////////////////////////// |
| 225 | |
| 226 | #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) |
| 227 | #ifndef SkLONGLONG |
| 228 | #ifdef SK_BUILD_FOR_WIN32 |
| 229 | #define SkLONGLONG __int64 |
| 230 | #else |
| 231 | #define SkLONGLONG long long |
| 232 | #endif |
| 233 | #endif |
| 234 | #endif |
| 235 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 236 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 237 | #ifndef SK_BUILD_FOR_WINCE |
| 238 | #include <string.h> |
| 239 | #include <stdlib.h> |
| 240 | #else |
| 241 | #define _CMNINTRIN_DECLARE_ONLY |
| 242 | #include "cmnintrin.h" |
| 243 | #endif |
| 244 | |
| 245 | #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32 |
| 246 | //#define _CRTDBG_MAP_ALLOC |
| 247 | #ifdef free |
| 248 | #undef free |
| 249 | #endif |
| 250 | #include <crtdbg.h> |
| 251 | #undef free |
| 252 | |
| 253 | #ifdef SK_DEBUGx |
| 254 | #if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus) |
| 255 | void * operator new( |
| 256 | size_t cb, |
| 257 | int nBlockUse, |
| 258 | const char * szFileName, |
| 259 | int nLine, |
| 260 | int foo |
| 261 | ); |
| 262 | void * operator new[]( |
| 263 | size_t cb, |
| 264 | int nBlockUse, |
| 265 | const char * szFileName, |
| 266 | int nLine, |
| 267 | int foo |
| 268 | ); |
| 269 | void operator delete( |
| 270 | void *pUserData, |
| 271 | int, const char*, int, int |
| 272 | ); |
| 273 | void operator delete( |
| 274 | void *pUserData |
| 275 | ); |
| 276 | void operator delete[]( void * p ); |
| 277 | #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0) |
| 278 | #else |
| 279 | #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) |
| 280 | #endif |
| 281 | #define new DEBUG_CLIENTBLOCK |
| 282 | #else |
| 283 | #define DEBUG_CLIENTBLOCK |
| 284 | #endif // _DEBUG |
| 285 | |
tomhudson@google.com | 1341304 | 2011-10-03 16:01:10 +0000 | [diff] [blame] | 286 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 287 | #endif |
| 288 | |
| 289 | #endif |
| 290 | |
tomhudson@google.com | 1341304 | 2011-10-03 16:01:10 +0000 | [diff] [blame] | 291 | ////////////////////////////////////////////////////////////////////// |
| 292 | |
| 293 | #ifndef SK_OVERRIDE |
george@mozilla.com | ece0100 | 2012-07-25 19:05:43 +0000 | [diff] [blame] | 294 | #if defined(_MSC_VER) |
| 295 | #define SK_OVERRIDE override |
caryclark@google.com | 867cbd8 | 2012-09-20 15:45:41 +0000 | [diff] [blame] | 296 | #elif defined(__clang__) && !defined(SK_BUILD_FOR_IOS) |
george@mozilla.com | ece0100 | 2012-07-25 19:05:43 +0000 | [diff] [blame] | 297 | #if __has_feature(cxx_override_control) |
| 298 | // Some documentation suggests we should be using __attribute__((override)), |
| 299 | // but it doesn't work. |
| 300 | #define SK_OVERRIDE override |
| 301 | #elif defined(__has_extension) |
| 302 | #if __has_extension(cxx_override_control) |
| 303 | #define SK_OVERRIDE override |
| 304 | #endif |
| 305 | #endif |
| 306 | #else |
| 307 | // Linux GCC ignores "__attribute__((override))" and rejects "override". |
| 308 | #define SK_OVERRIDE |
| 309 | #endif |
tomhudson@google.com | 1341304 | 2011-10-03 16:01:10 +0000 | [diff] [blame] | 310 | #endif |
| 311 | |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 312 | ////////////////////////////////////////////////////////////////////// |
| 313 | |
senorblanco@chromium.org | 3a67a66 | 2012-07-09 18:22:08 +0000 | [diff] [blame] | 314 | #ifndef SK_PRINTF_LIKE |
| 315 | #if defined(__clang__) || defined(__GNUC__) |
| 316 | #define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) |
| 317 | #else |
| 318 | #define SK_PRINTF_LIKE(A, B) |
| 319 | #endif |
| 320 | #endif |
| 321 | |
| 322 | ////////////////////////////////////////////////////////////////////// |
| 323 | |
| 324 | #ifndef SK_SIZE_T_SPECIFIER |
| 325 | #if defined(_MSC_VER) |
| 326 | #define SK_SIZE_T_SPECIFIER "%Iu" |
| 327 | #else |
| 328 | #define SK_SIZE_T_SPECIFIER "%zu" |
| 329 | #endif |
| 330 | #endif |
| 331 | |
| 332 | ////////////////////////////////////////////////////////////////////// |
| 333 | |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 334 | #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 335 | #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1 |
| 336 | #endif |