Make clear a GrDrawTarget virtual method and implement in GrInOrderDrawBuffer
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 25 Apr 2011 19:17:44 +0000 (19:17 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 25 Apr 2011 19:17:44 +0000 (19:17 +0000)
Review URL: http://codereview.appspot.com/4442081/

git-svn-id: http://skia.googlecode.com/svn/trunk@1176 2bbb7eff-a529-9590-31e7-b0007b416f81

gpu/include/GrDrawTarget.h
gpu/include/GrGpu.h
gpu/include/GrInOrderDrawBuffer.h
gpu/src/GrInOrderDrawBuffer.cpp

index 038e776..1be2601 100644 (file)
@@ -718,6 +718,12 @@ public:
          drawRect(rect, matrix, stageEnableBitfield, NULL, NULL);
     }
 
+    /**
+     * Clear the entire render target. Ignores the clip an all other draw state
+     * (blend mode, stages, etc).
+     */
+    virtual void clear(GrColor color) = 0;
+
     ///////////////////////////////////////////////////////////////////////////
 
     class AutoStateRestore : ::GrNoncopyable {
index 1966f22..19f3746 100644 (file)
@@ -180,13 +180,6 @@ public:
     GrIndexBuffer* createIndexBuffer(uint32_t size, bool dynamic);
 
     /**
-     * Clear the entire render target, ignoring any clips/scissors.
-     *
-     * This is issued to the GPU driver immediately.
-     */
-    void clear(GrColor color);
-
-    /**
      * Are 8 bit paletted textures supported.
      *
      * @return    true if 8bit palette textures are supported, false otherwise
@@ -270,6 +263,7 @@ public:
     virtual void drawNonIndexed(GrPrimitiveType type,
                                 int startVertex,
                                 int vertexCount);
+    virtual void clear(GrColor color);
 
     /**
      * Installs a path renderer that will be used to draw paths that are
index c80afd9..03a2f2d 100644 (file)
@@ -100,6 +100,8 @@ public:
                                int* vertexCount,
                                int* indexCount) const;
 
+    virtual void clear(GrColor color);
+
 private:
 
     struct Draw {
@@ -115,6 +117,11 @@ private:
         const GrIndexBuffer*    fIndexBuffer;
     };
 
+    struct Clear {
+        int fBeforeDrawIdx;
+        GrColor fColor;
+    };
+
     virtual bool onAcquireGeometry(GrVertexLayout vertexLayout,
                                    void**         vertices,
                                    void**         indices);
@@ -135,6 +142,7 @@ private:
 
     GrTAllocator<Draw>              fDraws;
     GrTAllocator<SavedDrawState>    fStates;
+    GrTAllocator<Clear>             fClears;
 
     GrTAllocator<GrClip>            fClips;
     bool                            fClipSet;
@@ -163,11 +171,13 @@ private:
         kDrawPreallocCnt   = 8,
         kStatePreallocCnt  = 8,
         kClipPreallocCnt   = 8,
+        kClearPreallocCnt  = 4,
     };
 
     GrAlignedSTStorage<kDrawPreallocCnt, Draw>              fDrawStorage;
     GrAlignedSTStorage<kStatePreallocCnt, SavedDrawState>   fStateStorage;
     GrAlignedSTStorage<kClipPreallocCnt, GrClip>            fClipStorage;
+    GrAlignedSTStorage<kClearPreallocCnt, Clear>            fClearStorage;
 
     typedef GrDrawTarget INHERITED;
 };
index eebae00..93acc12 100644 (file)
@@ -26,6 +26,7 @@ GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrVertexBufferAllocPool* vertexPool,
                                          GrIndexBufferAllocPool* indexPool) :
         fDraws(&fDrawStorage),
         fStates(&fStateStorage),
+        fClears(&fClearStorage),
         fClips(&fClipStorage),
         fClipSet(true),
 
@@ -287,6 +288,16 @@ void GrInOrderDrawBuffer::drawNonIndexed(GrPrimitiveType primitiveType,
     draw.fIndexBuffer = NULL;
 }
 
+void GrInOrderDrawBuffer::clear(GrColor color) {
+    Clear& clr = fClears.push_back();
+    clr.fColor = color;
+    clr.fBeforeDrawIdx = fDraws.count();
+
+    // We could do something smart and remove previous draws and clears to the
+    // current render target. If we get that smart we have to make sure those
+    // draws aren't read before this clear (render-to-texture).
+}
+
 void GrInOrderDrawBuffer::reset() {
     GrAssert(!fReservedGeometry.fLocked);
     uint32_t numStates = fStates.count();
@@ -307,6 +318,8 @@ void GrInOrderDrawBuffer::reset() {
     fDraws.reset();
     fStates.reset();
 
+    fClears.reset();
+
     fVertexPool.reset();
     fIndexPool.reset();
 
@@ -336,8 +349,15 @@ void GrInOrderDrawBuffer::playback(GrDrawTarget* target) {
 
     uint32_t currState = ~0;
     uint32_t currClip  = ~0;
+    uint32_t currClear = 0;
 
     for (uint32_t i = 0; i < numDraws; ++i) {
+        while (currClear < fClears.count() && 
+               i == fClears[currClear].fBeforeDrawIdx) {
+            target->clear(fClears[currClear].fColor);
+            ++currClear;
+        }
+
         const Draw& draw = fDraws[i];
         if (draw.fStateChanged) {
             ++currState;
@@ -366,6 +386,11 @@ void GrInOrderDrawBuffer::playback(GrDrawTarget* target) {
                                    draw.fVertexCount);
         }
     }
+    while (currClear < fClears.count()) {
+        GrAssert(fDraws.count() == fClears[currClear].fBeforeDrawIdx);
+        target->clear(fClears[currClear].fColor);
+        ++currClear;
+    }
 }
 
 bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout,