const GrMatrix* extMatrix) {
this->INHERITED::init(context, grPaint, extMatrix);
fGrPaint = grPaint;
- fDrawTarget = fContext->getTextTarget(fGrPaint);
+ fDrawTarget = NULL;
fMaxVertices = 0;
fCurrTexture = NULL;
}
void GrBatchedTextContext::finish() {
+ GrAssert(fDrawTarget);
+ if (fDrawTarget) {
+ fDrawTarget->drawState()->disableStages();
+ }
fDrawTarget = NULL;
this->INHERITED::finish();
void GrBatchedTextContext::reset() {
GrAssert(this->isValid());
+ GrAssert(fDrawTarget);
fDrawTarget->resetVertexSource();
fMaxVertices = 0;
fCurrVertex = 0;
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.
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;
#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);
#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};
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
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();
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();
////////////////////////////////////////////////////////////////////////////////
void GrContext::setPaint(const GrPaint& paint) {
+ GrAssert(fDrawState->stagesDisabled());
for (int i = 0; i < GrPaint::kMaxTextures; ++i) {
int s = i + GrPaint::kFirstTextureStage;
}
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
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: