Create GrOptDrawState directly in the cmd buffer in GrIODB.
authorbsalomon <bsalomon@google.com>
Mon, 24 Nov 2014 14:47:48 +0000 (06:47 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 24 Nov 2014 14:47:48 +0000 (06:47 -0800)
Review URL: https://codereview.chromium.org/746243002

include/gpu/GrGpuResourceRef.h
src/gpu/GrInOrderDrawBuffer.cpp
src/gpu/GrInOrderDrawBuffer.h
src/gpu/GrOptDrawState.h
tests/GLProgramsTest.cpp

index 1f7d31b..0e23eea 100644 (file)
@@ -77,8 +77,6 @@ private:
         called. */
     void pendingIOComplete() const;
 
-    friend class GrDrawState;
-    friend class GrOptDrawState;
     friend class GrProgramElement;
 
     GrGpuResource*  fResource;
index 2f90373..7fc201f 100644 (file)
@@ -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;
index ab7dd77..9d9f23c 100644 (file)
@@ -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;
index 91c39a1..bf4f78e 100644 (file)
@@ -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)
 
index 7da1e72..a6b2ee3 100644 (file)
@@ -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;