OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTypes_DEFINED | 8 #ifndef SkTypes_DEFINED |
9 #define SkTypes_DEFINED | 9 #define SkTypes_DEFINED |
10 | 10 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 */ | 289 */ |
290 static inline bool SkIsU16(long x) { | 290 static inline bool SkIsU16(long x) { |
291 return (uint16_t)x == x; | 291 return (uint16_t)x == x; |
292 } | 292 } |
293 | 293 |
294 ////////////////////////////////////////////////////////////////////////////// | 294 ////////////////////////////////////////////////////////////////////////////// |
295 #ifndef SK_OFFSETOF | 295 #ifndef SK_OFFSETOF |
296 #define SK_OFFSETOF(type, field) (size_t)((char*)&(((type*)1)->field) - (
char*)1) | 296 #define SK_OFFSETOF(type, field) (size_t)((char*)&(((type*)1)->field) - (
char*)1) |
297 #endif | 297 #endif |
298 | 298 |
| 299 // The SK_ARRAY_COUNT(arr) macro returns the # of elements in an array arr. |
| 300 // The expression is a compile-time constant, and therefore can be |
| 301 // used in defining new arrays, for example. If you use SK_ARRAY_COUNT on |
| 302 // a pointer by mistake, you will get a compile-time error. |
| 303 // |
| 304 // This template function declaration is used in defining SK_ARRAY_COUNT. |
| 305 // Note that the function doesn't need an implementation, as we only |
| 306 // use its type. |
| 307 template <typename T, size_t N> |
| 308 char (&ArraySizeHelper(T (&array)[N]))[N]; |
| 309 |
| 310 // That gcc wants both of these prototypes seems mysterious. VC, for |
| 311 // its part, can't decide which to use (another mystery). Matching of |
| 312 // template overloads: the final frontier. |
| 313 #ifndef _MSC_VER |
| 314 template <typename T, size_t N> |
| 315 char (&ArraySizeHelper(const T (&array)[N]))[N]; |
| 316 #endif |
| 317 |
299 /** Returns the number of entries in an array (not a pointer) | 318 /** Returns the number of entries in an array (not a pointer) |
300 */ | 319 */ |
301 #define SK_ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) | 320 #define SK_ARRAY_COUNT(array) (sizeof(::ArraySizeHelper(array))) |
302 | 321 |
303 #define SkAlign2(x) (((x) + 1) >> 1 << 1) | 322 #define SkAlign2(x) (((x) + 1) >> 1 << 1) |
304 #define SkIsAlign2(x) (0 == ((x) & 1)) | 323 #define SkIsAlign2(x) (0 == ((x) & 1)) |
305 | 324 |
306 #define SkAlign4(x) (((x) + 3) >> 2 << 2) | 325 #define SkAlign4(x) (((x) + 3) >> 2 << 2) |
307 #define SkIsAlign4(x) (0 == ((x) & 3)) | 326 #define SkIsAlign4(x) (0 == ((x) & 3)) |
308 | 327 |
309 #define SkAlign8(x) (((x) + 7) >> 3 << 3) | 328 #define SkAlign8(x) (((x) + 7) >> 3 << 3) |
310 #define SkIsAlign8(x) (0 == ((x) & 7)) | 329 #define SkIsAlign8(x) (0 == ((x) & 7)) |
311 | 330 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 private: | 694 private: |
676 void* fPtr; | 695 void* fPtr; |
677 size_t fSize; // can be larger than the requested size (see kReuse) | 696 size_t fSize; // can be larger than the requested size (see kReuse) |
678 uint32_t fStorage[(kSize + 3) >> 2]; | 697 uint32_t fStorage[(kSize + 3) >> 2]; |
679 }; | 698 }; |
680 // Can't guard the constructor because it's a template class. | 699 // Can't guard the constructor because it's a template class. |
681 | 700 |
682 #endif /* C++ */ | 701 #endif /* C++ */ |
683 | 702 |
684 #endif | 703 #endif |
OLD | NEW |