Simplify the boilerplate of cloning a fragment processor.

GrFragmentProcessor now provides an (explicit) copy constructor which
clones all child processors and flags from the passed-in FP. Since we no
longer have flags which propagate up to the root node of the FP tree,
all flags are now safe to copy, since a cloned FP also clones all of its
children.

Change-Id: Ia9f80e0ec540ed1056d25dbb1861a174a1d55f4b
Bug: skia:12299
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/437836
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
John Stiles 2021-08-09 15:36:59 -04:00 committed by SkCQ
parent e1428b08df
commit 307f8f525a
20 changed files with 36 additions and 89 deletions

View File

@ -42,9 +42,7 @@ private:
}
explicit DestColorTestFP(const DestColorTestFP& that)
: INHERITED(kTestFP_ClassID, that.optimizationFlags()) {
this->cloneAndRegisterAllChildProcessors(that);
}
: INHERITED(that) {}
const char* name() const override { return "DestColorTestFP"; }
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}

View File

@ -154,9 +154,7 @@ ColorTableEffect::ColorTableEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
}
ColorTableEffect::ColorTableEffect(const ColorTableEffect& that)
: INHERITED(kColorTableEffect_ClassID, that.optimizationFlags()) {
this->cloneAndRegisterAllChildProcessors(that);
}
: INHERITED(that) {}
std::unique_ptr<GrFragmentProcessor::ProgramImpl> ColorTableEffect::onMakeProgramImpl() const {
class Impl : public ProgramImpl {

View File

@ -477,13 +477,10 @@ GrDisplacementMapEffect::GrDisplacementMapEffect(SkColorChannel xChannelSelector
}
GrDisplacementMapEffect::GrDisplacementMapEffect(const GrDisplacementMapEffect& that)
: INHERITED(kGrDisplacementMapEffect_ClassID, that.optimizationFlags())
: INHERITED(that)
, fXChannelSelector(that.fXChannelSelector)
, fYChannelSelector(that.fYChannelSelector)
, fScale(that.fScale) {
this->cloneAndRegisterAllChildProcessors(that);
this->setUsesSampleCoordsDirectly();
}
, fScale(that.fScale) {}
GrDisplacementMapEffect::~GrDisplacementMapEffect() {}

View File

@ -1633,14 +1633,11 @@ GrLightingEffect::GrLightingEffect(ClassID classID,
}
GrLightingEffect::GrLightingEffect(const GrLightingEffect& that)
: INHERITED(that.classID(), that.optimizationFlags())
: INHERITED(that)
, fLight(that.fLight)
, fSurfaceScale(that.fSurfaceScale)
, fFilterMatrix(that.fFilterMatrix)
, fBoundaryMode(that.fBoundaryMode) {
this->cloneAndRegisterAllChildProcessors(that);
this->setUsesSampleCoordsDirectly();
}
, fBoundaryMode(that.fBoundaryMode) {}
bool GrLightingEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
const GrLightingEffect& s = sBase.cast<GrLightingEffect>();

View File

@ -319,13 +319,11 @@ GrMorphologyEffect::GrMorphologyEffect(std::unique_ptr<GrFragmentProcessor> inpu
}
GrMorphologyEffect::GrMorphologyEffect(const GrMorphologyEffect& that)
: INHERITED(kGrMorphologyEffect_ClassID, that.optimizationFlags())
: INHERITED(that)
, fDirection(that.fDirection)
, fRadius(that.fRadius)
, fType(that.fType)
, fUseRange(that.fUseRange) {
this->setUsesSampleCoordsDirectly();
this->cloneAndRegisterAllChildProcessors(that);
if (that.fUseRange) {
fRange[0] = that.fRange[0];
fRange[1] = that.fRange[1];

View File

@ -101,10 +101,8 @@ GrColorSpaceXformEffect::GrColorSpaceXformEffect(std::unique_ptr<GrFragmentProce
}
GrColorSpaceXformEffect::GrColorSpaceXformEffect(const GrColorSpaceXformEffect& that)
: INHERITED(kGrColorSpaceXformEffect_ClassID, that.optimizationFlags())
, fColorXform(that.fColorXform) {
this->cloneAndRegisterAllChildProcessors(that);
}
: INHERITED(that)
, fColorXform(that.fColorXform) {}
std::unique_ptr<GrFragmentProcessor> GrColorSpaceXformEffect::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new GrColorSpaceXformEffect(*this));

View File

@ -490,10 +490,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::Compose(
this->registerChild(std::move(g));
}
ComposeProcessor(const ComposeProcessor& that)
: INHERITED(kSeriesFragmentProcessor_ClassID, that.optimizationFlags()) {
this->cloneAndRegisterAllChildProcessors(that);
}
ComposeProcessor(const ComposeProcessor& that) : INHERITED(that) {}
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}

View File

@ -367,6 +367,11 @@ protected:
SkASSERT((optimizationFlags & ~kAll_OptimizationFlags) == 0);
}
explicit GrFragmentProcessor(const GrFragmentProcessor& src)
: INHERITED(src.classID()), fFlags(src.fFlags) {
this->cloneAndRegisterAllChildProcessors(src);
}
OptimizationFlags optimizationFlags() const {
return static_cast<OptimizationFlags>(kAll_OptimizationFlags & fFlags);
}

View File

@ -211,13 +211,10 @@ GrBicubicEffect::GrBicubicEffect(std::unique_ptr<GrFragmentProcessor> fp,
}
GrBicubicEffect::GrBicubicEffect(const GrBicubicEffect& that)
: INHERITED(kGrBicubicEffect_ClassID, that.optimizationFlags())
: INHERITED(that)
, fKernel(that.fKernel)
, fDirection(that.fDirection)
, fClamp(that.fClamp) {
this->setUsesSampleCoordsDirectly();
this->cloneAndRegisterAllChildProcessors(that);
}
, fClamp(that.fClamp) {}
void GrBicubicEffect::onAddToKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
uint32_t key = (static_cast<uint32_t>(fDirection) << 0) | (static_cast<uint32_t>(fClamp) << 2);

View File

@ -52,11 +52,8 @@ private:
}
BlendFragmentProcessor(const BlendFragmentProcessor& that)
: INHERITED(kBlendFragmentProcessor_ClassID, ProcessorOptimizationFlags(&that))
, fMode(that.fMode) {
this->setIsBlendFunction();
this->cloneAndRegisterAllChildProcessors(that);
}
: INHERITED(that)
, fMode(that.fMode) {}
#if GR_TEST_UTILS
SkString onDumpInfo() const override {

View File

@ -187,10 +187,9 @@ GrConvexPolyEffect::GrConvexPolyEffect(std::unique_ptr<GrFragmentProcessor> inpu
}
GrConvexPolyEffect::GrConvexPolyEffect(const GrConvexPolyEffect& that)
: INHERITED(kGrConvexPolyEffect_ClassID, that.optimizationFlags())
: INHERITED(that)
, fEdgeType(that.fEdgeType)
, fEdgeCount(that.fEdgeCount) {
this->cloneAndRegisterAllChildProcessors(that);
memcpy(fEdges, that.fEdges, 3 * that.fEdgeCount * sizeof(SkScalar));
}

View File

@ -227,13 +227,11 @@ GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
GrGaussianConvolutionFragmentProcessor::GrGaussianConvolutionFragmentProcessor(
const GrGaussianConvolutionFragmentProcessor& that)
: INHERITED(kGrGaussianConvolutionFragmentProcessor_ClassID, that.optimizationFlags())
: INHERITED(that)
, fRadius(that.fRadius)
, fDirection(that.fDirection) {
this->cloneAndRegisterAllChildProcessors(that);
memcpy(fKernel, that.fKernel, SkGpuBlurUtils::LinearKernelWidth(fRadius) * sizeof(float));
memcpy(fOffsets, that.fOffsets, SkGpuBlurUtils::LinearKernelWidth(fRadius) * sizeof(float));
this->setUsesSampleCoordsDirectly();
}
void GrGaussianConvolutionFragmentProcessor::onAddToKey(const GrShaderCaps& caps,

View File

@ -302,15 +302,12 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(std::unique_ptr<GrFragmentP
}
GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(const GrMatrixConvolutionEffect& that)
: INHERITED(kGrMatrixConvolutionEffect_ClassID, kNone_OptimizationFlags)
: INHERITED(that)
, fKernel(that.fKernel)
, fGain(that.fGain)
, fBias(that.fBias)
, fKernelOffset(that.fKernelOffset)
, fConvolveAlpha(that.fConvolveAlpha) {
this->cloneAndRegisterAllChildProcessors(that);
this->setUsesSampleCoordsDirectly();
}
, fConvolveAlpha(that.fConvolveAlpha) {}
std::unique_ptr<GrFragmentProcessor> GrMatrixConvolutionEffect::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new GrMatrixConvolutionEffect(*this));

View File

@ -70,10 +70,8 @@ bool GrMatrixEffect::onIsEqual(const GrFragmentProcessor& other) const {
}
GrMatrixEffect::GrMatrixEffect(const GrMatrixEffect& src)
: INHERITED(kGrMatrixEffect_ClassID, src.optimizationFlags())
, fMatrix(src.fMatrix) {
this->cloneAndRegisterAllChildProcessors(src);
}
: INHERITED(src)
, fMatrix(src.fMatrix) {}
std::unique_ptr<GrFragmentProcessor> GrMatrixEffect::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new GrMatrixEffect(*this));

