Reland "Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines."

This reverts commit ab17347df3.

Reason for revert: Chromium should now be ok.

Original change's description:
> Revert "Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines."
>
> This reverts commit e1bc7de7c0.
>
> Reason for revert: chrome used it
>
> Original change's description:
> > Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines.
> >
> > sed 's/SK_MaxSizeT/SIZE_MAX/g'
> > sed 's/SK_MaxU32/UINT32_MAX/g'
> > sed 's/SK_MaxU16/UINT16_MAX/g'
> >
> > SK_MinU32 and SK_MinU16 were unused
> >
> > Change-Id: I6b6c824df47b05bde7e73b13a58e851a5f63fe0e
> > Reviewed-on: https://skia-review.googlesource.com/134607
> > Commit-Queue: Hal Canary <halcanary@google.com>
> > Reviewed-by: Ben Wagner <bungeman@google.com>
>
> TBR=halcanary@google.com,bungeman@google.com,reed@google.com
>
> Change-Id: I1e2c440dcf9f59bf87c1fea113248cd5136f7519
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/134921
> Reviewed-by: Hal Canary <halcanary@google.com>
> Commit-Queue: Hal Canary <halcanary@google.com>

CQ_INCLUDE_TRYBOTS=luci.chromium.try:linux-ozone-rel
TBR=halcanary@google.com,bungeman@google.com,reed@google.com

Change-Id: I7709f9715bea0463b85b5b0a89712ac1020fcddb
Reviewed-on: https://skia-review.googlesource.com/135180
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2018-06-15 15:37:57 +00:00 committed by Skia Commit-Bot
parent 46f2563547
commit b0897650f1
19 changed files with 36 additions and 41 deletions

View File

