diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp index 586e9e412a..94f373acf8 100644 --- a/src/core/SkGlyphRunPainter.cpp +++ b/src/core/SkGlyphRunPainter.cpp @@ -331,6 +331,8 @@ void GrTextContext::drawGlyphRunList( } bool forceW = fOptions.fDistanceFieldVerticesAlwaysHaveW; + bool supportsSDFT = context->priv().caps()->shaderCaps()->supportsDistanceFieldText(); + SkGlyphRunListPainter* painter = target->glyphPainter(); if (cachedBlob) { if (cachedBlob->mustRegenerate(blobPaint, glyphRunList.anyRunsSubpixelPositioned(), blurRec, viewMatrix, origin.x(), origin.y())) { @@ -341,10 +343,9 @@ void GrTextContext::drawGlyphRunList( cachedBlob = textBlobCache->makeCachedBlob( glyphRunList, grStrikeCache, key, blurRec, viewMatrix, initialVertexColor, forceW); - cachedBlob->generateFromGlyphRunList( - *context->priv().caps()->shaderCaps(), fOptions, - blobPaint, viewMatrix, props, - glyphRunList, target->glyphPainter()); + + painter->processGlyphRunList( + glyphRunList, viewMatrix, props, supportsSDFT, fOptions, cachedBlob.get()); } else { textBlobCache->makeMRU(cachedBlob.get()); } @@ -357,10 +358,8 @@ void GrTextContext::drawGlyphRunList( cachedBlob = textBlobCache->makeBlob( glyphRunList, grStrikeCache, viewMatrix, initialVertexColor, forceW); } - cachedBlob->generateFromGlyphRunList( - *context->priv().caps()->shaderCaps(), fOptions, blobPaint, - viewMatrix, props, glyphRunList, - target->glyphPainter()); + painter->processGlyphRunList( + glyphRunList, viewMatrix, props, supportsSDFT, fOptions, cachedBlob.get()); } cachedBlob->flush(target, props, fDistanceAdjustTable.get(), blobPaint, drawingColor, @@ -404,10 +403,10 @@ std::unique_ptr GrTextContext::createOp_TestingOnly(GrRecordingContext if (!glyphRunList.empty()) { blob = direct->priv().getTextBlobCache()->makeBlob( glyphRunList, strikeCache, viewMatrix, color, false); - blob->generateFromGlyphRunList( - *context->priv().caps()->shaderCaps(), textContext->fOptions, - skPaint, viewMatrix, surfaceProps, - glyphRunList, rtc->textTarget()->glyphPainter()); + SkGlyphRunListPainter* painter = rtc->textTarget()->glyphPainter(); + painter->processGlyphRunList(glyphRunList, viewMatrix, surfaceProps, + context->priv().caps()->shaderCaps()->supportsDistanceFieldText(), + textContext->fOptions, blob.get()); } return blob->test_makeOp(textLen, viewMatrix, x, y, skPaint, filteredColor, surfaceProps, diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp index 7ae8d52b06..56bec654ec 100644 --- a/src/gpu/text/GrTextBlob.cpp +++ b/src/gpu/text/GrTextBlob.cpp @@ -243,9 +243,10 @@ sk_sp GrTextBlob::Make(const SkGlyphRunList& glyphRunList, void* allocation = ::operator new (allocationSize); + SkColor initialLuminance = SkPaintPriv::ComputeLuminanceColor(glyphRunList.paint()); sk_sp blob{new (allocation) GrTextBlob{ subRunsSize, strikeCache, viewMatrix, glyphRunList.origin(), - color, forceWForDistanceFields}}; + color, initialLuminance, forceWForDistanceFields}}; // setup offsets for vertices / glyphs blob->fVertices = SkTAddOffset(blob.get(), vertexOffset); @@ -254,24 +255,6 @@ sk_sp GrTextBlob::Make(const SkGlyphRunList& glyphRunList, return blob; } -void GrTextBlob::generateFromGlyphRunList(const GrShaderCaps& shaderCaps, - const GrTextContext::Options& options, - const SkPaint& paint, - const SkMatrix& viewMatrix, - const SkSurfaceProps& props, - const SkGlyphRunList& glyphRunList, - SkGlyphRunListPainter* glyphPainter) { - const SkPaint& runPaint = glyphRunList.paint(); - this->initReusableBlob(SkPaintPriv::ComputeLuminanceColor(runPaint)); - - glyphPainter->processGlyphRunList(glyphRunList, - viewMatrix, - props, - shaderCaps.supportsDistanceFieldText(), - options, - this); -} - void GrTextBlob::setupKey(const GrTextBlob::Key& key, const SkMaskFilterBase::BlurRec& blurRec, const SkPaint& paint) { fKey = key; @@ -320,7 +303,7 @@ bool GrTextBlob::mustRegenerate(const SkPaint& paint, bool anyRunHasSubpixelPosi // to regenerate the blob on any color change // We use the grPaint to get any color filter effects if (fKey.fCanonicalColor == SK_ColorTRANSPARENT && - fLuminanceColor != SkPaintPriv::ComputeLuminanceColor(paint)) { + fInitialLuminance != SkPaintPriv::ComputeLuminanceColor(paint)) { return true; } @@ -530,10 +513,6 @@ void GrTextBlob::computeSubRunBounds(SkRect* outBounds, const GrTextBlob::SubRun } } -void GrTextBlob::initReusableBlob(SkColor luminanceColor) { - fLuminanceColor = luminanceColor; -} - const GrTextBlob::Key& GrTextBlob::key() const { return fKey; } size_t GrTextBlob::size() const { return fSize; } @@ -636,6 +615,7 @@ GrTextBlob::GrTextBlob(size_t allocSize, const SkMatrix& viewMatrix, SkPoint origin, GrColor color, + SkColor initialLuminance, bool forceWForDistanceFields) : fSize{allocSize} , fStrikeCache{strikeCache} @@ -644,6 +624,7 @@ GrTextBlob::GrTextBlob(size_t allocSize, , fInitialOrigin{origin} , fForceWForDistanceFields{forceWForDistanceFields} , fColor{color} + , fInitialLuminance{initialLuminance} , fAlloc{SkTAddOffset(this, sizeof(GrTextBlob)), allocSize, allocSize/2} { } void GrTextBlob::insertSubRun(SubRun* subRun) { diff --git a/src/gpu/text/GrTextBlob.h b/src/gpu/text/GrTextBlob.h index cd5cc25b25..6d98bdb0b7 100644 --- a/src/gpu/text/GrTextBlob.h +++ b/src/gpu/text/GrTextBlob.h @@ -180,14 +180,6 @@ public: GrColor color, bool forceWForDistanceFields); - void generateFromGlyphRunList(const GrShaderCaps& shaderCaps, - const GrTextContext::Options& options, - const SkPaint& paint, - const SkMatrix& viewMatrix, - const SkSurfaceProps& props, - const SkGlyphRunList& glyphRunList, - SkGlyphRunListPainter* glyphPainter); - // Key manipulation functions void setupKey(const GrTextBlob::Key& key, const SkMaskFilterBase::BlurRec& blurRec, @@ -241,12 +233,6 @@ public: static const int kVerticesPerGlyph = 4; - // This function will only be called when we are generating a blob from scratch. - // The color here is the GrPaint color, and it is used to determine whether we - // have to regenerate LCD text blobs. - // We use this color vs the SkPaint color because it has the color filter applied. - void initReusableBlob(SkColor luminanceColor); - const Key& key() const; size_t size() const; @@ -298,6 +284,7 @@ private: const SkMatrix& viewMatrix, SkPoint origin, GrColor color, + SkColor initialLuminance, bool forceWForDistanceFields); void insertSubRun(SubRun* subRun); @@ -345,6 +332,7 @@ private: // The color of the text to draw for solid colors. const GrColor fColor; + const SkColor fInitialLuminance; // Pool of bytes for vertex data. char* fVertices; @@ -358,7 +346,6 @@ private: SkMaskFilterBase::BlurRec fBlurRec; StrokeInfo fStrokeInfo; Key fKey; - SkColor fLuminanceColor; // We can reuse distance field text, but only if the new view matrix would not result in // a mip change. Because there can be multiple runs in a blob, we track the overall