View File

@ -28,12 +28,9 @@ GrModulateAtlasCoverageEffect::GrModulateAtlasCoverageEffect(
GrModulateAtlasCoverageEffect::GrModulateAtlasCoverageEffect(
const GrModulateAtlasCoverageEffect& that)
: GrFragmentProcessor(kTessellate_GrModulateAtlasCoverageEffect_ClassID,
kCompatibleWithCoverageAsAlpha_OptimizationFlag)
: GrFragmentProcessor(that)
, fFlags(that.fFlags)
, fBounds(that.fBounds) {
this->cloneAndRegisterAllChildProcessors(that);
}
, fBounds(that.fBounds) {}
std::unique_ptr<GrFragmentProcessor::ProgramImpl>
GrModulateAtlasCoverageEffect::onMakeProgramImpl() const {

View File

@ -104,12 +104,10 @@ CircularRRectEffect::CircularRRectEffect(std::unique_ptr<GrFragmentProcessor> in
}
CircularRRectEffect::CircularRRectEffect(const CircularRRectEffect& that)
: INHERITED(kCircularRRectEffect_ClassID, that.optimizationFlags())
: INHERITED(that)
, fRRect(that.fRRect)
, fEdgeType(that.fEdgeType)
, fCircularCornerFlags(that.fCircularCornerFlags) {
this->cloneAndRegisterAllChildProcessors(that);
}
, fCircularCornerFlags(that.fCircularCornerFlags) {}
std::unique_ptr<GrFragmentProcessor> CircularRRectEffect::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new CircularRRectEffect(*this));
@ -453,11 +451,9 @@ EllipticalRRectEffect::EllipticalRRectEffect(std::unique_ptr<GrFragmentProcessor
}
EllipticalRRectEffect::EllipticalRRectEffect(const EllipticalRRectEffect& that)
: INHERITED(kEllipticalRRectEffect_ClassID, that.optimizationFlags())
: INHERITED(that)
, fRRect(that.fRRect)
, fEdgeType(that.fEdgeType) {
this->cloneAndRegisterAllChildProcessors(that);
}
, fEdgeType(that.fEdgeType) {}
std::unique_ptr<GrFragmentProcessor> EllipticalRRectEffect::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new EllipticalRRectEffect(*this));

