aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-07-07 08:15:07 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-07 08:15:07 -0700
commita70353e841638166e7bd2416301474c9ba8c9a1a (patch)
treee943a7cbf49f362b833a8b1ceeee15551aaad59c
parent5f7f9d04dc3a2d2c3ef9d8f1703d8e13c2d15c6e (diff)
Remove deferred version of GrDrawState.
R=robertphillips@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/368913003
-rw-r--r--src/gpu/GrDrawState.h97
-rw-r--r--src/gpu/GrInOrderDrawBuffer.cpp15
-rw-r--r--src/gpu/GrInOrderDrawBuffer.h4
3 files changed, 11 insertions, 105 deletions
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 4e226c5eb0..11a5af9870 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -902,7 +902,7 @@ private:
fCommon.fDrawFace = kBoth_DrawFace;
}
- /** Fields that are identical in GrDrawState and GrDrawState::DeferredState. */
+ /** This will be removed soon. The fields will become members of GrDrawState. */
struct CommonState {
// These fields are roughly sorted by decreasing likelihood of being different in op==
GrColor fColor;
@@ -941,101 +941,6 @@ private:
bool operator!= (const CommonState& other) const { return !(*this == other); }
};
- /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on GrEffectRef.
- DeferredState must directly reference GrEffects, however. */
- struct SavedEffectStage {
- SavedEffectStage() : fEffect(NULL) {}
- const GrEffect* fEffect;
- GrEffectStage::SavedCoordChange fCoordChange;
- };
-
-public:
- /**
- * DeferredState contains all of the data of a GrDrawState but does not hold refs on GrResource
- * objects. Resources are allowed to hit zero ref count while in DeferredStates. Their internal
- * dispose mechanism returns them to the cache. This allows recycling resources through the
- * the cache while they are in a deferred draw queue.
- */
- class DeferredState {
- public:
- DeferredState() : fRenderTarget(NULL) {
- SkDEBUGCODE(fInitialized = false;)
- }
- // TODO: Remove this when DeferredState no longer holds a ref to the RT
- ~DeferredState() { SkSafeUnref(fRenderTarget); }
-
- void saveFrom(const GrDrawState& drawState) {
- fCommon = drawState.fCommon;
- // TODO: Here we will copy the GrRenderTarget pointer without taking a ref.
- fRenderTarget = drawState.fRenderTarget.get();
- SkSafeRef(fRenderTarget);
- // Here we ref the effects directly rather than the effect-refs. TODO: When the effect-
- // ref gets fully unref'ed it will cause the underlying effect to unref its resources
- // and recycle them to the cache (if no one else is holding a ref to the resources).
- fStages.reset(drawState.fColorStages.count() + drawState.fCoverageStages.count());
- fColorStageCnt = drawState.fColorStages.count();
- for (int i = 0; i < fColorStageCnt; ++i) {
- fStages[i].saveFrom(drawState.fColorStages[i]);
- }
- for (int i = 0; i < drawState.fCoverageStages.count(); ++i) {
- fStages[i + fColorStageCnt].saveFrom(drawState.fCoverageStages[i]);
- }
- SkDEBUGCODE(fInitialized = true;)
- }
-
- void restoreTo(GrDrawState* drawState) const {
- SkASSERT(fInitialized);
- drawState->fCommon = fCommon;
- drawState->setRenderTarget(fRenderTarget);
- // reinflate color/cov stage arrays.
- drawState->fColorStages.reset();
- for (int i = 0; i < fColorStageCnt; ++i) {
- SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage, (fStages[i]));
- }
- int coverageStageCnt = fStages.count() - fColorStageCnt;
- drawState->fCoverageStages.reset();
- for (int i = 0; i < coverageStageCnt; ++i) {
- SkNEW_APPEND_TO_TARRAY(&drawState->fCoverageStages,
- GrEffectStage, (fStages[i + fColorStageCnt]));
- }
- }
-
- bool isEqual(const GrDrawState& state) const {
- int numCoverageStages = fStages.count() - fColorStageCnt;
- if (fRenderTarget != state.fRenderTarget.get() ||
- fColorStageCnt != state.fColorStages.count() ||
- numCoverageStages != state.fCoverageStages.count() ||
- fCommon != state.fCommon) {
- return false;
- }
- bool explicitLocalCoords = state.hasLocalCoordAttribute();
- for (int i = 0; i < fColorStageCnt; ++i) {
- if (!fStages[i].isEqual(state.fColorStages[i], explicitLocalCoords)) {
- return false;
- }
- }
- for (int i = 0; i < numCoverageStages; ++i) {
- int s = fColorStageCnt + i;
- if (!fStages[s].isEqual(state.fCoverageStages[i], explicitLocalCoords)) {
- return false;
- }
- }
- return true;
- }
-
- private:
- typedef SkAutoSTArray<8, GrEffectStage::DeferredStage> DeferredStageArray;
-
- GrRenderTarget* fRenderTarget;
- CommonState fCommon;
- int fColorStageCnt;
- DeferredStageArray fStages;
-
- SkDEBUGCODE(bool fInitialized;)
- };
-
-private:
-
SkAutoTUnref<GrRenderTarget> fRenderTarget;
CommonState fCommon;
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index 1cd7f539de..cdb1d892ce 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -577,10 +577,7 @@ void GrInOrderDrawBuffer::flush() {
GrDrawTarget::AutoClipRestore acr(fDstGpu);
AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit);
- GrDrawState playbackState;
- GrDrawState* prevDrawState = fDstGpu->drawState();
- prevDrawState->ref();
- fDstGpu->setDrawState(&playbackState);
+ GrDrawState* prevDrawState = SkRef(fDstGpu->drawState());
GrClipData clipData;
@@ -606,6 +603,7 @@ void GrInOrderDrawBuffer::flush() {
}
switch (strip_trace_bit(fCmds[c])) {
case kDraw_Cmd: {
+ SkASSERT(fDstGpu->drawState() != prevDrawState);
SkAssertResult(drawIter.next());
fDstGpu->setVertexSourceToBuffer(drawIter->fVertexBuffer);
if (drawIter->isIndexed()) {
@@ -615,11 +613,13 @@ void GrInOrderDrawBuffer::flush() {
break;
}
case kStencilPath_Cmd: {
+ SkASSERT(fDstGpu->drawState() != prevDrawState);
SkAssertResult(stencilPathIter.next());
fDstGpu->stencilPath(stencilPathIter->fPath.get(), stencilPathIter->fFill);
break;
}
case kDrawPath_Cmd: {
+ SkASSERT(fDstGpu->drawState() != prevDrawState);
SkAssertResult(drawPathIter.next());
fDstGpu->executeDrawPath(drawPathIter->fPath.get(), drawPathIter->fFill,
NULL != drawPathIter->fDstCopy.texture() ?
@@ -628,6 +628,7 @@ void GrInOrderDrawBuffer::flush() {
break;
}
case kDrawPaths_Cmd: {
+ SkASSERT(fDstGpu->drawState() != prevDrawState);
SkAssertResult(drawPathsIter.next());
const GrDeviceCoordTexture* dstCopy =
NULL !=drawPathsIter->fDstCopy.texture() ? &drawPathsIter->fDstCopy : NULL;
@@ -638,7 +639,7 @@ void GrInOrderDrawBuffer::flush() {
}
case kSetState_Cmd:
SkAssertResult(stateIter.next());
- stateIter->restoreTo(&playbackState);
+ fDstGpu->setDrawState(stateIter.get());
break;
case kSetClip_Cmd:
SkAssertResult(clipIter.next());
@@ -920,7 +921,7 @@ void GrInOrderDrawBuffer::geometrySourceWillPop(
}
bool GrInOrderDrawBuffer::needsNewState() const {
- return fStates.empty() || !fStates.back().isEqual(this->getDrawState());
+ return fStates.empty() || fStates.back() != this->getDrawState();
}
bool GrInOrderDrawBuffer::needsNewClip() const {
@@ -954,7 +955,7 @@ void GrInOrderDrawBuffer::recordClip() {
}
void GrInOrderDrawBuffer::recordState() {
- fStates.push_back().saveFrom(this->getDrawState());
+ fStates.push_back() = this->getDrawState();
this->addToCmdBuffer(kSetState_Cmd);
}
diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h
index b31a9957d1..3025c067f7 100644
--- a/src/gpu/GrInOrderDrawBuffer.h
+++ b/src/gpu/GrInOrderDrawBuffer.h
@@ -232,7 +232,7 @@ private:
typedef GrTAllocator<StencilPath> StencilPathAllocator;
typedef GrTAllocator<DrawPath> DrawPathAllocator;
typedef GrTAllocator<DrawPaths> DrawPathsAllocator;
- typedef GrTAllocator<GrDrawState::DeferredState> StateAllocator;
+ typedef GrTAllocator<GrDrawState> StateAllocator;
typedef GrTAllocator<Clear> ClearAllocator;
typedef GrTAllocator<CopySurface> CopySurfaceAllocator;
typedef GrTAllocator<Clip> ClipAllocator;
@@ -241,7 +241,7 @@ private:
GrSTAllocator<kStencilPathPreallocCnt, StencilPath> fStencilPaths;
GrSTAllocator<kDrawPathPreallocCnt, DrawPath> fDrawPath;
GrSTAllocator<kDrawPathsPreallocCnt, DrawPaths> fDrawPaths;
- GrSTAllocator<kStatePreallocCnt, GrDrawState::DeferredState> fStates;
+ GrSTAllocator<kStatePreallocCnt, GrDrawState> fStates;
GrSTAllocator<kClearPreallocCnt, Clear> fClears;
GrSTAllocator<kCopySurfacePreallocCnt, CopySurface> fCopySurfaces;
GrSTAllocator<kClipPreallocCnt, Clip> fClips;