Make GrSamplerState::operator==() use GrCustomStage::isEquivalent() rather

than just bit-compare all fields.



git-svn-id: http://skia.googlecode.com/svn/trunk@3805 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
tomhudson@google.com 2012-05-01 12:48:07 +00:00
parent 7c2578d392
commit b88bbd2a53
2 changed files with 23 additions and 5 deletions

View File

@ -30,7 +30,13 @@ public:
/** This pointer, besides creating back-end-specific helper
objects, is used for run-time-type-identification. Every
subclass must return a consistent unique value for it. */
virtual GrGLProgramStageFactory* getGLFactory() = 0;
virtual GrGLProgramStageFactory* getGLFactory() const = 0;
/** Returns true if the other custom stage will generate
a compatible/equivalent shader. Must only be called if
the two are already known to be of the same type (i.e.
they return the same value from getGLFactory()). */
virtual bool isEquivalent(const GrCustomStage *) const = 0;
};

View File

@ -111,10 +111,10 @@ public:
* unfiltered, and use identity matrix.
*/
GrSamplerState()
: fCustomStage (NULL)
, fRadial2CenterX1()
: fRadial2CenterX1()
, fRadial2Radius0()
, fRadial2PosRoot() {
, fRadial2PosRoot()
, fCustomStage (NULL) {
this->reset();
}
@ -123,7 +123,19 @@ public:
}
bool operator ==(const GrSamplerState& s) const {
return !memcmp(this, &s, sizeof(GrSamplerState));
/* We must be bit-identical as far as the CustomStage;
there may be multiple CustomStages that will produce
the same shader code and so are equivalent.
Can't take the address of fWrapX because it's :8 */
int bitwiseRegion = (intptr_t) &fCustomStage - (intptr_t) this;
GrAssert(sizeof(GrSamplerState) ==
bitwiseRegion + sizeof(fCustomStage));
return !memcmp(this, &s, bitwiseRegion) &&
((fCustomStage == s.fCustomStage) ||
(fCustomStage && s.fCustomStage &&
(fCustomStage->getGLFactory() ==
s.fCustomStage->getGLFactory()) &&
fCustomStage->isEquivalent(s.fCustomStage)));
}
bool operator !=(const GrSamplerState& s) const { return !(*this == s); }