Move path leaf loop to drawer

This CL makes GPU and Raster use the same path drawing interface. When
I get the main body of regenerate over into the glyph run system, I
I can refactor a lot of annoyingly similar code away.

Change-Id: I6bd2e6119570062695d6943565749d85555b03fa
Reviewed-on: https://skia-review.googlesource.com/144350
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2018-07-30 10:10:40 -04:00 committed by Skia Commit-Bot
parent a83bb57bfe
commit 0ab5ce151c
4 changed files with 48 additions and 50 deletions

View File

@ -1628,9 +1628,18 @@ void SkDraw::drawGlyphRunList(
return; return;
} }
auto perPathBuilder = [this](const SkPaint& paint, SkArenaAlloc*) { SkMatrix renderMatrix{*fMatrix};
auto perPath = [this, &paint](const SkPath& path, const SkMatrix& matrix) { auto perPathBuilder = [this, &renderMatrix]
this->drawPath(path, paint, &matrix, false); (const SkPaint& paint, SkScalar scaleMatrix, SkArenaAlloc*) {
renderMatrix.setScale(scaleMatrix, scaleMatrix);
auto perPath =
[this, &renderMatrix, &paint]
(const SkPath* path, const SkGlyph&, SkPoint position) {
if (path != nullptr) {
renderMatrix[SkMatrix::kMTransX] = position.fX;
renderMatrix[SkMatrix::kMTransY] = position.fY;
this->drawPath(*path, paint, &renderMatrix, false);
}
}; };
return perPath; return perPath;
}; };

View File

