Revert "Add target SkColorSpace to SkImage_GpuYUVA."

This reverts commit 2232b9ed3998110ed613ae01f3637d2ce7317f05.

Reason for revert: Causing crashes on some ES devices and ANGLE.

Original change's description:
> Add target SkColorSpace to SkImage_GpuYUVA.
> 
> Bug: skia:8868
> Change-Id: I91f58bf88aec14c17ea904adca792e20099c36eb
> Reviewed-on: https://skia-review.googlesource.com/c/182816
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>

TBR=jvanverth@google.com,brianosman@google.com

Change-Id: I61752dbd244c0b4c25578bae08f8da40db6bb514
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:8668
Reviewed-on: https://skia-review.googlesource.com/c/183301
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/gm/wacky_yuv_formats.cpp b/gm/wacky_yuv_formats.cpp
index 155ec6d..0e4abc7 100644
--- a/gm/wacky_yuv_formats.cpp
+++ b/gm/wacky_yuv_formats.cpp
@@ -719,18 +719,14 @@
 // YV12
 class WackyYUVFormatsGM : public GM {
 public:
-    WackyYUVFormatsGM(bool useTargetColorSpace) : fUseTargetColorSpace(useTargetColorSpace) {
+    WackyYUVFormatsGM() {
         this->setBGColor(0xFFCCCCCC);
     }
 
 protected:
 
     SkString onShortName() override {
-        SkString name("wacky_yuv_formats");
-        if (fUseTargetColorSpace) {
-            name += "_cs";
-        }
-        return name;
+        return SkString("wacky_yuv_formats");
     }
 
     SkISize onISize() override {
@@ -758,10 +754,6 @@
             SkPath path = create_splat(origin, innerRadius, outerRadius, 1.0f, 7, &circles);
             fOriginalBMs[1] = make_bitmap(path, circles, true);
         }
-
-        if (fUseTargetColorSpace) {
-            fTargetColorSpace = SkColorSpace::MakeSRGB()->makeColorSpin();
-        }
     }
 
     void createImages(GrContext* context) {
@@ -858,13 +850,8 @@
 
                 for (int format = kAYUV_YUVFormat; format <= kLast_YUVFormat; ++format) {
                     draw_row_label(canvas, y, format);
-                    if (fUseTargetColorSpace) {
-                        sk_sp<SkImage> csImage =
-                            fImages[opaque][cs][format]->makeColorSpace(fTargetColorSpace);
-                        canvas->drawImage(csImage, x, y);
-                    } else {
-                        canvas->drawImage(fImages[opaque][cs][format], x, y);
-                    }
+                    canvas->drawImage(fImages[opaque][cs][format], x, y);
+
                     y += kTileWidthHeight + kPad;
                 }
 
@@ -876,14 +863,11 @@
 private:
     SkBitmap       fOriginalBMs[2];
     sk_sp<SkImage> fImages[2][kLastEnum_SkYUVColorSpace+1][kLast_YUVFormat+1];
-    bool           fUseTargetColorSpace;
-    sk_sp<SkColorSpace> fTargetColorSpace;
 
     typedef GM INHERITED;
 };
 
 //////////////////////////////////////////////////////////////////////////////
 
-DEF_GM(return new WackyYUVFormatsGM(false);)
-DEF_GM(return new WackyYUVFormatsGM(true);)
+DEF_GM(return new WackyYUVFormatsGM;)
 }
diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp
index fa87037..567e91e 100644
--- a/src/gpu/GrImageTextureMaker.cpp
+++ b/src/gpu/GrImageTextureMaker.cpp
@@ -81,9 +81,6 @@
 SkColorSpace* GrYUVAImageTextureMaker::colorSpace() const {
     return fImage->colorSpace();
 }
-SkColorSpace* GrYUVAImageTextureMaker::targetColorSpace() const {
-    return fImage->targetColorSpace();
-}
 
 std::unique_ptr<GrFragmentProcessor> GrYUVAImageTextureMaker::createFragmentProcessor(
     const SkMatrix& textureMatrix,
diff --git a/src/gpu/GrImageTextureMaker.h b/src/gpu/GrImageTextureMaker.h
index 8024579..544705f 100644
--- a/src/gpu/GrImageTextureMaker.h
+++ b/src/gpu/GrImageTextureMaker.h
@@ -65,7 +65,6 @@
 
     SkAlphaType alphaType() const override;
     SkColorSpace* colorSpace() const override;
-    SkColorSpace* targetColorSpace() const override;
 
 private:
     const SkImage_GpuYUVA*  fImage;
diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h
index 68c1b47..1994f8b 100644
--- a/src/gpu/GrTextureProducer.h
+++ b/src/gpu/GrTextureProducer.h
@@ -109,7 +109,6 @@
     bool isAlphaOnly() const { return fIsAlphaOnly; }
     virtual SkAlphaType alphaType() const = 0;
     virtual SkColorSpace* colorSpace() const = 0;
-    virtual SkColorSpace* targetColorSpace() const { return nullptr; }
 
 protected:
     friend class GrTextureProducer_TestAccess;
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index a891c03..3867465 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -289,11 +289,8 @@
     }
     auto fp = producer->createFragmentProcessor(*textureMatrix, clippedSrcRect, constraintMode,
                                                 coordsAllInsideSrcRect, filterMode);
