aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkTypes.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/core/SkTypes.h')
-rw-r--r--include/core/SkTypes.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index ba747ef2f1..3e9dea6b21 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -102,6 +102,26 @@ typedef int S16CPU;
*/
typedef unsigned U16CPU;
+/**
+ * Meant to be a small version of bool, for storage purposes. Will be 0 or 1
+ */
+typedef uint8_t SkBool8;
+
+#include "../private/SkTFitsIn.h"
+template <typename D, typename S> constexpr D SkTo(S s) {
+ return SkASSERT(SkTFitsIn<D>(s)),
+ 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
*/
#define SkToBool(cond) ((cond) != 0)