Convert more code to use color space xform FP

Special images, image shaders, and all texture producers,
as well as bicubic (which simplifies factory call sites).

Bug: skia:
Change-Id: I3f7c178060f25db8b659fe66e132f5ea066317b1
Reviewed-on: https://skia-review.googlesource.com/61261
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp
index da31758..9971627 100644
--- a/src/gpu/GrTextureAdjuster.cpp
+++ b/src/gpu/GrTextureAdjuster.cpp
@@ -155,10 +155,7 @@
     }
     SkASSERT(kNoDomain_DomainMode == domainMode ||
              (domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom));
-    sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(fColorSpace,
-                                                                       dstColorSpace);
-    return CreateFragmentProcessorForDomainAndFilter(std::move(proxy),
-                                                     std::move(colorSpaceXform),
-                                                     textureMatrix, domainMode, domain,
-                                                     filterOrNullForBicubic);
+    auto fp = CreateFragmentProcessorForDomainAndFilter(std::move(proxy), textureMatrix,
+                                                        domainMode, domain, filterOrNullForBicubic);
+    return GrColorSpaceXformEffect::Make(std::move(fp), fColorSpace, dstColorSpace);
 }
diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp
index 8183188..cc3d490 100644
--- a/src/gpu/GrTextureMaker.cpp
+++ b/src/gpu/GrTextureMaker.cpp
@@ -117,12 +117,9 @@
                             proxy.get(),
                             nullptr, fmForDetermineDomain, &domain);
     SkASSERT(kTightCopy_DomainMode != domainMode);
