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 | 672d5c2 | 2013-01-02 20:33:18 +0000 | [diff] [blame] | 79 | static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn)); |
| 80 | static inline void SkNO_RETURN_HINT() {} |
bsalomon@google.com | 0442380 | 2011-11-23 21:25:35 +0000 | [diff] [blame] | 81 | #else |
| 82 | #define SkNO_RETURN_HINT() do {} while (false) |
| 83 | #endif |
| 84 | #endif |
| 85 | |
justinlin@google.com | fffb2f1 | 2012-04-16 19:10:21 +0000 | [diff] [blame] | 86 | #if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB) |
| 87 | #error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB" |
| 88 | #elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB) |
| 89 | #define SK_HAS_ZLIB |
| 90 | #endif |
| 91 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 92 | /////////////////////////////////////////////////////////////////////////////// |
| 93 | |
| 94 | #ifndef SkNEW |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 95 | #define SkNEW(type_name) (new type_name) |
| 96 | #define SkNEW_ARGS(type_name, args) (new type_name args) |
| 97 | #define SkNEW_ARRAY(type_name, count) (new type_name[(count)]) |
| 98 | #define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name) |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 99 | #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \ |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 100 | (new (buf) type_name args) |
| 101 | #define SkDELETE(obj) (delete (obj)) |
| 102 | #define SkDELETE_ARRAY(array) (delete[] (array)) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | #endif |
| 104 | |
| 105 | #ifndef SK_CRASH |
| 106 | #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] | 107 | #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] | 108 | #else |
bsalomon@google.com | b1277c9 | 2011-11-23 21:58:39 +0000 | [diff] [blame] | 109 | #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 110 | #endif |
| 111 | #endif |
| 112 | |
| 113 | /////////////////////////////////////////////////////////////////////////////// |
| 114 | |
bsalomon@google.com | 4e23068 | 2013-01-15 20:37:04 +0000 | [diff] [blame] | 115 | // SK_ENABLE_INST_COUNT defaults to 1 in DEBUG and 0 in RELEASE |
| 116 | #ifndef SK_ENABLE_INST_COUNT |
| 117 | #ifdef SK_DEBUG |
| 118 | #define SK_ENABLE_INST_COUNT 1 |
| 119 | #else |
| 120 | #define SK_ENABLE_INST_COUNT 0 |
| 121 | #endif |
| 122 | #endif |
| 123 | |
| 124 | /////////////////////////////////////////////////////////////////////////////// |
| 125 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 126 | #if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT) |
| 127 | // if this is defined, we convert floats to 2scompliment ints for compares |
| 128 | #ifndef SK_SCALAR_SLOW_COMPARES |
| 129 | #define SK_SCALAR_SLOW_COMPARES |
| 130 | #endif |
reed@android.com | 5c80ea1 | 2009-01-08 17:49:50 +0000 | [diff] [blame] | 131 | #ifndef SK_USE_FLOATBITS |
| 132 | #define SK_USE_FLOATBITS |
| 133 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 134 | #endif |
| 135 | |
| 136 | #ifdef SK_BUILD_FOR_WIN |
reed@android.com | 16690af | 2009-04-06 16:09:53 +0000 | [diff] [blame] | 137 | // we want lean_and_mean when we include windows.h |
| 138 | #ifndef WIN32_LEAN_AND_MEAN |
| 139 | #define WIN32_LEAN_AND_MEAN |
| 140 | #define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED |
| 141 | #endif |
| 142 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | #include <windows.h> |
reed@android.com | 16690af | 2009-04-06 16:09:53 +0000 | [diff] [blame] | 144 | |
| 145 | #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED |
| 146 | #undef WIN32_LEAN_AND_MEAN |
| 147 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 148 | |
| 149 | #ifndef SK_DEBUGBREAK |
bsalomon@google.com | 0442380 | 2011-11-23 21:25:35 +0000 | [diff] [blame] | 150 | #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] | 151 | #endif |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 152 | |
| 153 | #ifndef SK_A32_SHIFT |
| 154 | #define SK_A32_SHIFT 24 |
| 155 | #define SK_R32_SHIFT 16 |
| 156 | #define SK_G32_SHIFT 8 |
| 157 | #define SK_B32_SHIFT 0 |
| 158 | #endif |
| 159 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 160 | #else |
| 161 | #ifdef SK_DEBUG |
| 162 | #include <stdio.h> |
| 163 | #ifndef SK_DEBUGBREAK |
| 164 | #define SK_DEBUGBREAK(cond) do { if (cond) break; \ |
| 165 | SkDebugf("%s:%d: failed assertion \"%s\"\n", \ |
| 166 | __FILE__, __LINE__, #cond); SK_CRASH(); } while (false) |
| 167 | #endif |
| 168 | #endif |
| 169 | #endif |
| 170 | |
bsalomon@google.com | 2766118 | 2011-05-19 15:57:44 +0000 | [diff] [blame] | 171 | /* |
| 172 | * We check to see if the SHIFT value has already been defined. |
| 173 | * if not, we define it ourself to some default values. We default to OpenGL |
| 174 | * order (in memory: r,g,b,a) |
| 175 | */ |
| 176 | #ifndef SK_A32_SHIFT |
| 177 | #ifdef SK_CPU_BENDIAN |
| 178 | #define SK_R32_SHIFT 24 |
| 179 | #define SK_G32_SHIFT 16 |
| 180 | #define SK_B32_SHIFT 8 |
| 181 | #define SK_A32_SHIFT 0 |
| 182 | #else |
| 183 | #define SK_R32_SHIFT 0 |
| 184 | #define SK_G32_SHIFT 8 |
| 185 | #define SK_B32_SHIFT 16 |
| 186 | #define SK_A32_SHIFT 24 |
| 187 | #endif |
| 188 | #endif |
| 189 | |
commit-bot@chromium.org | e4657ed | 2013-03-19 14:16:31 +0000 | [diff] [blame] | 190 | /** |
| 191 | * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The |
| 192 | * relationship between the byte order and shift values depends on machine endianness. If the shift |
| 193 | * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little |
| 194 | * endian machine and the A channel on a big endian machine. Thus, given those shifts values, |
| 195 | * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and |
| 196 | * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine. |
| 197 | */ |
| 198 | #ifdef SK_CPU_BENDIAN |
| 199 | #define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \ |
| 200 | (SK_ ## C3 ## 32_SHIFT == 0 && \ |
| 201 | SK_ ## C2 ## 32_SHIFT == 8 && \ |
| 202 | SK_ ## C1 ## 32_SHIFT == 16 && \ |
| 203 | SK_ ## C0 ## 32_SHIFT == 24) |
| 204 | #else |
| 205 | #define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \ |
| 206 | (SK_ ## C0 ## 32_SHIFT == 0 && \ |
| 207 | SK_ ## C1 ## 32_SHIFT == 8 && \ |
| 208 | SK_ ## C2 ## 32_SHIFT == 16 && \ |
| 209 | SK_ ## C3 ## 32_SHIFT == 24) |
| 210 | #endif |
| 211 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 212 | // stdlib macros |
| 213 | |
| 214 | #if 0 |
| 215 | #if !defined(strlen) && defined(SK_DEBUG) |
| 216 | extern size_t sk_strlen(const char*); |
| 217 | #define strlen(s) sk_strlen(s) |
| 218 | #endif |
| 219 | #ifndef sk_strcpy |
| 220 | #define sk_strcpy(dst, src) strcpy(dst, src) |
| 221 | #endif |
| 222 | #ifndef sk_strchr |
| 223 | #define sk_strchr(s, c) strchr(s, c) |
| 224 | #endif |
| 225 | #ifndef sk_strrchr |
| 226 | #define sk_strrchr(s, c) strrchr(s, c) |
| 227 | #endif |
| 228 | #ifndef sk_strcmp |
| 229 | #define sk_strcmp(s, t) strcmp(s, t) |
| 230 | #endif |
| 231 | #ifndef sk_strncmp |
| 232 | #define sk_strncmp(s, t, n) strncmp(s, t, n) |
| 233 | #endif |
| 234 | #ifndef sk_memcpy |
| 235 | #define sk_memcpy(dst, src, n) memcpy(dst, src, n) |
| 236 | #endif |
| 237 | #ifndef memmove |
| 238 | #define memmove(dst, src, n) memmove(dst, src, n) |
| 239 | #endif |
| 240 | #ifndef sk_memset |
| 241 | #define sk_memset(dst, val, n) memset(dst, val, n) |
| 242 | #endif |
| 243 | #ifndef sk_memcmp |
| 244 | #define sk_memcmp(s, t, n) memcmp(s, t, n) |
| 245 | #endif |
| 246 | |
| 247 | #define sk_strequal(s, t) (!sk_strcmp(s, t)) |
| 248 | #define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n)) |
| 249 | #endif |
| 250 | |
reed@android.com | 5c80ea1 | 2009-01-08 17:49:50 +0000 | [diff] [blame] | 251 | ////////////////////////////////////////////////////////////////////// |
| 252 | |
| 253 | #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC) |
| 254 | #ifndef SkLONGLONG |
| 255 | #ifdef SK_BUILD_FOR_WIN32 |
| 256 | #define SkLONGLONG __int64 |
| 257 | #else |
| 258 | #define SkLONGLONG long long |
| 259 | #endif |
| 260 | #endif |
| 261 | #endif |
| 262 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 263 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 264 | #ifndef SK_BUILD_FOR_WINCE |
| 265 | #include <string.h> |
| 266 | #include <stdlib.h> |
| 267 | #else |
| 268 | #define _CMNINTRIN_DECLARE_ONLY |
| 269 | #include "cmnintrin.h" |
| 270 | #endif |
| 271 | |
| 272 | #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32 |
| 273 | //#define _CRTDBG_MAP_ALLOC |
| 274 | #ifdef free |
| 275 | #undef free |
| 276 | #endif |
| 277 | #include <crtdbg.h> |
| 278 | #undef free |
| 279 | |
| 280 | #ifdef SK_DEBUGx |
| 281 | #if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus) |
| 282 | void * operator new( |
| 283 | size_t cb, |
| 284 | int nBlockUse, |
| 285 | const char * szFileName, |
| 286 | int nLine, |
| 287 | int foo |
| 288 | ); |
| 289 | void * operator new[]( |
| 290 | size_t cb, |
| 291 | int nBlockUse, |
| 292 | const char * szFileName, |
| 293 | int nLine, |
| 294 | int foo |
| 295 | ); |
| 296 | void operator delete( |
| 297 | void *pUserData, |
| 298 | int, const char*, int, int |
| 299 | ); |
| 300 | void operator delete( |
| 301 | void *pUserData |
| 302 | ); |
| 303 | void operator delete[]( void * p ); |
| 304 | #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0) |
| 305 | #else |
| 306 | #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) |
| 307 | #endif |
| 308 | #define new DEBUG_CLIENTBLOCK |
| 309 | #else |
| 310 | #define DEBUG_CLIENTBLOCK |
| 311 | #endif // _DEBUG |
| 312 | |
tomhudson@google.com | 1341304 | 2011-10-03 16:01:10 +0000 | [diff] [blame] | 313 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 314 | #endif |
| 315 | |
| 316 | #endif |
| 317 | |
tomhudson@google.com | 1341304 | 2011-10-03 16:01:10 +0000 | [diff] [blame] | 318 | ////////////////////////////////////////////////////////////////////// |
| 319 | |
| 320 | #ifndef SK_OVERRIDE |
george@mozilla.com | ece0100 | 2012-07-25 19:05:43 +0000 | [diff] [blame] | 321 | #if defined(_MSC_VER) |
| 322 | #define SK_OVERRIDE override |
caryclark@google.com | 867cbd8 | 2012-09-20 15:45:41 +0000 | [diff] [blame] | 323 | #elif defined(__clang__) && !defined(SK_BUILD_FOR_IOS) |
george@mozilla.com | ece0100 | 2012-07-25 19:05:43 +0000 | [diff] [blame] | 324 | #if __has_feature(cxx_override_control) |
| 325 | // Some documentation suggests we should be using __attribute__((override)), |
| 326 | // but it doesn't work. |
| 327 | #define SK_OVERRIDE override |
| 328 | #elif defined(__has_extension) |
| 329 | #if __has_extension(cxx_override_control) |
| 330 | #define SK_OVERRIDE override |
| 331 | #endif |
| 332 | #endif |
| 333 | #else |
| 334 | // Linux GCC ignores "__attribute__((override))" and rejects "override". |
| 335 | #define SK_OVERRIDE |
| 336 | #endif |
tomhudson@google.com | 1341304 | 2011-10-03 16:01:10 +0000 | [diff] [blame] | 337 | #endif |
| 338 | |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 339 | ////////////////////////////////////////////////////////////////////// |
| 340 | |
senorblanco@chromium.org | 3a67a66 | 2012-07-09 18:22:08 +0000 | [diff] [blame] | 341 | #ifndef SK_PRINTF_LIKE |
| 342 | #if defined(__clang__) || defined(__GNUC__) |
| 343 | #define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B)))) |
| 344 | #else |
| 345 | #define SK_PRINTF_LIKE(A, B) |
| 346 | #endif |
| 347 | #endif |
| 348 | |
| 349 | ////////////////////////////////////////////////////////////////////// |
| 350 | |
| 351 | #ifndef SK_SIZE_T_SPECIFIER |
| 352 | #if defined(_MSC_VER) |
| 353 | #define SK_SIZE_T_SPECIFIER "%Iu" |
| 354 | #else |
| 355 | #define SK_SIZE_T_SPECIFIER "%zu" |
| 356 | #endif |
| 357 | #endif |
| 358 | |
| 359 | ////////////////////////////////////////////////////////////////////// |
| 360 | |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 361 | #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
| 362 | #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1 |
| 363 | #endif |