Compose and YUV fragment processor clone implementations

Change-Id: If4d9f1aaf0e5939afb5ad5825d7198db18541926
Reviewed-on: https://skia-review.googlesource.com/27060
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/effects/GrYUVEffect.cpp b/src/gpu/effects/GrYUVEffect.cpp
index 7a18b02..0d7f218 100644
--- a/src/gpu/effects/GrYUVEffect.cpp
+++ b/src/gpu/effects/GrYUVEffect.cpp
@@ -92,6 +92,10 @@
 
     const char* name() const override { return "YUV to RGB"; }
 
+    sk_sp<GrFragmentProcessor> clone() const override {
+        return sk_sp<GrFragmentProcessor>(new YUVtoRGBEffect(*this));
+    }
+
     SkYUVColorSpace getColorSpace() const { return fColorSpace; }
 
     bool isNV12() const {
@@ -175,6 +179,27 @@
         }
     }
 
+    YUVtoRGBEffect(const YUVtoRGBEffect& that)
+            : INHERITED(kPreservesOpaqueInput_OptimizationFlag)
+            , fYTransform(that.fYTransform)
+            , fYSampler(that.fYSampler)
+            , fUTransform(that.fUTransform)
+            , fUSampler(that.fUSampler)
+            , fVTransform(that.fVTransform)
+            , fVSampler(that.fVSampler)
+            , fColorSpace(that.fColorSpace)
+            , fNV12(that.fNV12) {
+        this->initClassID<YUVtoRGBEffect>();
+        this->addCoordTransform(&fYTransform);
+        this->addTextureSampler(&fYSampler);
+        this->addCoordTransform(&fUTransform);
+        this->addTextureSampler(&fUSampler);
+        if (!fNV12) {
+            this->addCoordTransform(&fVTransform);
+            this->addTextureSampler(&fVSampler);
+        }
+    }
+
     GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
         return new GLSLProcessor;
     }
@@ -224,6 +249,14 @@
 
     const char* name() const override { return "RGBToYUV"; }
 
+    sk_sp<GrFragmentProcessor> clone() const override {
+        auto child = this->childProcessor(0).clone();
+        if (!child) {
+            return nullptr;
+        }
+        return Make(std::move(child), fColorSpace, fOutputChannels);
+    }
+
     SkYUVColorSpace getColorSpace() const { return fColorSpace; }
 
     OutputChannels outputChannels() const { return fOutputChannels; }