diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-25 19:17:44 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-25 19:17:44 +0000 |
commit | 0b335c1ac100aeacf79a4c98a052286fd46661e7 (patch) | |
tree | 79f61ffb6168d0fafc84966d4be2f87eb4641ef2 | |
parent | 580aec6f7f8b27979fb5d677fd427eb9362edb8e (diff) |
Make clear a GrDrawTarget virtual method and implement in GrInOrderDrawBuffer
Review URL: http://codereview.appspot.com/4442081/
git-svn-id: http://skia.googlecode.com/svn/trunk@1176 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gpu/include/GrDrawTarget.h | 6 | ||||
-rw-r--r-- | gpu/include/GrGpu.h | 8 | ||||
-rw-r--r-- | gpu/include/GrInOrderDrawBuffer.h | 10 | ||||
-rw-r--r-- | gpu/src/GrInOrderDrawBuffer.cpp | 25 |
4 files changed, 42 insertions, 7 deletions
diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h index 038e776c5b..1be2601ffa 100644 --- a/gpu/include/GrDrawTarget.h +++ b/gpu/include/GrDrawTarget.h @@ -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 { diff --git a/gpu/include/GrGpu.h b/gpu/include/GrGpu.h index 1966f221b0..19f3746616 100644 --- a/gpu/include/GrGpu.h +++ b/gpu/include/GrGpu.h @@ -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 diff --git a/gpu/include/GrInOrderDrawBuffer.h b/gpu/include/GrInOrderDrawBuffer.h index c80afd9118..03a2f2d1ee 100644 --- a/gpu/include/GrInOrderDrawBuffer.h +++ b/gpu/include/GrInOrderDrawBuffer.h @@ -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; }; diff --git a/gpu/src/GrInOrderDrawBuffer.cpp b/gpu/src/GrInOrderDrawBuffer.cpp index eebae0067f..93acc12432 100644 --- a/gpu/src/GrInOrderDrawBuffer.cpp +++ b/gpu/src/GrInOrderDrawBuffer.cpp @@ -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, |