aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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,