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 <herb@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Auto-Submit: Herb Derby <herb@google.com>
This commit is contained in:
parent
270239d94a
commit
6de0fca928
@ -162,6 +162,10 @@ public:
|
||||
|
||||
void initWithGlyphID(SkPackedGlyphID glyph_id);
|
||||
|
||||
bool isEmpty() {
|
||||
return fWidth == 0 || fHeight == 0;
|
||||
}
|
||||
|
||||
size_t formatAlignment() const;
|
||||
size_t allocImage(SkArenaAlloc* alloc);
|
||||
|
||||
|
@ -75,23 +75,6 @@ void GrTextBlob::appendGlyph(int runIndex,
|
||||
GrGlyph* glyph,
|
||||
SkGlyphCache* cache, const SkGlyph& skGlyph,
|
||||
SkScalar x, SkScalar y, SkScalar scale, bool preTransformed) {
|
||||
if (positions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the glyph is too large we fall back to paths
|
||||
if (glyph->fTooLargeForAtlas) {
|
||||
if (nullptr == glyph->fPath) {
|
||||
const SkPath* glyphPath = cache->findPath(skGlyph);
|
||||
if (!glyphPath) {
|
||||
return;
|
||||
}
|
||||
|
||||
glyph->fPath = new SkPath(*glyphPath);
|
||||
}
|
||||
this->appendPathGlyph(runIndex, *glyph->fPath, x, y, scale, preTransformed);
|
||||
return;
|
||||
}
|
||||
|
||||
Run& run = fRuns[runIndex];
|
||||
GrMaskFormat format = glyph->fMaskFormat;
|
||||
|
@ -84,6 +84,32 @@ SkScalerContextFlags GrTextContext::ComputeScalerContextFlags(
|
||||
}
|
||||
}
|
||||
|
||||
bool glyph_too_big_for_atlas(const SkGlyph& glyph) {
|
||||
return glyph.fWidth >= 256 || glyph.fHeight >= 256;
|
||||
}
|
||||
|
||||
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,6 +162,7 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
SkPoint glyphPos = origin + *positionCursor++;
|
||||
if (glyph.fWidth > 0) {
|
||||
if (glyph.fMaskFormat == SkMask::kSDF_Format) {
|
||||
|
||||
AppendGlyph(
|
||||
cacheBlob, runIndex, glyphCache, &currStrike,
|
||||
glyph, GrGlyph::kDistance_MaskStyle,
|
||||
@ -199,10 +226,10 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
[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);
|
||||
glyph, GrGlyph::kCoverage_MaskStyle,
|
||||
SkScalarFloorToScalar(position.fX),
|
||||
SkScalarFloorToScalar(position.fY),
|
||||
runPaint.filteredPremulColor(), cache, SK_Scalar1, false);
|
||||
};
|
||||
|
||||
glyphDrawer->drawUsingMasks(cache.get(), glyphRun, origin, viewMatrix, drawOneGlyph);
|
||||
@ -211,6 +238,48 @@ void GrTextContext::regenerateGlyphRunList(GrTextBlob* cacheBlob,
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
// If the glyph is too large we fall back to paths
|
||||
if (glyph_too_big_for_atlas(skGlyph)) {
|
||||
if (glyph->fPath != nullptr) {
|
||||
const SkPath* glyphPath = skGlyphCache->findPath(skGlyph);
|
||||
if (glyphPath != nullptr) {
|
||||
glyph->fPath = new SkPath(*glyphPath);
|
||||
}
|
||||
blob->appendPathGlyph(runIndex, *glyph->fPath, sx, sy, textRatio, !needsTransform);
|
||||
}
|
||||
} else {
|
||||
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 +522,6 @@ void GrTextContext::DrawBmpPosTextAsPaths(GrTextBlob* blob, int runIndex,
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user