Remove sk_64_isS32 and sk_64_asS32

This is an API change. I assume that only Skia uses these routines.

Change-Id: Iefc98fa5c0b83eb4f52c478e345fd99121ecb254
Reviewed-on: https://skia-review.googlesource.com/129440
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Herb Derby 2017-09-20 11:56:00 -04:00 committed by Skia Commit-Bot
parent 0e42586036
commit c402b778d5
10 changed files with 16 additions and 31 deletions

View File

@ -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.

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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;
}

View File

@ -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 */

View File

@ -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;
}

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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);