Implement clone for 6 additional GrFragmentProcessor subclasses.

GrMagnifierEffect
GrMorphologyEffect
GrBicubicEffect
GrGaussianConvolutionFragmentProcessor
GrMatrixConvolutionEffect
GrTextureDomainEffect

Bug: skia:
Change-Id: I69721b9b95346b365723e5ee21dff2dee8884466
Reviewed-on: https://skia-review.googlesource.com/27900
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Brian Salomon 2017-07-28 07:34:05 -04:00 committed by Skia Commit-Bot
parent 71603cca8e
commit 3f6f965a5a
10 changed files with 113 additions and 6 deletions

View File

@ -68,6 +68,10 @@ public:
const char* name() const override { return "Magnifier"; }
sk_sp<GrFragmentProcessor> clone() const override {
return sk_sp<GrFragmentProcessor>(new GrMagnifierEffect(*this));
}
SkString dumpInfo() const override {
SkString str;
str.appendf("Texture: %d", fTextureSampler.proxy()->uniqueID().asUInt());
@ -112,6 +116,22 @@ private:
this->addTextureSampler(&fTextureSampler);
}
explicit GrMagnifierEffect(const GrMagnifierEffect& that)
: INHERITED(that.optimizationFlags())
, fCoordTransform(that.fCoordTransform)
, fTextureSampler(that.fTextureSampler)
, fColorSpaceXform(that.fColorSpaceXform)
, fBounds(that.fBounds)
, fSrcRect(that.fSrcRect)
, fXInvZoom(that.fXInvZoom)
, fYInvZoom(that.fYInvZoom)
, fXInvInset(that.fXInvInset)
, fYInvInset(that.fYInvInset) {
this->initClassID<GrMagnifierEffect>();
this->addCoordTransform(&fCoordTransform);
this->addTextureSampler(&fTextureSampler);
}
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -179,6 +179,7 @@ private:
bool onIsEqual(const GrFragmentProcessor&) const override;
GrMorphologyEffect(sk_sp<GrTextureProxy>, Direction, int radius, Type, const float range[2]);
explicit GrMorphologyEffect(const GrMorphologyEffect&);
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
@ -339,6 +340,23 @@ GrMorphologyEffect::GrMorphologyEffect(sk_sp<GrTextureProxy> proxy,
}
}
GrMorphologyEffect::GrMorphologyEffect(const GrMorphologyEffect& that)
: INHERITED(that.optimizationFlags())
, fCoordTransform(that.fCoordTransform)
, fTextureSampler(that.fTextureSampler)
, fDirection(that.fDirection)
, fRadius(that.fRadius)
, fType(that.fType)
, fUseRange(that.fUseRange) {
this->initClassID<GrMorphologyEffect>();
this->addCoordTransform(&fCoordTransform);
this->addTextureSampler(&fTextureSampler);
if (that.fUseRange) {
fRange[0] = that.fRange[0];
fRange[1] = that.fRange[1];
}
}
void GrMorphologyEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
GrGLMorphologyEffect::GenKey(*this, caps, b);

View File

@ -160,7 +160,15 @@ GrBicubicEffect::GrBicubicEffect(sk_sp<GrTextureProxy> proxy,
this->addTextureSampler(&fTextureSampler);
}
GrBicubicEffect::~GrBicubicEffect() {
GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that)
: INHERITED(that.optimizationFlags())
, fCoordTransform(that.fCoordTransform)
, fDomain(that.fDomain)
, fTextureSampler(that.fTextureSampler)
, fColorSpaceXform(that.fColorSpaceXform) {
this->initClassID<GrBicubicEffect>();
this->addCoordTransform(&fCoordTransform);
this->addTextureSampler(&fTextureSampler);
}
void GrBicubicEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,

View File

@ -19,10 +19,13 @@ public:
kFilterTexelPad = 2, // Given a src rect in texels to be filtered, this number of
// surrounding texels are needed by the kernel in x and y.
};
~GrBicubicEffect() override;
const char* name() const override { return "Bicubic"; }
sk_sp<GrFragmentProcessor> clone() const override {
return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(*this));
}
const GrTextureDomain& domain() const { return fDomain; }
const GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
@ -66,6 +69,7 @@ private:
const SkMatrix &matrix, const SkShader::TileMode tileModes[2]);
GrBicubicEffect(sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
const SkMatrix &matrix, const SkRect& domain);
explicit GrBicubicEffect(const GrBicubicEffect&);
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

View File

