ComposeShader GPU implementations

Bug: skia:
Change-Id: I007b46ead1900a8f5cce82dec33b6d662fc63d8e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206918
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/gpu/effects/GrComposeLerpEffect.cpp b/src/gpu/effects/GrComposeLerpEffect.cpp
new file mode 100644
index 0000000..a768b5c
--- /dev/null
+++ b/src/gpu/effects/GrComposeLerpEffect.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2019 Google LLC.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**************************************************************************************************
+ *** This file was autogenerated from GrComposeLerpEffect.fp; do not modify.
+ **************************************************************************************************/
+#include "GrComposeLerpEffect.h"
+#include "glsl/GrGLSLFragmentProcessor.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+#include "GrTexture.h"
+#include "SkSLCPP.h"
+#include "SkSLUtil.h"
+class GrGLSLComposeLerpEffect : public GrGLSLFragmentProcessor {
+public:
+    GrGLSLComposeLerpEffect() {}
+    void emitCode(EmitArgs& args) override {
+        GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
+        const GrComposeLerpEffect& _outer = args.fFp.cast<GrComposeLerpEffect>();
+        (void)_outer;
+        auto weight = _outer.weight;
+        (void)weight;
+        weightVar =
+                args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kFloat_GrSLType, "weight");
+        SkString _child0("_child0");
+        if (_outer.child1_index >= 0) {
+            this->emitChild(_outer.child1_index, &_child0, args);
+        } else {
+            fragBuilder->codeAppendf("half4 %s;", _child0.c_str());
+        }
+        SkString _child1("_child1");
+        if (_outer.child2_index >= 0) {
+            this->emitChild(_outer.child2_index, &_child1, args);
+        } else {
+            fragBuilder->codeAppendf("half4 %s;", _child1.c_str());
+        }
+        fragBuilder->codeAppendf("%s = mix(%s ? %s : %s, %s ? %s : %s, half(%s));\n",
+                                 args.fOutputColor, _outer.child1_index >= 0 ? "true" : "false",
+                                 _child0.c_str(), args.fInputColor,
+                                 _outer.child2_index >= 0 ? "true" : "false", _child1.c_str(),
+                                 args.fInputColor, args.fUniformHandler->getUniformCStr(weightVar));
+    }
+
+private:
+    void onSetData(const GrGLSLProgramDataManager& pdman,
+                   const GrFragmentProcessor& _proc) override {
+        const GrComposeLerpEffect& _outer = _proc.cast<GrComposeLerpEffect>();
+        { pdman.set1f(weightVar, (_outer.weight)); }
+    }
+    UniformHandle weightVar;
+};
+GrGLSLFragmentProcessor* GrComposeLerpEffect::onCreateGLSLInstance() const {
+    return new GrGLSLComposeLerpEffect();
+}
+void GrComposeLerpEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
+                                                GrProcessorKeyBuilder* b) const {}
+bool GrComposeLerpEffect::onIsEqual(const GrFragmentProcessor& other) const {
+    const GrComposeLerpEffect& that = other.cast<GrComposeLerpEffect>();
+    (void)that;
+    if (weight != that.weight) return false;
+    return true;
+}
+GrComposeLerpEffect::GrComposeLerpEffect(const GrComposeLerpEffect& src)
+        : INHERITED(kGrComposeLerpEffect_ClassID, src.optimizationFlags())
+        , child1_index(src.child1_index)
+        , child2_index(src.child2_index)
+        , weight(src.weight) {
+    if (child1_index >= 0) {
+        this->registerChildProcessor(src.childProcessor(child1_index).clone());
+    }
+    if (child2_index >= 0) {
+        this->registerChildProcessor(src.childProcessor(child2_index).clone());
+    }
+}
+std::unique_ptr<GrFragmentProcessor> GrComposeLerpEffect::clone() const {
+    return std::unique_ptr<GrFragmentProcessor>(new GrComposeLerpEffect(*this));
+}
diff --git a/src/gpu/effects/GrComposeLerpEffect.fp b/src/gpu/effects/GrComposeLerpEffect.fp
new file mode 100644
index 0000000..4f55d21
--- /dev/null
+++ b/src/gpu/effects/GrComposeLerpEffect.fp
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2019 Google LLC.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+in fragmentProcessor? child1;
+in fragmentProcessor? child2;
+in uniform float weight;
+
+void main() {
+    sk_OutColor = mix(child1 != null ? process(child1) : sk_InColor,
+                      child2 != null ? process(child2) : sk_InColor,
+                      half(weight));
+}
diff --git a/src/gpu/effects/GrComposeLerpEffect.h b/src/gpu/effects/GrComposeLerpEffect.h
new file mode 100644
index 0000000..823d44d
--- /dev/null
+++ b/src/gpu/effects/GrComposeLerpEffect.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2019 Google LLC.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**************************************************************************************************
+ *** This file was autogenerated from GrComposeLerpEffect.fp; do not modify.
+ **************************************************************************************************/
+#ifndef GrComposeLerpEffect_DEFINED
+#define GrComposeLerpEffect_DEFINED
+#include "SkTypes.h"
+#include "GrFragmentProcessor.h"
+#include "GrCoordTransform.h"
+class GrComposeLerpEffect : public GrFragmentProcessor {
+public:
+    static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child1,
+                                                     std::unique_ptr<GrFragmentProcessor> child2,
+                                                     float weight) {
+        return std::unique_ptr<GrFragmentProcessor>(
+                new GrComposeLerpEffect(std::move(child1), std::move(child2), weight));
+    }
+    GrComposeLerpEffect(const GrComposeLerpEffect& src);
+    std::unique_ptr<GrFragmentProcessor> clone() const override;
+    const char* name() const override { return "ComposeLerpEffect"; }
+    int child1_index = -1;
+    int child2_index = -1;
+    float weight;
+
+private:
+    GrComposeLerpEffect(std::unique_ptr<GrFragmentProcessor> child1,
+                        std::unique_ptr<GrFragmentProcessor> child2, float weight)
+            : INHERITED(kGrComposeLerpEffect_ClassID, kNone_OptimizationFlags), weight(weight) {
+        if (child1) {
+            child1_index = this->numChildProcessors();
+            this->registerChildProcessor(std::move(child1));
+        }
+        if (child2) {
+            child2_index = this->numChildProcessors();
+            this->registerChildProcessor(std::move(child2));
+        }
+    }
+    GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
+    void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
+    bool onIsEqual(const GrFragmentProcessor&) const override;
+    GR_DECLARE_FRAGMENT_PROCESSOR_TEST
+    typedef GrFragmentProcessor INHERITED;
+};
+#endif
diff --git a/src/gpu/effects/GrComposeLerpRedEffect.cpp b/src/gpu/effects/GrComposeLerpRedEffect.cpp
new file mode 100644
index 0000000..fceeff1
--- /dev/null
+++ b/src/gpu/effects/GrComposeLerpRedEffect.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2019 Google LLC.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**************************************************************************************************
+ *** This file was autogenerated from GrComposeLerpRedEffect.fp; do not modify.
+ **************************************************************************************************/
+#include "GrComposeLerpRedEffect.h"
+#include "glsl/GrGLSLFragmentProcessor.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+#include "GrTexture.h"
+#include "SkSLCPP.h"
+#include "SkSLUtil.h"
+class GrGLSLComposeLerpRedEffect : public GrGLSLFragmentProcessor {
+public:
+    GrGLSLComposeLerpRedEffect() {}
+    void emitCode(EmitArgs& args) override {
+        GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
+        const GrComposeLerpRedEffect& _outer = args.fFp.cast<GrComposeLerpRedEffect>();
+        (void)_outer;
+        SkString _child0("_child0");
+        if (_outer.child1_index >= 0) {
+            this->emitChild(_outer.child1_index, &_child0, args);
+        } else {
+            fragBuilder->codeAppendf("half4 %s;", _child0.c_str());
+        }
+        SkString _child1("_child1");
+        if (_outer.child2_index >= 0) {
+            this->emitChild(_outer.child2_index, &_child1, args);
+        } else {
+            fragBuilder->codeAppendf("half4 %s;", _child1.c_str());
+        }
+        SkString _child2("_child2");
+        this->emitChild(_outer.lerp_index, &_child2, args);
+        fragBuilder->codeAppendf(
+                "%s = mix(%s ? %s : %s, %s ? %s : %s, %s.x);\n%s = half4(1.0, 0.0, 1.0, 1.0);\n",
+                args.fOutputColor, _outer.child1_index >= 0 ? "true" : "false", _child0.c_str(),
+                args.fInputColor, _outer.child2_index >= 0 ? "true" : "false", _child1.c_str(),
+                args.fInputColor, _child2.c_str(), args.fOutputColor);
+    }
+
+private:
+    void onSetData(const GrGLSLProgramDataManager& pdman,
+                   const GrFragmentProcessor& _proc) override {}
+};
+GrGLSLFragmentProcessor* GrComposeLerpRedEffect::onCreateGLSLInstance() const {
+    return new GrGLSLComposeLerpRedEffect();
+}
+void GrComposeLerpRedEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
+                                                   GrProcessorKeyBuilder* b) const {}
+bool GrComposeLerpRedEffect::onIsEqual(const GrFragmentProcessor& other) const {
+    const GrComposeLerpRedEffect& that = other.cast<GrComposeLerpRedEffect>();
+    (void)that;
+    return true;
+}
+GrComposeLerpRedEffect::GrComposeLerpRedEffect(const GrComposeLerpRedEffect& src)
+        : INHERITED(kGrComposeLerpRedEffect_ClassID, src.optimizationFlags())
+        , child1_index(src.child1_index)
+        , child2_index(src.child2_index)
+        , lerp_index(src.lerp_index) {
+    if (child1_index >= 0) {
+        this->registerChildProcessor(src.childProcessor(child1_index).clone());
+    }
+    if (child2_index >= 0) {
+        this->registerChildProcessor(src.childProcessor(child2_index).clone());
+    }
+    this->registerChildProcessor(src.childProcessor(lerp_index).clone());
+}
+std::unique_ptr<GrFragmentProcessor> GrComposeLerpRedEffect::clone() const {
+    return std::unique_ptr<GrFragmentProcessor>(new GrComposeLerpRedEffect(*this));
+}
diff --git a/src/gpu/effects/GrComposeLerpRedEffect.fp b/src/gpu/effects/GrComposeLerpRedEffect.fp
new file mode 100644
index 0000000..6179c93
--- /dev/null
+++ b/src/gpu/effects/GrComposeLerpRedEffect.fp
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2019 Google LLC.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+in fragmentProcessor? child1;
+in fragmentProcessor? child2;
+in fragmentProcessor lerp;
+
+void main() {
+    sk_OutColor = mix(child1 != null ? process(child1) : sk_InColor,
+                      child2 != null ? process(child2) : sk_InColor,
+                      process(lerp).r);
+}
diff --git a/src/gpu/effects/GrComposeLerpRedEffect.h b/src/gpu/effects/GrComposeLerpRedEffect.h
new file mode 100644
index 0000000..f109c8c
--- /dev/null
+++ b/src/gpu/effects/GrComposeLerpRedEffect.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2019 Google LLC.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**************************************************************************************************
+ *** This file was autogenerated from GrComposeLerpRedEffect.fp; do not modify.
+ **************************************************************************************************/
+#ifndef GrComposeLerpRedEffect_DEFINED
+#define GrComposeLerpRedEffect_DEFINED
+#include "SkTypes.h"
+#include "GrFragmentProcessor.h"
+#include "GrCoordTransform.h"
+class GrComposeLerpRedEffect : public GrFragmentProcessor {
+public:
+    static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child1,
+                                                     std::unique_ptr<GrFragmentProcessor> child2,
+                                                     std::unique_ptr<GrFragmentProcessor> lerp) {
+        return std::unique_ptr<GrFragmentProcessor>(
+                new GrComposeLerpRedEffect(std::move(child1), std::move(child2), std::move(lerp)));
+    }
+    GrComposeLerpRedEffect(const GrComposeLerpRedEffect& src);
+    std::unique_ptr<GrFragmentProcessor> clone() const override;
+    const char* name() const override { return "ComposeLerpRedEffect"; }
+    int child1_index = -1;
+    int child2_index = -1;
+    int lerp_index = -1;
+
+private:
+    GrComposeLerpRedEffect(std::unique_ptr<GrFragmentProcessor> child1,
+                           std::unique_ptr<GrFragmentProcessor> child2,
+                           std::unique_ptr<GrFragmentProcessor> lerp)
+            : INHERITED(kGrComposeLerpRedEffect_ClassID, kNone_OptimizationFlags) {
+        if (child1) {
+            child1_index = this->numChildProcessors();
+            this->registerChildProcessor(std::move(child1));
+        }
+        if (child2) {
+            child2_index = this->numChildProcessors();
+            this->registerChildProcessor(std::move(child2));
+        }
+        SkASSERT(lerp);
+        lerp_index = this->numChildProcessors();
+        this->registerChildProcessor(std::move(lerp));
+    }
+    GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
+    void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
+    bool onIsEqual(const GrFragmentProcessor&) const override;
+    GR_DECLARE_FRAGMENT_PROCESSOR_TEST
+    typedef GrFragmentProcessor INHERITED;
+};
+#endif