Make GrEffectStage copy constructor work correctly with pending execution refs.

R=egdaniel@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/551083002
This commit is contained in:
bsalomon 2014-09-08 12:06:20 -07:00 committed by Commit bot
parent 46625e06e2
commit 655ad128d0
2 changed files with 26 additions and 6 deletions

View File

@ -17,6 +17,11 @@
#include "SkMatrix.h"
#include "SkShader.h"
// TODO: Make two variations on this class: One for GrDrawState that only owns regular refs
// and supports compatibility checks and changing local coords. The second is for GrOptDrawState,
// is immutable, and only owns pending execution refs. This requries removing the common base
// class from GrDrawState and GrOptDrawState called GrRODrawState and converting to GrOptDrawState
// when draws are enqueued in the GrInOrderDrawBuffer.
class GrEffectStage {
public:
explicit GrEffectStage(const GrEffect* effect, int attrIndex0 = -1, int attrIndex1 = -1)
@ -27,17 +32,12 @@ public:
}
GrEffectStage(const GrEffectStage& other) {
*this = other;
}
GrEffectStage& operator= (const GrEffectStage& other) {
fCoordChangeMatrixSet = other.fCoordChangeMatrixSet;
if (other.fCoordChangeMatrixSet) {
fCoordChangeMatrix = other.fCoordChangeMatrix;
}
fEffect.reset(SkRef(other.fEffect.get()));
fEffect.initAndRef(other.fEffect);
memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexAttribIndices));
return *this;
}
static bool AreCompatible(const GrEffectStage& a, const GrEffectStage& b,

View File

@ -38,6 +38,26 @@ public:
fOwnPendingExec = true;
}
// In the short term we need to support copying a GrEffectStage and making the copy own
// the same type of ref as the source. This function exists to support this. TODO: Once
// GrDrawState and GrOptDrawState no longer share a base class they won't have to share
// GrEffectStage and we can have GrOptDrawState always own pending executions rather than
// refs on GrProgramElements. At that point we should be able to delete this function.
// This function makes assumptions that are valid in the GrEffectStage use case and should
// not be used elsewhere.
void initAndRef(const GrProgramElementRef& that) {
SkASSERT(!fObj);
SkASSERT(that.fObj);
if (that.fOwnPendingExec) {
SkASSERT(that.fObj->fPendingExecutions > 0);
that.fObj->fPendingExecutions++;
} else {
that.fObj->ref();
}
this->fOwnPendingExec = that.fOwnPendingExec;
this->fObj = that.fObj;
}
T* get() const { return fObj; }
operator T*() { return fObj; }