Skip to content

Commit 1400d38

Browse files
jvanverthSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Revert "Hoist path check"
This reverts commit 6de0fca. Reason for revert: Busted some GMs, e.g., largeglyphblur and mixedtextblobs. Original change's description: > Hoist path check > > Hoist path check up one level in on the way to > moving it to regenerateGlyphRunList. > > Change-Id: I77d24c1d80daf72ddd3e9f09dd264c1e9d504573 > Reviewed-on: https://skia-review.googlesource.com/144902 > Commit-Queue: Herb Derby <[email protected]> > Reviewed-by: Jim Van Verth <[email protected]> > Auto-Submit: Herb Derby <[email protected]> [email protected],[email protected] Change-Id: Idf1ea5818f6a97989c520b93804627af385b5045 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/145327 Reviewed-by: Jim Van Verth <[email protected]> Commit-Queue: Jim Van Verth <[email protected]>
1 parent f513682 commit 1400d38

File tree

3 files changed

+67
-77
lines changed

3 files changed

+67
-77
lines changed

src/core/SkGlyph.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ class SkGlyph {
162162

163163
void initWithGlyphID(SkPackedGlyphID glyph_id);
164164

165-
bool isEmpty() {
166-
return fWidth == 0 || fHeight == 0;
167-
}
168-
169165
size_t formatAlignment() const;
170166
size_t allocImage(SkArenaAlloc* alloc);
171167

src/gpu/text/GrTextBlob.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ void GrTextBlob::appendGlyph(int runIndex,
7575
GrGlyph* glyph,
7676
SkGlyphCache* cache, const SkGlyph& skGlyph,
7777
SkScalar x, SkScalar y, SkScalar scale, bool preTransformed) {
78+
if (positions.isEmpty()) {
79+
return;
80+
}
81+
82+
// If the glyph is too large we fall back to paths
83+
if (glyph->fTooLargeForAtlas) {
84+
if (nullptr == glyph->fPath) {
85+
const SkPath* glyphPath = cache->findPath(skGlyph);
86+
if (!glyphPath) {
87+
return;
88+
}
89+
90+
glyph->fPath = new SkPath(*glyphPath);
91+
}
92+
this->appendPathGlyph(runIndex, *glyph->fPath, x, y, scale, preTransformed);
93+
return;
94+
}
7895

7996
Run& run = fRuns[runIndex];
8097
GrMaskFormat format = glyph->fMaskFormat;

src/gpu/text/GrTextContext.cpp

Lines changed: 50 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,6 @@ SkScalerContextFlags GrTextContext::ComputeScalerContextFlags(
8484
}
8585
}
8686

87-
bool glyph_too_big_for_atlas(const SkGlyph& glyph) {
88-
return glyph.fWidth >= 256 || glyph.fHeight >= 256;
89-
}
90-
91-
static SkRect rect_to_draw(
92-
const SkGlyph& glyph, SkPoint origin, SkScalar textScale, GrGlyph::MaskStyle maskStyle) {
93-
94-
SkScalar dx = SkIntToScalar(glyph.fLeft);
95-
SkScalar dy = SkIntToScalar(glyph.fTop);
96-
SkScalar width = SkIntToScalar(glyph.fWidth);
97-
SkScalar height = SkIntToScalar(glyph.fHeight);
98-
99-
if (maskStyle == GrGlyph::kDistance_MaskStyle) {
100-
dx += SK_DistanceFieldInset;
101-
dy += SK_DistanceFieldInset;
102-
width -= 2 * SK_DistanceFieldInset;
103-
height -= 2 * SK_DistanceFieldInset;
104-
}
105-
106-
dx *= textScale;
107-
dy *= textScale;
108-
width *= textScale;
109-
height *= textScale;
110-
111-
return SkRect::MakeXYWH(origin.x() + dx, origin.y() + dy, width, height);
112-
}
11387

11488
void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
11589
GrGlyphCache* glyphCache,
@@ -162,7 +136,6 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
162136
SkPoint glyphPos = origin + *positionCursor++;
163137
if (glyph.fWidth > 0) {
164138
if (glyph.fMaskFormat == SkMask::kSDF_Format) {
165-
166139
AppendGlyph(
167140
cacheBlob, runIndex, glyphCache, &currStrike,
168141
glyph, GrGlyph::kDistance_MaskStyle,
@@ -226,10 +199,10 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
226199
[cacheBlob, runIndex, glyphCache, &currStrike, runPaint, cache{cache.get()}]
227200
(const SkMask& mask, const SkGlyph& glyph, SkPoint position) {
228201
AppendGlyph(cacheBlob, runIndex, glyphCache, &currStrike,
229-
glyph, GrGlyph::kCoverage_MaskStyle,
230-
SkScalarFloorToScalar(position.fX),
231-
SkScalarFloorToScalar(position.fY),
232-
runPaint.filteredPremulColor(), cache, SK_Scalar1, false);
202+
glyph, GrGlyph::kCoverage_MaskStyle,
203+
SkScalarFloorToScalar(position.fX),
204+
SkScalarFloorToScalar(position.fY),
205+
runPaint.filteredPremulColor(), cache, SK_Scalar1, false);
233206
};
234207

235208
glyphDrawer->drawUsingMasks(cache.get(), glyphRun, origin, viewMatrix, drawOneGlyph);
@@ -238,48 +211,6 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
238211
}
239212
}
240213

241-
void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex,
242-
GrGlyphCache* grGlyphCache,
243-
sk_sp<GrTextStrike>* strike,
244-
const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle,
245-
SkScalar sx, SkScalar sy,
246-
GrColor color, SkGlyphCache* skGlyphCache,
247-
SkScalar textRatio, bool needsTransform) {
248-
if (!*strike) {
249-
*strike = grGlyphCache->getStrike(skGlyphCache);
250-
}
251-
252-
GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
253-
skGlyph.getSubXFixed(),
254-
skGlyph.getSubYFixed(),
255-
maskStyle);
256-
GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, skGlyphCache);
257-
if (!glyph) {
258-
return;
259-
}
260-
261-
SkASSERT(skGlyph.fWidth == glyph->width());
262-
SkASSERT(skGlyph.fHeight == glyph->height());
263-
264-
SkRect glyphRect = rect_to_draw(skGlyph, {sx, sy}, textRatio, maskStyle);
265-
266-
if (!glyphRect.isEmpty()) {
267-
// If the glyph is too large we fall back to paths
268-
if (glyph_too_big_for_atlas(skGlyph)) {
269-
if (glyph->fPath != nullptr) {
270-
const SkPath* glyphPath = skGlyphCache->findPath(skGlyph);
271-
if (glyphPath != nullptr) {
272-
glyph->fPath = new SkPath(*glyphPath);
273-
}
274-
blob->appendPathGlyph(runIndex, *glyph->fPath, sx, sy, textRatio, !needsTransform);
275-
}
276-
} else {
277-
blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph,
278-
skGlyphCache, skGlyph, sx, sy, textRatio, !needsTransform);
279-
}
280-
}
281-
}
282-
283214
void GrTextContext::drawGlyphRunList(
284215
GrContext* context, GrTextUtils::Target* target, const GrClip& clip,
285216
const SkMatrix& viewMatrix, const SkSurfaceProps& props, const SkGlyphRunList& glyphRunList,
@@ -522,6 +453,52 @@ void GrTextContext::DrawBmpPosTextAsPaths(GrTextBlob* blob, int runIndex,
522453
fallbackTextHelper.drawText(blob, runIndex, glyphCache, props, origPaint, scalerContextFlags);
523454
}
524455

456+
void GrTextContext::AppendGlyph(GrTextBlob* blob, int runIndex,
457+
GrGlyphCache* grGlyphCache,
458+
sk_sp<GrTextStrike>* strike,
459+
const SkGlyph& skGlyph, GrGlyph::MaskStyle maskStyle,
460+
SkScalar sx, SkScalar sy,
461+
GrColor color, SkGlyphCache* skGlyphCache,
462+
SkScalar textRatio, bool needsTransform) {
463+
if (!*strike) {
464+
*strike = grGlyphCache->getStrike(skGlyphCache);
465+
}
466+
467+
GrGlyph::PackedID id = GrGlyph::Pack(skGlyph.getGlyphID(),
468+
skGlyph.getSubXFixed(),
469+
skGlyph.getSubYFixed(),
470+
maskStyle);
471+
GrGlyph* glyph = (*strike)->getGlyph(skGlyph, id, skGlyphCache);
472+
if (!glyph) {
473+
return;
474+
}
475+
476+
SkASSERT(skGlyph.fWidth == glyph->width());
477+
SkASSERT(skGlyph.fHeight == glyph->height());
478+
479+
SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft);
480+
SkScalar dy = SkIntToScalar(glyph->fBounds.fTop);
481+
SkScalar width = SkIntToScalar(glyph->fBounds.width());
482+
SkScalar height = SkIntToScalar(glyph->fBounds.height());
483+
484+
if (maskStyle == GrGlyph::kDistance_MaskStyle) {
485+
dx += SK_DistanceFieldInset;
486+
dy += SK_DistanceFieldInset;
487+
width -= 2 * SK_DistanceFieldInset;
488+
height -= 2 * SK_DistanceFieldInset;
489+
}
490+
491+
dx *= textRatio;
492+
dy *= textRatio;
493+
width *= textRatio;
494+
height *= textRatio;
495+
496+
SkRect glyphRect = SkRect::MakeXYWH(sx + dx, sy + dy, width, height);
497+
498+
blob->appendGlyph(runIndex, glyphRect, color, *strike, glyph, skGlyphCache, skGlyph, sx, sy,
499+
textRatio, !needsTransform);
500+
}
501+
525502
void GrTextContext::SanitizeOptions(Options* options) {
526503
if (options->fMaxDistanceFieldFontSize < 0.f) {
527504
options->fMaxDistanceFieldFontSize = kDefaultMaxDistanceFieldFontSize;

0 commit comments

Comments
 (0)