Make a glyphrun version of DrawBmpPosTextAsPaths
Make a copy of DrawBmpPosTextAsPaths called DrawBmpGlyphRunAsPaths
which uses a glyph run instead of having to process all the text
types.
In addition, rearrange the other loops to be located closely in the code.
So, only DrawBmpGlyphRunAsPaths is changed code.
Change-Id: Ic19678ee59189341d2151ccf55f78c8e111f8f4c
Reviewed-on: https://skia-review.googlesource.com/144300
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Auto-Submit: Herb Derby <herb@google.com>
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index 4a3c0ba..4ad29f3 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -84,6 +84,161 @@
}
}
+
+void GrTextContext::drawDFGlyphRun(GrTextBlob* blob, int runIndex,
+ GrGlyphCache* glyphCache, const SkSurfaceProps& props,
+ const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix, const SkGlyphRun& glyphRun,
+ const SkPoint& offset) const {
+ bool hasWCoord = viewMatrix.hasPerspective() || fOptions.fDistanceFieldVerticesAlwaysHaveW;
+
+ // Setup distance field paint and text ratio
+ SkScalar textRatio;
+ SkPaint dfPaint(paint);
+ SkScalerContextFlags flags;
+ InitDistanceFieldPaint(blob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags);
+ blob->setHasDistanceField();
+ blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(),
+ paint.skPaint().isAntiAlias(), hasWCoord);
+
+ FallbackGlyphRunHelper fallbackTextHelper(viewMatrix, paint, glyphCache->getGlyphSizeLimit(),
+ textRatio);
+
+ sk_sp<GrTextStrike> currStrike;
+
+ {
+ auto cache = blob->setupCache(runIndex, props, flags, dfPaint, nullptr);
+
+ const SkPoint* positionCursor = glyphRun.positions().data();
+ for (auto glyphID : glyphRun.shuntGlyphsIDs()) {
+ const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID);
+ SkPoint glyphPos = offset + *positionCursor++;
+ if (glyph.fWidth > 0) {
+ if (glyph.fMaskFormat == SkMask::kSDF_Format) {
+ DfAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph, glyphPos.fX,
+ glyphPos.fY, paint.filteredPremulColor(), cache.get(), textRatio);
+ } else {
+ // can't append non-SDF glyph to SDF batch, send to fallback
+ fallbackTextHelper.appendText(glyph, glyphID, glyphPos);
+ }
+ }
+ }
+ }
+
+ fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, paint, scalerContextFlags);
+}
+
+void GrTextContext::DrawBmpGlyphRunAsPaths(GrTextBlob* blob, int runIndex,
+ GrGlyphCache* glyphCache,
+ const SkSurfaceProps& props,
+ const GrTextUtils::Paint& origPaint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix,
+ const SkGlyphRun& glyphRun,
+ const SkPoint& offset) {
+
+ // setup our std paint, in hopes of getting hits in the cache
+ SkPaint pathPaint(origPaint);
+ SkScalar matrixScale = pathPaint.setupForAsPaths();
+
+ FallbackGlyphRunHelper fallbackTextHelper(
+ viewMatrix, origPaint, glyphCache->getGlyphSizeLimit(), matrixScale);
+
+ // 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 cache = SkStrikeCache::FindOrCreateStrikeExclusive(
+ pathPaint, &props, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
+
+ const SkPoint* positionCursor = glyphRun.positions().data();
+ for (auto glyphID : glyphRun.shuntGlyphsIDs()) {
+ const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID);
+ SkPoint loc = offset + *positionCursor++;
+ if (glyph.fWidth > 0) {
+ if (glyph.fMaskFormat == SkMask::kARGB32_Format) {
+ fallbackTextHelper.appendText(glyph, glyphID, loc);
+ } else {
+ const SkPath* path = cache->findPath(glyph);
+ if (path != nullptr) {
+ blob->appendPathGlyph(runIndex, *path, loc.fX, loc.fY, matrixScale, false);
+ }
+ }
+ }
+ }
+
+ fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, origPaint, scalerContextFlags);
+}
+
+void GrTextContext::DrawBmpGlyphRun(GrTextBlob* blob, int runIndex,
+ GrGlyphCache* glyphCache, const SkSurfaceProps& props,
+ const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix,
+ const SkGlyphRun& glyphRun, const SkPoint& offset) {
+
+ // Ensure the blob is set for bitmaptext
+ blob->setHasBitmap();
+
+ if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) {
+ DrawBmpGlyphRunAsPaths(
+ blob, runIndex, glyphCache, props, paint, scalerContextFlags, viewMatrix,
+ glyphRun, offset);
+ return;
+ }
+
+ sk_sp<GrTextStrike> currStrike;
+ auto cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix);
+ SkFindAndPlaceGlyph::ProcessPosText(
+ SkPaint::kGlyphID_TextEncoding,
+ (const char*)glyphRun.shuntGlyphsIDs().data(),
+ glyphRun.shuntGlyphsIDs().size() * sizeof(SkGlyphID),
+ offset, viewMatrix, (const SkScalar*)glyphRun.positions().data(), 2, cache.get(),
+ [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
+ position += rounding;
+ BmpAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph,
+ SkScalarFloorToScalar(position.fX),
+ SkScalarFloorToScalar(position.fY),
+ paint.filteredPremulColor(), cache.get(), SK_Scalar1, false);
+ }
+ );
+}
+
+void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
+ GrGlyphCache* glyphCache,
+ const GrShaderCaps& shaderCaps,
+ const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix,
+ const SkSurfaceProps& props,
+ const SkGlyphRunList& glyphRunList) const {
+ SkPoint origin = glyphRunList.origin();
+ cacheBlob->initReusableBlob(paint.luminanceColor(), viewMatrix, origin.x(), origin.y());
+
+ // Regenerate textblob
+ GrTextUtils::RunPaint runPaint(&paint);
+ int runNum = 0;
+ for (const auto& glyphRun : glyphRunList) {
+ cacheBlob->push_back_run(runNum);
+
+ if (!runPaint.modifyForRun([glyphRun](SkPaint* p) { *p = glyphRun.paint(); })) {
+ continue;
+ }
+ cacheBlob->setRunPaintFlags(runNum, runPaint.skPaint().getFlags());
+
+ if (CanDrawAsDistanceFields(runPaint, viewMatrix, props,
+ shaderCaps.supportsDistanceFieldText(), fOptions)) {
+ this->drawDFGlyphRun(cacheBlob, runNum, glyphCache, props, runPaint,
+ scalerContextFlags, viewMatrix, glyphRun, origin);
+ } else {
+ DrawBmpGlyphRun(cacheBlob, runNum, glyphCache, props, runPaint, scalerContextFlags,
+ viewMatrix, glyphRun, origin);
+ }
+ runNum += 1;
+ }
+}
+
void GrTextContext::drawGlyphRunList(
GrContext* context, GrTextUtils::Target* target, const GrClip& clip,
const SkMatrix& viewMatrix, const SkSurfaceProps& props, const SkGlyphRunList& glyphRunList,
@@ -173,40 +328,6 @@
clip, viewMatrix, clipBounds, origin.x(), origin.y());
}
-void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
- GrGlyphCache* glyphCache,
- const GrShaderCaps& shaderCaps,
- const GrTextUtils::Paint& paint,
- SkScalerContextFlags scalerContextFlags,
- const SkMatrix& viewMatrix,
- const SkSurfaceProps& props,
- const SkGlyphRunList& glyphRunList) const {
- SkPoint origin = glyphRunList.origin();
- cacheBlob->initReusableBlob(paint.luminanceColor(), viewMatrix, origin.x(), origin.y());
-
- // Regenerate textblob
- GrTextUtils::RunPaint runPaint(&paint);
- int runNum = 0;
- for (const auto& glyphRun : glyphRunList) {
- cacheBlob->push_back_run(runNum);
-
- if (!runPaint.modifyForRun([glyphRun](SkPaint* p) { *p = glyphRun.paint(); })) {
- continue;
- }
- cacheBlob->setRunPaintFlags(runNum, runPaint.skPaint().getFlags());
-
- if (CanDrawAsDistanceFields(runPaint, viewMatrix, props,
- shaderCaps.supportsDistanceFieldText(), fOptions)) {
- this->drawDFGlyphRun(cacheBlob, runNum, glyphCache, props, runPaint,
- scalerContextFlags, viewMatrix, glyphRun, origin);
- } else {
- DrawBmpGlyphRun(cacheBlob, runNum, glyphCache, props, runPaint, scalerContextFlags,
- viewMatrix, glyphRun, origin);
- }
- runNum += 1;
- }
-}
-
inline sk_sp<GrTextBlob>
GrTextContext::makeDrawPosTextBlob(GrTextBlobCache* blobCache,
GrGlyphCache* glyphCache,
@@ -300,42 +421,6 @@
});
}
-void GrTextContext::DrawBmpGlyphRun(GrTextBlob* blob, int runIndex,
- GrGlyphCache* glyphCache, const SkSurfaceProps& props,
- const GrTextUtils::Paint& paint,
- SkScalerContextFlags scalerContextFlags,
- const SkMatrix& viewMatrix,
- const SkGlyphRun& glyphRun, const SkPoint& offset) {
-
- // Ensure the blob is set for bitmaptext
- blob->setHasBitmap();
-
- if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) {
- DrawBmpPosTextAsPaths(
- blob, runIndex, glyphCache, props, paint, scalerContextFlags, viewMatrix,
- (const char*)glyphRun.shuntGlyphsIDs().data(),
- glyphRun.shuntGlyphsIDs().size() * sizeof(SkGlyphID),
- (const SkScalar*)glyphRun.positions().data(), 2, offset);
- return;
- }
-
- sk_sp<GrTextStrike> currStrike;
- auto cache = blob->setupCache(runIndex, props, scalerContextFlags, paint, &viewMatrix);
- SkFindAndPlaceGlyph::ProcessPosText(
- SkPaint::kGlyphID_TextEncoding,
- (const char*)glyphRun.shuntGlyphsIDs().data(),
- glyphRun.shuntGlyphsIDs().size() * sizeof(SkGlyphID),
- offset, viewMatrix, (const SkScalar*)glyphRun.positions().data(), 2, cache.get(),
- [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) {
- position += rounding;
- BmpAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph,
- SkScalarFloorToScalar(position.fX),
- SkScalarFloorToScalar(position.fY),
- paint.filteredPremulColor(), cache.get(), SK_Scalar1, false);
- }
- );
-}
-
void GrTextContext::DrawBmpPosTextAsPaths(GrTextBlob* blob, int runIndex,
GrGlyphCache* glyphCache,
const SkSurfaceProps& props,
@@ -610,50 +695,6 @@
fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, paint, scalerContextFlags);
}
-void GrTextContext::drawDFGlyphRun(GrTextBlob* blob, int runIndex,
- GrGlyphCache* glyphCache, const SkSurfaceProps& props,
- const GrTextUtils::Paint& paint,
- SkScalerContextFlags scalerContextFlags,
- const SkMatrix& viewMatrix, const SkGlyphRun& glyphRun,
- const SkPoint& offset) const {
- bool hasWCoord = viewMatrix.hasPerspective() || fOptions.fDistanceFieldVerticesAlwaysHaveW;
-
- // Setup distance field paint and text ratio
- SkScalar textRatio;
- SkPaint dfPaint(paint);
- SkScalerContextFlags flags;
- InitDistanceFieldPaint(blob, &dfPaint, viewMatrix, fOptions, &textRatio, &flags);
- blob->setHasDistanceField();
- blob->setSubRunHasDistanceFields(runIndex, paint.skPaint().isLCDRenderText(),
- paint.skPaint().isAntiAlias(), hasWCoord);
-
- FallbackGlyphRunHelper fallbackTextHelper(viewMatrix, paint, glyphCache->getGlyphSizeLimit(),
- textRatio);
-
- sk_sp<GrTextStrike> currStrike;
-
- {
- auto cache = blob->setupCache(runIndex, props, flags, dfPaint, nullptr);
-
- const SkPoint* positionCursor = glyphRun.positions().data();
- for (auto glyphID : glyphRun.shuntGlyphsIDs()) {
- const SkGlyph& glyph = cache->getGlyphIDMetrics(glyphID);
- SkPoint glyphPos = offset + *positionCursor++;
- if (glyph.fWidth > 0) {
- if (glyph.fMaskFormat == SkMask::kSDF_Format) {
- DfAppendGlyph(blob, runIndex, glyphCache, &currStrike, glyph, glyphPos.fX,
- glyphPos.fY, paint.filteredPremulColor(), cache.get(), textRatio);
- } else {
- // can't append non-SDF glyph to SDF batch, send to fallback
- fallbackTextHelper.appendText(glyph, glyphID, glyphPos);
- }
- }
- }
- }
-
- fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, paint, scalerContextFlags);
-}
-
// TODO: merge with BmpAppendGlyph
void GrTextContext::DfAppendGlyph(GrTextBlob* blob, int runIndex,
GrGlyphCache* grGlyphCache, sk_sp<GrTextStrike>* strike,