From d936f63c35fb7dfb2b6c20802206adbfc3cc48d0 Mon Sep 17 00:00:00 2001 From: benjaminwagner Date: Tue, 23 Feb 2016 10:44:31 -0800 Subject: Simplify and combine SkDrawCacheProc and SkMeasureCacheProc to SkPaint::GlyphCacheProc. All callers of (the result of) SkPaint::getDrawCacheProc were passing zero as the last two arguments. This is the same as (the result of) SkPaint::getMeasureCacheProc(true). Per bungeman, make this typedef a member of SkPaint. Although the typedef is technically public, the only uses are private, so this is not really an API change. TBR=reed GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1718423002 Review URL: https://codereview.chromium.org/1718423002 --- src/core/SkPaint.cpp | 120 ++++----------------------------------------------- 1 file changed, 8 insertions(+), 112 deletions(-) (limited to 'src/core/SkPaint.cpp') diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index d2ea8eeda0..d3384a628d 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -682,8 +682,8 @@ static const SkGlyph& sk_getAdvance_glyph_next(SkGlyphCache* cache, return cache->getGlyphIDAdvance(glyphID); } -SkMeasureCacheProc SkPaint::getMeasureCacheProc(bool needFullMetrics) const { - static const SkMeasureCacheProc gMeasureCacheProcs[] = { +SkPaint::GlyphCacheProc SkPaint::getGlyphCacheProc(bool needFullMetrics) const { + static const GlyphCacheProc gGlyphCacheProcs[] = { sk_getMetrics_utf8_next, sk_getMetrics_utf16_next, sk_getMetrics_utf32_next, @@ -701,111 +701,8 @@ SkMeasureCacheProc SkPaint::getMeasureCacheProc(bool needFullMetrics) const { index += 4; } - SkASSERT(index < SK_ARRAY_COUNT(gMeasureCacheProcs)); - return gMeasureCacheProcs[index]; -} - -/////////////////////////////////////////////////////////////////////////////// - -static const SkGlyph& sk_getMetrics_utf8_00(SkGlyphCache* cache, - const char** text, SkFixed, SkFixed) { - SkASSERT(cache != nullptr); - SkASSERT(text != nullptr); - - return cache->getUnicharMetrics(SkUTF8_NextUnichar(text)); -} - -static const SkGlyph& sk_getMetrics_utf8_xy(SkGlyphCache* cache, - const char** text, SkFixed x, SkFixed y) { - SkASSERT(cache != nullptr); - SkASSERT(text != nullptr); - - return cache->getUnicharMetrics(SkUTF8_NextUnichar(text), x, y); -} - -static const SkGlyph& sk_getMetrics_utf16_00(SkGlyphCache* cache, - const char** text, SkFixed, SkFixed) { - SkASSERT(cache != nullptr); - SkASSERT(text != nullptr); - - return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text)); -} - -static const SkGlyph& sk_getMetrics_utf16_xy(SkGlyphCache* cache, - const char** text, SkFixed x, SkFixed y) { - SkASSERT(cache != nullptr); - SkASSERT(text != nullptr); - - return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text), - x, y); -} - -static const SkGlyph& sk_getMetrics_utf32_00(SkGlyphCache* cache, - const char** text, SkFixed, SkFixed) { - SkASSERT(cache != nullptr); - SkASSERT(text != nullptr); - - const int32_t* ptr = *(const int32_t**)text; - SkUnichar uni = *ptr++; - *text = (const char*)ptr; - return cache->getUnicharMetrics(uni); -} - -static const SkGlyph& sk_getMetrics_utf32_xy(SkGlyphCache* cache, - const char** text, SkFixed x, SkFixed y) { - SkASSERT(cache != nullptr); - SkASSERT(text != nullptr); - - const int32_t* ptr = *(const int32_t**)text; - SkUnichar uni = *ptr++; - *text = (const char*)ptr; - return cache->getUnicharMetrics(uni, x, y); -} - -static const SkGlyph& sk_getMetrics_glyph_00(SkGlyphCache* cache, - const char** text, SkFixed, SkFixed) { - SkASSERT(cache != nullptr); - SkASSERT(text != nullptr); - - const uint16_t* ptr = *(const uint16_t**)text; - unsigned glyphID = *ptr; - ptr += 1; - *text = (const char*)ptr; - return cache->getGlyphIDMetrics(glyphID); -} - -static const SkGlyph& sk_getMetrics_glyph_xy(SkGlyphCache* cache, - const char** text, SkFixed x, SkFixed y) { - SkASSERT(cache != nullptr); - SkASSERT(text != nullptr); - - const uint16_t* ptr = *(const uint16_t**)text; - unsigned glyphID = *ptr; - ptr += 1; - *text = (const char*)ptr; - return cache->getGlyphIDMetrics(glyphID, x, y); -} - -SkDrawCacheProc SkPaint::getDrawCacheProc() const { - static const SkDrawCacheProc gDrawCacheProcs[] = { - sk_getMetrics_utf8_00, - sk_getMetrics_utf16_00, - sk_getMetrics_utf32_00, - sk_getMetrics_glyph_00, - - sk_getMetrics_utf8_xy, - sk_getMetrics_utf16_xy, - sk_getMetrics_utf32_xy, - sk_getMetrics_glyph_xy - }; - - unsigned index = this->getTextEncoding(); - if (fBitfields.fFlags & kSubpixelText_Flag) { - index += 4; - } - - SkASSERT(index < SK_ARRAY_COUNT(gDrawCacheProcs)); - return gDrawCacheProcs[index]; + SkASSERT(index < SK_ARRAY_COUNT(gGlyphCacheProcs)); + return gGlyphCacheProcs[index]; } /////////////////////////////////////////////////////////////////////////////// @@ -900,7 +797,7 @@ SkScalar SkPaint::measure_text(SkGlyphCache* cache, return 0; } - SkMeasureCacheProc glyphCacheProc = this->getMeasureCacheProc(nullptr != bounds); + GlyphCacheProc glyphCacheProc = this->getGlyphCacheProc(nullptr != bounds); int xyIndex; JoinBoundsProc joinBoundsProc; @@ -1025,7 +922,7 @@ size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth, SkAutoGlyphCache autoCache(paint, nullptr, nullptr); SkGlyphCache* cache = autoCache.getCache(); - SkMeasureCacheProc glyphCacheProc = paint.getMeasureCacheProc(false); + GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(false); const int xyIndex = paint.isVerticalText() ? 1 : 0; // use 64bits for our accumulator, to avoid overflowing 16.16 Sk48Dot16 max = SkScalarToFixed(maxWidth); @@ -1143,8 +1040,7 @@ int SkPaint::getTextWidths(const void* textData, size_t byteLength, SkAutoGlyphCache autoCache(paint, nullptr, nullptr); SkGlyphCache* cache = autoCache.getCache(); - SkMeasureCacheProc glyphCacheProc; - glyphCacheProc = paint.getMeasureCacheProc(nullptr != bounds); + GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(nullptr != bounds); const char* text = (const char*)textData; const char* stop = text + byteLength; @@ -2397,7 +2293,7 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length, const SkPaint& paint, bool applyStrokeAndPathEffects) : fPaint(paint) { - fGlyphCacheProc = paint.getMeasureCacheProc(true); + fGlyphCacheProc = paint.getGlyphCacheProc(true); fPaint.setLinearText(true); fPaint.setMaskFilter(nullptr); // don't want this affecting our path-cache lookup -- cgit v1.2.3