Hoist path check into regenerateGlyphRunList.
Now, regenerateGlyphRunList is making all the rendering
position, and cache choice decisions. Mostly.
Change-Id: Ib946e2ef2f422c915b324ac93459c65bf559f608
Reviewed-on: https://skia-review.googlesource.com/144905
Auto-Submit: Herb Derby <herb@google.com>
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp
index f089a65..45145f6 100644
--- a/src/gpu/text/GrTextContext.cpp
+++ b/src/gpu/text/GrTextContext.cpp
@@ -84,6 +84,32 @@
}
}
+bool glyph_too_big_for_atlas(const SkGlyph& glyph) {
+ return GrDrawOpAtlas::GlyphTooLargeForAtlas(glyph.fWidth, glyph.fHeight);
+}
+
+static SkRect rect_to_draw(
+ const SkGlyph& glyph, SkPoint origin, SkScalar textScale, GrGlyph::MaskStyle maskStyle) {
+
+ SkScalar dx = SkIntToScalar(glyph.fLeft);
+ SkScalar dy = SkIntToScalar(glyph.fTop);
+ SkScalar width = SkIntToScalar(glyph.fWidth);
+ SkScalar height = SkIntToScalar(glyph.fHeight);
+
+ if (maskStyle == GrGlyph::kDistance_MaskStyle) {
+ dx += SK_DistanceFieldInset;
+ dy += SK_DistanceFieldInset;
+ width -= 2 * SK_DistanceFieldInset;
+ height -= 2 * SK_DistanceFieldInset;
+ }
+
+ dx *= textScale;
+ dy *= textScale;
+ width *= textScale;
+ height *= textScale;
+
+ return SkRect::MakeXYWH(origin.x() + dx, origin.y() + dy, width, height);
+}
void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
GrGlyphCache* glyphCache,
@@ -136,11 +162,28 @@
SkPoint glyphPos = origin + *positionCursor++;
if (glyph.fWidth > 0) {
if (glyph.fMaskFormat == SkMask::kSDF_Format) {
- AppendGlyph(
- cacheBlob, runIndex, glyphCache, &currStrike,
- glyph, GrGlyph::kDistance_MaskStyle,
- glyphPos.fX, glyphPos.fY, runPaint.filteredPremulColor(),
- cache.get(), textRatio, true);
+
+ SkScalar sx = glyphPos.fX,
+ sy = glyphPos.fY;
+
+ if (glyph_too_big_for_atlas(glyph)) {
+ SkRect glyphRect =
+ rect_to_draw(glyph, glyphPos, textRatio,
+ GrGlyph::kDistance_MaskStyle);
+ if (!glyphRect.isEmpty()) {
+ const SkPath* glyphPath = cache->findPath(glyph);
+ if (glyphPath != nullptr) {
+ cacheBlob->appendPathGlyph(
+ runIndex, *glyphPath, sx, sy, textRatio, false);
+ }
+ }
+ } else {
+ AppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike,
+ glyph, GrGlyph::kDistance_MaskStyle, sx, sy,
+ runPaint.filteredPremulColor(),
+ cache.get(), textRatio, true);
+ }
+
} else {
// can't append non-SDF glyph to SDF batch, send to fallback
fallbackTextHelper.appendText(glyph, glyphID, glyphPos);
@@ -198,11 +241,25 @@
auto drawOneGlyph =
[cacheBlob, runIndex, glyphCache, &currStrike, runPaint, cache{cache.get()}]
(const SkMask& mask, const SkGlyph& glyph, SkPoint position) {
- AppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike,
- glyph, GrGlyph::kCoverage_MaskStyle,
- SkScalarFloorToScalar(position.fX),
- SkScalarFloorToScalar(position.fY),
- runPaint.filteredPremulColor(), cache, SK_Scalar1, false);
+ SkScalar sx = SkScalarFloorToScalar(position.fX),
+ sy = SkScalarFloorToScalar(position.fY);
+
+ if (glyph_too_big_for_atlas(glyph)) {
+ SkRect glyphRect =
+ rect_to_draw(glyph, {sx, sy}, SK_Scalar1,
+ GrGlyph::kCoverage_MaskStyle);
+ if (!glyphRect.isEmpty()) {
+ const SkPath* glyphPath = cache->findPath(glyph);
+ if (glyphPath != nullptr) {
+ cacheBlob->appendPathGlyph(
+ runIndex, *glyphPath, sx, sy, SK_Scalar1, true);
+ }
+ }
+ } else {
+ AppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike,
+ glyph, GrGlyph::kCoverage_MaskStyle, sx, sy,
+ runPaint.filteredPremulColor(), cache, SK_Scalar1, false);
+ }
};
glyphDrawer->drawUsingMasks(cache.get(), glyphRun, origin, viewMatrix, drawOneGlyph);
@@ -211,6 +268,37 @@
}
}
+void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex,
+ GrGlyphCache* grGlyphCache,
+ sk_sp<GrTextStrike>* strike,
+ const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle,
+ SkScalar sx, SkScalar sy,
+ GrColor color, SkGlyphCache* skGlyphCache,
+ SkScalar textRatio, bool needsTransform) {
+ if (!*strike) {
+ *strike = grGlyphCache->getStrike(skGlyphCache);
+ }
+
+ GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
+ skGlyph.getSubXFixed(),
+ skGlyph.getSubYFixed(),
+ maskStyle);
+ GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, skGlyphCache);
+ if (!glyph) {
+ return;
+ }
+
+ SkASSERT(skGlyph.fWidth == glyph->width());
+ SkASSERT(skGlyph.fHeight == glyph->height());
+
+ SkRect glyphRect = rect_to_draw(skGlyph, {sx, sy}, textRatio, maskStyle);
+
+ if (!glyphRect.isEmpty()) {
+ blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph,
+ skGlyphCache, skGlyph, sx, sy, textRatio, !needsTransform);
+ }
+}
+
void GrTextContext::drawGlyphRunList(
GrContext* context, GrTextUtils::Target* target, const GrClip& clip,
const SkMatrix& viewMatrix, const SkSurfaceProps& props, const SkGlyphRunList& glyphRunList,
@@ -453,52 +541,6 @@
fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, origPaint, scalerContextFlags);
}
-void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex,
- GrGlyphCache* grGlyphCache,
- sk_sp<GrTextStrike>* strike,
- const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle,
- SkScalar sx, SkScalar sy,
- GrColor color, SkGlyphCache* skGlyphCache,
- SkScalar textRatio, bool needsTransform) {
- if (!*strike) {
- *strike = grGlyphCache->getStrike(skGlyphCache);
- }
-
- GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
- skGlyph.getSubXFixed(),
- skGlyph.getSubYFixed(),
- maskStyle);
- GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, skGlyphCache);
- if (!glyph) {
- return;
- }
-
- SkASSERT(skGlyph.fWidth == glyph->width());
- SkASSERT(skGlyph.fHeight == glyph->height());
-
- SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft);
- SkScalar dy = SkIntToScalar(glyph->fBounds.fTop);
- SkScalar width = SkIntToScalar(glyph->fBounds.width());
- SkScalar height = SkIntToScalar(glyph->fBounds.height());
-
- if (maskStyle == GrGlyph::kDistance_MaskStyle) {
- dx += SK_DistanceFieldInset;
- dy += SK_DistanceFieldInset;
- width -= 2 * SK_DistanceFieldInset;
- height -= 2 * SK_DistanceFieldInset;
- }
-
- dx *= textRatio;
- dy *= textRatio;
- width *= textRatio;
- height *= textRatio;
-
- SkRect glyphRect = SkRect::MakeXYWH(sx + dx, sy + dy, width, height);
-
- blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph, skGlyphCache, skGlyph, sx, sy,
- textRatio, !needsTransform);
-}
-
void GrTextContext::SanitizeOptions(Options* options) {
if (options->fMaxDistanceFieldFontSize < 0.f) {
options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize;