diff options
Diffstat (limited to 'include/private')
-rw-r--r-- | include/private/SkFixed.h | 4 | ||||
-rw-r--r-- | include/private/SkPathRef.h | 7 | ||||
-rw-r--r-- | include/private/SkTDArray.h | 4 | ||||
-rw-r--r-- | include/private/SkTo.h | 28 |
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 |