Clean up GPU strike sk_sp
Change-Id: Icece7d2e34307a52e58b195ba964d981999e15d1
Reviewed-on: https://skia-review.googlesource.com/155642
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 52e0669..8da07c7 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -388,21 +388,16 @@
}
void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex,
- GrGlyphCache* grGlyphCache,
- sk_sp<GrTextStrike>* strike,
+ const sk_sp<GrTextStrike>& 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 @@
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 @@
FallbackGlyphRunHelper fallbackTextHelper(viewMatrix, runPaint, textRatio);
- sk_sp<GrTextStrike> currStrike;
-
{
auto cache = cacheBlob->setupCache(
runIndex, props, flags, distanceFieldPaint, nullptr);
+ sk_sp<GrTextStrike> 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 @@
} else {
// Ensure the blob is set for bitmaptext
cacheBlob->setHasBitmap();
- sk_sp<GrTextStrike> currStrike;
+
auto cache = cacheBlob->setupCache(
runIndex, props, scalerContextFlags, runPaint, &viewMatrix);
+ sk_sp<GrTextStrike> 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 9144e90..58ab5f5 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -71,10 +71,10 @@
}
void GrTextBlob::appendGlyph(int runIndex,
- const SkRect& positions,
- GrColor color,
- sk_sp<GrTextStrike> strike,
- GrGlyph* glyph, bool preTransformed) {
+ const SkRect& positions,
+ GrColor color,
+ const sk_sp<GrTextStrike>& strike,
+ GrGlyph* glyph, bool preTransformed) {
Run& run = fRuns[runIndex];
GrMaskFormat format = glyph->fMaskFormat;
@@ -82,9 +82,9 @@
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 6fa9d04..f8a4565 100644
--- a/src/gpu/text/GrTextBlob.h
+++ b/src/gpu/text/GrTextBlob.h
@@ -177,7 +177,7 @@
void appendGlyph(int runIndex,
const SkRect& positions,
GrColor color,
- sk_sp<GrTextStrike> strike,
+ const sk_sp<GrTextStrike>& 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 7ef44bf..0e89b6b 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -243,7 +243,7 @@
SkExclusiveStrikePtr cache =
blob->setupCache(runIndex, props, scalerContextFlags, fallbackPaint, &matrix);
- sk_sp<GrTextStrike> currStrike;
+ sk_sp<GrTextStrike> currStrike = glyphCache->getStrike(cache.get());
auto glyphPos = fFallbackPos.begin();
for (auto glyphID : fFallbackTxt) {
const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID);
@@ -252,10 +252,10 @@
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 b313d4d..ac5e94f 100644
--- a/src/gpu/text/GrTextContext.h
+++ b/src/gpu/text/GrTextContext.h
@@ -122,9 +122,9 @@
const SkGlyphRunList& glyphRunList,
SkGlyphRunListPainter* glyphPainter);
- static void AppendGlyph(GrTextBlob*, int runIndex, GrGlyphCache*,
- sk_sp<GrTextStrike>*, const SkGlyph&, GrGlyph::MaskStyle maskStyle,
- SkScalar sx, SkScalar sy,
+ static void AppendGlyph(GrTextBlob*, int runIndex,
+ const sk_sp<GrTextStrike>&, const SkGlyph&,
+ GrGlyph::MaskStyle maskStyle, SkScalar sx, SkScalar sy,
GrColor color, SkGlyphCache*, SkScalar textRatio,
bool needsTransform);