diff options
author | Jim Van Verth <jvanverth@google.com> | 2017-06-08 11:14:35 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-08 15:49:20 +0000 |
commit | bc2cdd154bf5a031ca9d3a530123d9f7a4c0925d (patch) | |
tree | f346ec9baf75db146109e35330f89dd15086471c /src | |
parent | e03a72917e5ce7ab8f19260c627e00a7fe0ceefd (diff) |
Fix LCD distance field text color filtering
Distance field text was applying the color filter to determine any gamma
adjustments, but not any effects of the shader as well.
Bug: skia:6669
Change-Id: I73384f68141fb523ea2058e00d0a9fbb2fbc622b
Reviewed-on: https://skia-review.googlesource.com/19049
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/ops/GrAtlasTextOp.cpp | 25 | ||||
-rw-r--r-- | src/gpu/ops/GrAtlasTextOp.h | 11 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextBlob.cpp | 6 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextBlob.h | 6 | ||||
-rw-r--r-- | src/gpu/text/GrAtlasTextContext.cpp | 2 | ||||
-rw-r--r-- | src/gpu/text/GrTextUtils.cpp | 2 | ||||
-rw-r--r-- | src/gpu/text/GrTextUtils.h | 4 |
7 files changed, 20 insertions, 36 deletions
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp index 69e8b4ea49..2f2def662a 100644 --- a/src/gpu/ops/GrAtlasTextOp.cpp +++ b/src/gpu/ops/GrAtlasTextOp.cpp @@ -20,15 +20,6 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// -#ifdef SK_GAMMA_APPLY_TO_A8 -static inline SkColor unpremultiplied_grcolor_to_skcolor(GrColor c) { - unsigned r = GrColorUnpackR(c); - unsigned g = GrColorUnpackG(c); - unsigned b = GrColorUnpackB(c); - return SkColorSetRGB(r, g, b); -} -#endif - static const int kDistanceAdjustLumShift = 5; SkString GrAtlasTextOp::dumpInfo() const { @@ -99,7 +90,7 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) const { flushInfo.fGeometryProcessor = this->setupDfProcessor(fFontCache->context()->resourceProvider(), this->viewMatrix(), - fFilteredColor, this->color(), std::move(proxy)); + fLuminanceColor, this->color(), std::move(proxy)); } else { GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode); flushInfo.fGeometryProcessor = GrBitmapTextGeoProc::Make( @@ -182,7 +173,7 @@ bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { return false; } - if (fFilteredColor != that->fFilteredColor) { + if (fLuminanceColor != that->fLuminanceColor) { return false; } @@ -224,7 +215,7 @@ bool GrAtlasTextOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { // TODO trying to figure out why lcd is so whack sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(GrResourceProvider* resourceProvider, const SkMatrix& viewMatrix, - GrColor filteredColor, + SkColor luminanceColor, GrColor color, sk_sp<GrTextureProxy> proxy) const { GrSamplerParams params(SkShader::kClamp_TileMode, GrSamplerParams::kBilerp_FilterMode); @@ -240,13 +231,13 @@ sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(GrResourceProvider* r flags |= fUseBGR ? kBGR_DistanceFieldEffectFlag : 0; float redCorrection = fDistanceAdjustTable->getAdjustment( - GrColorUnpackR(filteredColor) >> kDistanceAdjustLumShift, + SkColorGetR(luminanceColor) >> kDistanceAdjustLumShift, fUseGammaCorrectDistanceTable); float greenCorrection = fDistanceAdjustTable->getAdjustment( - GrColorUnpackG(filteredColor) >> kDistanceAdjustLumShift, + SkColorGetG(luminanceColor) >> kDistanceAdjustLumShift, fUseGammaCorrectDistanceTable); float blueCorrection = fDistanceAdjustTable->getAdjustment( - GrColorUnpackB(filteredColor) >> kDistanceAdjustLumShift, + SkColorGetB(luminanceColor) >> kDistanceAdjustLumShift, fUseGammaCorrectDistanceTable); GrDistanceFieldLCDTextGeoProc::DistanceAdjust widthAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make( @@ -258,9 +249,7 @@ sk_sp<GrGeometryProcessor> GrAtlasTextOp::setupDfProcessor(GrResourceProvider* r this->usesLocalCoords()); } else { #ifdef SK_GAMMA_APPLY_TO_A8 - SkColor filteredSkColor = unpremultiplied_grcolor_to_skcolor(filteredColor); - - U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, filteredSkColor); + U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, luminanceColor); float correction = fDistanceAdjustTable->getAdjustment(lum >> kDistanceAdjustLumShift, fUseGammaCorrectDistanceTable); return GrDistanceFieldA8TextGeoProc::Make(resourceProvider, color, diff --git a/src/gpu/ops/GrAtlasTextOp.h b/src/gpu/ops/GrAtlasTextOp.h index ac59d4c613..e0a4ed0135 100644 --- a/src/gpu/ops/GrAtlasTextOp.h +++ b/src/gpu/ops/GrAtlasTextOp.h @@ -55,7 +55,7 @@ public: } op->fNumGlyphs = glyphCount; op->fGeoCount = 1; - op->fFilteredColor = 0; + op->fLuminanceColor = 0; op->fFontCache = fontCache; op->fUseBGR = false; return op; @@ -64,14 +64,14 @@ public: static std::unique_ptr<GrAtlasTextOp> MakeDistanceField( int glyphCount, GrAtlasGlyphCache* fontCache, const GrDistanceFieldAdjustTable* distanceAdjustTable, - bool useGammaCorrectDistanceTable, GrColor filteredColor, bool isLCD, bool useBGR) { + bool useGammaCorrectDistanceTable, SkColor luminanceColor, bool isLCD, bool useBGR) { std::unique_ptr<GrAtlasTextOp> op(new GrAtlasTextOp); op->fFontCache = fontCache; op->fMaskType = isLCD ? kLCDDistanceField_MaskType : kGrayscaleDistanceField_MaskType; op->fDistanceAdjustTable.reset(SkRef(distanceAdjustTable)); op->fUseGammaCorrectDistanceTable = useGammaCorrectDistanceTable; - op->fFilteredColor = filteredColor; + op->fLuminanceColor = luminanceColor; op->fUseBGR = useBGR; op->fNumGlyphs = glyphCount; op->fGeoCount = 1; @@ -148,9 +148,8 @@ private: bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override; // TODO just use class params - // TODO trying to figure out why lcd is so whack sk_sp<GrGeometryProcessor> setupDfProcessor(GrResourceProvider*, - const SkMatrix& viewMatrix, GrColor filteredColor, + const SkMatrix& viewMatrix, SkColor luminanceColor, GrColor color, sk_sp<GrTextureProxy> proxy) const; GrColor fColor; @@ -175,7 +174,7 @@ private: // Distance field properties sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable; - GrColor fFilteredColor; + SkColor fLuminanceColor; bool fUseGammaCorrectDistanceTable; friend class GrBlobRegenHelper; // Needs to trigger flushes diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp index be9bb27408..a68f6f9cfa 100644 --- a/src/gpu/text/GrAtlasTextBlob.cpp +++ b/src/gpu/text/GrAtlasTextBlob.cpp @@ -179,7 +179,7 @@ bool GrAtlasTextBlob::mustRegenerate(const GrTextUtils::Paint& paint, // to regenerate the blob on any color change // We use the grPaint to get any color filter effects if (fKey.fCanonicalColor == SK_ColorTRANSPARENT && - fFilteredPaintColor != paint.filteredUnpremulColor()) { + fLuminanceColor != paint.luminanceColor()) { return true; } @@ -266,10 +266,10 @@ inline std::unique_ptr<GrLegacyMeshDrawOp> GrAtlasTextBlob::makeOp( std::unique_ptr<GrAtlasTextOp> op; if (info.drawAsDistanceFields()) { - GrColor filteredColor = paint.filteredUnpremulColor(); + SkColor luminanceColor = paint.luminanceColor(); bool useBGR = SkPixelGeometryIsBGR(props.pixelGeometry()); op = GrAtlasTextOp::MakeDistanceField(glyphCount, cache, distanceAdjustTable, - useGammaCorrectDistanceTable, filteredColor, + useGammaCorrectDistanceTable, luminanceColor, info.hasUseLCDText(), useBGR); } else { op = GrAtlasTextOp::MakeBitmap(format, glyphCount, cache); diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h index 4cc10282d8..470d26f457 100644 --- a/src/gpu/text/GrAtlasTextBlob.h +++ b/src/gpu/text/GrAtlasTextBlob.h @@ -240,9 +240,9 @@ public: // 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. - void initReusableBlob(GrColor filteredColor, const SkMatrix& viewMatrix, SkScalar x, + void initReusableBlob(SkColor luminanceColor, const SkMatrix& viewMatrix, SkScalar x, SkScalar y) { - fFilteredPaintColor = filteredColor; + fLuminanceColor = luminanceColor; this->setupViewMatrix(viewMatrix, x, y); } @@ -530,7 +530,7 @@ private: SkMatrix fInitialViewMatrix; SkMatrix fInitialViewMatrixInverse; size_t fSize; - GrColor fFilteredPaintColor; + SkColor fLuminanceColor; SkScalar fInitialX; SkScalar fInitialY; diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp index 9efe4665c5..71c410eab7 100644 --- a/src/gpu/text/GrAtlasTextContext.cpp +++ b/src/gpu/text/GrAtlasTextContext.cpp @@ -166,7 +166,7 @@ void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob, uint32_t scalerContextFlags, const SkMatrix& viewMatrix, const SkSurfaceProps& props, const SkTextBlob* blob, SkScalar x, SkScalar y, SkDrawFilter* drawFilter) { - cacheBlob->initReusableBlob(paint.filteredUnpremulColor(), viewMatrix, x, y); + cacheBlob->initReusableBlob(paint.luminanceColor(), viewMatrix, x, y); // Regenerate textblob SkTextBlobRunIterator it(blob); diff --git a/src/gpu/text/GrTextUtils.cpp b/src/gpu/text/GrTextUtils.cpp index 9baf3412dc..20001a4f8a 100644 --- a/src/gpu/text/GrTextUtils.cpp +++ b/src/gpu/text/GrTextUtils.cpp @@ -60,14 +60,12 @@ void GrTextUtils::Paint::initFilteredColor() { fPaint->getColorFilter()->filterColor4f(filteredColor.toSkColor4f())); } fFilteredPremulColor = filteredColor.premul().toGrColor(); - fFilteredUnpremulColor = filteredColor.toGrColor(); } else { SkColor filteredSkColor = fPaint->getColor(); if (fPaint->getColorFilter()) { filteredSkColor = fPaint->getColorFilter()->filterColor(filteredSkColor); } fFilteredPremulColor = SkColorToPremulGrColor(filteredSkColor); - fFilteredUnpremulColor = SkColorToUnpremulGrColor(filteredSkColor); } } diff --git a/src/gpu/text/GrTextUtils.h b/src/gpu/text/GrTextUtils.h index 9f38699010..bbf3ca49a9 100644 --- a/src/gpu/text/GrTextUtils.h +++ b/src/gpu/text/GrTextUtils.h @@ -59,7 +59,7 @@ public: // These expose the paint's color run through its color filter (if any). This is only valid // when drawing grayscale/lcd glyph masks and not when drawing color glyphs. GrColor filteredPremulColor() const { return fFilteredPremulColor; } - GrColor filteredUnpremulColor() const { return fFilteredUnpremulColor; } + SkColor luminanceColor() const { return fPaint->computeLuminanceColor(); } const SkPaint& skPaint() const { return *fPaint; } operator const SkPaint&() const { return this->skPaint(); } @@ -80,7 +80,6 @@ public: // This is the paint's color run through its color filter, if present. This color should // be used except when rendering bitmap text, in which case the bitmap must be filtered in // the fragment shader. - GrColor fFilteredUnpremulColor; GrColor fFilteredPremulColor; }; @@ -98,7 +97,6 @@ public: fDstColorSpace = fOriginalPaint->dstColorSpace(); fColorXformFromSRGB = fOriginalPaint->colorXformFromSRGB(); fFilteredPremulColor = fOriginalPaint->filteredPremulColor(); - fFilteredUnpremulColor = fOriginalPaint->filteredUnpremulColor(); } bool modifyForRun(const SkTextBlobRunIterator&); |