View File

@ -305,7 +305,7 @@ GrSkSLFP::GrSkSLFP(sk_sp<SkRuntimeEffect> effect, const char* name, OptFlags opt
}
GrSkSLFP::GrSkSLFP(const GrSkSLFP& other)
: INHERITED(kGrSkSLFP_ClassID, other.optimizationFlags())
: INHERITED(other)
, fEffect(other.fEffect)
, fName(other.fName)
, fUniformSize(other.fUniformSize)
@ -314,15 +314,6 @@ GrSkSLFP::GrSkSLFP(const GrSkSLFP& other)
other.uniformFlags(),
fEffect->uniforms().count() * sizeof(UniformFlags));
sk_careful_memcpy(this->uniformData(), other.uniformData(), fUniformSize);
if (fEffect->usesSampleCoords()) {
this->setUsesSampleCoordsDirectly();
}
if (fEffect->allowBlender()) {
this->setIsBlendFunction();
}
this->cloneAndRegisterAllChildProcessors(other);
}
void GrSkSLFP::addChild(std::unique_ptr<GrFragmentProcessor> child, bool mergeOptFlags) {

View File

@ -373,14 +373,9 @@ bool GrYUVtoRGBEffect::onIsEqual(const GrFragmentProcessor& other) const {
}
GrYUVtoRGBEffect::GrYUVtoRGBEffect(const GrYUVtoRGBEffect& src)
: GrFragmentProcessor(kGrYUVtoRGBEffect_ClassID, src.optimizationFlags())
: GrFragmentProcessor(src)
, fLocations((src.fLocations))
, fYUVColorSpace(src.fYUVColorSpace) {
this->cloneAndRegisterAllChildProcessors(src);
if (src.fSnap[0] || src.fSnap[1]) {
this->setUsesSampleCoordsDirectly();
}
std::copy_n(src.fSnap, 2, fSnap);
}

View File

@ -660,15 +660,11 @@ private:
}
GrPerlinNoise2Effect(const GrPerlinNoise2Effect& that)
: INHERITED(kGrPerlinNoise2Effect_ClassID, kNone_OptimizationFlags)
: INHERITED(that)
, fType(that.fType)
, fNumOctaves(that.fNumOctaves)
, fStitchTiles(that.fStitchTiles)
, fPaintingData(new SkPerlinNoiseShaderImpl::PaintingData(*that.fPaintingData)) {
this->cloneAndRegisterAllChildProcessors(that);
this->setUsesSampleCoordsDirectly();
}
, fPaintingData(new SkPerlinNoiseShaderImpl::PaintingData(*that.fPaintingData)) {}
GR_DECLARE_FRAGMENT_PROCESSOR_TEST

View File

@ -120,9 +120,7 @@ private:
this->registerChild(std::move(child));
}
explicit TestFP(const TestFP& that) : INHERITED(kTestFP_ClassID, that.optimizationFlags()) {
this->cloneAndRegisterAllChildProcessors(that);
}
explicit TestFP(const TestFP& that) : INHERITED(that) {}
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
class TestGLSLFP : public ProgramImpl {