-    sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(texColorSpace.get(),
-                                                                       dstColorSpace);
-    return CreateFragmentProcessorForDomainAndFilter(std::move(proxy),
-                                                     std::move(colorSpaceXform),
-                                                     adjustedMatrix, domainMode, domain,
-                                                     filterOrNullForBicubic);
+    auto fp = CreateFragmentProcessorForDomainAndFilter(std::move(proxy), adjustedMatrix,
+                                                        domainMode, domain, filterOrNullForBicubic);
+    return GrColorSpaceXformEffect::Make(std::move(fp), texColorSpace.get(), dstColorSpace);
 }
 
 sk_sp<GrTextureProxy> GrTextureMaker::generateTextureProxyForParams(const CopyParams& copyParams,
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index 2b9679a..f8a0df7 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -221,7 +221,6 @@
 
 std::unique_ptr<GrFragmentProcessor> GrTextureProducer::CreateFragmentProcessorForDomainAndFilter(
         sk_sp<GrTextureProxy> proxy,
-        sk_sp<GrColorSpaceXform> colorSpaceXform,
         const SkMatrix& textureMatrix,
         DomainMode domainMode,
         const SkRect& domain,
@@ -229,24 +228,21 @@
     SkASSERT(kTightCopy_DomainMode != domainMode);
     if (filterOrNullForBicubic) {
         if (kDomain_DomainMode == domainMode) {
-            return GrTextureDomainEffect::Make(std::move(proxy),
-                                               std::move(colorSpaceXform), textureMatrix,
-                                               domain, GrTextureDomain::kClamp_Mode,
+            return GrTextureDomainEffect::Make(std::move(proxy), nullptr, textureMatrix, domain,
+                                               GrTextureDomain::kClamp_Mode,
                                                *filterOrNullForBicubic);
         } else {
             GrSamplerState samplerState(GrSamplerState::WrapMode::kClamp, *filterOrNullForBicubic);
-            return GrSimpleTextureEffect::Make(std::move(proxy), std::move(colorSpaceXform),
-                                               textureMatrix, samplerState);
+            return GrSimpleTextureEffect::Make(std::move(proxy), nullptr, textureMatrix,
+                                               samplerState);
         }
     } else {
         if (kDomain_DomainMode == domainMode) {
-            return GrBicubicEffect::Make(std::move(proxy), std::move(colorSpaceXform),
-                                         textureMatrix, domain);
+            return GrBicubicEffect::Make(std::move(proxy), textureMatrix, domain);
         } else {
             static const GrSamplerState::WrapMode kClampClamp[] = {
                     GrSamplerState::WrapMode::kClamp, GrSamplerState::WrapMode::kClamp};
-            return GrBicubicEffect::Make(std::move(proxy), std::move(colorSpaceXform),
-                                         textureMatrix, kClampClamp);
+            return GrBicubicEffect::Make(std::move(proxy), textureMatrix, kClampClamp);
         }
     }
 }
diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h
index 24b23b6..432e7b3 100644
--- a/src/gpu/GrTextureProducer.h
+++ b/src/gpu/GrTextureProducer.h
@@ -13,7 +13,6 @@
 #include "SkImageInfo.h"
 
 class GrContext;
-class GrColorSpaceXform;
 class GrFragmentProcessor;
 class GrTexture;
 class GrTextureProxy;
@@ -138,7 +137,6 @@
 
     static std::unique_ptr<GrFragmentProcessor> CreateFragmentProcessorForDomainAndFilter(
             sk_sp<GrTextureProxy> proxy,
-            sk_sp<GrColorSpaceXform>,
             const SkMatrix& textureMatrix,
             DomainMode,
             const SkRect& domain,
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index bbc23c2..4473335 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -979,8 +979,6 @@
     if (!proxy) {
         return;
     }
-    sk_sp<GrColorSpaceXform> colorSpaceXform =
-        GrColorSpaceXform::Make(bitmap.colorSpace(), fRenderTargetContext->getColorSpace());
 
     // Compute a matrix that maps the rect we will draw to the src rect.
     const SkMatrix texMatrix = SkMatrix::MakeRectToRect(dstRect, srcRect,
@@ -1006,23 +1004,21 @@
             domain.fTop = domain.fBottom = srcRect.centerY();
         }
         if (bicubic) {
-            fp = GrBicubicEffect::Make(std::move(proxy),
-                                       std::move(colorSpaceXform), texMatrix, domain);
+            fp = GrBicubicEffect::Make(std::move(proxy), texMatrix, domain);
         } else {
-            fp = GrTextureDomainEffect::Make(std::move(proxy), std::move(colorSpaceXform),
-                                             texMatrix, domain, GrTextureDomain::kClamp_Mode,
-                                             samplerState.filter());
+            fp = GrTextureDomainEffect::Make(std::move(proxy), nullptr, texMatrix, domain,
+                                             GrTextureDomain::kClamp_Mode, samplerState.filter());
         }
     } else if (bicubic) {
         SkASSERT(GrSamplerState::Filter::kNearest == samplerState.filter());
         GrSamplerState::WrapMode wrapMode[2] = {samplerState.wrapModeX(), samplerState.wrapModeY()};
-        fp = GrBicubicEffect::Make(std::move(proxy), std::move(colorSpaceXform), texMatrix,
-                                   wrapMode);
+        fp = GrBicubicEffect::Make(std::move(proxy), texMatrix, wrapMode);
     } else {
-        fp = GrSimpleTextureEffect::Make(std::move(proxy), std::move(colorSpaceXform), texMatrix,
-                                         samplerState);
+        fp = GrSimpleTextureEffect::Make(std::move(proxy), nullptr, texMatrix, samplerState);
     }
 
+    fp = GrColorSpaceXformEffect::Make(std::move(fp), bitmap.colorSpace(),
+                                       fRenderTargetContext->getColorSpace());
     GrPaint grPaint;
     if (!SkPaintToGrPaintWithTexture(this->context(), fRenderTargetContext.get(), paint, viewMatrix,
                                      std::move(fp), kAlpha_8_SkColorType == bitmap.colorType(),
@@ -1086,11 +1082,9 @@
     SkPaint tmpUnfiltered(paint);
     tmpUnfiltered.setImageFilter(nullptr);
 
-    sk_sp<GrColorSpaceXform> colorSpaceXform =
-        GrColorSpaceXform::Make(result->getColorSpace(), fRenderTargetContext->getColorSpace());
-
-    auto fp = GrSimpleTextureEffect::Make(std::move(proxy), std::move(colorSpaceXform),
-                                          SkMatrix::I());
+    auto fp = GrSimpleTextureEffect::Make(std::move(proxy), nullptr, SkMatrix::I());
+    fp = GrColorSpaceXformEffect::Make(std::move(fp), result->getColorSpace(),
+                                       fRenderTargetContext->getColorSpace());
     if (GrPixelConfigIsAlphaOnly(config)) {
         fp = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp));
     } else {
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index e95b7a4..c2cedf2 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -8,7 +8,6 @@
 #include "GrBicubicEffect.h"
 
 #include "GrTexture.h"
-#include "glsl/GrGLSLColorSpaceXformHelper.h"
 #include "glsl/GrGLSLFragmentShaderBuilder.h"
 #include "glsl/GrGLSLProgramDataManager.h"
 #include "glsl/GrGLSLUniformHandler.h"
@@ -22,7 +21,6 @@
                               GrProcessorKeyBuilder* b) {
         const GrBicubicEffect& bicubicEffect = effect.cast<GrBicubicEffect>();
         b->add32(GrTextureDomain::GLDomain::DomainKey(bicubicEffect.domain()));
-        b->add32(GrColorSpaceXform::XformKey(bicubicEffect.colorSpaceXform()));
     }
 
 protected:
@@ -32,7 +30,6 @@
     typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
 
     UniformHandle               fImageIncrementUni;
-    GrGLSLColorSpaceXformHelper fColorSpaceHelper;
     GrTextureDomain::GLDomain   fDomain;
 
     typedef GrGLSLFragmentProcessor INHERITED;
@@ -47,8 +44,6 @@
 
     const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
 
-    fColorSpaceHelper.emitCode(uniformHandler, bicubicEffect.colorSpaceXform());
-
     GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
     SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
 
@@ -105,11 +100,6 @@
             y);
     }
     SkString bicubicColor("(wy.x * s0 + wy.y * s1 + wy.z * s2 + wy.w * s3)");