@ -552,7 +552,7 @@ public:
and rowBytes. rowBytes is assumed to be at least as large as minRowBytes().
Returns zero if height is zero.
Returns SK_MaxSizeT if answer exceeds the range of size_t.
Returns SIZE_MAX if answer exceeds the range of size_t.
@param rowBytes size of pixel row or larger
@return memory required by pixel buffer
@ -563,7 +563,7 @@ public:
SkColorType. Uses minRowBytes() to compute bytes for pixel row.
Returns zero if height is zero.
Returns SK_MaxSizeT if answer exceeds the range of size_t.
Returns SIZE_MAX if answer exceeds the range of size_t.
@return least memory required by pixel buffer
*/
@ -571,14 +571,14 @@ public:
return this->computeByteSize(this->minRowBytes());
}
/** Returns true if byteSize equals SK_MaxSizeT. computeByteSize() and
computeMinByteSize() return SK_MaxSizeT if size_t can not hold buffer size.
/** Returns true if byteSize equals SIZE_MAX. computeByteSize() and
computeMinByteSize() return SIZE_MAX if size_t can not hold buffer size.
@param byteSize result of computeByteSize() or computeMinByteSize()
@return true if computeByteSize() or computeMinByteSize() result exceeds size_t
*/
static bool ByteSizeOverflowed(size_t byteSize) {
return SK_MaxSizeT == byteSize;
return SIZE_MAX == byteSize;
}
/** Returns true if rowBytes is smaller than width times pixel size.

View File

@ -100,17 +100,12 @@ typedef unsigned U16CPU;
*/
#define SkToBool(cond) ((cond) != 0)
#define SK_MaxS16 32767
#define SK_MinS16 -32767
#define SK_MaxU16 0xFFFF
#define SK_MinU16 0
#define SK_MaxS32 0x7FFFFFFF
#define SK_MaxS16 INT16_MAX
#define SK_MinS16 -SK_MaxS16
#define SK_MaxS32 INT32_MAX
#define SK_MinS32 -SK_MaxS32
#define SK_MaxU32 0xFFFFFFFF
#define SK_MinU32 0
#define SK_NaN32 ((int) (1U << 31))
#define SK_MaxSizeT SIZE_MAX
static constexpr int64_t SK_MaxS64 = 0x7FFFFFFFFFFFFFFF;
#define SK_NaN32 INT32_MIN
static constexpr int64_t SK_MaxS64 = INT64_MAX;
static constexpr int64_t SK_MinS64 = -SK_MaxS64;
static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) {

View File

@ -67,7 +67,7 @@ size_t SkImageInfo::computeByteSize(size_t rowBytes) const {
SkSafeMath safe;
size_t bytes = safe.add(safe.mul(safe.addInt(this->height(), -1), rowBytes),
safe.mul(this->width(), this->bytesPerPixel()));
return safe ? bytes : SK_MaxSizeT;
return safe ? bytes : SIZE_MAX;
}
SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) {

View File

@ -89,11 +89,11 @@ float SkScalarSinCos(float radians, float* cosValue) {
size_t SkSafeMath::Add(size_t x, size_t y) {
SkSafeMath tmp;
size_t sum = tmp.add(x, y);
return tmp.ok() ? sum : SK_MaxSizeT;
return tmp.ok() ? sum : SIZE_MAX;
}
size_t SkSafeMath::Mul(size_t x, size_t y) {
SkSafeMath tmp;
size_t prod = tmp.mul(x, y);
return tmp.ok() ? prod : SK_MaxSizeT;
return tmp.ok() ? prod : SIZE_MAX;
}

View File

@ -197,7 +197,7 @@ void SkResourceCache::purgeAsNeeded(bool forcePurge) {
if (fDiscardableFactory) {
countLimit = SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT;
byteLimit = SK_MaxU32; // no limit based on bytes
byteLimit = UINT32_MAX; // no limit based on bytes
} else {
countLimit = SK_MaxS32; // no limit based on count
byteLimit = fTotalByteLimit;

View File

@ -181,18 +181,18 @@ const SkString::Rec SkString::gEmptyRec(0, 0);
static uint32_t trim_size_t_to_u32(size_t value) {
if (sizeof(size_t) > sizeof(uint32_t)) {
if (value > SK_MaxU32) {
value = SK_MaxU32;
if (value > UINT32_MAX) {
value = UINT32_MAX;
}
}
return (uint32_t)value;
}
static size_t check_add32(size_t base, size_t extra) {
SkASSERT(base <= SK_MaxU32);
SkASSERT(base <= UINT32_MAX);
if (sizeof(size_t) > sizeof(uint32_t)) {
if (base + extra > SK_MaxU32) {
extra = SK_MaxU32 - base;
if (base + extra > UINT32_MAX) {
extra = UINT32_MAX - base;
}
}
return extra;

View File

@ -63,7 +63,7 @@ SkString SkStringFromUTF16(const uint16_t* src, size_t count) {
const uint16_t* last = ptr;
SkUnichar u = SkUTF16_NextUnichar(&ptr);
size_t s = SkUTF8_FromUnichar(u);
if (n > SK_MaxU32 - s) {
if (n > UINT32_MAX - s) {
end = last; // truncate input string
break;
}

View File

@ -45,7 +45,7 @@ struct SkVertices::Sizes {
numFanTris = vertexCount - 2;
// By forcing this to become indexed we are adding a constraint to the maximum
// number of vertices.
if (vertexCount > (SK_MaxU16 + 1)) {
if (vertexCount > (UINT16_MAX + 1)) {
sk_bzero(this, sizeof(*this));
return;
}

View File

@ -102,7 +102,7 @@ static bool gen_meta_key(const GrResourceIOProcessor& proc,
uint32_t classID = proc.classID();
// Currently we allow 16 bits for the class id and the overall processor key size.
static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16);
static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)UINT16_MAX);
if ((processorKeySize | classID) & kMetaKeyInvalidMask) {
return false;
}
@ -122,7 +122,7 @@ static bool gen_meta_key(const GrXferProcessor& xp,
uint32_t classID = xp.classID();
// Currently we allow 16 bits for the class id and the overall processor key size.
static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16);
static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)UINT16_MAX);
if ((processorKeySize | classID) & kMetaKeyInvalidMask) {
return false;
}

View File

@ -29,7 +29,7 @@ GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() {
static int32_t gType = INHERITED::kInvalidDomain + 1;
int32_t type = sk_atomic_inc(&gType);
if (type > SK_MaxU16) {
if (type > UINT16_MAX) {
SK_ABORT("Too many Resource Types");
}
@ -40,7 +40,7 @@ GrUniqueKey::Domain GrUniqueKey::GenerateDomain() {
static int32_t gDomain = INHERITED::kInvalidDomain + 1;
int32_t domain = sk_atomic_inc(&gDomain);
if (domain > SK_MaxU16) {
if (domain > UINT16_MAX) {
SK_ABORT("Too many GrUniqueKey Domains");
}

View File

@ -619,7 +619,7 @@ private:
class GLPDLCDXferProcessor : public GrGLSLXferProcessor {
public:
GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(SK_MaxU32) {}
GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(UINT32_MAX) {}
~GLPDLCDXferProcessor() override {}

View File

@ -395,7 +395,7 @@ private:
}
void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {
GR_STATIC_ASSERT(((int)SkBlendMode::kLastMode & SK_MaxU16) == (int)SkBlendMode::kLastMode);
GR_STATIC_ASSERT(((int)SkBlendMode::kLastMode & UINT16_MAX) == (int)SkBlendMode::kLastMode);
b->add32((int)fMode | (fChild << 16));
}

View File

@ -276,7 +276,7 @@ bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) {
return false;
}
if (fVertexCount + that->fVertexCount > SK_MaxU16) {
if (fVertexCount + that->fVertexCount > UINT16_MAX) {
return false;
}
@ -366,7 +366,7 @@ static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca
colors->push_back(GrRandomColor(random));
}
if (hasIndices) {
SkASSERT(maxVertex <= SK_MaxU16);
SkASSERT(maxVertex <= UINT16_MAX);
indices->push_back(random->nextULessThan((uint16_t)maxVertex));
}
}

View File

@ -149,7 +149,7 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface,
return ptr->get(); // canon retains ownership.
}
int count = typeface->countGlyphs();
if (count <= 0 || count > 1 + SK_MaxU16) {
if (count <= 0 || count > 1 + UINT16_MAX) {
// Cache nullptr to skip this check. Use SkSafeUnref().
canon->fTypefaceMetrics.set(id, nullptr);
return nullptr;

View File

@ -169,7 +169,7 @@ static unsigned calculateGlyphCount(HDC hdc, const LOGFONT& lf) {
// Binary search for glyph count.
static const MAT2 mat2 = {{0, 1}, {0, 0}, {0, 0}, {0, 1}};
int32_t max = SK_MaxU16 + 1;
int32_t max = UINT16_MAX + 1;
int32_t min = 0;
GLYPHMETRICS gm;
while (min < max) {

View File

@ -15,7 +15,7 @@
#include "SkStream.h"
#include "SkTo.h"
static const int kMaximumGlyphCount = SK_MaxU16 + 1;
static const int kMaximumGlyphCount = UINT16_MAX + 1;
static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset,
const char* buffer, size_t len) {

View File

@ -1094,7 +1094,7 @@ static void test_timestamp_wrap(skiatest::Reporter* reporter) {
GrGpu* gpu = context->contextPriv().getGpu();
// Pick a random number of resources to add before the timestamp will wrap.
cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1));
cache->changeTimestamp(UINT32_MAX - random.nextULessThan(kCount + 1));
static const int kNumToPurge = kCount - kBudgetCnt;

View File

@ -300,7 +300,7 @@ DEF_TEST(String_Threaded, r) {
// let us create a string with a requested length longer than we can manage.
DEF_TEST(String_huge, r) {
// start testing slightly below max 32
size_t size = SK_MaxU32 - 16;
size_t size = UINT32_MAX - 16;
// See where we crash, and manually check that its at the right point.
//
// To test, change the false to true

View File

@ -91,13 +91,13 @@ DEF_TEST(Vertices, reporter) {
{
// This has the maximum number of vertices to be rewritten as indexed triangles without
// overflowing a 16bit index.
SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, SK_MaxU16 + 1, 0,
SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, UINT16_MAX + 1, 0,
SkVertices::kHasColors_BuilderFlag);
REPORTER_ASSERT(reporter, builder.isValid());
}
{
// This has too many to be rewritten.
SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, SK_MaxU16 + 2, 0,
SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, UINT16_MAX + 2, 0,
SkVertices::kHasColors_BuilderFlag);
REPORTER_ASSERT(reporter, !builder.isValid());
}