diff options
-rw-r--r-- | include/gpu/GrEffectStage.h | 83 | ||||
-rw-r--r-- | src/gpu/GrDrawState.h | 9 | ||||
-rw-r--r-- | tests/GLProgramsTest.cpp | 4 |
3 files changed, 35 insertions, 61 deletions
diff --git a/include/gpu/GrEffectStage.h b/include/gpu/GrEffectStage.h index 3f10bdcf1e..08fb159260 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; - } - 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; } diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h index 52058f5732..c4f872608b 100644 --- a/src/gpu/GrDrawState.h +++ b/src/gpu/GrDrawState.h @@ -1024,14 +1024,15 @@ public: drawState->fCommon = fCommon; drawState->setRenderTarget(fRenderTarget); // reinflate color/cov stage arrays. - drawState->fColorStages.reset(fColorStageCnt); + drawState->fColorStages.reset(); for (int i = 0; i < fColorStageCnt; ++i) { - fStages[i].restoreTo(&drawState->fColorStages[i]); + SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage, (fStages[i])); } int coverageStageCnt = fStages.count() - fColorStageCnt; - drawState->fCoverageStages.reset(coverageStageCnt); + drawState->fCoverageStages.reset(); for (int i = 0; i < coverageStageCnt; ++i) { - fStages[fColorStageCnt + i].restoreTo(&drawState->fCoverageStages[i]); + SkNEW_APPEND_TO_TARRAY(&drawState->fCoverageStages, + GrEffectStage, (fStages[i + fColorStageCnt])); } } diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 55c4c0919f..17ad6064f3 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -172,8 +172,8 @@ bool GrGpuGL::programUnitTest(int maxStages) { for (int i = 0; i < numAttribs; ++i) { attribIndices[i] = currAttribIndex++; } - GrEffectStage* stage = SkNEW(GrEffectStage); - stage->setEffect(effect.get(), attribIndices[0], attribIndices[1]); + GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, + (effect.get(), attribIndices[0], attribIndices[1])); stages[s] = stage; } const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dummyTextures[1]; |