Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Side by Side Diff: include/core/SkTypes.h

Issue 2372083002: Revert of My take on SkAlign changes. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests/MathTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // Can be used to bracket data types that must be dense, e.g. hash keys. 325 // Can be used to bracket data types that must be dense, e.g. hash keys.
326 #if defined(__clang__) // This should work on GCC too, but GCC diagnostic pop d idn't seem to work! 326 #if defined(__clang__) // This should work on GCC too, but GCC diagnostic pop d idn't seem to work!
327 #define SK_BEGIN_REQUIRE_DENSE _Pragma("GCC diagnostic push") \ 327 #define SK_BEGIN_REQUIRE_DENSE _Pragma("GCC diagnostic push") \
328 _Pragma("GCC diagnostic error \"-Wpadded\"") 328 _Pragma("GCC diagnostic error \"-Wpadded\"")
329 #define SK_END_REQUIRE_DENSE _Pragma("GCC diagnostic pop") 329 #define SK_END_REQUIRE_DENSE _Pragma("GCC diagnostic pop")
330 #else 330 #else
331 #define SK_BEGIN_REQUIRE_DENSE 331 #define SK_BEGIN_REQUIRE_DENSE
332 #define SK_END_REQUIRE_DENSE 332 #define SK_END_REQUIRE_DENSE
333 #endif 333 #endif
334 334
335 template <int N, typename T> 335 #define SkAlign2(x) (((x) + 1) >> 1 << 1)
336 struct SkAlign_traits { 336 #define SkIsAlign2(x) (0 == ((x) & 1))
337 static_assert (N > 0 && (N & (N-1)) == 0, "N must be a positive power of 2." );
338 constexpr static int Lg(int k) { return (k == 1) ? 0 : 1 + Lg(k/2); }
339 337
340 constexpr static T Align(T x) { return (x + N-1) >> Lg(N) << Lg(N); } 338 #define SkAlign4(x) (((x) + 3) >> 2 << 2)
341 constexpr static bool IsAligned(T x) { return 0 == (x & (N-1)); } 339 #define SkIsAlign4(x) (0 == ((x) & 3))
342 };
343 340
344 template <int N, typename P> 341 #define SkAlign8(x) (((x) + 7) >> 3 << 3)
345 struct SkAlign_traits<N, P*> { 342 #define SkIsAlign8(x) (0 == ((x) & 7))
346 constexpr static P* Align(P* p) {
347 return (P*)SkAlign_traits<N, uintptr_t>::Align((uintptr_t)p);
348 }
349 constexpr static bool IsAligned(P* p) {
350 return SkAlign_traits<N, uintptr_t>::IsAligned((uintptr_t)p);
351 }
352 };
353 343
354 template <int N, typename T> 344 #define SkAlign16(x) (((x) + 15) >> 4 << 4)
355 constexpr static inline T SkAlign(T x) { return SkAlign_traits<N,T>::Align(x); } 345 #define SkIsAlign16(x) (0 == ((x) & 15))
356 346
357 template <int N, typename T> 347 #define SkAlignPtr(x) (sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x))
358 constexpr static bool SkIsAligned(T x) { return SkAlign_traits<N,T>::IsAligned(x ); } 348 #define SkIsAlignPtr(x) (sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x))
359
360 #define SkAlign2(x) SkAlign<2>(x)
361 #define SkIsAlign2(x) SkIsAligned<2>(x)
362
363 #define SkAlign4(x) SkAlign<4>(x)
364 #define SkIsAlign4(x) SkIsAligned<4>(x)
365
366 #define SkAlign8(x) SkAlign<8>(x)
367 #define SkIsAlign8(x) SkIsAligned<8>(x)
368
369 #define SkAlign16(x) SkAlign<16>(x)
370 #define SkIsAlign16(x) SkIsAligned<16>(x)
371
372 #define SkAlignPtr(x) SkAlign<sizeof(void*)>(x)
373 #define SkIsAlignPtr(x) SkIsAligned<sizeof(void*)>(x)
374 349
375 typedef uint32_t SkFourByteTag; 350 typedef uint32_t SkFourByteTag;
376 #define SkSetFourByteTag(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) 351 #define SkSetFourByteTag(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
377 352
378 /** 32 bit integer to hold a unicode value 353 /** 32 bit integer to hold a unicode value
379 */ 354 */
380 typedef int32_t SkUnichar; 355 typedef int32_t SkUnichar;
381 356
382 /** 16 bit unsigned integer to hold a glyph index 357 /** 16 bit unsigned integer to hold a glyph index
383 */ 358 */
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 721
747 void* fPtr; 722 void* fPtr;
748 size_t fSize; // can be larger than the requested size (see kReuse) 723 size_t fSize; // can be larger than the requested size (see kReuse)
749 uint32_t fStorage[kSize >> 2]; 724 uint32_t fStorage[kSize >> 2];
750 }; 725 };
751 // Can't guard the constructor because it's a template class. 726 // Can't guard the constructor because it's a template class.
752 727
753 #endif /* C++ */ 728 #endif /* C++ */
754 729
755 #endif 730 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/MathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698