diff options
author | tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-22 20:10:50 +0000 |
---|---|---|
committer | tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-22 20:10:50 +0000 |
commit | 7d6afdd795eb4c7ce8f5a327117cfdba5f957ddb (patch) | |
tree | 5f597a3898ba6623ee6921211768178ed119b6df | |
parent | 6cf5303b93e2afbabefc8123b6e2efac8e27a603 (diff) |
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
-rw-r--r-- | src/gpu/GrBatchedTextContext.cpp | 8 | ||||
-rw-r--r-- | src/gpu/GrBatchedTextContext.h | 2 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 13 | ||||
-rw-r--r-- | src/gpu/GrDefaultTextContext.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrDrawState.h | 31 |
5 files changed, 38 insertions, 18 deletions
diff --git a/src/gpu/GrBatchedTextContext.cpp b/src/gpu/GrBatchedTextContext.cpp index 9de2badb17..666d894e04 100644 --- a/src/gpu/GrBatchedTextContext.cpp +++ b/src/gpu/GrBatchedTextContext.cpp @@ -26,7 +26,7 @@ void GrBatchedTextContext::init(GrContext* context, const GrMatrix* extMatrix) { this->INHERITED::init(context, grPaint, extMatrix); fGrPaint = grPaint; - fDrawTarget = fContext->getTextTarget(fGrPaint); + fDrawTarget = NULL; fMaxVertices = 0; fCurrTexture = NULL; @@ -34,6 +34,10 @@ void GrBatchedTextContext::init(GrContext* context, } void GrBatchedTextContext::finish() { + GrAssert(fDrawTarget); + if (fDrawTarget) { + fDrawTarget->drawState()->disableStages(); + } fDrawTarget = NULL; this->INHERITED::finish(); @@ -41,6 +45,7 @@ void GrBatchedTextContext::finish() { void GrBatchedTextContext::reset() { GrAssert(this->isValid()); + GrAssert(fDrawTarget); fDrawTarget->resetVertexSource(); fMaxVertices = 0; fCurrVertex = 0; @@ -61,6 +66,7 @@ void GrBatchedTextContext::prepareForGlyph(GrTexture* texture) { void GrBatchedTextContext::setupVertexBuff(void** vertexBuff, GrVertexLayout vertexLayout) { GrAssert(this->isValid()); + GrAssert(fDrawTarget); if (NULL == *vertexBuff) { // If we need to reserve vertices allow the draw target to suggest // a number of verts to reserve and whether to perform a flush. diff --git a/src/gpu/GrBatchedTextContext.h b/src/gpu/GrBatchedTextContext.h index c0a136ba26..e1f4736631 100644 --- a/src/gpu/GrBatchedTextContext.h +++ b/src/gpu/GrBatchedTextContext.h @@ -38,6 +38,8 @@ protected: }; GrPaint fGrPaint; + + /** fDrawTarget is not set by init() - MUST be set by subclasses! */ GrDrawTarget* fDrawTarget; int32_t fMaxVertices; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index c426405039..61f37ff2ad 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -784,7 +784,7 @@ void GrContext::drawRect(const GrPaint& paint, SK_TRACE_EVENT0("GrContext::drawRect"); GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory); - GrDrawState::AutoTextureRelease atr(fDrawState); + GrDrawState::AutoStageDisable atr(fDrawState); int stageMask = paint.getActiveStageMask(); GrRect devRect = rect; @@ -904,7 +904,7 @@ void GrContext::drawRectToRect(const GrPaint& paint, #if GR_STATIC_RECT_VB GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory); - GrDrawState::AutoTextureRelease atr(fDrawState); + GrDrawState::AutoStageDisable atr(fDrawState); GrDrawState* drawState = target->drawState(); GrVertexLayout layout = PaintStageVertexLayoutBits(paint, NULL); GrDrawState::AutoViewMatrixRestore avmr(drawState); @@ -949,7 +949,7 @@ void GrContext::drawRectToRect(const GrPaint& paint, #else target = this->prepareToDraw(paint, kUnbuffered_DrawCategory); #endif - GrDrawState::AutoTextureRelease atr(fDrawState); + GrDrawState::AutoStageDisable atr(fDrawState); const GrRect* srcRects[GrDrawState::kNumStages] = {NULL}; const GrMatrix* srcMatrices[GrDrawState::kNumStages] = {NULL}; @@ -973,7 +973,7 @@ void GrContext::drawVertices(const GrPaint& paint, GrDrawTarget::AutoReleaseGeometry geo; GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory); - GrDrawState::AutoTextureRelease atr(fDrawState); + GrDrawState::AutoStageDisable atr(fDrawState); bool hasTexCoords[GrPaint::kTotalStages] = { NULL != texCoords, // texCoordSrc provides explicit stage 0 coords @@ -1078,7 +1078,7 @@ void GrContext::drawOval(const GrPaint& paint, DrawCategory category = (DEFER_PATHS) ? kBuffered_DrawCategory : kUnbuffered_DrawCategory; GrDrawTarget* target = this->prepareToDraw(paint, category); - GrDrawState::AutoTextureRelease atr(fDrawState); + GrDrawState::AutoStageDisable atr(fDrawState); GrDrawState* drawState = target->drawState(); GrMatrix vm = drawState->getViewMatrix(); @@ -1187,7 +1187,7 @@ void GrContext::internalDrawPath(const GrPaint& paint, const SkPath& path, DrawCategory category = (DEFER_PATHS) ? kBuffered_DrawCategory : kUnbuffered_DrawCategory; GrDrawTarget* target = this->prepareToDraw(paint, category); - GrDrawState::AutoTextureRelease atr(fDrawState); + GrDrawState::AutoStageDisable atr(fDrawState); GrDrawState::StageMask stageMask = paint.getActiveStageMask(); bool prAA = paint.fAntiAlias && !this->getRenderTarget()->isMultisampled(); @@ -1588,6 +1588,7 @@ void GrContext::internalWriteRenderTargetPixels(GrRenderTarget* target, //////////////////////////////////////////////////////////////////////////////// void GrContext::setPaint(const GrPaint& paint) { + GrAssert(fDrawState->stagesDisabled()); for (int i = 0; i < GrPaint::kMaxTextures; ++i) { int s = i + GrPaint::kFirstTextureStage; diff --git a/src/gpu/GrDefaultTextContext.cpp b/src/gpu/GrDefaultTextContext.cpp index 21cb99087e..c6f34e2c53 100644 --- a/src/gpu/GrDefaultTextContext.cpp +++ b/src/gpu/GrDefaultTextContext.cpp @@ -131,8 +131,6 @@ void GrDefaultTextContext::init(GrContext* context, } } - // this has been already done in the baseclass, but we need to repeat - // due to new matrix fDrawTarget = fContext->getTextTarget(fGrPaint); fVertices = NULL; diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h index 5feccb57cb..acfca8c1e1 100644 --- a/src/gpu/GrDrawState.h +++ b/src/gpu/GrDrawState.h @@ -74,16 +74,18 @@ public: } 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 @@ public: 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: |