aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/private
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2018-06-13 09:59:02 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-14 14:55:17 +0000
commitc640d0dc96924699fdbb1a3cbdc907aa07b1cb3c (patch)
treed8973c4700da0bbe95c73bb3bc0c7d8f4589186d /include/private
parent4d4665436e540bd2ca393c139cbaff1eabd62ee2 (diff)
Revert "Revert "SkTypes: extract SkTo""
This reverts commit fdcfb8b7c23fbf18f872d2c31d27978235033876. > Original change's description: > > SkTypes: extract SkTo > > > > Change-Id: I8de790d5013db2105ad885fa2683303d7c250b09 > > Reviewed-on: https://skia-review.googlesource.com/133620 > > Reviewed-by: Mike Klein <mtklein@google.com> Change-Id: Ida74fbc5c21248a724a5edbf9fae18a33bcb23aa Reviewed-on: https://skia-review.googlesource.com/134506 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'include/private')
-rw-r--r--include/private/SkFixed.h4
-rw-r--r--include/private/SkPathRef.h7
-rw-r--r--include/private/SkTDArray.h4
-rw-r--r--include/private/SkTo.h28
4 files changed, 36 insertions, 7 deletions
diff --git a/include/private/SkFixed.h b/include/private/SkFixed.h
index 15062f55b3..0d15e02aa9 100644
--- a/include/private/SkFixed.h
+++ b/include/private/SkFixed.h
@@ -8,9 +8,9 @@
#ifndef SkFixed_DEFINED
#define SkFixed_DEFINED
-#include "SkScalar.h"
#include "SkSafe_math.h"
-
+#include "SkScalar.h"
+#include "SkTo.h"
#include "SkTypes.h"
/** \file SkFixed.h
diff --git a/include/private/SkPathRef.h b/include/private/SkPathRef.h
index 5f64f1ae07..5a5a04118c 100644
--- a/include/private/SkPathRef.h
+++ b/include/private/SkPathRef.h
@@ -1,4 +1,3 @@
-
/*
* Copyright 2012 Google Inc.
*
@@ -9,14 +8,16 @@
#ifndef SkPathRef_DEFINED
#define SkPathRef_DEFINED
-#include "../private/SkAtomics.h"
-#include "../private/SkTDArray.h"
+#include "SkAtomics.h"
#include "SkMatrix.h"
#include "SkPoint.h"
#include "SkRRect.h"
#include "SkRect.h"
#include "SkRefCnt.h"
+#include "SkTDArray.h"
#include "SkTemplates.h"
+#include "SkTo.h"
+
#include <limits>
class SkRBuffer;
diff --git a/include/private/SkTDArray.h b/include/private/SkTDArray.h
index b030dc5627..dd3212d0dd 100644
--- a/include/private/SkTDArray.h
+++ b/include/private/SkTDArray.h
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -10,8 +9,9 @@
#ifndef SkTDArray_DEFINED
#define SkTDArray_DEFINED
-#include "SkTypes.h"
#include "SkMalloc.h"
+#include "SkTo.h"
+#include "SkTypes.h"
template <typename T> class SkTDArray {
public:
diff --git a/include/private/SkTo.h b/include/private/SkTo.h
new file mode 100644
index 0000000000..9b5b7fd164
--- /dev/null
+++ b/include/private/SkTo.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkTo_DEFINED
+#define SkTo_DEFINED
+
+#include "SkTypes.h"
+#include "SkTFitsIn.h"
+
+template <typename D, typename S> constexpr D SkTo(S s) {
+ return SkASSERT(SkTFitsIn<D>(s)),
+ static_cast<D>(s);
+}
+
+template <typename S> constexpr int8_t SkToS8(S x) { return SkTo<int8_t>(x); }
+template <typename S> constexpr uint8_t SkToU8(S x) { return SkTo<uint8_t>(x); }
+template <typename S> constexpr int16_t SkToS16(S x) { return SkTo<int16_t>(x); }
+template <typename S> constexpr uint16_t SkToU16(S x) { return SkTo<uint16_t>(x); }
+template <typename S> constexpr int32_t SkToS32(S x) { return SkTo<int32_t>(x); }
+template <typename S> constexpr uint32_t SkToU32(S x) { return SkTo<uint32_t>(x); }
+template <typename S> constexpr int SkToInt(S x) { return SkTo<int>(x); }
+template <typename S> constexpr unsigned SkToUInt(S x) { return SkTo<unsigned>(x); }
+template <typename S> constexpr size_t SkToSizeT(S x) { return SkTo<size_t>(x); }
+
+#endif // SkTo_DEFINED