From cf370b1fc1d4fa4a2ada67995c0482b26b570a53 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Wed, 19 Sep 2018 14:42:45 -0400 Subject: [PATCH] Clean up GPU strike sk_sp Change-Id: Icece7d2e34307a52e58b195ba964d981999e15d1 Reviewed-on: https://skia-review.googlesource.com/155642 Commit-Queue: Herb Derby Reviewed-by: Ben Wagner --- src/core/SkGlyphRunPainter.cpp | 104 ++++++++++++++++----------------- src/gpu/text/GrTextBlob.cpp | 12 ++-- src/gpu/text/GrTextBlob.h | 2 +- src/gpu/text/GrTextContext.cpp | 10 ++-- src/gpu/text/GrTextContext.h | 6 +- 5 files changed, 65 insertions(+), 69 deletions(-) diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp index 52e0669128..8da07c70bf 100644 --- a/src/core/SkGlyphRunPainter.cpp +++ b/src/core/SkGlyphRunPainter.cpp @@ -388,21 +388,16 @@ void GrTextContext::drawGlyphRunList( } void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex, - GrGlyphCache* grGlyphCache, - sk_sp* strike, + const sk_sp& strike, const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle, SkScalar sx, SkScalar sy, GrColor color, SkGlyphCache* skGlyphCache, SkScalar textRatio, bool needsTransform) { - if (!*strike) { - *strike = grGlyphCache->getStrike(skGlyphCache); - } - GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(), skGlyph.getSubXFixed(), skGlyph.getSubYFixed(), maskStyle); - GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, skGlyphCache); + GrGlyph* glyph = strike->getGlyph(skGlyph, id, skGlyphCache); if (!glyph) { return; } @@ -415,7 +410,7 @@ void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex, SkRect glyphRect = rect_to_draw(skGlyph, {sx, sy}, textRatio, isDFT); if (!glyphRect.isEmpty()) { - blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph, !needsTransform); + blob->appendGlyph(runIndex, glyphRect, color, strike, glyph, !needsTransform); } } @@ -457,39 +452,38 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, FallbackGlyphRunHelper fallbackTextHelper(viewMatrix, runPaint, textRatio); - sk_sp currStrike; - { auto cache = cacheBlob->setupCache( runIndex, props, flags, distanceFieldPaint, nullptr); + sk_sp currStrike = glyphCache->getStrike(cache.get()); + auto perSDF = - [cacheBlob, runIndex, glyphCache, &currStrike, - filteredColor, cache{cache.get()}, textRatio] - (const SkGlyph& glyph, SkPoint position) { - SkScalar sx = position.fX, - sy = position.fY; - AppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike, - glyph, GrGlyph::kDistance_MaskStyle, sx, sy, - filteredColor, - cache, textRatio, true); - }; + [cacheBlob, runIndex, &currStrike, filteredColor, cache{cache.get()}, textRatio] + (const SkGlyph& glyph, SkPoint position) { + SkScalar sx = position.fX, + sy = position.fY; + AppendGlyph(cacheBlob, runIndex, currStrike, + glyph, GrGlyph::kDistance_MaskStyle, sx, sy, + filteredColor, + cache, textRatio, true); + }; auto perPath = - [cacheBlob, runIndex, textRatio] - (const SkPath* path, const SkGlyph& glyph, SkPoint position) { - SkScalar sx = position.fX, - sy = position.fY; - cacheBlob->appendPathGlyph( - runIndex, *path, sx, sy, textRatio, false); - }; + [cacheBlob, runIndex, textRatio] + (const SkPath* path, const SkGlyph& glyph, SkPoint position) { + SkScalar sx = position.fX, + sy = position.fY; + cacheBlob->appendPathGlyph( + runIndex, *path, sx, sy, textRatio, false); + }; auto perFallback = - [&fallbackTextHelper] - (const SkGlyph& glyph, SkPoint position) { - fallbackTextHelper.appendGlyph(glyph, glyph.getGlyphID(), position); - }; + [&fallbackTextHelper] + (const SkGlyph& glyph, SkPoint position) { + fallbackTextHelper.appendGlyph(glyph, glyph.getGlyphID(), position); + }; glyphPainter->drawGlyphRunAsSDFWithFallback( cache.get(), glyphRun, origin, textRatio, perSDF, perPath, perFallback); @@ -546,36 +540,38 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob, } else { // Ensure the blob is set for bitmaptext cacheBlob->setHasBitmap(); - sk_sp currStrike; + auto cache = cacheBlob->setupCache( runIndex, props, scalerContextFlags, runPaint, &viewMatrix); + sk_sp currStrike = glyphCache->getStrike(cache.get()); + auto perGlyph = - [cacheBlob, runIndex, glyphCache, &currStrike, filteredColor, cache{cache.get()}] - (const SkGlyph& glyph, SkPoint mappedPt) { - if (!glyph.isEmpty()) { - const void* glyphImage = cache->findImage(glyph); - if (glyphImage != nullptr) { - SkScalar sx = SkScalarFloorToScalar(mappedPt.fX), - sy = SkScalarFloorToScalar(mappedPt.fY); - AppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike, - glyph, GrGlyph::kCoverage_MaskStyle, sx, sy, - filteredColor, cache, SK_Scalar1, false); - } + [cacheBlob, runIndex, &currStrike, filteredColor, cache{cache.get()}] + (const SkGlyph& glyph, SkPoint mappedPt) { + if (!glyph.isEmpty()) { + const void* glyphImage = cache->findImage(glyph); + if (glyphImage != nullptr) { + SkScalar sx = SkScalarFloorToScalar(mappedPt.fX), + sy = SkScalarFloorToScalar(mappedPt.fY); + AppendGlyph(cacheBlob, runIndex, currStrike, + glyph, GrGlyph::kCoverage_MaskStyle, sx, sy, + filteredColor, cache, SK_Scalar1, false); } - }; + } + }; auto perPath = - [cacheBlob, runIndex, cache{cache.get()}] - (const SkGlyph& glyph, SkPoint position) { - const SkPath* glyphPath = cache->findPath(glyph); - if (glyphPath != nullptr) { - SkScalar sx = SkScalarFloorToScalar(position.fX), - sy = SkScalarFloorToScalar(position.fY); - cacheBlob->appendPathGlyph( - runIndex, *glyphPath, sx, sy, SK_Scalar1, true); - } - }; + [cacheBlob, runIndex, cache{cache.get()}] + (const SkGlyph& glyph, SkPoint position) { + const SkPath* glyphPath = cache->findPath(glyph); + if (glyphPath != nullptr) { + SkScalar sx = SkScalarFloorToScalar(position.fX), + sy = SkScalarFloorToScalar(position.fY); + cacheBlob->appendPathGlyph( + runIndex, *glyphPath, sx, sy, SK_Scalar1, true); + } + }; glyphPainter->drawGlyphRunAsBMPWithPathFallback( cache.get(), glyphRun, origin, viewMatrix, perGlyph, perPath); diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp index 9144e90e1a..58ab5f5330 100644 --- a/src/gpu/text/GrTextBlob.cpp +++ b/src/gpu/text/GrTextBlob.cpp @@ -71,10 +71,10 @@ SkExclusiveStrikePtr GrTextBlob::setupCache(int runIndex, } void GrTextBlob::appendGlyph(int runIndex, - const SkRect& positions, - GrColor color, - sk_sp strike, - GrGlyph* glyph, bool preTransformed) { + const SkRect& positions, + GrColor color, + const sk_sp& strike, + GrGlyph* glyph, bool preTransformed) { Run& run = fRuns[runIndex]; GrMaskFormat format = glyph->fMaskFormat; @@ -82,9 +82,9 @@ void GrTextBlob::appendGlyph(int runIndex, Run::SubRunInfo* subRun = &run.fSubRunInfo.back(); if (run.fInitialized && subRun->maskFormat() != format) { subRun = &run.push_back(); - subRun->setStrike(std::move(strike)); + subRun->setStrike(strike); } else if (!run.fInitialized) { - subRun->setStrike(std::move(strike)); + subRun->setStrike(strike); } run.fInitialized = true; diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h index 6fa9d04cb0..f8a45659e1 100644 --- a/src/gpu/text/GrTextBlob.h +++ b/src/gpu/text/GrTextBlob.h @@ -177,7 +177,7 @@ public: void appendGlyph(int runIndex, const SkRect& positions, GrColor color, - sk_sp strike, + const sk_sp& strike, GrGlyph* glyph, bool preTransformed); // Appends a glyph to the blob as a path only. diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp index 7ef44bfd0e..0e89b6b0b9 100644 --- a/src/gpu/text/GrTextContext.cpp +++ b/src/gpu/text/GrTextContext.cpp @@ -243,7 +243,7 @@ void GrTextContext::FallbackGlyphRunHelper::drawGlyphs( SkExclusiveStrikePtr cache = blob->setupCache(runIndex, props, scalerContextFlags, fallbackPaint, &matrix); - sk_sp currStrike; + sk_sp currStrike = glyphCache->getStrike(cache.get()); auto glyphPos = fFallbackPos.begin(); for (auto glyphID : fFallbackTxt) { const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID); @@ -252,10 +252,10 @@ void GrTextContext::FallbackGlyphRunHelper::drawGlyphs( glyphPos->fX = SkScalarFloorToScalar(glyphPos->fX); glyphPos->fY = SkScalarFloorToScalar(glyphPos->fY); } - GrTextContext::AppendGlyph(blob, runIndex, glyphCache, &currStrike, - glyph, GrGlyph::kCoverage_MaskStyle, - glyphPos->fX, glyphPos->fY, textColor, - cache.get(), textRatio, fUseTransformedFallback); + GrTextContext::AppendGlyph(blob, runIndex, currStrike, + glyph, GrGlyph::kCoverage_MaskStyle, + glyphPos->fX, glyphPos->fY, textColor, + cache.get(), textRatio, fUseTransformedFallback); glyphPos++; } } diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h index b313d4db40..ac5e94fb0e 100644 --- a/src/gpu/text/GrTextContext.h +++ b/src/gpu/text/GrTextContext.h @@ -122,9 +122,9 @@ private: const SkGlyphRunList& glyphRunList, SkGlyphRunListPainter* glyphPainter); - static void AppendGlyph(GrTextBlob*, int runIndex, GrGlyphCache*, - sk_sp*, const SkGlyph&, GrGlyph::MaskStyle maskStyle, - SkScalar sx, SkScalar sy, + static void AppendGlyph(GrTextBlob*, int runIndex, + const sk_sp&, const SkGlyph&, + GrGlyph::MaskStyle maskStyle, SkScalar sx, SkScalar sy, GrColor color, SkGlyphCache*, SkScalar textRatio, bool needsTransform);