aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-07-28 14:27:48 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-30 14:22:45 +0000
commit12e42565886ac6b28cbcae40d63ee093bde3e630 (patch)
tree8dc479b7b0e9a878cecf6015205d45884a1734b3 /src
parent13449ce2439044c06847c5f9487352d98931d11d (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/text/GrTextContext.cpp269
-rw-r--r--src/gpu/text/GrTextContext.h28
2 files changed, 174 insertions, 123 deletions
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index 4a3c0baa10..4ad29f3a38 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -84,6 +84,161 @@ SkScalerContextFlags GrTextContext::ComputeScalerContextFlags(
}
}
+
+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 @@ void GrTextContext::drawGlyphRunList(
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::DrawBmpPosText(GrTextBlob* blob, int runIndex,
});
}
-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 @@ void GrTextContext::drawDFPosText(GrTextBlob* blob, int runIndex,
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,
diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h
index 21657469c5..6bfa718712 100644
--- a/src/gpu/text/GrTextContext.h
+++ b/src/gpu/text/GrTextContext.h
@@ -151,6 +151,24 @@ private:
// Determines if we need to use fake gamma (and contrast boost):
static SkScalerContextFlags ComputeScalerContextFlags(const GrColorSpaceInfo&);
+ void drawDFGlyphRun(GrTextBlob* blob, int runIndex, GrGlyphCache*,
+ const SkSurfaceProps&, const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix, const SkGlyphRun& glyphRun,
+ const SkPoint& offset) const;
+
+ static void DrawBmpGlyphRunAsPaths(GrTextBlob*, int runIndex, GrGlyphCache*,
+ const SkSurfaceProps&, const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix,
+ const SkGlyphRun& glyphRun,
+ const SkPoint& offset);
+
+ static void DrawBmpGlyphRun(GrTextBlob*, int runIndex, GrGlyphCache*,
+ const SkSurfaceProps&, const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags, const SkMatrix& viewMatrix,
+ const SkGlyphRun& glyphRun, const SkPoint& offset);
+
void regenerateGlyphRunList(GrTextBlob* bmp,
GrGlyphCache*,
const GrShaderCaps&,
@@ -178,10 +196,7 @@ private:
const char text[], size_t byteLength, const SkScalar pos[],
int scalarsPerPosition, const SkPoint& offset);
- static void DrawBmpGlyphRun(GrTextBlob*, int runIndex, GrGlyphCache*,
- const SkSurfaceProps&, const GrTextUtils::Paint& paint,
- SkScalerContextFlags scalerContextFlags, const SkMatrix& viewMatrix,
- const SkGlyphRun& glyphRun, const SkPoint& offset);
+
static void DrawBmpPosTextAsPaths(GrTextBlob*, int runIndex, GrGlyphCache*,
const SkSurfaceProps&, const GrTextUtils::Paint& paint,
@@ -199,11 +214,6 @@ private:
size_t byteLength, const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) const;
- void drawDFGlyphRun(GrTextBlob* blob, int runIndex, GrGlyphCache*,
- const SkSurfaceProps&, const GrTextUtils::Paint& paint,
- SkScalerContextFlags scalerContextFlags,
- const SkMatrix& viewMatrix, const SkGlyphRun& glyphRun,
- const SkPoint& offset) const;
static void BmpAppendGlyph(GrTextBlob*, int runIndex, GrGlyphCache*,
sk_sp<GrTextStrike>*, const SkGlyph&, SkScalar sx, SkScalar sy,