@ -163,38 +163,16 @@ bool SkGlyphRunListDrawer::ensureBitmapBuffers(size_t runSize) {
} }
void SkGlyphRunListDrawer::drawUsingPaths( void SkGlyphRunListDrawer::drawUsingPaths(
const SkGlyphRun& glyphRun, SkPoint origin, const SkGlyphRun& glyphRun, SkPoint origin, SkGlyphCache* cache, PerPath perPath) const {
const SkSurfaceProps& props, PerPath perPath) const {
// setup our std paint, in hopes of getting hits in the cache
const SkPaint& origPaint = glyphRun.paint();
SkPaint paint(glyphRun.paint());
SkScalar matrixScale = paint.setupForAsPaths();
SkMatrix matrix; auto eachGlyph =
matrix.setScale(matrixScale, matrixScale); [perPath{std::move(perPath)}, origin, &cache]
// Temporarily jam in kFill, so we only ever ask for the raw outline from the cache.
paint.setStyle(SkPaint::kFill_Style);
paint.setPathEffect(nullptr);
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
paint, &props, fScalerContextFlags, nullptr);
// Now restore the original settings, so we "draw" with whatever style/stroking.
paint.setStyle(origPaint.getStyle());
paint.setPathEffect(origPaint.refPathEffect());
auto eachGlyph = [perPath{std::move(perPath)}, origin, &cache, &matrix]
(SkGlyphID glyphID, SkPoint position) { (SkGlyphID glyphID, SkPoint position) {
const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID); const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID);
if (glyph.fWidth > 0) { if (glyph.fWidth > 0) {
const SkPath* path = cache->findPath(glyph); const SkPath* path = cache->findPath(glyph);
if (path != nullptr) { SkPoint loc = position + origin;
SkPoint loc = position + origin; perPath(path, glyph, loc);
matrix[SkMatrix::kMTransX] = loc.fX;
matrix[SkMatrix::kMTransY] = loc.fY;
perPath(*path, matrix);
}
} }
}; };
@ -319,8 +297,20 @@ void SkGlyphRunListDrawer::drawForBitmapDevice(
: fBitmapFallbackProps; : fBitmapFallbackProps;
auto paint = glyphRun.paint(); auto paint = glyphRun.paint();
if (ShouldDrawAsPath(glyphRun.paint(), deviceMatrix)) { if (ShouldDrawAsPath(glyphRun.paint(), deviceMatrix)) {
auto perPath = perPathCreator(paint, &alloc);
this->drawUsingPaths(glyphRun, origin, props, perPath); // setup our std pathPaint, in hopes of getting hits in the cache
SkPaint pathPaint(glyphRun.paint());
SkScalar matrixScale = pathPaint.setupForAsPaths();
// Temporarily jam in kFill, so we only ever ask for the raw outline from the cache.
pathPaint.setStyle(SkPaint::kFill_Style);
pathPaint.setPathEffect(nullptr);
auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive(
pathPaint, &props, fScalerContextFlags, nullptr);
auto perPath = perPathCreator(paint, matrixScale, &alloc);
this->drawUsingPaths(glyphRun, origin, pathCache.get(), perPath);
} else { } else {
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
paint, &props, fScalerContextFlags, &deviceMatrix); paint, &props, fScalerContextFlags, &deviceMatrix);

View File

@ -119,21 +119,21 @@ public:
using PerMask = std::function<void(const SkMask&, const SkGlyph&, SkPoint)>; using PerMask = std::function<void(const SkMask&, const SkGlyph&, SkPoint)>;
using PerMaskCreator = std::function<PerMask(const SkPaint&, SkArenaAlloc* alloc)>; using PerMaskCreator = std::function<PerMask(const SkPaint&, SkArenaAlloc* alloc)>;
using PerPath = std::function<void(const SkPath&, const SkMatrix&)>; using PerPath = std::function<void(const SkPath*, const SkGlyph&, SkPoint)>;
using PerPathCreator = std::function<PerPath(const SkPaint&, SkArenaAlloc* alloc)>; using PerPathCreator = std::function<PerPath(
const SkPaint&, SkScalar matrixScale,SkArenaAlloc* alloc)>;
void drawForBitmapDevice( void drawForBitmapDevice(
const SkGlyphRunList& glyphRunList, const SkMatrix& deviceMatrix, const SkGlyphRunList& glyphRunList, const SkMatrix& deviceMatrix,
PerMaskCreator perMaskCreator, PerPathCreator perPathCreator); PerMaskCreator perMaskCreator, PerPathCreator perPathCreator);
void drawUsingMasks( void drawUsingMasks(
SkGlyphCache* cache, const SkGlyphRun& glyphRun, SkPoint origin, SkGlyphCache* cache, const SkGlyphRun& glyphRun, SkPoint origin,
const SkMatrix& deviceMatrix, PerMask perMask); const SkMatrix& deviceMatrix, PerMask perMask);
void drawUsingPaths(
const SkGlyphRun& glyphRun, SkPoint origin, SkGlyphCache* cache, PerPath perPath) const;
private: private:
static bool ShouldDrawAsPath(const SkPaint& paint, const SkMatrix& matrix); static bool ShouldDrawAsPath(const SkPaint& paint, const SkMatrix& matrix);
bool ensureBitmapBuffers(size_t runSize); bool ensureBitmapBuffers(size_t runSize);
void drawUsingPaths(
const SkGlyphRun& glyphRun, SkPoint origin,
const SkSurfaceProps& props, PerPath perPath) const;
void drawGlyphRunAsSubpixelMask( void drawGlyphRunAsSubpixelMask(
SkGlyphCache* cache, const SkGlyphRun& glyphRun, SkGlyphCache* cache, const SkGlyphRun& glyphRun,
SkPoint origin, const SkMatrix& deviceMatrix, SkPoint origin, const SkMatrix& deviceMatrix,

View File

@ -169,21 +169,20 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive( auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
pathPaint, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr); pathPaint, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
const SkPoint* positionCursor = glyphRun.positions().data(); auto drawOnePath =
for (auto glyphID : glyphRun.shuntGlyphsIDs()) { [&fallbackTextHelper, matrixScale, runIndex, cacheBlob]
const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID); (const SkPath* path, const SkGlyph& glyph, SkPoint position) {
SkPoint loc = origin + *positionCursor++; if (glyph.fMaskFormat == SkMask::kARGB32_Format) {
if (glyph.fWidth > 0) { fallbackTextHelper.appendText(glyph, glyph.getGlyphID(), position);
if (glyph.fMaskFormat == SkMask::kARGB32_Format) { } else {
fallbackTextHelper.appendText(glyph, glyphID, loc); if (path != nullptr) {
} else { cacheBlob->appendPathGlyph(
const SkPath* path = cache->findPath(glyph); runIndex, *path, position.fX, position.fY, matrixScale, false);
if (path != nullptr) {
cacheBlob->appendPathGlyph(runIndex, *path, loc.fX, loc.fY, matrixScale, false);
}
} }
} }
} };
glyphDrawer->drawUsingPaths(glyphRun, origin, cache.get(), drawOnePath);
fallbackTextHelper.drawText( fallbackTextHelper.drawText(
cacheBlob, runIndex, glyphCache, props, runPaint, scalerContextFlags); cacheBlob, runIndex, glyphCache, props, runPaint, scalerContextFlags);