Change fallback for path glyphs to bulk api
This is a different approach to handling fallback, but it ultimately simplifies handling fallback. If this works out, the remote code will not have to use the GPU's fallback code. Change-Id: I20b159f224771a4b900055ad33ae625f0cf210a4 Reviewed-on: https://skia-review.googlesource.com/154121 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
5152c4acfb
commit
1a0f189049
@ -520,20 +520,28 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
|
||||
pathPaint, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
|
||||
|
||||
auto drawOnePath =
|
||||
[&fallbackTextHelper, matrixScale, runIndex, cacheBlob]
|
||||
(const SkPath* path, const SkGlyph& glyph, SkPoint position) {
|
||||
if (glyph.fMaskFormat == SkMask::kARGB32_Format) {
|
||||
fallbackTextHelper.appendGlyph(glyph, glyph.getGlyphID(), position);
|
||||
} else {
|
||||
if (path != nullptr) {
|
||||
cacheBlob->appendPathGlyph(
|
||||
runIndex, *path, position.fX, position.fY, matrixScale, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
auto perPath = [matrixScale, runIndex, cacheBlob, &cache]
|
||||
(const SkGlyph& glyph, SkPoint position) {
|
||||
const SkPath* path = cache->findPath(glyph);
|
||||
if (path != nullptr) {
|
||||
cacheBlob->appendPathGlyph(
|
||||
runIndex, *path, position.fX, position.fY, matrixScale, false);
|
||||
}
|
||||
};
|
||||
|
||||
glyphPainter->drawUsingPaths(glyphRun, origin, cache.get(), drawOnePath);
|
||||
auto fallbackARGB = [cache{cache.get()}, &fallbackTextHelper]
|
||||
(SkSpan<const SkGlyphID> glyphIDs,
|
||||
SkSpan<const SkPoint>positions) {
|
||||
const SkPoint* pos = positions.data();
|
||||
for (auto glyphID : glyphIDs) {
|
||||
SkPoint position = *pos++;
|
||||
const SkGlyph& glyph = cache->getGlyphMetrics(glyphID, {0, 0});
|
||||
fallbackTextHelper.appendGlyph(glyph, glyph.getGlyphID(), position);
|
||||
}
|
||||
};
|
||||
|
||||
glyphPainter->drawGlyphRunAsPathWithARGBFallback(
|
||||
cache.get(), glyphRun, origin, perPath, fallbackARGB);
|
||||
|
||||
fallbackTextHelper.drawGlyphs(
|
||||
cacheBlob, runIndex, glyphCache, props,
|
||||
|
@ -40,13 +40,23 @@ public:
|
||||
void drawUsingPaths(
|
||||
const SkGlyphRun& glyphRun, SkPoint origin, SkGlyphCache* cache, PerPath perPath) const;
|
||||
|
||||
//using PerGlyph = std::function<void(const SkGlyph&, SkPoint)>;
|
||||
template <typename PerGlyphT, typename PerPathT>
|
||||
void drawGlyphRunAsBMPWithPathFallback(
|
||||
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
|
||||
SkPoint origin, const SkMatrix& deviceMatrix,
|
||||
PerGlyphT perGlyph, PerPathT perPath);
|
||||
|
||||
// Draw glyphs as paths with fallback to scaled ARGB glyphs if color is needed.
|
||||
// PerPath - perPath(const SkGlyph&, SkPoint position)
|
||||
// FallbackARGB - fallbackARGB(SkSpan<const SkGlyphID>, SkSpan<const SkPoint>)
|
||||
// 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
|
||||
// fallback glyphIDs and positions to fallbackARGB.
|
||||
template <typename PerPath, typename FallbackARGB>
|
||||
void drawGlyphRunAsPathWithARGBFallback(
|
||||
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
|
||||
SkPoint origin, PerPath perPath, FallbackARGB fallbackARGB);
|
||||
|
||||
template <typename PerSDFT, typename PerPathT, typename PerFallbackT>
|
||||
void drawGlyphRunAsSDFWithFallback(
|
||||
SkGlyphCache* cache, const SkGlyphRun& glyphRun,
|
||||
@ -133,6 +143,35 @@ void SkGlyphRunListPainter::forEachMappedDrawableGlyph(
|
||||
}
|
||||
}
|
||||
|
||||
template <typename PerPathT, typename FallbackARGB>
|
||||
void SkGlyphRunListPainter::drawGlyphRunAsPathWithARGBFallback(
|
||||
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
|
||||
SkPoint origin, PerPathT perPath, FallbackARGB fallbackARGB) {
|
||||
std::vector<SkGlyphID> fallbackGlyphIDs;
|
||||
std::vector<SkPoint> fallbackPositions;
|
||||
|
||||
auto eachGlyph =
|
||||
[cache, origin, perPath{std::move(perPath)}, &fallbackGlyphIDs, &fallbackPositions]
|
||||
(SkGlyphID glyphID, SkPoint position) {
|
||||
if (SkScalarsAreFinite(position.x(), position.y())) {
|
||||
const SkGlyph& glyph = cache->getGlyphMetrics(glyphID, {0, 0});
|
||||
if (!glyph.isEmpty()) {
|
||||
if (glyph.fMaskFormat != SkMask::kARGB32_Format) {
|
||||
perPath(glyph, origin + position);
|
||||
} else {
|
||||
fallbackGlyphIDs.push_back(glyphID);
|
||||
fallbackPositions.push_back(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
glyphRun.forEachGlyphAndPosition(eachGlyph);
|
||||
|
||||
fallbackARGB(SkSpan<const SkGlyphID>{fallbackGlyphIDs},
|
||||
SkSpan<const SkPoint>{fallbackPositions});
|
||||
}
|
||||
|
||||
template <typename PerGlyphT, typename PerPathT>
|
||||
void SkGlyphRunListPainter::drawGlyphRunAsBMPWithPathFallback(
|
||||
SkGlyphCacheInterface* cache, const SkGlyphRun& glyphRun,
|
||||
|
Loading…
Reference in New Issue
Block a user