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>
This commit is contained in:
Herb Derby 2018-09-19 14:42:45 -04:00 committed by Skia Commit-Bot
parent 473b40b7ca
commit cf370b1fc1
5 changed files with 65 additions and 69 deletions

View File

@ -388,21 +388,16 @@ void GrTextContext::drawGlyphRunList(
}
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 @@ 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<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 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
} 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);

View File

@ -71,10 +71,10 @@ SkExclusiveStrikePtr GrTextBlob::setupCache(int runIndex,
}
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 @@ 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;

View File

@ -177,7 +177,7 @@ public:
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.

View File

@ -243,7 +243,7 @@ void GrTextContext::FallbackGlyphRunHelper::drawGlyphs(
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 @@ 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++;
}
}

View File

@ -122,9 +122,9 @@ private:
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);