From d936f63c35fb7dfb2b6c20802206adbfc3cc48d0 Mon Sep 17 00:00:00 2001 From: benjaminwagner Date: Tue, 23 Feb 2016 10:44:31 -0800 Subject: [PATCH] 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 --- include/core/SkPaint.h | 10 +-- src/core/SkDraw.cpp | 6 +- src/core/SkPaint.cpp | 120 ++------------------------ src/core/SkTextToPathIter.h | 2 +- src/gpu/text/GrStencilAndCoverTextContext.cpp | 10 +-- src/gpu/text/GrTextUtils.cpp | 18 ++-- src/pdf/SkPDFDevice.cpp | 8 +- 7 files changed, 33 insertions(+), 141 deletions(-) diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 482483f..b58a3f3 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -35,11 +35,6 @@ class SkShader; class SkSurfaceProps; class SkTypeface; -typedef const SkGlyph& (*SkDrawCacheProc)(SkGlyphCache*, const char**, - SkFixed x, SkFixed y); - -typedef const SkGlyph& (*SkMeasureCacheProc)(SkGlyphCache*, const char**); - #define kBicubicFilterBitmap_Flag kHighQualityFilterBitmap_Flag /** \class SkPaint @@ -1030,6 +1025,8 @@ public: return SetTextMatrix(matrix, fTextSize, fTextScaleX, fTextSkewX); } + typedef const SkGlyph& (*GlyphCacheProc)(SkGlyphCache*, const char**); + SK_TO_STRING_NONVIRT() private: @@ -1066,8 +1063,7 @@ private: uint32_t fBitfieldsUInt; }; - SkDrawCacheProc getDrawCacheProc() const; - SkMeasureCacheProc getMeasureCacheProc(bool needFullMetrics) const; + GlyphCacheProc getGlyphCacheProc(bool needFullMetrics) const; SkScalar measure_text(SkGlyphCache*, const char* text, size_t length, int* count, SkRect* bounds) const; diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 0c17c94..4db7594 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -1606,8 +1606,8 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, paint.setStyle(SkPaint::kFill_Style); paint.setPathEffect(nullptr); - SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); - SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->fakeGamma(), nullptr); + SkPaint::GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(true); + SkAutoGlyphCache cache(paint, &fDevice->surfaceProps(), this->fakeGamma(), nullptr); const char* stop = text + byteLength; SkTextAlignProc alignProc(paint.getTextAlign()); @@ -1618,7 +1618,7 @@ void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, paint.setPathEffect(origPaint.getPathEffect()); while (text < stop) { - const SkGlyph& glyph = glyphCacheProc(cache.get(), &text, 0, 0); + const SkGlyph& glyph = glyphCacheProc(cache.get(), &text); if (glyph.fWidth) { const SkPath* path = cache->findPath(glyph); if (path) { diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index d2ea8ee..d3384a6 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 diff --git a/src/core/SkTextToPathIter.h b/src/core/SkTextToPathIter.h index e299552..435c1c7 100644 --- a/src/core/SkTextToPathIter.h +++ b/src/core/SkTextToPathIter.h @@ -25,7 +25,7 @@ protected: SkFixed fPrevAdvance; const char* fText; const char* fStop; - SkMeasureCacheProc fGlyphCacheProc; + SkPaint::GlyphCacheProc fGlyphCacheProc; SkScalar fXPos; // accumulated xpos, returned in next SkAutoKern fAutoKern; diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp index a87e5d2..52281b2 100644 --- a/src/gpu/text/GrStencilAndCoverTextContext.cpp +++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp @@ -440,7 +440,7 @@ void GrStencilAndCoverTextContext::TextRun::setText(const char text[], size_t by SkASSERT(byteLength == 0 || text != nullptr); SkGlyphCache* glyphCache = this->getGlyphCache(); - SkDrawCacheProc glyphCacheProc = fFont.getDrawCacheProc(); + SkPaint::GlyphCacheProc glyphCacheProc = fFont.getGlyphCacheProc(true); fTotalGlyphCount = fFont.countText(text, byteLength); fInstanceData.reset(InstanceData::Alloc(GrPathRendering::kTranslate_PathTransformType, @@ -457,7 +457,7 @@ void GrStencilAndCoverTextContext::TextRun::setText(const char text[], size_t by while (textPtr < stop) { // We don't need x, y here, since all subpixel variants will have the // same advance. - const SkGlyph& glyph = glyphCacheProc(glyphCache, &textPtr, 0, 0); + const SkGlyph& glyph = glyphCacheProc(glyphCache, &textPtr); stopX += glyph.fAdvanceX; stopY += glyph.fAdvanceY; @@ -484,7 +484,7 @@ void GrStencilAndCoverTextContext::TextRun::setText(const char text[], size_t by SkFixed fy = SkScalarToFixed(y); FallbackBlobBuilder fallback; while (text < stop) { - const SkGlyph& glyph = glyphCacheProc(glyphCache, &text, 0, 0); + const SkGlyph& glyph = glyphCacheProc(glyphCache, &text); fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); if (glyph.fWidth) { this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedToScalar(fy)), @@ -505,7 +505,7 @@ void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); SkGlyphCache* glyphCache = this->getGlyphCache(); - SkDrawCacheProc glyphCacheProc = fFont.getDrawCacheProc(); + SkPaint::GlyphCacheProc glyphCacheProc = fFont.getGlyphCacheProc(true); fTotalGlyphCount = fFont.countText(text, byteLength); fInstanceData.reset(InstanceData::Alloc(GrPathRendering::kTranslate_PathTransformType, @@ -517,7 +517,7 @@ void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t SkTextAlignProc alignProc(fFont.getTextAlign()); FallbackBlobBuilder fallback; while (text < stop) { - const SkGlyph& glyph = glyphCacheProc(glyphCache, &text, 0, 0); + const SkGlyph& glyph = glyphCacheProc(glyphCache, &text); if (glyph.fWidth) { SkPoint tmsLoc; tmsProc(pos, &tmsLoc); diff --git a/src/gpu/text/GrTextUtils.cpp b/src/gpu/text/GrTextUtils.cpp index 112f5bd..c46ea73 100644 --- a/src/gpu/text/GrTextUtils.cpp +++ b/src/gpu/text/GrTextUtils.cpp @@ -258,7 +258,7 @@ void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex, return; } - SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); + SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true); SkAutoDescriptor desc; skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nullptr); SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface(), @@ -281,7 +281,7 @@ void GrTextUtils::DrawDFText(GrAtlasTextBlob* blob, int runIndex, while (textPtr < stop) { // don't need x, y here, since all subpixel variants will have the // same advance - const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr, 0, 0); + const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr); SkFixed width = glyph.fAdvanceX + autokern.adjust(glyph); positions.push_back(SkFixedToScalar(stopX + SkFixedMul(origin, width))); @@ -343,7 +343,7 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, SkGlyphCache* cache = blob->setupCache(runIndex, props, SkPaint::FakeGamma::Off, dfPaint, nullptr); - SkDrawCacheProc glyphCacheProc = dfPaint.getDrawCacheProc(); + SkPaint::GlyphCacheProc glyphCacheProc = dfPaint.getGlyphCacheProc(true); GrFontScaler* fontScaler = GrTextUtils::GetGrFontScaler(cache); const char* stop = text + byteLength; @@ -352,7 +352,7 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, while (text < stop) { const char* lastText = text; // the last 2 parameters are ignored - const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); + const SkGlyph& glyph = glyphCacheProc(cache, &text); if (glyph.fWidth) { SkScalar x = offset.x() + pos[0]; @@ -381,7 +381,7 @@ void GrTextUtils::DrawDFPosText(GrAtlasTextBlob* blob, int runIndex, while (text < stop) { const char* lastText = text; // the last 2 parameters are ignored - const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); + const SkGlyph& glyph = glyphCacheProc(cache, &text); if (glyph.fWidth) { SkScalar x = offset.x() + pos[0]; @@ -507,9 +507,9 @@ void GrTextUtils::DrawPosTextAsPath(GrContext* context, paint.setStyle(SkPaint::kFill_Style); paint.setPathEffect(nullptr); - SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); - SkAutoGlyphCache autoCache(paint, &props, nullptr); - SkGlyphCache* cache = autoCache.getCache(); + SkPaint::GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(true); + SkAutoGlyphCache autoCache(paint, &props, nullptr); + SkGlyphCache* cache = autoCache.getCache(); const char* stop = text + byteLength; SkTextAlignProc alignProc(paint.getTextAlign()); @@ -520,7 +520,7 @@ void GrTextUtils::DrawPosTextAsPath(GrContext* context, paint.setPathEffect(origPaint.getPathEffect()); while (text < stop) { - const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); + const SkGlyph& glyph = glyphCacheProc(cache, &text); if (glyph.fWidth) { const SkPath* path = cache->findPath(glyph); if (path) { diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 0e11f61..315c843 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -80,7 +80,7 @@ static SkPaint calculate_text_paint(const SkPaint& paint) { } // Stolen from measure_text in SkDraw.cpp and then tweaked. -static void align_text(SkDrawCacheProc glyphCacheProc, const SkPaint& paint, +static void align_text(SkPaint::GlyphCacheProc glyphCacheProc, const SkPaint& paint, const uint16_t* glyphs, size_t len, SkScalar* x, SkScalar* y) { if (paint.getTextAlign() == SkPaint::kLeft_Align) { @@ -98,7 +98,7 @@ static void align_text(SkDrawCacheProc glyphCacheProc, const SkPaint& paint, // TODO(vandebo): This probably needs to take kerning into account. while (start < stop) { - const SkGlyph& glyph = glyphCacheProc(cache, &start, 0, 0); + const SkGlyph& glyph = glyphCacheProc(cache, &start); xAdv += glyph.fAdvanceX; yAdv += glyph.fAdvanceY; }; @@ -1302,7 +1302,7 @@ void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len, int numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphIDs); textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc(); + SkPaint::GlyphCacheProc glyphCacheProc = textPaint.getGlyphCacheProc(true); align_text(glyphCacheProc, textPaint, glyphIDs, numGlyphs, &x, &y); content.entry()->fContent.writeText("BT\n"); set_text_transform(x, y, textPaint.getTextSkewX(), @@ -1378,7 +1378,7 @@ void SkPDFDevice::drawPosText(const SkDraw& d, const void* text, size_t len, size_t numGlyphs = force_glyph_encoding(paint, text, len, &storage, &glyphIDs); textPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - SkDrawCacheProc glyphCacheProc = textPaint.getDrawCacheProc(); + SkPaint::GlyphCacheProc glyphCacheProc = textPaint.getGlyphCacheProc(true); content.entry()->fContent.writeText("BT\n"); this->updateFont(textPaint, glyphIDs[0], content.entry()); for (size_t i = 0; i < numGlyphs; i++) { -- 2.7.4