diff options
author | Brian Osman <brianosman@google.com> | 2018-07-03 10:40:57 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-07-03 15:28:54 +0000 |
commit | 34ec37458b0a6e157912e0ff6ee8e136885474b9 (patch) | |
tree | 4effe9b5fd3f56fde4129b808a3c9eb21958c87d /src | |
parent | 630741c7c0ea8e504b04afd2f758232fb5c839a4 (diff) |
Replace isGammaCorrect with isLinearlyBlended
We were using isGammaCorrect (presence of a color space) to trigger
rendering effects that should only apply when doing linear blending.
Rename and redefine that function to fix many of those issues.
In a few places, we really do care about the color space.
The big win here is text rendering, which is now the same on legacy
gl and glsrgb configs. Also left some comments about our desire to
do something smarter for text in the future.
Bug: skia:
Change-Id: I94106e95f5f81aaa0a28dbaccd65f5d94cf0de67
Reviewed-on: https://skia-review.googlesource.com/139109
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkDraw.cpp | 11 | ||||
-rw-r--r-- | src/effects/SkHighContrastFilter.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrColorSpaceInfo.h | 2 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 4 | ||||
-rw-r--r-- | src/gpu/GrRenderTargetContext.cpp | 4 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 3 | ||||
-rw-r--r-- | src/gpu/effects/GrDitherEffect.fp | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrDitherEffect.h | 4 | ||||
-rw-r--r-- | src/gpu/text/GrTextBlob.cpp | 3 | ||||
-rw-r--r-- | src/gpu/text/GrTextContext.cpp | 5 |
10 files changed, 23 insertions, 19 deletions
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp index 98cfd87a84..ae1a873f2b 100644 --- a/src/core/SkDraw.cpp +++ b/src/core/SkDraw.cpp @@ -1512,11 +1512,14 @@ private: //////////////////////////////////////////////////////////////////////////////////////////////////// SkScalerContextFlags SkDraw::scalerContextFlags() const { - SkScalerContextFlags flags = SkScalerContextFlags::kBoostContrast; - if (!fDst.colorSpace()) { - flags = kFakeGammaAndBoostContrast; + // If we're doing linear blending, then we can disable the gamma hacks. + // Otherwise, leave them on. In either case, we still want the contrast boost: + // TODO: Can we be even smarter about mask gamma based on the dest transfer function? + if (fDst.colorSpace() && fDst.colorSpace()->gammaIsLinear()) { + return SkScalerContextFlags::kBoostContrast; + } else { + return SkScalerContextFlags::kFakeGammaAndBoostContrast; } - return flags; } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/SkHighContrastFilter.cpp b/src/effects/SkHighContrastFilter.cpp index 607033ef20..be6180a531 100644 --- a/src/effects/SkHighContrastFilter.cpp +++ b/src/effects/SkHighContrastFilter.cpp @@ -364,7 +364,7 @@ void GLHighContrastFilterEffect::emitCode(EmitArgs& args) { std::unique_ptr<GrFragmentProcessor> SkHighContrast_Filter::asFragmentProcessor( GrContext*, const GrColorSpaceInfo& csi) const { - bool linearize = !csi.isGammaCorrect(); + bool linearize = !csi.isLinearlyBlended(); return HighContrastFilterEffect::Make(fConfig, linearize); } #endif diff --git a/src/gpu/GrColorSpaceInfo.h b/src/gpu/GrColorSpaceInfo.h index 42a61b054d..9dd471b7d4 100644 --- a/src/gpu/GrColorSpaceInfo.h +++ b/src/gpu/GrColorSpaceInfo.h @@ -18,7 +18,7 @@ class GrColorSpaceInfo { public: GrColorSpaceInfo(sk_sp<SkColorSpace>, GrPixelConfig); - bool isGammaCorrect() const { return static_cast<bool>(fColorSpace); } + bool isLinearlyBlended() const { return fColorSpace && fColorSpace->gammaIsLinear(); } SkColorSpace* colorSpace() const { return fColorSpace.get(); } sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index a34ee88a33..067c223314 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -478,7 +478,7 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst, int left, int top, // that are premultiplied on the GPU. This is kept as narrow as possible for now. bool canvas2DFastPath = premul && - !dst->colorSpaceInfo().isGammaCorrect() && + !dst->colorSpaceInfo().colorSpace() && (srcColorType == GrColorType::kRGBA_8888 || srcColorType == GrColorType::kBGRA_8888) && SkToBool(dst->asRenderTargetContext()) && (dstProxy->config() == kRGBA_8888_GrPixelConfig || @@ -656,7 +656,7 @@ bool GrContextPriv::readSurfacePixels(GrSurfaceContext* src, int left, int top, // fContext->vaildaPMUPMConversionExists()). bool canvas2DFastPath = unpremul && - !src->colorSpaceInfo().isGammaCorrect() && + !src->colorSpaceInfo().colorSpace() && (GrColorType::kRGBA_8888 == dstColorType || GrColorType::kBGRA_8888 == dstColorType) && SkToBool(srcProxy->asTextureProxy()) && (srcProxy->config() == kRGBA_8888_GrPixelConfig || diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index b6a9b5a78b..05b3c2475a 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -1605,7 +1605,7 @@ bool GrRenderTargetContextPriv::drawAndStencilPath(const GrHardClip& clip, &viewMatrix, &shape, aaType, - fRenderTargetContext->colorSpaceInfo().isGammaCorrect()}; + fRenderTargetContext->colorSpaceInfo().isLinearlyBlended()}; pr->drawPath(args); return true; } @@ -1701,7 +1701,7 @@ void GrRenderTargetContext::drawShapeUsingPathRenderer(const GrClip& clip, &viewMatrix, canDrawArgs.fShape, aaType, - this->colorSpaceInfo().isGammaCorrect()}; + this->colorSpaceInfo().isLinearlyBlended()}; pr->drawPath(args); } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index a0a934094e..cc2b8fda9e 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -420,8 +420,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context, // Conservative default, in case GrPixelConfigToColorType() fails. SkColorType ct = SkColorType::kRGB_565_SkColorType; GrPixelConfigToColorType(colorSpaceInfo.config(), &ct); - if (SkPaintPriv::ShouldDither(skPaint, ct) && grPaint->numColorFragmentProcessors() > 0 && - !colorSpaceInfo.isGammaCorrect()) { + if (SkPaintPriv::ShouldDither(skPaint, ct) && grPaint->numColorFragmentProcessors() > 0) { auto ditherFP = GrDitherEffect::Make(colorSpaceInfo.config()); if (ditherFP) { grPaint->addColorFragmentProcessor(std::move(ditherFP)); diff --git a/src/gpu/effects/GrDitherEffect.fp b/src/gpu/effects/GrDitherEffect.fp index c51865e38b..ed6c0e6b70 100644 --- a/src/gpu/effects/GrDitherEffect.fp +++ b/src/gpu/effects/GrDitherEffect.fp @@ -18,8 +18,6 @@ layout(key) in int rangeType; case kRGBA_8888_GrPixelConfig: case kRGB_888_GrPixelConfig: case kBGRA_8888_GrPixelConfig: - case kSRGBA_8888_GrPixelConfig: - case kSBGRA_8888_GrPixelConfig: rangeType = 0; break; case kRGB_565_GrPixelConfig: @@ -29,6 +27,8 @@ layout(key) in int rangeType; rangeType = 2; break; case kUnknown_GrPixelConfig: + case kSRGBA_8888_GrPixelConfig: + case kSBGRA_8888_GrPixelConfig: case kRGBA_1010102_GrPixelConfig: case kAlpha_half_GrPixelConfig: case kAlpha_half_as_Red_GrPixelConfig: diff --git a/src/gpu/effects/GrDitherEffect.h b/src/gpu/effects/GrDitherEffect.h index 9355a5907c..70adc45e6a 100644 --- a/src/gpu/effects/GrDitherEffect.h +++ b/src/gpu/effects/GrDitherEffect.h @@ -26,8 +26,6 @@ public: case kRGBA_8888_GrPixelConfig: case kRGB_888_GrPixelConfig: case kBGRA_8888_GrPixelConfig: - case kSRGBA_8888_GrPixelConfig: - case kSBGRA_8888_GrPixelConfig: rangeType = 0; break; case kRGB_565_GrPixelConfig: @@ -37,6 +35,8 @@ public: rangeType = 2; break; case kUnknown_GrPixelConfig: + case kSRGBA_8888_GrPixelConfig: + case kSBGRA_8888_GrPixelConfig: case kRGBA_1010102_GrPixelConfig: case kAlpha_half_GrPixelConfig: case kAlpha_half_as_Red_GrPixelConfig: diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp index 08491f525e..62f7d74f57 100644 --- a/src/gpu/text/GrTextBlob.cpp +++ b/src/gpu/text/GrTextBlob.cpp @@ -251,9 +251,10 @@ inline std::unique_ptr<GrAtlasTextOp> GrTextBlob::makeOp( target->makeGrPaint(info.maskFormat(), paint, viewMatrix, &grPaint); std::unique_ptr<GrAtlasTextOp> op; if (info.drawAsDistanceFields()) { + // TODO: Can we be even smarter based on the dest transfer function? op = GrAtlasTextOp::MakeDistanceField( target->getContext(), std::move(grPaint), glyphCount, distanceAdjustTable, - target->colorSpaceInfo().isGammaCorrect(), paint.luminanceColor(), + target->colorSpaceInfo().isLinearlyBlended(), paint.luminanceColor(), props, info.isAntiAliased(), info.hasUseLCDText()); } else { op = GrAtlasTextOp::MakeBitmap(target->getContext(), std::move(grPaint), format, glyphCount, diff --git a/src/gpu/text/GrTextContext.cpp b/src/gpu/text/GrTextContext.cpp index a20ba4424a..16f164c9c8 100644 --- a/src/gpu/text/GrTextContext.cpp +++ b/src/gpu/text/GrTextContext.cpp @@ -75,9 +75,10 @@ SkColor GrTextContext::ComputeCanonicalColor(const SkPaint& paint, bool lcd) { SkScalerContextFlags GrTextContext::ComputeScalerContextFlags( const GrColorSpaceInfo& colorSpaceInfo) { - // If we're doing gamma-correct rendering, then we can disable the gamma hacks. + // If we're doing linear blending, then we can disable the gamma hacks. // Otherwise, leave them on. In either case, we still want the contrast boost: - if (colorSpaceInfo.isGammaCorrect()) { + // TODO: Can we be even smarter about mask gamma based on the dest transfer function? + if (colorSpaceInfo.isLinearlyBlended()) { return SkScalerContextFlags::kBoostContrast; } else { return SkScalerContextFlags::kFakeGammaAndBoostContrast; |