diff options
author | Hal Canary <halcanary@google.com> | 2018-06-12 14:16:11 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-12 19:31:04 +0000 |
commit | bc718c1e9ce0b4c2d10458f4c3549fd98e10a9f2 (patch) | |
tree | 22f1f039c8c71e21eb1b59281fef9f24fcb73777 /include/core | |
parent | d9d33c33dee064da260301faa313703e465d44c5 (diff) |
SkTypes: templates are usually better than macros
Change-Id: If55797642e839154ca06d09c991257031e1d319e
Reviewed-on: https://skia-review.googlesource.com/134331
Commit-Queue: Hal Canary <halcanary@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkTypes.h | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 65867509e5..ef27a7f42b 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -78,6 +78,8 @@ SK_API extern void sk_abort_no_print(void); #define SkAssertResult(cond) if (cond) {} do {} while(false) #endif +//////////////////////////////////////////////////////////////////////////////// + // some clients (e.g. third_party/WebKit/Source/platform/fonts/FontCustomPlatformData.h) // depend on SkString forward declaration below. Remove this once dependencies are fixed. class SkString; @@ -124,11 +126,11 @@ typedef uint8_t SkBool8; static constexpr int64_t SK_MaxS64 = 0x7FFFFFFFFFFFFFFF; static constexpr int64_t SK_MinS64 = -SK_MaxS64; -static inline int32_t SkLeftShift(int32_t value, int32_t shift) { +inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { return (int32_t) ((uint32_t) value << shift); } -static inline int64_t SkLeftShift(int64_t value, int32_t shift) { +inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { return (int64_t) ((uint64_t) value << shift); } @@ -148,20 +150,29 @@ template <typename T, size_t N> char (&SkArrayCountHelper(T (&array)[N]))[N]; #define SK_END_REQUIRE_DENSE #endif -#define SkAlign2(x) (((x) + 1) >> 1 << 1) -#define SkIsAlign2(x) (0 == ((x) & 1)) +//////////////////////////////////////////////////////////////////////////////// -#define SkAlign4(x) (((x) + 3) >> 2 << 2) -#define SkIsAlign4(x) (0 == ((x) & 3)) +template <typename T> inline constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } +template <typename T> inline constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } +template <typename T> inline constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } -#define SkAlign8(x) (((x) + 7) >> 3 << 3) -#define SkIsAlign8(x) (0 == ((x) & 7)) +template <typename T> inline constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } +template <typename T> inline constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } +template <typename T> inline constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } -#define SkAlignPtr(x) (sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x)) -#define SkIsAlignPtr(x) (sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x)) +template <typename T> inline constexpr T SkAlignPtr(T x) { + return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); +} +template <typename T> inline constexpr bool SkIsAlignPtr(T x) { + return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); +} typedef uint32_t SkFourByteTag; -#define SkSetFourByteTag(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) +inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) { + return (((uint8_t)a << 24) | ((uint8_t)b << 16) | ((uint8_t)c << 8) | (uint8_t)d); +} + +//////////////////////////////////////////////////////////////////////////////// /** 32 bit integer to hold a unicode value */ |