From 5a7ae7e337a68dc42723fce80752c93b7d26d469 Mon Sep 17 00:00:00 2001 From: brianosman Date: Mon, 12 Sep 2016 12:07:25 -0700 Subject: [PATCH] Gamut transformation of the paint color in Ganesh Conversion from sRGB to destination gamut is going to be very common, so I'm caching that xform (if there is one) on the draw context. Results verified in the gamut GM (two more boxes correct). BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2330553003 Review-Url: https://codereview.chromium.org/2330553003 --- include/gpu/GrColorSpaceXform.h | 3 +++ include/gpu/GrDrawContext.h | 2 ++ src/gpu/GrColorSpaceXform.cpp | 6 ++++++ src/gpu/GrDrawContext.cpp | 6 ++++++ src/gpu/SkGr.cpp | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/include/gpu/GrColorSpaceXform.h b/include/gpu/GrColorSpaceXform.h index 38b5ccf..2d2cc86 100644 --- a/include/gpu/GrColorSpaceXform.h +++ b/include/gpu/GrColorSpaceXform.h @@ -8,6 +8,7 @@ #ifndef GrColorSpaceXform_DEFINED #define GrColorSpaceXform_DEFINED +#include "GrColor.h" #include "SkMatrix44.h" #include "SkRefCnt.h" @@ -33,6 +34,8 @@ public: return SkToBool(xform) ? 1 : 0; } + GrColor4f apply(const GrColor4f& srcColor); + private: SkMatrix44 fSrcToDst; }; diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h index cad2b82..29a70f9 100644 --- a/include/gpu/GrDrawContext.h +++ b/include/gpu/GrDrawContext.h @@ -335,6 +335,7 @@ public: } const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } SkColorSpace* getColorSpace() const { return fColorSpace.get(); } + GrColorSpaceXform* getColorXformFromSRGB() const { return fColorXformFromSRGB.get(); } GrSurfaceOrigin origin() const { return fRenderTarget->origin(); } bool wasAbandoned() const; @@ -425,6 +426,7 @@ private: GrInstancedPipelineInfo fInstancedPipelineInfo; sk_sp fColorSpace; + sk_sp fColorXformFromSRGB; SkSurfaceProps fSurfaceProps; GrAuditTrail* fAuditTrail; diff --git a/src/gpu/GrColorSpaceXform.cpp b/src/gpu/GrColorSpaceXform.cpp index 2d17610..3380b0f 100644 --- a/src/gpu/GrColorSpaceXform.cpp +++ b/src/gpu/GrColorSpaceXform.cpp @@ -58,3 +58,9 @@ sk_sp GrColorSpaceXform::Make(SkColorSpace* src, SkColorSpace return sk_make_sp(srcToDst); } + +GrColor4f GrColorSpaceXform::apply(const GrColor4f& srcColor) { + GrColor4f result; + fSrcToDst.mapScalars(srcColor.fRGBA, result.fRGBA); + return result; +} diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp index 50965ba..e9a9619 100644 --- a/src/gpu/GrDrawContext.cpp +++ b/src/gpu/GrDrawContext.cpp @@ -86,12 +86,18 @@ GrDrawContext::GrDrawContext(GrContext* context, , fContext(context) , fInstancedPipelineInfo(fRenderTarget.get()) , fColorSpace(std::move(colorSpace)) + , fColorXformFromSRGB(nullptr) , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps)) , fAuditTrail(auditTrail) #ifdef SK_DEBUG , fSingleOwner(singleOwner) #endif { + if (fColorSpace) { + // sRGB sources are very common (SkColor, etc...), so we cache that gamut transformation + auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); + fColorXformFromSRGB = GrColorSpaceXform::Make(srgbColorSpace.get(), fColorSpace.get()); + } SkDEBUGCODE(this->validate();) } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 7c0d09b..c8839f3 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -537,6 +537,10 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context, origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]); origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]); origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]); + + if (dc->getColorXformFromSRGB()) { + origColor = dc->getColorXformFromSRGB()->apply(origColor); + } } // Setup the initial color considering the shader, the SkPaint color, and the presence or not -- 2.7.4