aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
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
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')
-rw-r--r--src/shaders/SkLightingShader.cpp31
-rw-r--r--src/shaders/SkPerlinNoiseShader.cpp53
2 files changed, 78 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 {
diff --git a/src/shaders/SkPerlinNoiseShader.cpp b/src/shaders/SkPerlinNoiseShader.cpp
index d5b83930b5..d8c6047ca5 100644
--- a/src/shaders/SkPerlinNoiseShader.cpp
+++ b/src/shaders/SkPerlinNoiseShader.cpp
@@ -136,6 +136,22 @@ public:
#endif
}
+ #if SK_SUPPORT_GPU
+ PaintingData(const PaintingData& that)
+ : fSeed(that.fSeed)
+ , fTileSize(that.fTileSize)
+ , fBaseFrequency(that.fBaseFrequency)
+ , fStitchDataInit(that.fStitchDataInit)
+ , fPermutationsBitmap(that.fPermutationsBitmap)
+ , fNoiseBitmap(that.fNoiseBitmap)
+ , fImprovedPermutationsBitmap(that.fImprovedPermutationsBitmap)
+ , fGradientBitmap(that.fGradientBitmap) {
+ memcpy(fLatticeSelector, that.fLatticeSelector, sizeof(fLatticeSelector));
+ memcpy(fNoise, that.fNoise, sizeof(fNoise));
+ memcpy(fGradient, that.fGradient, sizeof(fGradient));
+ }
+ #endif
+
int fSeed;
uint8_t fLatticeSelector[kBlockSize];
uint16_t fNoise[4][kBlockSize][2];
@@ -691,6 +707,10 @@ public:
const char* name() const override { return "PerlinNoise"; }
+ sk_sp<GrFragmentProcessor> clone() const override {
+ return sk_sp<GrFragmentProcessor>(new GrPerlinNoise2Effect(*this));
+ }
+
const SkPerlinNoiseShaderImpl::StitchData& stitchData() const { return fPaintingData->fStitchDataInit; }
SkPerlinNoiseShaderImpl::Type type() const { return fType; }
@@ -737,6 +757,21 @@ private:
this->addCoordTransform(&fCoordTransform);
}
+ GrPerlinNoise2Effect(const GrPerlinNoise2Effect& that)
+ : INHERITED(kNone_OptimizationFlags)
+ , fType(that.fType)
+ , fCoordTransform(that.fCoordTransform)
+ , fNumOctaves(that.fNumOctaves)
+ , fStitchTiles(that.fStitchTiles)
+ , fPermutationsSampler(that.fPermutationsSampler)
+ , fNoiseSampler(that.fNoiseSampler)
+ , fPaintingData(new SkPerlinNoiseShaderImpl::PaintingData(*that.fPaintingData)) {
+ this->initClassID<GrPerlinNoise2Effect>();
+ this->addTextureSampler(&fPermutationsSampler);
+ this->addTextureSampler(&fNoiseSampler);
+ this->addCoordTransform(&fCoordTransform);
+ }
+
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
SkPerlinNoiseShaderImpl::Type fType;
@@ -1106,6 +1141,10 @@ public:
const char* name() const override { return "ImprovedPerlinNoise"; }
+ sk_sp<GrFragmentProcessor> clone() const override {
+ return sk_sp<GrFragmentProcessor>(new GrImprovedPerlinNoiseEffect(*this));
+ }
+
const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency; }
SkScalar z() const { return fZ; }
int octaves() const { return fOctaves; }
@@ -1144,6 +1183,20 @@ private:
this->addCoordTransform(&fCoordTransform);
}
+ GrImprovedPerlinNoiseEffect(const GrImprovedPerlinNoiseEffect& that)
+ : INHERITED(kNone_OptimizationFlags)
+ , fCoordTransform(that.fCoordTransform)
+ , fOctaves(that.fOctaves)
+ , fZ(that.fZ)
+ , fPermutationsSampler(that.fPermutationsSampler)
+ , fGradientSampler(that.fGradientSampler)
+ , fPaintingData(new SkPerlinNoiseShaderImpl::PaintingData(*that.fPaintingData)) {
+ this->initClassID<GrImprovedPerlinNoiseEffect>();
+ this->addTextureSampler(&fPermutationsSampler);
+ this->addTextureSampler(&fGradientSampler);
+ this->addCoordTransform(&fCoordTransform);
+ }
+
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
GrCoordTransform fCoordTransform;