Chromium Code Reviews| Index: include/gpu/GrEffectStage.h |
| diff --git a/include/gpu/GrEffectStage.h b/include/gpu/GrEffectStage.h |
| index 3f10bdcf1e22a1d1363df54b34fc8f03f01f34ac..08fb159260750682af680bf85aed11cef2dd3d58 100644 |
| --- a/include/gpu/GrEffectStage.h |
| +++ b/include/gpu/GrEffectStage.h |
| @@ -20,14 +20,8 @@ |
| class GrEffectStage { |
| public: |
| - GrEffectStage() { |
| - fCoordChangeMatrixSet = false; |
| - fVertexAttribIndices[0] = -1; |
| - fVertexAttribIndices[1] = -1; |
| - } |
|
jvanverth1
2013/07/15 13:20:02
You may want to make the default constructor priva
bsalomon
2013/07/15 13:24:53
Since we have other constructors, there is no auto
|
| - |
| explicit GrEffectStage(const GrEffectRef* effectRef, int attrIndex0 = -1, int attrIndex1 = -1) |
| - : fEffectRef(SkSafeRef(effectRef)) { |
| + : fEffectRef(SkRef(effectRef)) { |
| fCoordChangeMatrixSet = false; |
| fVertexAttribIndices[0] = attrIndex0; |
| fVertexAttribIndices[1] = attrIndex1; |
| @@ -37,23 +31,25 @@ public: |
| *this = other; |
| } |
| + class DeferredStage; |
| + // This constructor balances DeferredStage::saveFrom(). |
| + explicit GrEffectStage(const DeferredStage& deferredStage) { |
| + deferredStage.restoreTo(this); |
| + } |
| + |
| GrEffectStage& operator= (const GrEffectStage& other) { |
| fCoordChangeMatrixSet = other.fCoordChangeMatrixSet; |
| if (other.fCoordChangeMatrixSet) { |
| fCoordChangeMatrix = other.fCoordChangeMatrix; |
| } |
| - fEffectRef.reset(SkSafeRef(other.fEffectRef.get())); |
| + fEffectRef.reset(SkRef(other.fEffectRef.get())); |
| memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexAttribIndices)); |
| return *this; |
| } |
| bool operator== (const GrEffectStage& other) const { |
| - // first handle cases where one or the other has no effect |
| - if (NULL == fEffectRef.get()) { |
| - return NULL == other.fEffectRef.get(); |
| - } else if (NULL == other.fEffectRef.get()) { |
| - return false; |
| - } |
| + GrAssert(NULL != fEffectRef.get()); |
| + GrAssert(NULL != other.fEffectRef.get()); |
| if (!(*this->getEffect())->isEqual(*other.getEffect())) { |
| return false; |
| @@ -108,7 +104,7 @@ public: |
| savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; |
| } |
| GrAssert(NULL == savedCoordChange->fEffectRef.get()); |
| - GR_DEBUGCODE(GrSafeRef(fEffectRef.get());) |
| + GR_DEBUGCODE(SkRef(fEffectRef.get());) |
| GR_DEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef.get());) |
| } |
| @@ -142,43 +138,32 @@ public: |
| void saveFrom(const GrEffectStage& stage) { |
| GrAssert(!fInitialized); |
| - if (NULL != stage.fEffectRef.get()) { |
| - stage.fEffectRef->get()->incDeferredRefCounts(); |
| - fEffect = stage.fEffectRef->get(); |
| - fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet; |
| - if (fCoordChangeMatrixSet) { |
| - fCoordChangeMatrix = stage.fCoordChangeMatrix; |
| - } |
| - fVertexAttribIndices[0] = stage.fVertexAttribIndices[0]; |
| - fVertexAttribIndices[1] = stage.fVertexAttribIndices[1]; |
| + GrAssert(NULL != stage.fEffectRef.get()); |
| + stage.fEffectRef->get()->incDeferredRefCounts(); |
| + fEffect = stage.fEffectRef->get(); |
| + fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet; |
| + if (fCoordChangeMatrixSet) { |
| + fCoordChangeMatrix = stage.fCoordChangeMatrix; |
| } |
| + fVertexAttribIndices[0] = stage.fVertexAttribIndices[0]; |
| + fVertexAttribIndices[1] = stage.fVertexAttribIndices[1]; |
| SkDEBUGCODE(fInitialized = true;) |
| } |
| - void restoreTo(GrEffectStage* stage) { |
| + void restoreTo(GrEffectStage* stage) const { |
| GrAssert(fInitialized); |
| - if (NULL != fEffect) { |
| - stage->fEffectRef.reset(GrEffect::CreateEffectRef(fEffect)); |
| - stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet; |
| - if (fCoordChangeMatrixSet) { |
| - stage->fCoordChangeMatrix = fCoordChangeMatrix; |
| - } |
| - stage->fVertexAttribIndices[0] = fVertexAttribIndices[0]; |
| - stage->fVertexAttribIndices[1] = fVertexAttribIndices[1]; |
| - } else { |
| - stage->fEffectRef.reset(NULL); |
| + stage->fEffectRef.reset(GrEffect::CreateEffectRef(fEffect)); |
| + stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet; |
| + if (fCoordChangeMatrixSet) { |
| + stage->fCoordChangeMatrix = fCoordChangeMatrix; |
| } |
| + stage->fVertexAttribIndices[0] = fVertexAttribIndices[0]; |
| + stage->fVertexAttribIndices[1] = fVertexAttribIndices[1]; |
| } |
| bool isEqual(const GrEffectStage& stage, bool ignoreCoordChange) const { |
| - if (NULL == stage.fEffectRef.get()) { |
| - return NULL == fEffect; |
| - } else if (NULL == fEffect) { |
| - return false; |
| - } |
| - |
| - if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] |
| - || fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) { |
| + if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] || |
| + fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) { |
| return false; |
| } |
| @@ -223,18 +208,6 @@ public: |
| } |
| } |
| - void reset() { fEffectRef.reset(NULL); } |
| - |
| - const GrEffectRef* setEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) { |
| - fEffectRef.reset(SkSafeRef(effect)); |
| - fCoordChangeMatrixSet = false; |
| - |
| - fVertexAttribIndices[0] = attr0; |
| - fVertexAttribIndices[1] = attr1; |
| - |
| - return effect; |
| - } |
| - |
| const GrEffectRef* getEffect() const { return fEffectRef.get(); } |
| const int* getVertexAttribIndices() const { return fVertexAttribIndices; } |