Change behavior of GrDS::AutoEffectRestort wrt GPs.

BUG=skia:2889
R=robertphillips@google.com, joshualitt@chromium.org

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/545253002
This commit is contained in:
bsalomon 2014-09-05 09:18:51 -07:00 committed by Commit bot
parent a1ae66d252
commit 9b536523ca
2 changed files with 39 additions and 13 deletions

View File

@ -299,7 +299,14 @@ GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(
void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
if (NULL != fDrawState) {
fDrawState->fGeometryProcessor.reset(fGeometryProcessor.detach());
// See the big comment on the class definition about GPs.
if (NULL != fOriginalGP) {
SkASSERT(fDrawState->getGeometryProcessor()->getEffect() == fOriginalGP);
fOriginalGP->unref();
fOriginalGP = NULL;
} else {
fDrawState->fGeometryProcessor.reset(NULL);
}
int m = fDrawState->numColorStages() - fColorEffectCnt;
SkASSERT(m >= 0);
@ -315,10 +322,9 @@ void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
}
fDrawState = ds;
if (NULL != ds) {
if (ds->hasGeometryProcessor()) {
fGeometryProcessor.reset(SkNEW_ARGS(GrEffectStage, (*ds->getGeometryProcessor())));
} else {
fGeometryProcessor.reset(NULL);
SkASSERT(NULL == fOriginalGP);
if (NULL != ds->getGeometryProcessor()) {
fOriginalGP = SkRef(ds->getGeometryProcessor()->getEffect());
}
fColorEffectCnt = ds->numColorStages();
fCoverageEffectCnt = ds->numCoverageStages();

View File

@ -237,14 +237,34 @@ public:
}
/**
* When this object is destroyed it will remove any effects from the draw state that were added
* after its constructor.
* When this object is destroyed it will remove any color/coverage effects from the draw state
* that were added after its constructor.
*
* This class has strange behavior around geometry processor. If there is a GP on the draw state
* it will assert that the GP is not modified until after the destructor of the ARE. If the
* draw state has a NULL GP when the ARE is constructed then it will reset it to null in the
* destructor.
*
* TODO: We'd prefer for the ARE to just save and restore the GP. However, this would add
* significant complexity to the multi-ref architecture for deferred drawing. Once GrDrawState
* and GrOptDrawState are fully separated then GrDrawState will never be in the deferred
* execution state and GrOptDrawState always will be (and will be immutable and therefore
* unable to have an ARE). At this point we can restore sanity and have the ARE save and restore
* the GP.
*/
class AutoRestoreEffects : public ::SkNoncopyable {
public:
AutoRestoreEffects() : fDrawState(NULL), fColorEffectCnt(0), fCoverageEffectCnt(0) {}
AutoRestoreEffects()
: fDrawState(NULL)
, fOriginalGP(NULL)
, fColorEffectCnt(0)
, fCoverageEffectCnt(0) {}
AutoRestoreEffects(GrDrawState* ds) : fDrawState(NULL), fColorEffectCnt(0), fCoverageEffectCnt(0) {
AutoRestoreEffects(GrDrawState* ds)
: fDrawState(NULL)
, fOriginalGP(NULL)
, fColorEffectCnt(0)
, fCoverageEffectCnt(0) {
this->set(ds);
}
@ -256,7 +276,7 @@ public:
private:
GrDrawState* fDrawState;
SkAutoTDelete<GrEffectStage> fGeometryProcessor;
const GrEffect* fOriginalGP;
int fColorEffectCnt;
int fCoverageEffectCnt;
};