-    if (fColorSpaceHelper.isValid()) {
-        SkString xformedColor;
-        fragBuilder->appendColorGamutXform(&xformedColor, bicubicColor.c_str(), &fColorSpaceHelper);
-        bicubicColor.swap(xformedColor);
-    }
     fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, bicubicColor.c_str(),
                              args.fInputColor);
 }
@@ -125,34 +115,27 @@
     imageIncrement[1] = 1.0f / texture->height();
     pdman.set2fv(fImageIncrementUni, 1, imageIncrement);
     fDomain.setData(pdman, bicubicEffect.domain(), proxy);
-    if (SkToBool(bicubicEffect.colorSpaceXform())) {
-        fColorSpaceHelper.setData(pdman, bicubicEffect.colorSpaceXform());
-    }
 }
 
 GrBicubicEffect::GrBicubicEffect(sk_sp<GrTextureProxy> proxy,
-                                 sk_sp<GrColorSpaceXform> colorSpaceXform,
                                  const SkMatrix& matrix,
                                  const GrSamplerState::WrapMode wrapModes[2])
         : INHERITED{kGrBicubicEffect_ClassID, ModulateByConfigOptimizationFlags(proxy->config())}
         , fCoordTransform(matrix, proxy.get())
         , fDomain(GrTextureDomain::IgnoredDomain())
         , fTextureSampler(std::move(proxy),
-                          GrSamplerState(wrapModes, GrSamplerState::Filter::kNearest))
-        , fColorSpaceXform(std::move(colorSpaceXform)) {
+                          GrSamplerState(wrapModes, GrSamplerState::Filter::kNearest)) {
     this->addCoordTransform(&fCoordTransform);
     this->addTextureSampler(&fTextureSampler);
 }
 
 GrBicubicEffect::GrBicubicEffect(sk_sp<GrTextureProxy> proxy,
-                                 sk_sp<GrColorSpaceXform> colorSpaceXform,
                                  const SkMatrix& matrix,
                                  const SkRect& domain)
         : INHERITED(kGrBicubicEffect_ClassID, ModulateByConfigOptimizationFlags(proxy->config()))
         , fCoordTransform(matrix, proxy.get())
         , fDomain(proxy.get(), domain, GrTextureDomain::kClamp_Mode)
