Revert "Calculate strike in path case"

This reverts commit b5c1a79b55.

Reason for revert: Based on bad CL 192424

Original change's description:
> Calculate strike in path case
> 
> Change-Id: I9036b23df7279003a41f6189117fb7dec784ee2a
> Reviewed-on: https://skia-review.googlesource.com/c/192440
> Reviewed-by: Mike Klein <mtklein@google.com>
> Commit-Queue: Herb Derby <herb@google.com>

TBR=mtklein@google.com,herb@google.com

Change-Id: I218871efeff921663d4a2f26e04b4e0e41ca42ab
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/192831
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2019-02-15 16:24:24 +00:00 committed by Skia Commit-Bot
parent 28bafb01c9
commit 5f5a016b1b
2 changed files with 59 additions and 73 deletions

View File

@ -331,74 +331,58 @@ void SkGlyphRunListPainter::processARGBFallback(
// Beware! The following code will end up holding two glyph caches at the same time, but they // Beware! The following code will end up holding two glyph caches at the same time, but they
// will not be the same cache (which would cause two separate caches to be created). // will not be the same cache (which would cause two separate caches to be created).
template <typename ProcessPathsT, typename CreatorT> template <typename ProcessPathsT>
void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback( void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback(
const SkPaint& runPaint, const SkFont& runFont, CreatorT&& strikeCreator, SkStrikeInterface* strike, const SkGlyphRun& glyphRun,
const SkGlyphRun& glyphRun, SkPoint origin, const SkMatrix& viewMatrix, SkPoint origin, const SkPaint& runPaint, const SkMatrix& viewMatrix, SkScalar textScale,
ProcessPathsT&& processPaths, ARGBFallback&& argbFallback) { ProcessPathsT&& processPaths, ARGBFallback&& argbFallback) {
fARGBGlyphsIDs.clear(); fARGBGlyphsIDs.clear();
fARGBPositions.clear(); fARGBPositions.clear();
ScopedBuffers _ = ensureBuffers(glyphRun); ScopedBuffers _ = ensureBuffers(glyphRun);
SkScalar maxFallbackDimension{-SK_ScalarInfinity}; SkScalar maxFallbackDimension{-SK_ScalarInfinity};
// setup our std runPaint, in hopes of getting hits in the cache // Four empty glyphs are expected; one for each horizontal subpixel position.
SkPaint pathPaint{runPaint}; SkSTArray<4, const SkGlyph*> emptyGlyphs;
SkFont pathFont{runFont};
// The factor to get from the size stored in the strike to the size needed for the source. int glyphCount = 0;
SkScalar strikeToSourceRatio = pathFont.setupForAsPaths(&pathPaint); const SkPoint* positionCursor = glyphRun.positions().data();
for (auto glyphID : glyphRun.glyphsIDs()) {
SkPoint glyphPos = origin + *positionCursor++;
SkAutoDescriptor ad; if (std::any_of(emptyGlyphs.begin(), emptyGlyphs.end(),
SkScalerContextEffects effects; [glyphID](const SkGlyph* g) { return g->getGlyphID() == glyphID; })) {
SkScalerContext::CreateDescriptorAndEffectsUsingPaint( continue;
pathFont, pathPaint, fDeviceProps, fScalerContextFlags, SkMatrix::I(), &ad, &effects);
{
SkScopedStrike strike = strikeCreator(*ad.getDesc(), effects,
*pathFont.getTypefaceOrDefault());
// Four empty glyphs are expected; one for each horizontal subpixel position.
SkSTArray<4, const SkGlyph*> emptyGlyphs;
int glyphCount = 0;
const SkPoint* positionCursor = glyphRun.positions().data();
for (auto glyphID : glyphRun.glyphsIDs()) {
SkPoint glyphPos = origin + *positionCursor++;
if (std::any_of(emptyGlyphs.begin(), emptyGlyphs.end(),
[glyphID](const SkGlyph* g) { return g->getGlyphID() == glyphID; })) {
continue;
}
const SkGlyph& glyph = strike->getGlyphMetrics(glyphID, glyphPos);
if (glyph.isEmpty()) {
emptyGlyphs.push_back(&glyph);
} else if (glyph.fMaskFormat != SkMask::kARGB32_Format) {
if (strike->decideCouldDrawFromPath(glyph)) {
fGlyphPos[glyphCount++] = {&glyph, glyphPos};
} else {
// This happens when a bitmap-only font is forced to scale very large. This
// doesn't happen in practice.
emptyGlyphs.push_back(&glyph);
}
} else {
SkScalar largestDimension = std::max(glyph.fWidth, glyph.fHeight);
maxFallbackDimension = std::max(maxFallbackDimension, largestDimension);
fARGBGlyphsIDs.push_back(glyphID);
fARGBPositions.push_back(glyphPos);
}
} }
if (glyphCount > 0) { const SkGlyph& glyph = strike->getGlyphMetrics(glyphID, glyphPos);
processPaths(SkSpan<const GlyphAndPos>{fGlyphPos, SkTo<size_t>(glyphCount)}, if (glyph.isEmpty()) {
strike.get(), emptyGlyphs.push_back(&glyph);
strikeToSourceRatio); } else if (glyph.fMaskFormat != SkMask::kARGB32_Format) {
if (strike->decideCouldDrawFromPath(glyph)) {
fGlyphPos[glyphCount++] = {&glyph, glyphPos};
} else {
// This happens when a bitmap-only font is forced to scale very large. This
// doesn't happen in practice.
emptyGlyphs.push_back(&glyph);
}
} else {
SkScalar largestDimension = std::max(glyph.fWidth, glyph.fHeight);
maxFallbackDimension = std::max(maxFallbackDimension, largestDimension);
fARGBGlyphsIDs.push_back(glyphID);
fARGBPositions.push_back(glyphPos);
} }
} }
if (glyphCount > 0) {
processPaths(SkSpan<const GlyphAndPos>{fGlyphPos, SkTo<size_t>(glyphCount)},
strike,
textScale);
}
if (!fARGBGlyphsIDs.empty()) { if (!fARGBGlyphsIDs.empty()) {
this->processARGBFallback( this->processARGBFallback(
maxFallbackDimension, runPaint, glyphRun.font(), viewMatrix, strikeToSourceRatio, maxFallbackDimension, runPaint, glyphRun.font(), viewMatrix, textScale,
std::move(argbFallback)); std::move(argbFallback));
} }
@ -838,6 +822,15 @@ void GrTextBlob::generateFromGlyphRunList(GrStrikeCache* glyphCache,
// Ensure the blob is set for bitmaptext // Ensure the blob is set for bitmaptext
this->setHasBitmap(); this->setHasBitmap();
// setup our std runPaint, in hopes of getting hits in the cache
SkPaint pathPaint{runPaint};
SkFont pathFont{runFont};
SkScalar textScale = pathFont.setupForAsPaths(&pathPaint);
auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive(
pathFont, pathPaint, props,
scalerContextFlags, SkMatrix::I());
// Given a glyph that is not ARGB, draw it. // Given a glyph that is not ARGB, draw it.
auto processPath = [run]( auto processPath = [run](
SkSpan<const SkGlyphRunListPainter::GlyphAndPos> paths, SkSpan<const SkGlyphRunListPainter::GlyphAndPos> paths,
@ -852,19 +845,9 @@ void GrTextBlob::generateFromGlyphRunList(GrStrikeCache* glyphCache,
ARGBFallbackHelper argbFallback{this, run, props, scalerContextFlags, glyphCache}; ARGBFallbackHelper argbFallback{this, run, props, scalerContextFlags, glyphCache};
auto strikeCache = SkStrikeCache::GlobalStrikeCache();
auto creator = [strikeCache]
(const SkDescriptor& desc,
SkScalerContextEffects effects,
const SkTypeface& typeface) {
return strikeCache->findOrCreateScopedStrike(desc, effects, typeface);
};
glyphPainter->drawGlyphRunAsPathWithARGBFallback( glyphPainter->drawGlyphRunAsPathWithARGBFallback(
runPaint, runFont, std::move(creator), pathCache.get(), glyphRun, origin, runPaint, viewMatrix, textScale,
glyphRun, origin, viewMatrix, std::move(processPath), std::move(argbFallback));
std::move(processPath), std::move(argbFallback));
} else { } else {
// Ensure the blob is set for bitmaptext // Ensure the blob is set for bitmaptext
this->setHasBitmap(); this->setHasBitmap();
@ -1039,10 +1022,14 @@ void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths(
SkPoint origin, const SkPaint& runPaint) { SkPoint origin, const SkPaint& runPaint) {
TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForPaths"); TRACE_EVENT0("skia", "SkTextBlobCacheDiffCanvas::processGlyphRunForPaths");
auto creator = [this] SkPaint pathPaint{runPaint};
(const SkDescriptor& desc, SkScalerContextEffects effects, const SkTypeface& typeface) { SkFont pathFont{glyphRun.font()};
return SkScopedStrike{fStrikeServer->getOrCreateCache(desc, typeface, effects)}; SkScalar textScale = SetupForPath(&pathPaint, &pathFont);
};
SkScalerContextEffects effects;
auto* glyphCacheState = fStrikeServer->getOrCreateCache(
pathPaint, pathFont, this->surfaceProps(), SkMatrix::I(),
SkScalerContextFlags::kFakeGammaAndBoostContrast, &effects);
// This processor is empty because all changes to the cache are tracked through // This processor is empty because all changes to the cache are tracked through
// getGlyphMetrics and decideCouldDrawFromPath. // getGlyphMetrics and decideCouldDrawFromPath.
@ -1052,8 +1039,7 @@ void SkTextBlobCacheDiffCanvas::TrackLayerDevice::processGlyphRunForPaths(
ARGBHelper argbFallback{runMatrix, surfaceProps(), fStrikeServer}; ARGBHelper argbFallback{runMatrix, surfaceProps(), fStrikeServer};
fPainter.drawGlyphRunAsPathWithARGBFallback( fPainter.drawGlyphRunAsPathWithARGBFallback(
runPaint, glyphRun.font(), std::move(creator), glyphCacheState, glyphRun, origin, runPaint, runMatrix, textScale,
glyphRun, origin, runMatrix,
std::move(processPaths), std::move(argbFallback)); std::move(processPaths), std::move(argbFallback));
} }

View File

@ -131,10 +131,10 @@ public:
// For each glyph that is not ARGB call perPath. If the glyph is ARGB then store the glyphID // For each glyph that is not ARGB call perPath. If the glyph is ARGB then store the glyphID
// and the position in fallback vectors. After all the glyphs are processed, pass the // and the position in fallback vectors. After all the glyphs are processed, pass the
// fallback glyphIDs and positions to fallbackARGB. // fallback glyphIDs and positions to fallbackARGB.
template <typename ProcessPathsT, typename CreatorT> template <typename ProcessPathsT>
void drawGlyphRunAsPathWithARGBFallback( void drawGlyphRunAsPathWithARGBFallback(
const SkPaint& runPaint, const SkFont& runFont, CreatorT&& strikeCreator, SkStrikeInterface* cache, const SkGlyphRun& glyphRun,
const SkGlyphRun& glyphRun, SkPoint origin, const SkMatrix& viewMatrix, SkPoint origin, const SkPaint& paint, const SkMatrix& viewMatrix, SkScalar textScale,
ProcessPathsT&& processPaths, ARGBFallback&& fallbackARGB); ProcessPathsT&& processPaths, ARGBFallback&& fallbackARGB);
template <typename PerEmptyT, typename PerSDFT, typename PerPathT> template <typename PerEmptyT, typename PerSDFT, typename PerPathT>