From ab17347df32807cabd9f2a518d22c3bd420e482f Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Thu, 14 Jun 2018 16:17:29 +0000 Subject: Revert "Remove SK_MaxSizeT, SK_M{in|ax}U{16|32}, #defines." This reverts commit e1bc7de7c07686b28b00b850e44e0722189f3592. 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 > Reviewed-by: Ben Wagner 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 Commit-Queue: Hal Canary --- include/core/SkImageInfo.h | 10 +++++----- include/core/SkTypes.h | 15 ++++++++++----- src/core/SkImageInfo.cpp | 2 +- src/core/SkMath.cpp | 4 ++-- src/core/SkResourceCache.cpp | 2 +- src/core/SkString.cpp | 10 +++++----- src/core/SkStringUtils.cpp | 2 +- src/core/SkVertices.cpp | 2 +- src/gpu/GrProgramDesc.cpp | 4 ++-- src/gpu/GrResourceCache.cpp | 4 ++-- src/gpu/effects/GrPorterDuffXferProcessor.cpp | 2 +- src/gpu/effects/GrXfermodeFragmentProcessor.cpp | 2 +- src/gpu/ops/GrDrawVerticesOp.cpp | 4 ++-- src/pdf/SkPDFFont.cpp | 2 +- src/ports/SkFontHost_win.cpp | 2 +- tests/PDFGlyphsToUnicodeTest.cpp | 2 +- tests/ResourceCacheTest.cpp | 2 +- tests/StringTest.cpp | 2 +- tests/VerticesTest.cpp | 4 ++-- 19 files changed, 41 insertions(+), 36 deletions(-) diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index a60f26576d..0d9583e012 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -555,7 +555,7 @@ public: and rowBytes. rowBytes is assumed to be at least as large as minRowBytes(). Returns zero if height is zero. - Returns SIZE_MAX if answer exceeds the range of size_t. + Returns SK_MaxSizeT if answer exceeds the range of size_t. @param rowBytes size of pixel row or larger @return memory required by pixel buffer @@ -566,7 +566,7 @@ public: SkColorType. Uses minRowBytes() to compute bytes for pixel row. Returns zero if height is zero. - Returns SIZE_MAX if answer exceeds the range of size_t. + Returns SK_MaxSizeT if answer exceeds the range of size_t. @return least memory required by pixel buffer */ @@ -574,14 +574,14 @@ public: return this->computeByteSize(this->minRowBytes()); } - /** Returns true if byteSize equals SIZE_MAX. computeByteSize() and - computeMinByteSize() return SIZE_MAX if size_t can not hold buffer size. + /** Returns true if byteSize equals SK_MaxSizeT. computeByteSize() and + computeMinByteSize() return SK_MaxSizeT 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 SIZE_MAX == byteSize; + return SK_MaxSizeT == byteSize; } /** Returns true if rowBytes is smaller than width times pixel size. diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index e624d4518c..f906816587 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -100,12 +100,17 @@ typedef unsigned U16CPU; */ #define SkToBool(cond) ((cond) != 0) -#define SK_MaxS16 INT16_MAX -#define SK_MinS16 -SK_MaxS16 -#define SK_MaxS32 INT32_MAX +#define SK_MaxS16 32767 +#define SK_MinS16 -32767 +#define SK_MaxU16 0xFFFF +#define SK_MinU16 0 +#define SK_MaxS32 0x7FFFFFFF #define SK_MinS32 -SK_MaxS32 -#define SK_NaN32 INT32_MIN -static constexpr int64_t SK_MaxS64 = INT64_MAX; +#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; static constexpr int64_t SK_MinS64 = -SK_MaxS64; static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index 15c070cd4e..a743dbce70 100644 --- a/src/core/SkImageInfo.cpp +++ b/src/core/SkImageInfo.cpp @@ -67,7 +67,7 @@ size_t SkImageInfo::computeByteSize(size_t rowBytes) const { SkSafeMath safe; size_t bytes = safe.add(safe.mul(safe.addInt(fHeight, -1), rowBytes), safe.mul(fWidth, this->bytesPerPixel())); - return safe ? bytes : SIZE_MAX; + return safe ? bytes : SK_MaxSizeT; } SkImageInfo SkImageInfo::MakeS32(int width, int height, SkAlphaType at) { diff --git a/src/core/SkMath.cpp b/src/core/SkMath.cpp index 2d2ddacbaf..58645dab8f 100644 --- a/src/core/SkMath.cpp +++ b/src/core/SkMath.cpp @@ -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 : SIZE_MAX; + return tmp.ok() ? sum : SK_MaxSizeT; } size_t SkSafeMath::Mul(size_t x, size_t y) { SkSafeMath tmp; size_t prod = tmp.mul(x, y); - return tmp.ok() ? prod : SIZE_MAX; + return tmp.ok() ? prod : SK_MaxSizeT; } diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp index e016d23797..0e8ceb1947 100644 --- a/src/core/SkResourceCache.cpp +++ b/src/core/SkResourceCache.cpp @@ -197,7 +197,7 @@ void SkResourceCache::purgeAsNeeded(bool forcePurge) { if (fDiscardableFactory) { countLimit = SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT; - byteLimit = UINT32_MAX; // no limit based on bytes + byteLimit = SK_MaxU32; // no limit based on bytes } else { countLimit = SK_MaxS32; // no limit based on count byteLimit = fTotalByteLimit; diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp index 23c85f993e..7820f1d5bf 100644 --- a/src/core/SkString.cpp +++ b/src/core/SkString.cpp @@ -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 > UINT32_MAX) { - value = UINT32_MAX; + if (value > SK_MaxU32) { + value = SK_MaxU32; } } return (uint32_t)value; } static size_t check_add32(size_t base, size_t extra) { - SkASSERT(base <= UINT32_MAX); + SkASSERT(base <= SK_MaxU32); if (sizeof(size_t) > sizeof(uint32_t)) { - if (base + extra > UINT32_MAX) { - extra = UINT32_MAX - base; + if (base + extra > SK_MaxU32) { + extra = SK_MaxU32 - base; } } return extra; diff --git a/src/core/SkStringUtils.cpp b/src/core/SkStringUtils.cpp index c4c1739b19..00d8c8787c 100644 --- a/src/core/SkStringUtils.cpp +++ b/src/core/SkStringUtils.cpp @@ -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 > UINT32_MAX - s) { + if (n > SK_MaxU32 - s) { end = last; // truncate input string break; } diff --git a/src/core/SkVertices.cpp b/src/core/SkVertices.cpp index e8bf1b7d88..4aa56c8e43 100644 --- a/src/core/SkVertices.cpp +++ b/src/core/SkVertices.cpp @@ -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 > (UINT16_MAX + 1)) { + if (vertexCount > (SK_MaxU16 + 1)) { sk_bzero(this, sizeof(*this)); return; } diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp index c552789d9f..b73a439688 100644 --- a/src/gpu/GrProgramDesc.cpp +++ b/src/gpu/GrProgramDesc.cpp @@ -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)UINT16_MAX); + static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16); 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)UINT16_MAX); + static const uint32_t kMetaKeyInvalidMask = ~((uint32_t)SK_MaxU16); if ((processorKeySize | classID) & kMetaKeyInvalidMask) { return false; } diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 4e69444b61..ff6b1b2ebd 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -29,7 +29,7 @@ GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() { static int32_t gType = INHERITED::kInvalidDomain + 1; int32_t type = sk_atomic_inc(&gType); - if (type > UINT16_MAX) { + if (type > SK_MaxU16) { 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 > UINT16_MAX) { + if (domain > SK_MaxU16) { SK_ABORT("Too many GrUniqueKey Domains"); } diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index ca082603de..7a134da5c2 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp +++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp @@ -619,7 +619,7 @@ private: class GLPDLCDXferProcessor : public GrGLSLXferProcessor { public: - GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(UINT32_MAX) {} + GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(SK_MaxU32) {} ~GLPDLCDXferProcessor() override {} diff --git a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp index 2ce40c8fa4..6b764f453a 100644 --- a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp +++ b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp @@ -395,7 +395,7 @@ private: } void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override { - GR_STATIC_ASSERT(((int)SkBlendMode::kLastMode & UINT16_MAX) == (int)SkBlendMode::kLastMode); + GR_STATIC_ASSERT(((int)SkBlendMode::kLastMode & SK_MaxU16) == (int)SkBlendMode::kLastMode); b->add32((int)fMode | (fChild << 16)); } diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp index 55d97f6866..b35fee08a3 100644 --- a/src/gpu/ops/GrDrawVerticesOp.cpp +++ b/src/gpu/ops/GrDrawVerticesOp.cpp @@ -276,7 +276,7 @@ bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { return false; } - if (fVertexCount + that->fVertexCount > UINT16_MAX) { + if (fVertexCount + that->fVertexCount > SK_MaxU16) { 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 <= UINT16_MAX); + SkASSERT(maxVertex <= SK_MaxU16); indices->push_back(random->nextULessThan((uint16_t)maxVertex)); } } diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 022e214057..16f78a66ea 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -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 + UINT16_MAX) { + if (count <= 0 || count > 1 + SK_MaxU16) { // Cache nullptr to skip this check. Use SkSafeUnref(). canon->fTypefaceMetrics.set(id, nullptr); return nullptr; diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp index a9c0afcf28..85e92ce840 100644 --- a/src/ports/SkFontHost_win.cpp +++ b/src/ports/SkFontHost_win.cpp @@ -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 = UINT16_MAX + 1; + int32_t max = SK_MaxU16 + 1; int32_t min = 0; GLYPHMETRICS gm; while (min < max) { diff --git a/tests/PDFGlyphsToUnicodeTest.cpp b/tests/PDFGlyphsToUnicodeTest.cpp index ab520eba78..cf69705eb1 100644 --- a/tests/PDFGlyphsToUnicodeTest.cpp +++ b/tests/PDFGlyphsToUnicodeTest.cpp @@ -15,7 +15,7 @@ #include "SkStream.h" #include "SkTo.h" -static const int kMaximumGlyphCount = UINT16_MAX + 1; +static const int kMaximumGlyphCount = SK_MaxU16 + 1; static bool stream_equals(const SkDynamicMemoryWStream& stream, size_t offset, const char* buffer, size_t len) { diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 113945b414..b6ccd515c2 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -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(UINT32_MAX - random.nextULessThan(kCount + 1)); + cache->changeTimestamp(SK_MaxU32 - random.nextULessThan(kCount + 1)); static const int kNumToPurge = kCount - kBudgetCnt; diff --git a/tests/StringTest.cpp b/tests/StringTest.cpp index 503dbb8158..f8c319e9be 100644 --- a/tests/StringTest.cpp +++ b/tests/StringTest.cpp @@ -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 = UINT32_MAX - 16; + size_t size = SK_MaxU32 - 16; // See where we crash, and manually check that its at the right point. // // To test, change the false to true diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp index b38a9de8ba..59d06472ac 100644 --- a/tests/VerticesTest.cpp +++ b/tests/VerticesTest.cpp @@ -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, UINT16_MAX + 1, 0, + SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, SK_MaxU16 + 1, 0, SkVertices::kHasColors_BuilderFlag); REPORTER_ASSERT(reporter, builder.isValid()); } { // This has too many to be rewritten. - SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, UINT16_MAX + 2, 0, + SkVertices::Builder builder(SkVertices::kTriangleFan_VertexMode, SK_MaxU16 + 2, 0, SkVertices::kHasColors_BuilderFlag); REPORTER_ASSERT(reporter, !builder.isValid()); } -- cgit v1.2.3