-    SkColorSpace* rtColorSpace = fRenderTargetContext->colorSpaceInfo().colorSpace();
-    SkColorSpace* targetColorSpace = producer->targetColorSpace();
-    SkColorSpace* dstColorSpace = SkToBool(rtColorSpace) ? rtColorSpace : targetColorSpace;
     fp = GrColorSpaceXformEffect::Make(std::move(fp), producer->colorSpace(), producer->alphaType(),
-                                       dstColorSpace);
+                                       fRenderTargetContext->colorSpaceInfo().colorSpace());
     if (!fp) {
         return;
     }
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 2b28f1a..932b521 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -60,42 +60,6 @@
     return SkImageInfo::Make(fProxy->width(), fProxy->height(), colorType, fAlphaType, fColorSpace);
 }
 
-sk_sp<SkImage> SkImage_Gpu::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
-    auto xform = GrColorSpaceXformEffect::Make(fColorSpace.get(), fAlphaType,
-                                               target.get(), fAlphaType);
-    SkASSERT(xform);
-
-    sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef();
-
-    GrBackendFormat format = proxy->backendFormat().makeTexture2D();
-    if (!format.isValid()) {
-        return nullptr;
-    }
-
-    sk_sp<GrRenderTargetContext> renderTargetContext(
-        fContext->contextPriv().makeDeferredRenderTargetContextWithFallback(
-            format, SkBackingFit::kExact, this->width(), this->height(),
-            proxy->config(), nullptr));
-    if (!renderTargetContext) {
-        return nullptr;
-    }
-
-    GrPaint paint;
-    paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
-    paint.addColorTextureProcessor(std::move(proxy), SkMatrix::I());
-    paint.addColorFragmentProcessor(std::move(xform));
-
-    renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
-                                  SkRect::MakeIWH(this->width(), this->height()));
-    if (!renderTargetContext->asTextureProxy()) {
-        return nullptr;
-    }
-
-    // MDB: this call is okay bc we know 'renderTargetContext' was exact
-    return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, fAlphaType,
-                                   renderTargetContext->asTextureProxyRef(), std::move(target));
-}
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx,
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 42ba0a5..1f82539 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -37,8 +37,6 @@
 
     virtual bool onIsTextureBacked() const override { return SkToBool(fProxy.get()); }
 