-        , fTextureSampler(std::move(proxy))
-        , fColorSpaceXform(std::move(colorSpaceXform)) {
+        , fTextureSampler(std::move(proxy)) {
     this->addCoordTransform(&fCoordTransform);
     this->addTextureSampler(&fTextureSampler);
 }
@@ -161,8 +144,7 @@
         : INHERITED(kGrBicubicEffect_ClassID, that.optimizationFlags())
         , fCoordTransform(that.fCoordTransform)
         , fDomain(that.fDomain)
-        , fTextureSampler(that.fTextureSampler)
-        , fColorSpaceXform(that.fColorSpaceXform) {
+        , fTextureSampler(that.fTextureSampler) {
     this->addCoordTransform(&fCoordTransform);
     this->addTextureSampler(&fTextureSampler);
 }
@@ -187,11 +169,9 @@
 std::unique_ptr<GrFragmentProcessor> GrBicubicEffect::TestCreate(GrProcessorTestData* d) {
     int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
                                         : GrProcessorUnitTest::kAlphaTextureIdx;
-    sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(d->fRandom);
     static const GrSamplerState::WrapMode kClampClamp[] = {GrSamplerState::WrapMode::kClamp,
                                                            GrSamplerState::WrapMode::kClamp};
-    return GrBicubicEffect::Make(d->textureProxy(texIdx), std::move(colorSpaceXform),
-                                 SkMatrix::I(), kClampClamp);
+    return GrBicubicEffect::Make(d->textureProxy(texIdx), SkMatrix::I(), kClampClamp);
 }
 #endif
 
diff --git a/src/gpu/effects/GrBicubicEffect.h b/src/gpu/effects/GrBicubicEffect.h
index b0a28d9..1d70103 100644
--- a/src/gpu/effects/GrBicubicEffect.h
+++ b/src/gpu/effects/GrBicubicEffect.h
@@ -28,28 +28,24 @@
 
     const GrTextureDomain& domain() const { return fDomain; }
 
-    const GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
-
     /**
      * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
      */
     static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
-                                                     sk_sp<GrColorSpaceXform> colorSpaceXform,
                                                      const SkMatrix& matrix,
                                                      const GrSamplerState::WrapMode wrapModes[2]) {
-        return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(
-                std::move(proxy), std::move(colorSpaceXform), matrix, wrapModes));
+        return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix,
+                                                                        wrapModes));
     }
 
     /**
      * Create a Mitchell filter effect with a texture matrix and a domain.
      */
     static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy,
-                                                     sk_sp<GrColorSpaceXform> colorSpaceXform,
                                                      const SkMatrix& matrix,
                                                      const SkRect& domain) {
-        return std::unique_ptr<GrFragmentProcessor>(
-                new GrBicubicEffect(std::move(proxy), std::move(colorSpaceXform), matrix, domain));
+        return std::unique_ptr<GrFragmentProcessor>(new GrBicubicEffect(std::move(proxy), matrix,
+                                                                        domain));
     }
 
     /**
@@ -63,10 +59,9 @@
                                  GrSamplerState::Filter* filterMode);
 
 private:
-    GrBicubicEffect(sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
+    GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix& matrix,
                     const GrSamplerState::WrapMode wrapModes[2]);
-    GrBicubicEffect(sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
-                    const SkMatrix &matrix, const SkRect& domain);
+    GrBicubicEffect(sk_sp<GrTextureProxy>, const SkMatrix &matrix, const SkRect& domain);
     explicit GrBicubicEffect(const GrBicubicEffect&);
 
     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
@@ -78,7 +73,6 @@
     GrCoordTransform fCoordTransform;
     GrTextureDomain fDomain;
     TextureSampler fTextureSampler;
-    sk_sp<GrColorSpaceXform> fColorSpaceXform;
 
     GR_DECLARE_FRAGMENT_PROCESSOR_TEST