Don't take a ref on GP in AutoEffectRestore.

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

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/546043002
This commit is contained in:
bsalomon 2014-09-05 12:23:12 -07:00 committed by Commit bot
parent 5a80be2241
commit 52e9d63f71
5 changed files with 30 additions and 13 deletions

View File

@ -172,8 +172,8 @@ public:
const GrResourceKey& getScratchKey() const { return fScratchKey; }
/**
* Gets an id that is unique for this GrCacheable object. It is static in that it does
* not change when the content of the GrCacheable object changes. This will never return
* Gets an id that is unique for this GrGpuResource object. It is static in that it does
* not change when the content of the GrGpuResource object changes. This will never return
* 0.
*/
uint32_t getUniqueID() const { return fUniqueID; }

View File

@ -49,6 +49,11 @@ public:
}
}
/**
* Gets an id that is unique for this GrProgramElement object. This will never return 0.
*/
uint32_t getUniqueID() const { return fUniqueID; }
void validate() const {
#ifdef SK_DEBUG
SkASSERT(fRefCnt >= 0);
@ -58,7 +63,7 @@ public:
}
protected:
GrProgramElement() : fRefCnt(1), fPendingExecutions(0) {}
GrProgramElement() : fRefCnt(1), fPendingExecutions(0), fUniqueID(CreateUniqueID()) {}
/** Subclasses registers their resources using this function. It is assumed the GrProgramResouce
is and will remain owned by the subclass and this function will retain a raw ptr. Once a
@ -69,6 +74,8 @@ protected:
}
private:
static uint32_t CreateUniqueID();
void convertRefToPendingExecution() const;
void completedExecution() const;
@ -76,6 +83,7 @@ private:
mutable int32_t fRefCnt;
// Count of deferred executions not yet issued to the 3D API.
mutable int32_t fPendingExecutions;
uint32_t fUniqueID;
SkSTArray<4, const GrProgramResource*, true> fProgramResources;

View File

@ -300,12 +300,12 @@ GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(
void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
if (NULL != fDrawState) {
// See the big comment on the class definition about GPs.
if (NULL != fOriginalGP) {
SkASSERT(fDrawState->getGeometryProcessor()->getEffect() == fOriginalGP);
fOriginalGP->unref();
fOriginalGP = NULL;
} else {
if (SK_InvalidUniqueID == fOriginalGPID) {
fDrawState->fGeometryProcessor.reset(NULL);
} else {
SkASSERT(fDrawState->getGeometryProcessor()->getEffect()->getUniqueID() ==
fOriginalGPID);
fOriginalGPID = SK_InvalidUniqueID;
}
int m = fDrawState->numColorStages() - fColorEffectCnt;
@ -322,9 +322,9 @@ void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
}
fDrawState = ds;
if (NULL != ds) {
SkASSERT(NULL == fOriginalGP);
SkASSERT(SK_InvalidUniqueID == fOriginalGPID);
if (NULL != ds->getGeometryProcessor()) {
fOriginalGP = SkRef(ds->getGeometryProcessor()->getEffect());
fOriginalGPID = ds->getGeometryProcessor()->getEffect()->getUniqueID();
}
fColorEffectCnt = ds->numColorStages();
fCoverageEffectCnt = ds->numCoverageStages();

View File

@ -256,13 +256,13 @@ public:
public:
AutoRestoreEffects()
: fDrawState(NULL)
, fOriginalGP(NULL)
, fOriginalGPID(SK_InvalidUniqueID)
, fColorEffectCnt(0)
, fCoverageEffectCnt(0) {}
AutoRestoreEffects(GrDrawState* ds)
: fDrawState(NULL)
, fOriginalGP(NULL)
, fOriginalGPID(SK_InvalidUniqueID)
, fColorEffectCnt(0)
, fCoverageEffectCnt(0) {
this->set(ds);
@ -276,7 +276,7 @@ public:
private:
GrDrawState* fDrawState;
const GrEffect* fOriginalGP;
uint32_t fOriginalGPID;
int fColorEffectCnt;
int fCoverageEffectCnt;
};

View File

@ -8,6 +8,15 @@
#include "GrProgramElement.h"
#include "GrProgramResource.h"
uint32_t GrProgramElement::CreateUniqueID() {
static int32_t gUniqueID = SK_InvalidUniqueID;
uint32_t id;
do {
id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
} while (id == SK_InvalidUniqueID);
return id;
}
void GrProgramElement::convertRefToPendingExecution() const {
// This function makes it so that all the GrProgramResources own a single ref to their
// underlying GrGpuResource if there are any refs to the GrProgramElement and a single