aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shaders/SkLightingShader.cpp
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-07-26 14:58:11 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-26 19:20:04 +0000
commit4331e464d3d778a1357372234ff767e881e7a40d (patch)
tree92f0b054f09753e8eae036c8bb9170d59298c054 /src/shaders/SkLightingShader.cpp
parentfb7c83a946ef3977d4860e1647f3f2dc78d2cb89 (diff)
Implement GrFragmentProcessor::clone() for lighting and perlin noise classes
Change-Id: I4c6d426f170711a06d833257422092bb4b9de20c Reviewed-on: https://skia-review.googlesource.com/26945 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/shaders/SkLightingShader.cpp')
-rw-r--r--src/shaders/SkLightingShader.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/shaders/SkLightingShader.cpp b/src/shaders/SkLightingShader.cpp
index ea3de77932..96b87edd8c 100644
--- a/src/shaders/SkLightingShader.cpp
+++ b/src/shaders/SkLightingShader.cpp
@@ -119,6 +119,23 @@ public:
return sk_sp<GrFragmentProcessor>(new LightingFP(std::move(normalFP), std::move(lights)));
}
+ const char* name() const override { return "LightingFP"; }
+
+ sk_sp<GrFragmentProcessor> clone() const override {
+ // Currently we make the child clone here and pass it to the "copy" constructor. This is
+ // because clone() may fail for processor classes that haven't yet implemented it. Once all
+ // processors have an implementation the child can be cloned in a true copy constructor.
+ auto normalFPClone = this->childProcessor(0).clone();
+ if (!normalFPClone) {
+ return nullptr;
+ }
+ return sk_sp<GrFragmentProcessor>(new LightingFP(*this, std::move(normalFPClone)));
+ }
+
+ const SkTArray<SkLights::Light>& directionalLights() const { return fDirectionalLights; }
+ const SkColor3f& ambientColor() const { return fAmbientColor; }
+
+private:
class GLSLLightingFP : public GrGLSLFragmentProcessor {
public:
GLSLLightingFP() {
@@ -229,12 +246,6 @@ public:
GLSLLightingFP::GenKey(*this, caps, b);
}
- const char* name() const override { return "LightingFP"; }
-
- const SkTArray<SkLights::Light>& directionalLights() const { return fDirectionalLights; }
- const SkColor3f& ambientColor() const { return fAmbientColor; }
-
-private:
LightingFP(sk_sp<GrFragmentProcessor> normalFP, sk_sp<SkLights> lights)
: INHERITED(kPreservesOpaqueInput_OptimizationFlag) {
// fuse all ambient lights into a single one
@@ -252,6 +263,14 @@ private:
this->initClassID<LightingFP>();
}
+ LightingFP(const LightingFP& that, sk_sp<GrFragmentProcessor> normalFPClone)
+ : INHERITED(kPreservesOpaqueInput_OptimizationFlag)
+ , fDirectionalLights(that.fDirectionalLights)
+ , fAmbientColor(that.fAmbientColor) {
+ this->registerChildProcessor(std::move(normalFPClone));
+ this->initClassID<LightingFP>();
+ }
+
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLLightingFP; }
bool onIsEqual(const GrFragmentProcessor& proc) const override {