aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-11-24 06:47:48 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-24 06:47:48 -0800
commit932f8669875f5d63b8c04571931e6f4224e66e0b (patch)
tree435c07473abc322e172c998f9fdd628c7e21c03b
parent735f548c51d3824724b621fa836ca828a195d307 (diff)
Create GrOptDrawState directly in the cmd buffer in GrIODB.
-rw-r--r--include/gpu/GrGpuResourceRef.h2
-rw-r--r--src/gpu/GrInOrderDrawBuffer.cpp32
-rw-r--r--src/gpu/GrInOrderDrawBuffer.h27
-rw-r--r--src/gpu/GrOptDrawState.h2
-rw-r--r--tests/GLProgramsTest.cpp7
5 files changed, 37 insertions, 33 deletions
diff --git a/include/gpu/GrGpuResourceRef.h b/include/gpu/GrGpuResourceRef.h
index 1f7d31be94..0e23eeab61 100644
--- a/include/gpu/GrGpuResourceRef.h
+++ b/include/gpu/GrGpuResourceRef.h
@@ -77,8 +77,6 @@ private:
called. */
void pendingIOComplete() const;
- friend class GrDrawState;
- friend class GrOptDrawState;
friend class GrProgramElement;
GrGpuResource* fResource;
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index 2f90373c33..7fc201fb0b 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -20,7 +20,7 @@ GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu,
GrIndexBufferAllocPool* indexPool)
: INHERITED(gpu->getContext())
, fCmdBuffer(kCmdBufferInitialSizeInBytes)
- , fLastState(NULL)
+ , fPrevState(NULL)
, fDstGpu(gpu)
, fVertexPool(*vertexPool)
, fIndexPool(*indexPool)
@@ -435,7 +435,7 @@ void GrInOrderDrawBuffer::reset() {
this->resetIndexSource();
fCmdBuffer.reset();
- fLastState.reset(NULL);
+ fPrevState = NULL;
fVertexPool.reset();
fIndexPool.reset();
reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve);
@@ -470,7 +470,7 @@ void GrInOrderDrawBuffer::flush() {
// Updated every time we find a set state cmd to reflect the current state in the playback
// stream.
- SkAutoTUnref<const GrOptDrawState> currentOptState;
+ const GrOptDrawState* currentOptState = NULL;
while (iter.next()) {
GrGpuTraceMarker newMarker("", -1);
@@ -484,9 +484,9 @@ void GrInOrderDrawBuffer::flush() {
if (kSetState_Cmd == strip_trace_bit(iter->fType)) {
SetState* ss = reinterpret_cast<SetState*>(iter.get());
- currentOptState.reset(SkRef(ss->fState.get()));
+ currentOptState = &ss->fState;
} else {
- iter->execute(this, currentOptState.get());
+ iter->execute(this, currentOptState);
}
if (cmd_has_trace_marker(iter->fType)) {
@@ -502,29 +502,32 @@ void GrInOrderDrawBuffer::flush() {
}
void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState* optState) {
+ SkASSERT(optState);
buf->fDstGpu->draw(*optState, fInfo);
}
void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf,
const GrOptDrawState* optState) {
+ SkASSERT(optState);
buf->fDstGpu->stencilPath(*optState, this->path(), fStencilSettings);
}
void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf,
const GrOptDrawState* optState) {
+ SkASSERT(optState);
buf->fDstGpu->drawPath(*optState, this->path(), fStencilSettings);
}
void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf,
const GrOptDrawState* optState) {
+ SkASSERT(optState);
buf->fDstGpu->drawPaths(*optState, this->pathRange(),
&buf->fPathIndexBuffer[fIndicesLocation], fCount,
&buf->fPathTransformBuffer[fTransformsLocation], fTransformsType,
fStencilSettings);
}
-void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const GrOptDrawState*) {
-}
+void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const GrOptDrawState*) {}
void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const GrOptDrawState*) {
if (GrColor_ILLEGAL == fColor) {
@@ -727,15 +730,16 @@ bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds,
GrGpu::DrawType drawType,
const GrClipMaskManager::ScissorState& scissor,
const GrDeviceCoordTexture* dstCopy) {
- SkAutoTUnref<GrOptDrawState> optState(
- SkNEW_ARGS(GrOptDrawState, (ds, fDstGpu, scissor, dstCopy, drawType)));
- if (optState->mustSkip()) {
+ SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState,
+ (ds, fDstGpu, scissor, dstCopy, drawType));
+ if (ss->fState.mustSkip()) {
+ fCmdBuffer.pop_back();
return false;
}
- if (!fLastState || *optState != *fLastState) {
- SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (optState));
- fLastState.reset(SkRef(optState.get()));
- ss->fDrawType = drawType;
+ if (fPrevState && *fPrevState == ss->fState) {
+ fCmdBuffer.pop_back();
+ } else {
+ fPrevState = &ss->fState;
this->recordTraceMarkersIfNecessary();
}
return true;
diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h
index ab7dd77a6d..9d9f23cd1f 100644
--- a/src/gpu/GrInOrderDrawBuffer.h
+++ b/src/gpu/GrInOrderDrawBuffer.h
@@ -118,7 +118,7 @@ private:
struct Draw : public Cmd {
Draw(const DrawInfo& info) : Cmd(kDraw_Cmd), fInfo(info) {}
- virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
+ void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
DrawInfo fInfo;
};
@@ -128,7 +128,7 @@ private:
const GrPath* path() const { return fPath.get(); }
- virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
+ void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
GrStencilSettings fStencilSettings;
@@ -141,7 +141,7 @@ private:
const GrPath* path() const { return fPath.get(); }
- virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
+ void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
GrStencilSettings fStencilSettings;
@@ -154,7 +154,7 @@ private:
const GrPathRange* pathRange() const { return fPathRange.get(); }
- virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
+ void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
int fIndicesLocation;
size_t fCount;
@@ -172,7 +172,7 @@ private:
GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
- virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
+ void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
SkIRect fRect;
GrColor fColor;
@@ -188,7 +188,7 @@ private:
GrRenderTarget* renderTarget() const { return fRenderTarget.get(); }
- virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
+ void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
SkIRect fRect;
bool fInsideClip;
@@ -203,7 +203,7 @@ private:
GrSurface* dst() const { return fDst.get(); }
GrSurface* src() const { return fSrc.get(); }
- virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
+ void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
SkIPoint fDstPoint;
SkIRect fSrcRect;
@@ -214,12 +214,15 @@ private:
};
struct SetState : public Cmd {
- SetState(const GrOptDrawState* state) : Cmd(kSetState_Cmd), fState(SkRef(state)) {}
+ SetState(const GrDrawState& drawState, GrGpu* gpu, const ScissorState& scissor,
+ const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType drawType)
+ : Cmd(kSetState_Cmd)
+ , fState(drawState, gpu, scissor, dstCopy, drawType) {}
- virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*);
+ void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE;
- SkAutoTUnref<const GrOptDrawState> fState;
- GrGpu::DrawType fDrawType;
+ const GrOptDrawState fState;
+ GrGpu::DrawType fDrawType;
};
typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double.
@@ -310,7 +313,7 @@ private:
typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateStack;
CmdBuffer fCmdBuffer;
- SkAutoTUnref<const GrOptDrawState> fLastState;
+ const GrOptDrawState* fPrevState;
SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers;
GrGpu* fDstGpu;
GrVertexBufferAllocPool& fVertexPool;
diff --git a/src/gpu/GrOptDrawState.h b/src/gpu/GrOptDrawState.h
index 91c39a181c..bf4f78e5ef 100644
--- a/src/gpu/GrOptDrawState.h
+++ b/src/gpu/GrOptDrawState.h
@@ -24,7 +24,7 @@ class GrDrawState;
* Class that holds an optimized version of a GrDrawState. It is meant to be an immutable class,
* and contains all data needed to set the state for a gpu draw.
*/
-class GrOptDrawState : public SkRefCnt {
+class GrOptDrawState {
public:
SK_DECLARE_INST_COUNT(GrOptDrawState)
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 7da1e72012..a6b2ee397d 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -468,12 +468,11 @@ bool GrDrawTarget::programUnitTest(int maxStages) {
// create optimized draw state, setup readDst texture if required, and build a descriptor
// and program. ODS creation can fail, so we have to check
- SkAutoTUnref<GrOptDrawState> ods
- SkNEW_ARGS(GrOptDrawState, (ds, gpu, scissor, &dstCopy, drawType));
- if (ods->mustSkip()) {
+ GrOptDrawState ods(ds, gpu, scissor, &dstCopy, drawType);
+ if (ods.mustSkip()) {
continue;
}
- SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(*ods, drawType, gpu));
+ SkAutoTUnref<GrGLProgram> program(GrGLProgramBuilder::CreateProgram(ods, drawType, gpu));
if (NULL == program.get()) {
SkDebugf("Failed to create program!");
return false;