-    sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const final;
-
     /**
         Create a new SkImage that is very similar to an SkImage created by MakeFromTexture. The main
         difference is that the client doesn't have the backend texture on the gpu yet but they know
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 047b1a2..73aecf4 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -256,6 +256,42 @@
     return proxy->peekTexture();
 }
 
+sk_sp<SkImage> SkImage_GpuBase::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
+    auto xform = GrColorSpaceXformEffect::Make(fColorSpace.get(), fAlphaType,
+                                               target.get(),      fAlphaType);
+    SkASSERT(xform);
+
+    sk_sp<GrTextureProxy> proxy = this->asTextureProxyRef();
+
+    GrBackendFormat format = proxy->backendFormat().makeTexture2D();
+    if (!format.isValid()) {
+        return nullptr;
+    }
+
+    sk_sp<GrRenderTargetContext> renderTargetContext(
+        fContext->contextPriv().makeDeferredRenderTargetContextWithFallback(
+            format, SkBackingFit::kExact, this->width(), this->height(),
+            proxy->config(), nullptr));
+    if (!renderTargetContext) {
+        return nullptr;
+    }
+
+    GrPaint paint;
+    paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
+    paint.addColorTextureProcessor(std::move(proxy), SkMatrix::I());
+    paint.addColorFragmentProcessor(std::move(xform));
+
+    renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
+                                  SkRect::MakeIWH(this->width(), this->height()));
+    if (!renderTargetContext->asTextureProxy()) {
+        return nullptr;
+    }
+
+    // MDB: this call is okay bc we know 'renderTargetContext' was exact
+    return sk_make_sp<SkImage_Gpu>(fContext, kNeedNewImageUniqueID, fAlphaType,
+                                   renderTargetContext->asTextureProxyRef(), std::move(target));
+}
+
 bool SkImage_GpuBase::onIsValid(GrContext* context) const {
     // The base class has already checked that context isn't abandoned (if it's not nullptr)
     if (fContext->abandoned()) {
diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h
index 37d3b22..58b09c6 100644
--- a/src/image/SkImage_GpuBase.h
+++ b/src/image/SkImage_GpuBase.h
@@ -50,6 +50,8 @@
 
     GrTexture* onGetTexture() const final;
 
+    sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const final;
+
     bool onIsValid(GrContext*) const final;
 
 #if GR_TEST_UTILS
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index 55411cc..340f1ef 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -48,28 +48,6 @@
     memcpy(fYUVAIndices, yuvaIndices, 4*sizeof(SkYUVAIndex));
 }
 
-// For onMakeColorSpace()
-SkImage_GpuYUVA::SkImage_GpuYUVA(const SkImage_GpuYUVA* image, sk_sp<SkColorSpace> targetCS)
-    : INHERITED(image->fContext, image->width(), image->height(), kNeedNewImageUniqueID,
-                // If an alpha channel is present we always switch to kPremul. This is because,
-                // although the planar data is always un-premul, the final interleaved RGB image
-                // is/would-be premul.
-                GetAlphaTypeFromYUVAIndices(image->fYUVAIndices), image->fColorSpace)
-    , fNumProxies(image->fNumProxies)
-    , fYUVColorSpace(image->fYUVColorSpace)
-    , fOrigin(image->fOrigin)
-    , fTargetColorSpace(targetCS) {
-        // The caller should have done this work, just verifying
-    SkDEBUGCODE(int textureCount;)
-        SkASSERT(SkYUVAIndex::AreValidIndices(image->fYUVAIndices, &textureCount));
-    SkASSERT(textureCount == fNumProxies);
-
-    for (int i = 0; i < fNumProxies; ++i) {
-        fProxies[i] = image->fProxies[i];  // we ref in this case, not move
-    }
-    memcpy(fYUVAIndices, image->fYUVAIndices, 4 * sizeof(SkYUVAIndex));
-}
-
 SkImage_GpuYUVA::~SkImage_GpuYUVA() {}
 
 SkImageInfo SkImage_GpuYUVA::onImageInfo() const {
@@ -143,22 +121,6 @@
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
-sk_sp<SkImage> SkImage_GpuYUVA::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
-    // we may need a mutex here but for now we expect usage to be in a single thread
-    if (fOnMakeColorSpaceTarget &&
-        SkColorSpace::Equals(target.get(), fOnMakeColorSpaceTarget.get())) {
-        return fOnMakeColorSpaceResult;
-    }
-    sk_sp<SkImage> result = sk_sp<SkImage>(new SkImage_GpuYUVA(this, target));
-    if (result) {
-        fOnMakeColorSpaceTarget = target;
-        fOnMakeColorSpaceResult = result;
-    }
-    return result;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-
 sk_sp<SkImage> SkImage::MakeFromYUVATextures(GrContext* ctx,
                                              SkYUVColorSpace colorSpace,
                                              const GrBackendTexture yuvaTextures[],
diff --git a/src/image/SkImage_GpuYUVA.h b/src/image/SkImage_GpuYUVA.h
index c8b9616..1a6ab93 100644
--- a/src/image/SkImage_GpuYUVA.h
+++ b/src/image/SkImage_GpuYUVA.h
@@ -36,8 +36,6 @@
 
     virtual bool onIsTextureBacked() const override { return SkToBool(fProxies[0].get()); }
 
-    sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const final;
-
     virtual bool isYUVA() const override { return true; }
     virtual bool asYUVATextureProxiesRef(sk_sp<GrTextureProxy> proxies[4],
                                          SkYUVAIndex yuvaIndices[4],
@@ -55,8 +53,6 @@
     // Returns a ref-ed texture proxy with miplevels
     sk_sp<GrTextureProxy> asMippedTextureProxyRef() const;
 
-    SkColorSpace* targetColorSpace() const { return fTargetColorSpace.get(); }
-
     /**
         Create a new SkImage_GpuYUVA that's very similar to SkImage created by MakeFromYUVATextures.
         The main difference is that the client doesn't have the backend textures on the gpu yet but
@@ -113,8 +109,6 @@
                                                  PromiseImageTextureContext textureContexts[]);
 
 private:
-    SkImage_GpuYUVA(const SkImage_GpuYUVA* image, sk_sp<SkColorSpace>);
-
     // This array will usually only be sparsely populated.
     // The actual non-null fields are dictated by the 'fYUVAIndices' indices
     mutable sk_sp<GrTextureProxy>    fProxies[4];
@@ -122,12 +116,6 @@
     SkYUVAIndex                      fYUVAIndices[4];
     const SkYUVColorSpace            fYUVColorSpace;
     GrSurfaceOrigin                  fOrigin;
-    const sk_sp<SkColorSpace>        fTargetColorSpace;
-
-    // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and
-    // SkImage_GpuYUVA instances. Cache the result of the last successful onMakeColorSpace call.
-    mutable sk_sp<SkColorSpace>      fOnMakeColorSpaceTarget;
-    mutable sk_sp<SkImage>           fOnMakeColorSpaceResult;
 
     // This is only allocated when the image needs to be flattened rather than
     // using the separate YUVA planes. From thence forth we will only use the