diff options
Diffstat (limited to 'include/core/SkTypes.h')
-rw-r--r-- | include/core/SkTypes.h | 35 |
1 files changed, 14 insertions, 21 deletions
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index 1051f08cea..d7a791163b 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -256,27 +256,20 @@ typedef unsigned U16CPU; */ typedef uint8_t SkBool8; -#ifdef SK_DEBUG - SK_API int8_t SkToS8(intmax_t); - SK_API uint8_t SkToU8(uintmax_t); - SK_API int16_t SkToS16(intmax_t); - SK_API uint16_t SkToU16(uintmax_t); - SK_API int32_t SkToS32(intmax_t); - SK_API uint32_t SkToU32(uintmax_t); - SK_API int SkToInt(intmax_t); - SK_API unsigned SkToUInt(uintmax_t); - SK_API size_t SkToSizeT(uintmax_t); -#else - #define SkToS8(x) ((int8_t)(x)) - #define SkToU8(x) ((uint8_t)(x)) - #define SkToS16(x) ((int16_t)(x)) - #define SkToU16(x) ((uint16_t)(x)) - #define SkToS32(x) ((int32_t)(x)) - #define SkToU32(x) ((uint32_t)(x)) - #define SkToInt(x) ((int)(x)) - #define SkToUInt(x) ((unsigned)(x)) - #define SkToSizeT(x) ((size_t)(x)) -#endif +#include "../private/SkTFitsIn.h" +template <typename D, typename S> D SkTo(S s) { + SkASSERT(SkTFitsIn<D>(s)); + return static_cast<D>(s); +} +#define SkToS8(x) SkTo<int8_t>(x) +#define SkToU8(x) SkTo<uint8_t>(x) +#define SkToS16(x) SkTo<int16_t>(x) +#define SkToU16(x) SkTo<uint16_t>(x) +#define SkToS32(x) SkTo<int32_t>(x) +#define SkToU32(x) SkTo<uint32_t>(x) +#define SkToInt(x) SkTo<int>(x) +#define SkToUInt(x) SkTo<unsigned>(x) +#define SkToSizeT(x) SkTo<size_t>(x) /** Returns 0 or 1 based on the condition */ |