@ -217,7 +217,20 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
memcpy(fBounds, bounds, sizeof(fBounds));
}
GrGaussianConvolutionFragmentProcessor::~GrGaussianConvolutionFragmentProcessor() {}
GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
const GrGaussianConvolutionFragmentProcessor& that)
: INHERITED(that.optimizationFlags())
, fCoordTransform(that.fCoordTransform)
, fTextureSampler(that.fTextureSampler)
, fRadius(that.fRadius)
, fDirection(that.fDirection)
, fMode(that.fMode) {
this->initClassID<GrGaussianConvolutionFragmentProcessor>();
this->addCoordTransform(&fCoordTransform);
this->addTextureSampler(&fTextureSampler);
memcpy(fKernel, that.fKernel, that.width() * sizeof(float));
memcpy(fBounds, that.fBounds, sizeof(fBounds));
}
void GrGaussianConvolutionFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {

View File

@ -32,8 +32,6 @@ public:
std::move(proxy), dir, halfWidth, gaussianSigma, mode, bounds));
}
~GrGaussianConvolutionFragmentProcessor() override;
const float* kernel() const { return fKernel; }
const int* bounds() const { return fBounds; }
@ -46,6 +44,10 @@ public:
const char* name() const override { return "GaussianConvolution"; }
sk_sp<GrFragmentProcessor> clone() const override {
return sk_sp<GrFragmentProcessor>(new GrGaussianConvolutionFragmentProcessor(*this));
}
// This was decided based on the min allowed value for the max texture
// samples per fragment program run in DX9SM2 (32). A sigma param of 4.0
// on a blur filter gives a kernel width of 25 while a sigma of 5.0
@ -61,6 +63,8 @@ private:
int halfWidth, float gaussianSigma,
GrTextureDomain::Mode mode, int bounds[2]);
explicit GrGaussianConvolutionFragmentProcessor(const GrGaussianConvolutionFragmentProcessor&);
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -178,6 +178,26 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy
fKernelOffset[1] = static_cast<float>(kernelOffset.y());
}
GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(const GrMatrixConvolutionEffect& that)
: INHERITED(kNone_OptimizationFlags)
, fCoordTransform(that.fCoordTransform)
, fDomain(that.fDomain)
, fTextureSampler(that.fTextureSampler)
, fKernelSize(that.fKernelSize)
, fGain(that.fGain)
, fBias(that.fBias)
, fConvolveAlpha(that.fConvolveAlpha) {
this->initClassID<GrMatrixConvolutionEffect>();
this->addCoordTransform(&fCoordTransform);
this->addTextureSampler(&fTextureSampler);
memcpy(fKernel, that.fKernel, sizeof(float) * fKernelSize.width() * fKernelSize.height());
memcpy(fKernelOffset, that.fKernelOffset, sizeof(fKernelOffset));
}
sk_sp<GrFragmentProcessor> GrMatrixConvolutionEffect::clone() const {
return sk_sp<GrFragmentProcessor>(new GrMatrixConvolutionEffect(*this));
}
void GrMatrixConvolutionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
GrGLMatrixConvolutionEffect::GenKey(*this, caps, b);
@ -227,7 +247,6 @@ static void fill_in_2D_gaussian_kernel(float* kernel, int width, int height,
}
}
// Static function to create a 2D convolution
sk_sp<GrFragmentProcessor> GrMatrixConvolutionEffect::MakeGaussian(
sk_sp<GrTextureProxy> proxy,

View File

@ -52,6 +52,8 @@ public:
const char* name() const override { return "MatrixConvolution"; }
sk_sp<GrFragmentProcessor> clone() const override;
private:
GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy,
const SkIRect& bounds,
@ -63,6 +65,8 @@ private:
GrTextureDomain::Mode tileMode,
bool convolveAlpha);
GrMatrixConvolutionEffect(const GrMatrixConvolutionEffect&);
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

View File

@ -242,6 +242,17 @@ GrTextureDomainEffect::GrTextureDomainEffect(sk_sp<GrTextureProxy> proxy,
this->addTextureSampler(&fTextureSampler);
}
GrTextureDomainEffect::GrTextureDomainEffect(const GrTextureDomainEffect& that)
: INHERITED(that.optimizationFlags())
, fCoordTransform(that.fCoordTransform)
, fTextureDomain(that.fTextureDomain)
, fTextureSampler(that.fTextureSampler)
, fColorSpaceXform(that.fColorSpaceXform) {
this->initClassID<GrTextureDomainEffect>();
this->addCoordTransform(&fCoordTransform);
this->addTextureSampler(&fTextureSampler);
}
void GrTextureDomainEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32(GrTextureDomain::GLDomain::DomainKey(fTextureDomain));

View File

@ -162,6 +162,10 @@ public:
const char* name() const override { return "TextureDomain"; }
sk_sp<GrFragmentProcessor> clone() const override {
return sk_sp<GrFragmentProcessor>(new GrTextureDomainEffect(*this));
}
SkString dumpInfo() const override {
SkString str;
str.appendf("Domain: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]",
@ -184,6 +188,8 @@ private:
GrTextureDomain::Mode,
GrSamplerParams::FilterMode);
explicit GrTextureDomainEffect(const GrTextureDomainEffect&);
static OptimizationFlags OptFlags(GrPixelConfig config, GrTextureDomain::Mode mode);
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;