diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 45275b698a..db3917f944 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -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. diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h index f906816587..e624d4518c 100644 --- a/include/core/SkTypes.h +++ b/include/core/SkTypes.h @@ -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) { diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index 54c8af9656..b50dddf1f7 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(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) { diff --git a/src/core/SkMath.cpp b/src/core/SkMath.cpp index 58645dab8f..2d2ddacbaf 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 : 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; } diff --git a/src/core/SkResourceCache.cpp b/src/core/SkResourceCache.cpp index 0e8ceb1947..e016d23797 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 = 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; diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp index 7820f1d5bf..23c85f993e 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 > 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; diff --git a/src/core/SkStringUtils.cpp b/src/core/SkStringUtils.cpp index 00d8c8787c..c4c1739b19 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 > SK_MaxU32 - s) { + if (n > UINT32_MAX - s) { end = last; // truncate input string break; } diff --git a/src/core/SkVertices.cpp b/src/core/SkVertices.cpp index 4aa56c8e43..e8bf1b7d88 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 > (SK_MaxU16 + 1)) { + if (vertexCount > (UINT16_MAX + 1)) { sk_bzero(this, sizeof(*this)); return; } diff --git a/src/gpu/GrProgramDesc.cpp b/src/gpu/GrProgramDesc.cpp index b73a439688..c552789d9f 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)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; } diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index ff6b1b2ebd..4e69444b61 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 > 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"); } diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index 7a134da5c2..ca082603de 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(SK_MaxU32) {} + GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(UINT32_MAX) {} ~GLPDLCDXferProcessor() override {} diff --git a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp index 6b764f453a..2ce40c8fa4 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 & SK_MaxU16) == (int)SkBlendMode::kLastMode); + GR_STATIC_ASSERT(((int)SkBlendMode::kLastMode & UINT16_MAX) == (int)SkBlendMode::kLastMode); b->add32((int)fMode | (fChild << 16)); } diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp index b35fee08a3..55d97f6866 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 > 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)); } } diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 16f78a66ea..022e214057 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 + SK_MaxU16) { + if (count <= 0 || count > 1 + UINT16_MAX) { // 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 85e92ce840..a9c0afcf28 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 = SK_MaxU16 + 1; + int32_t max = UINT16_MAX + 1; int32_t min = 0; GLYPHMETRICS gm; while (min < max) { diff --git a/tests/PDFGlyphsToUnicodeTest.cpp b/tests/PDFGlyphsToUnicodeTest.cpp index cf69705eb1..ab520eba78 100644 --- a/tests/PDFGlyphsToUnicodeTest.cpp +++ b/tests/PDFGlyphsToUnicodeTest.cpp @@ -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) { diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index b6ccd515c2..113945b414 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(SK_MaxU32 - random.nextULessThan(kCount + 1)); + cache->changeTimestamp(UINT32_MAX - random.nextULessThan(kCount + 1)); static const int kNumToPurge = kCount - kBudgetCnt; diff --git a/tests/StringTest.cpp b/tests/StringTest.cpp index f8c319e9be..503dbb8158 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 = 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 diff --git a/tests/VerticesTest.cpp b/tests/VerticesTest.cpp index 59d06472ac..b38a9de8ba 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, 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()); }