Extend texture release on GrDrawState to also handle custom stages.
Add asserts to GrContext::setPaint() to make sure we're keeping things
cleaned up.
Remove double-call of setPaint() during text context initialization.
http://codereview.appspot.com/6324046/
git-svn-id: http://skia.googlecode.com/svn/trunk@4313 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 5feccb5..acfca8c 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -74,16 +74,18 @@
}
virtual ~GrDrawState() {
- this->releaseTextures();
+ this->disableStages();
GrSafeSetNull(fRenderTarget);
}
/**
- * Resets to the default state. Sampler states will not be modified.
+ * Resets to the default state.
+ * Sampler states *will* be modified: textures or CustomStage objects
+ * will be released.
*/
void reset() {
- this->releaseTextures();
+ this->disableStages();
GrSafeSetNull(fRenderTarget);
// make sure any pad is zero for memcmp
@@ -213,21 +215,32 @@
return fTextures[stage];
}
+ bool stagesDisabled() {
+ for (int i = 0; i < kNumStages; ++i) {
+ if (NULL != fTextures[i] ||
+ NULL != fSamplerStates[i].getCustomStage()) {
+ return false;
+ }
+ return true;
+ }
+ }
/**
- * Release all the textures referred to by this draw state
+ * Release all the textures and custom stages referred to by this
+ * draw state.
*/
- void releaseTextures() {
+ void disableStages() {
for (int i = 0; i < kNumStages; ++i) {
GrSafeSetNull(fTextures[i]);
+ fSamplerStates[i].setCustomStage(NULL);
}
}
- class AutoTextureRelease : public ::GrNoncopyable {
+ class AutoStageDisable : public ::GrNoncopyable {
public:
- AutoTextureRelease(GrDrawState* ds) : fDrawState(ds) {}
- ~AutoTextureRelease() {
+ AutoStageDisable(GrDrawState* ds) : fDrawState(ds) {}
+ ~AutoStageDisable() {
if (NULL != fDrawState) {
- fDrawState->releaseTextures();
+ fDrawState->disableStages();
}
}
private: