aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkImageInfo.h5
-rw-r--r--include/core/SkMath.h19
-rw-r--r--include/core/SkRect.h3
-rw-r--r--src/codec/SkWebpCodec.cpp2
-rw-r--r--src/core/SkBitmapProcState_utils.h2
-rw-r--r--src/core/SkMask.cpp4
-rw-r--r--src/core/SkMipMap.cpp4
-rw-r--r--src/core/SkPicture.cpp2
-rw-r--r--src/core/SkRegionPriv.h2
-rw-r--r--src/core/SkWriteBuffer.cpp4
10 files changed, 16 insertions, 31 deletions
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index 48edcd2181..eb96f19723 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -12,6 +12,7 @@
#include "SkMath.h"
#include "SkRect.h"
#include "SkSize.h"
+#include "../private/SkTFitsIn.h"
class SkReadBuffer;
class SkWriteBuffer;
@@ -551,10 +552,10 @@ public:
*/
size_t minRowBytes() const {
uint64_t minRowBytes = this->minRowBytes64();
- if (!sk_64_isS32(minRowBytes)) {
+ if (!SkTFitsIn<int32_t>(minRowBytes)) {
return 0;
}
- return sk_64_asS32(minRowBytes);
+ return SkTo<int32_t>(minRowBytes);
}
/** Returns byte offset of pixel from pixel base address.
diff --git a/include/core/SkMath.h b/include/core/SkMath.h
index 6e252306df..fb551abb40 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -14,23 +14,6 @@
// 64bit -> 32bit utilities
-/**
- * Return true iff the 64bit value can exactly be represented in signed 32bits
- */
-static inline bool sk_64_isS32(int64_t value) {
- return (int32_t)value == value;
-}
-
-/**
- * Return the 64bit argument as signed 32bits, asserting in debug that the arg
- * exactly fits in signed 32bits. In the release build, no checks are preformed
- * and the return value if the arg does not fit is undefined.
- */
-static inline int32_t sk_64_asS32(int64_t value) {
- SkASSERT(sk_64_isS32(value));
- return (int32_t)value;
-}
-
// Handy util that can be passed two ints, and will automatically promote to
// 64bits before the multiply, so the caller doesn't have to remember to cast
// e.g. (int64_t)a * b;
@@ -49,7 +32,7 @@ static inline int32_t SkMulDiv(int32_t numer1, int32_t numer2, int32_t denom) {
SkASSERT(denom);
int64_t tmp = sk_64_mul(numer1, numer2) / denom;
- return sk_64_asS32(tmp);
+ return SkTo<int32_t>(tmp);
}
/**
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index 7b8e0032e5..2a46da68c6 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -11,6 +11,7 @@
#include "SkPoint.h"
#include "SkSize.h"
#include "../private/SkSafe32.h"
+#include "../private/SkTFitsIn.h"
struct SkRect;
@@ -209,7 +210,7 @@ struct SK_API SkIRect {
return true;
}
// Return true if either exceeds int32_t
- return !sk_64_isS32(w | h);
+ return !SkTFitsIn<int32_t>(w | h);
}
/** Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index 95ae9b9593..757cde5699 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -81,7 +81,7 @@ std::unique_ptr<SkCodec> SkWebpCodec::MakeFromStream(std::unique_ptr<SkStream> s
{
const int64_t size = sk_64_mul(width, height);
// now check that if we are 4-bytes per pixel, we also don't overflow
- if (!sk_64_isS32(size) || sk_64_asS32(size) > (0x7FFFFFFF >> 2)) {
+ if (!SkTFitsIn<int32_t>(size) || SkTo<int32_t>(size) > (0x7FFFFFFF >> 2)) {
*result = kInvalidInput;
return nullptr;
}
diff --git a/src/core/SkBitmapProcState_utils.h b/src/core/SkBitmapProcState_utils.h
index 4609ff34e7..ec35ca108d 100644
--- a/src/core/SkBitmapProcState_utils.h
+++ b/src/core/SkBitmapProcState_utils.h
@@ -50,7 +50,7 @@ static inline bool can_truncate_to_fixed_for_decal(SkFixed fx,
// Promote to 64bit (48.16) to avoid overflow.
const uint64_t lastFx = fx + sk_64_mul(dx, count - 1);
- return sk_64_isS32(lastFx) && (unsigned)SkFixedFloorToInt(sk_64_asS32(lastFx)) < max;
+ return SkTFitsIn<int32_t>(lastFx) && (unsigned)SkFixedFloorToInt(SkTo<int32_t>(lastFx)) < max;
}
#endif /* #ifndef SkBitmapProcState_utils_DEFINED */
diff --git a/src/core/SkMask.cpp b/src/core/SkMask.cpp
index 7dd0f6d6dd..b3a6543706 100644
--- a/src/core/SkMask.cpp
+++ b/src/core/SkMask.cpp
@@ -14,8 +14,8 @@
*/
static int32_t safeMul32(int32_t a, int32_t b) {
int64_t size = sk_64_mul(a, b);
- if (size > 0 && sk_64_isS32(size)) {
- return sk_64_asS32(size);
+ if (size > 0 && SkTFitsIn<int32_t>(size)) {
+ return size;
}
return 0;
}
diff --git a/src/core/SkMipMap.cpp b/src/core/SkMipMap.cpp
index f9cb3f1cf5..1b5d84bf39 100644
--- a/src/core/SkMipMap.cpp
+++ b/src/core/SkMipMap.cpp
@@ -477,10 +477,10 @@ size_t SkMipMap::AllocLevelsSize(int levelCount, size_t pixelSize) {
return 0;
}
int64_t size = sk_64_mul(levelCount + 1, sizeof(Level)) + pixelSize;
- if (!sk_64_isS32(size)) {
+ if (!SkTFitsIn<int32_t>(size)) {
return 0;
}
- return sk_64_asS32(size);
+ return SkTo<int32_t>(size);
}
SkMipMap* SkMipMap::Build(const SkPixmap& src, SkDestinationSurfaceColorMode colorMode,
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp
index 5993e49972..2325fde864 100644
--- a/src/core/SkPicture.cpp
+++ b/src/core/SkPicture.cpp
@@ -245,7 +245,7 @@ static sk_sp<SkData> custom_serialize(const SkPicture* picture, const SkSerialPr
auto data = procs.fPictureProc(const_cast<SkPicture*>(picture), procs.fPictureCtx);
if (data) {
size_t size = data->size();
- if (!sk_64_isS32(size) || size <= 1) {
+ if (!SkTFitsIn<int32_t>(size) || size <= 1) {
return SkData::MakeEmpty();
}
return data;
diff --git a/src/core/SkRegionPriv.h b/src/core/SkRegionPriv.h
index d9d472a1d2..08db564174 100644
--- a/src/core/SkRegionPriv.h
+++ b/src/core/SkRegionPriv.h
@@ -73,7 +73,7 @@ public:
}
const int64_t size = sk_64_mul(count, sizeof(RunType)) + sizeof(RunHead);
- if (count < 0 || !sk_64_isS32(size)) { SK_ABORT("Invalid Size"); }
+ if (count < 0 || !SkTFitsIn<int32_t>(size)) { SK_ABORT("Invalid Size"); }
RunHead* head = (RunHead*)sk_malloc_throw(size);
head->fRefCnt = 1;
diff --git a/src/core/SkWriteBuffer.cpp b/src/core/SkWriteBuffer.cpp
index de0b613996..cb752c491f 100644
--- a/src/core/SkWriteBuffer.cpp
+++ b/src/core/SkWriteBuffer.cpp
@@ -151,7 +151,7 @@ void SkBinaryWriteBuffer::writeImage(const SkImage* image) {
}
size_t size = data ? data->size() : 0;
- if (!sk_64_isS32(size)) {
+ if (!SkTFitsIn<int32_t>(size)) {
size = 0; // too big to store
}
this->write32(SkToS32(size)); // writing 0 signals failure
@@ -177,7 +177,7 @@ void SkBinaryWriteBuffer::writeTypeface(SkTypeface* obj) {
auto data = fProcs.fTypefaceProc(obj, fProcs.fTypefaceCtx);
if (data) {
size_t size = data->size();
- if (!sk_64_isS32(size)) {
+ if (!SkTFitsIn<int32_t>(size)) {
size = 0; // fall back to default font
}
int32_t ssize = SkToS32(size);