diff options
author | 2016-05-10 06:19:21 -0700 | |
---|---|---|
committer | 2016-05-10 06:19:21 -0700 | |
commit | 85d9667f59d4138438427bb2cdf67992d100e1a0 (patch) | |
tree | 1d86fd1d78a1bdd36f6b250bf31dd285986db5ef /src/gpu/text/GrStencilAndCoverTextContext.cpp | |
parent | 00e9452791a80ed9fb824214b259ecb9af0c25c6 (diff) |
Revert of Replace GrStrokeInfo with GrStyle. (patchset #4 id:160001 of https://codereview.chromium.org/1957363002/ )
Reason for revert:
Breaking some bots
Original issue's description:
> Replace GrStrokeInfo with GrStyle.
>
> A side effect is that arbitrary path effects can no be pushed deeper into the Ganesh flow for paths. They may be applied by path renderers.
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1957363002
>
> Committed: https://skia.googlesource.com/skia/+/33595bdf4b64a745f6340338d307e806e96c587f
TBR=egdaniel@google.com,robertphillips@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review-Url: https://codereview.chromium.org/1967513002
Diffstat (limited to 'src/gpu/text/GrStencilAndCoverTextContext.cpp')
-rw-r--r-- | src/gpu/text/GrStencilAndCoverTextContext.cpp | 77 |
1 files changed, 26 insertions, 51 deletions
diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp index cc018845f6..c2c1c569e8 100644 --- a/src/gpu/text/GrStencilAndCoverTextContext.cpp +++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp @@ -235,18 +235,6 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrContext* context, GrDrawContex } } -static inline int style_key_cnt(const GrStyle& style) { - int cnt = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec); - // We should be able to make a key because we filtered out arbitrary path effects. - SkASSERT(cnt > 0); - return cnt; -} - -static inline void write_style_key(uint32_t* dst, const GrStyle& style) { - // Pass 1 for the scale since the GPU will apply the style not GrStyle::applyToPath(). - GrStyle::WriteKey(dst, style, GrStyle::Apply::kPathEffectAndStrokeRec, SK_Scalar1); -} - const GrStencilAndCoverTextContext::TextBlob& GrStencilAndCoverTextContext::findOrCreateTextBlob(const SkTextBlob* skBlob, const SkPaint& skPaint) { @@ -265,11 +253,11 @@ GrStencilAndCoverTextContext::findOrCreateTextBlob(const SkTextBlob* skBlob, fCacheSize += blob->cpuMemorySize(); return *blob; } else { - GrStyle style(skPaint); + GrStrokeInfo stroke(skPaint); SkSTArray<4, uint32_t, true> key; - key.reset(1 + style_key_cnt(style)); + key.reset(1 + stroke.computeUniqueKeyFragmentData32Cnt()); key[0] = skBlob->uniqueID(); - write_style_key(&key[1], style); + stroke.asUniqueKeyFragment(&key[1]); if (TextBlob** found = fBlobKeyCache.find(key)) { fLRUList.remove(*found); fLRUList.addToTail(*found); @@ -365,48 +353,41 @@ private: //////////////////////////////////////////////////////////////////////////////////////////////////// GrStencilAndCoverTextContext::TextRun::TextRun(const SkPaint& fontAndStroke) - : fStyle(fontAndStroke), + : fStroke(fontAndStroke), fFont(fontAndStroke), fTotalGlyphCount(0), fFallbackGlyphCount(0), fDetachedGlyphCache(nullptr), fLastDrawnGlyphsID(SK_InvalidUniqueID) { SkASSERT(fFont.getTextSize() > 0); - SkASSERT(!fStyle.hasNonDashPathEffect()); // Arbitrary path effects not supported. - SkASSERT(!fStyle.isSimpleHairline()); // Hairlines are not supported. + SkASSERT(!fStroke.isHairlineStyle()); // Hairlines are not supported. // Setting to "fill" ensures that no strokes get baked into font outlines. (We use the GPU path // rendering API for stroking). fFont.setStyle(SkPaint::kFill_Style); - if (fFont.isFakeBoldText() && fStyle.isSimpleFill()) { - const SkStrokeRec& stroke = fStyle.strokeRec(); + if (fFont.isFakeBoldText() && SkStrokeRec::kStroke_Style != fStroke.getStyle()) { // Instead of letting fake bold get baked into the glyph outlines, do it with GPU stroke. SkScalar fakeBoldScale = SkScalarInterpFunc(fFont.getTextSize(), kStdFakeBoldInterpKeys, kStdFakeBoldInterpValues, kStdFakeBoldInterpLength); SkScalar extra = SkScalarMul(fFont.getTextSize(), fakeBoldScale); + fStroke.setStrokeStyle(fStroke.needToApply() ? fStroke.getWidth() + extra : extra, + true /*strokeAndFill*/); - SkStrokeRec strokeRec(SkStrokeRec::kFill_InitStyle); - strokeRec.setStrokeStyle(stroke.needToApply() ? stroke.getWidth() + extra : extra, - true /*strokeAndFill*/); - fStyle = GrStyle(strokeRec, fStyle.pathEffect()); fFont.setFakeBoldText(false); } - if (!fFont.getPathEffect() && !fStyle.isDashed()) { - const SkStrokeRec& stroke = fStyle.strokeRec(); + if (!fFont.getPathEffect() && !fStroke.isDashed()) { // We can draw the glyphs from canonically sized paths. fTextRatio = fFont.getTextSize() / SkPaint::kCanonicalTextSizeForPaths; fTextInverseRatio = SkPaint::kCanonicalTextSizeForPaths / fFont.getTextSize(); // Compensate for the glyphs being scaled by fTextRatio. - if (!fStyle.isSimpleFill()) { - SkStrokeRec strokeRec(SkStrokeRec::kFill_InitStyle); - strokeRec.setStrokeStyle(stroke.getWidth() / fTextRatio, - SkStrokeRec::kStrokeAndFill_Style == stroke.getStyle()); - fStyle = GrStyle(strokeRec, fStyle.pathEffect()); + if (!fStroke.isFillStyle()) { + fStroke.setStrokeStyle(fStroke.getWidth() / fTextRatio, + SkStrokeRec::kStrokeAndFill_Style == fStroke.getStyle()); } fFont.setLinearText(true); @@ -426,7 +407,7 @@ GrStencilAndCoverTextContext::TextRun::TextRun(const SkPaint& fontAndStroke) } // Generate the key that will be used to cache the GPU glyph path objects. - if (fUsingRawGlyphPaths && fStyle.isSimpleFill()) { + if (fUsingRawGlyphPaths && fStroke.isFillStyle()) { static const GrUniqueKey::Domain kRawFillPathGlyphDomain = GrUniqueKey::GenerateDomain(); const SkTypeface* typeface = fFont.getTypeface(); @@ -435,30 +416,24 @@ GrStencilAndCoverTextContext::TextRun::TextRun(const SkPaint& fontAndStroke) } else { static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDomain(); - int styleDataCount = GrStyle::KeySize(fStyle, GrStyle::Apply::kPathEffectAndStrokeRec); - // Key should be valid since we opted out of drawing arbitrary path effects. - SkASSERT(styleDataCount >= 0); + int strokeDataCount = fStroke.computeUniqueKeyFragmentData32Cnt(); if (fUsingRawGlyphPaths) { const SkTypeface* typeface = fFont.getTypeface(); - GrUniqueKey::Builder builder(&fGlyphPathsKey, kPathGlyphDomain, 2 + styleDataCount); + GrUniqueKey::Builder builder(&fGlyphPathsKey, kPathGlyphDomain, 2 + strokeDataCount); reinterpret_cast<uint32_t&>(builder[0]) = typeface ? typeface->uniqueID() : 0; - reinterpret_cast<uint32_t&>(builder[1]) = styleDataCount; - if (styleDataCount) { - write_style_key(&builder[2], fStyle); - } + reinterpret_cast<uint32_t&>(builder[1]) = strokeDataCount; + fStroke.asUniqueKeyFragment(&builder[2]); } else { SkGlyphCache* glyphCache = this->getGlyphCache(); const SkTypeface* typeface = glyphCache->getScalerContext()->getTypeface(); const SkDescriptor* desc = &glyphCache->getDescriptor(); int descDataCount = (desc->getLength() + 3) / 4; GrUniqueKey::Builder builder(&fGlyphPathsKey, kPathGlyphDomain, - 2 + styleDataCount + descDataCount); + 2 + strokeDataCount + descDataCount); reinterpret_cast<uint32_t&>(builder[0]) = typeface ? typeface->uniqueID() : 0; - reinterpret_cast<uint32_t&>(builder[1]) = styleDataCount | (descDataCount << 16); - if (styleDataCount) { - write_style_key(&builder[2], fStyle); - } - memcpy(&builder[2 + styleDataCount], desc, desc->getLength()); + reinterpret_cast<uint32_t&>(builder[1]) = strokeDataCount | (descDataCount << 16); + fStroke.asUniqueKeyFragment(&builder[2]); + memcpy(&builder[2 + strokeDataCount], desc, desc->getLength()); } } } @@ -566,13 +541,13 @@ GrPathRange* GrStencilAndCoverTextContext::TextRun::createGlyphs(GrContext* ctx) if (fUsingRawGlyphPaths) { SkScalerContextEffects noeffects; glyphs = ctx->resourceProvider()->createGlyphs(fFont.getTypeface(), noeffects, - nullptr, fStyle); + nullptr, fStroke); } else { SkGlyphCache* cache = this->getGlyphCache(); glyphs = ctx->resourceProvider()->createGlyphs(cache->getScalerContext()->getTypeface(), cache->getScalerContext()->getEffects(), &cache->getDescriptor(), - fStyle); + fStroke); } ctx->resourceProvider()->assignUniqueKeyToResource(fGlyphPathsKey, glyphs); } @@ -646,9 +621,9 @@ void GrStencilAndCoverTextContext::TextRun::draw(GrContext* ctx, if (fFallbackTextBlob) { SkPaint fallbackSkPaint(originalSkPaint); - fStyle.strokeRec().applyToPaint(&fallbackSkPaint); - if (!fStyle.isSimpleFill()) { - fallbackSkPaint.setStrokeWidth(fStyle.strokeRec().getWidth() * fTextRatio); + fStroke.applyToPaint(&fallbackSkPaint); + if (!fStroke.isFillStyle()) { + fallbackSkPaint.setStrokeWidth(fStroke.getWidth() * fTextRatio); } fallbackTextContext->drawTextBlob(ctx, dc, pipelineBuilder->clip(), fallbackSkPaint, |