Made isEqual in GrFragmentProcessor recursive

Added comment about how computeInvariantOutput() is non-recursive in GrFragmentProcessor

Made isEqual() recursive in GrFragmentProcessor

BUG=skia:4182

Review URL: https://codereview.chromium.org/1287343005
This commit is contained in:
wangyix 2015-08-18 07:39:33 -07:00 committed by Commit bot
parent cd47b71ac6
commit 54017d7e5b
2 changed files with 31 additions and 14 deletions

View File

@ -74,20 +74,7 @@ public:
A return value of true from isEqual() should not be used to test whether the processor would
generate the same shader code. To test for identical code generation use getGLProcessorKey*/
bool isEqual(const GrFragmentProcessor& that, bool ignoreCoordTransforms) const {
if (this->classID() != that.classID() ||
!this->hasSameTextureAccesses(that)) {
return false;
}
if (ignoreCoordTransforms) {
if (this->numTransforms() != that.numTransforms()) {
return false;
}
} else if (!this->hasSameTransforms(that)) {
return false;
}
return this->onIsEqual(that);
}
bool isEqual(const GrFragmentProcessor& that, bool ignoreCoordTransforms) const;
/**
* This function is used to perform optimizations. When called the invarientOuput param
@ -131,6 +118,9 @@ protected:
/**
* Subclass implements this to support getConstantColorComponents(...).
*
* Note: it's up to the subclass implementation to do any recursive call to compute the child
* procs' output invariants; computeInvariantOutput will not be recursive.
*/
virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const = 0;

View File

@ -129,6 +129,33 @@ bool GrProcessor::hasSameTextureAccesses(const GrProcessor& that) const {
///////////////////////////////////////////////////////////////////////////////////////////////////
bool GrFragmentProcessor::isEqual(const GrFragmentProcessor& that,
bool ignoreCoordTransforms) const {
if (this->classID() != that.classID() ||
!this->hasSameTextureAccesses(that)) {
return false;
}
if (ignoreCoordTransforms) {
if (this->numTransforms() != that.numTransforms()) {
return false;
}
} else if (!this->hasSameTransforms(that)) {
return false;
}
if (!this->onIsEqual(that)) {
return false;
}
if (this->numChildProcessors() != that.numChildProcessors()) {
return false;
}
for (int i = 0; i < this->numChildProcessors(); ++i) {
if (!this->childProcessor(i).isEqual(that.childProcessor(i), ignoreCoordTransforms)) {
return false;
}
}
return true;
}
void GrFragmentProcessor::addCoordTransform(const GrCoordTransform* transform) {
fCoordTransforms.push_back(transform);
fUsesLocalCoords = fUsesLocalCoords || transform->sourceCoords() == kLocal_GrCoordSet;