From 0628a52b0cd11a7d5e3415f85c8b8d7cfa655151 Mon Sep 17 00:00:00 2001 From: jvanverth Date: Tue, 18 Aug 2015 07:44:22 -0700 Subject: Regenerate LCD text blobs if GrPaint's color changes, not SkPaint. The GrPaint's color takes into account shaders and color filters, so is a more accurate picture of the color state. BUG=chromium:511787 Review URL: https://codereview.chromium.org/1297053004 --- src/gpu/GrAtlasTextBlob.h | 2 +- src/gpu/GrAtlasTextContext.cpp | 38 ++++++++++++++++++++++---------------- src/gpu/GrAtlasTextContext.h | 7 +++---- 3 files changed, 26 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/gpu/GrAtlasTextBlob.h b/src/gpu/GrAtlasTextBlob.h index 63f9185d97..5b7b52ea26 100644 --- a/src/gpu/GrAtlasTextBlob.h +++ b/src/gpu/GrAtlasTextBlob.h @@ -184,7 +184,7 @@ struct GrAtlasTextBlob : public SkRefCnt { SkTArray fBigGlyphs; Key fKey; SkMatrix fViewMatrix; - SkColor fPaintColor; + GrColor fPaintColor; SkScalar fX; SkScalar fY; diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp index 56486e9ccb..a556128be5 100644 --- a/src/gpu/GrAtlasTextContext.cpp +++ b/src/gpu/GrAtlasTextContext.cpp @@ -242,11 +242,13 @@ bool GrAtlasTextContext::HasLCD(const SkTextBlob* blob) { bool GrAtlasTextContext::MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTransY, const GrAtlasTextBlob& blob, const SkPaint& paint, - const SkMaskFilter::BlurRec& blurRec, + GrColor color, const SkMaskFilter::BlurRec& blurRec, const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { // If we have LCD text then our canonical color will be set to transparent, in this case we have // to regenerate the blob on any color change - if (blob.fKey.fCanonicalColor == SK_ColorTRANSPARENT && blob.fPaintColor != paint.getColor()) { + // We use the grPaint to get any color filter effects + if (blob.fKey.fCanonicalColor == SK_ColorTRANSPARENT && + blob.fPaintColor != color) { return true; } @@ -395,7 +397,8 @@ void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, } if (cacheBlob) { - if (MustRegenerateBlob(&transX, &transY, *cacheBlob, skPaint, blurRec, viewMatrix, x, y)) { + if (MustRegenerateBlob(&transX, &transY, *cacheBlob, skPaint, grPaint.getColor(), blurRec, + viewMatrix, x, y)) { // We have to remake the blob because changes may invalidate our masks. // TODO we could probably get away reuse most of the time if the pointer is unique, // but we'd have to clear the subrun information @@ -403,7 +406,7 @@ void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint, kGrayTextVASize))); this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix, - blob, x, y, drawFilter, clipRect, rt, clip, grPaint); + blob, x, y, drawFilter, clipRect, rt, clip); } else { // If we can reuse the blob, then make sure we update the blob's viewmatrix, and x/y // offsets. Note, we offset the vertex bounds right before flushing @@ -420,7 +423,7 @@ void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, kGrayTextVASize)); GrTextBlobCache::SetupCacheBlobKey(sanityBlob, key, blurRec, skPaint); this->regenerateTextBlob(sanityBlob, skPaint, grPaint.getColor(), viewMatrix, - blob, x, y, drawFilter, clipRect, rt, clip, grPaint); + blob, x, y, drawFilter, clipRect, rt, clip); GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob); } @@ -434,7 +437,7 @@ void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, cacheBlob.reset(fCache->createBlob(blob, kGrayTextVASize)); } this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix, - blob, x, y, drawFilter, clipRect, rt, clip, grPaint); + blob, x, y, drawFilter, clipRect, rt, clip); } this->flush(blob, cacheBlob, rt, skPaint, grPaint, drawFilter, @@ -485,9 +488,11 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, const SkMatrix& viewMatrix, const SkTextBlob* blob, SkScalar x, SkScalar y, SkDrawFilter* drawFilter, const SkIRect& clipRect, - GrRenderTarget* rt, const GrClip& clip, - const GrPaint& paint) { - cacheBlob->fPaintColor = skPaint.getColor(); + GrRenderTarget* rt, const GrClip& clip) { + // 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 colorfilter applied. + cacheBlob->fPaintColor = color; cacheBlob->fViewMatrix = viewMatrix; cacheBlob->fX = x; cacheBlob->fY = y; @@ -566,7 +571,7 @@ void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, } } if (fallbackTxt.count()) { - this->fallbackDrawPosText(cacheBlob, run, rt, clip, paint, runPaint, viewMatrix, + this->fallbackDrawPosText(cacheBlob, run, rt, clip, color, runPaint, viewMatrix, fallbackTxt, fallbackPos, scalarsPerPosition, dfOffset, clipRect); } @@ -662,7 +667,7 @@ inline void GrAtlasTextContext::initDistanceFieldPaint(GrAtlasTextBlob* blob, inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob, int runIndex, GrRenderTarget* rt, const GrClip& clip, - const GrPaint& paint, + GrColor color, const SkPaint& skPaint, const SkMatrix& viewMatrix, const SkTDArray& fallbackTxt, @@ -680,7 +685,7 @@ inline void GrAtlasTextContext::fallbackDrawPosText(GrAtlasTextBlob* blob, fSurfaceProps, &viewMatrix, false); SkGlyphCache* cache = SkGlyphCache::DetachCache(run.fTypeface, run.fOverrideDescriptor->getDesc()); - this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, paint.getColor(), viewMatrix, + this->internalDrawBMPPosText(blob, runIndex, cache, skPaint, color, viewMatrix, fallbackTxt.begin(), fallbackTxt.count(), fallbackPos.begin(), scalarsPerPosition, offset, clipRect); SkGlyphCache::AttachCache(cache); @@ -729,8 +734,8 @@ GrAtlasTextContext::createDrawTextBlob(GrRenderTarget* rt, const GrClip& clip, &offset, skPaint); SkGlyphCache::AttachCache(cache); if (fallbackTxt.count()) { - this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMatrix, fallbackTxt, - fallbackPos, 2, offset, clipRect); + this->fallbackDrawPosText(blob, 0, rt, clip, paint.getColor(), skPaint, viewMatrix, + fallbackTxt, fallbackPos, 2, offset, clipRect); } } else { blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); @@ -770,8 +775,9 @@ GrAtlasTextContext::createDrawPosTextBlob(GrRenderTarget* rt, const GrClip& clip textRatio, &fallbackTxt, &fallbackPos); SkGlyphCache::AttachCache(cache); if (fallbackTxt.count()) { - this->fallbackDrawPosText(blob, 0, rt, clip, paint, skPaint, viewMatrix, fallbackTxt, - fallbackPos, scalarsPerPosition, offset, clipRect); + this->fallbackDrawPosText(blob, 0, rt, clip, paint.getColor(), skPaint, viewMatrix, + fallbackTxt, fallbackPos, scalarsPerPosition, offset, + clipRect); } } else { blob = fCache->createBlob(glyphCount, 1, kGrayTextVASize); diff --git a/src/gpu/GrAtlasTextContext.h b/src/gpu/GrAtlasTextContext.h index 2945b02152..7ebe42e019 100644 --- a/src/gpu/GrAtlasTextContext.h +++ b/src/gpu/GrAtlasTextContext.h @@ -96,8 +96,7 @@ private: // A helper for drawing BitmapText in a run of distance fields inline void fallbackDrawPosText(GrAtlasTextBlob*, int runIndex, - GrRenderTarget*, const GrClip&, - const GrPaint&, + GrRenderTarget*, const GrClip&, GrColor color, const SkPaint&, const SkMatrix& viewMatrix, const SkTDArray& fallbackTxt, const SkTDArray& fallbackPos, @@ -136,14 +135,14 @@ private: inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMatrix, bool noGamma); static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTransY, - const GrAtlasTextBlob&, const SkPaint&, + const GrAtlasTextBlob&, const SkPaint&, GrColor, const SkMaskFilter::BlurRec&, const SkMatrix& viewMatrix, SkScalar x, SkScalar y); void regenerateTextBlob(GrAtlasTextBlob* bmp, const SkPaint& skPaint, GrColor, const SkMatrix& viewMatrix, const SkTextBlob* blob, SkScalar x, SkScalar y, SkDrawFilter* drawFilter, const SkIRect& clipRect, GrRenderTarget*, - const GrClip&, const GrPaint&); + const GrClip&); inline static bool HasLCD(const SkTextBlob*); inline void initDistanceFieldPaint(GrAtlasTextBlob*, SkPaint*, SkScalar* textRatio, const SkMatrix&); -- cgit v1.2.3