From 0b335c1ac100aeacf79a4c98a052286fd46661e7 Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Mon, 25 Apr 2011 19:17:44 +0000 Subject: [PATCH] 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 --- gpu/include/GrDrawTarget.h | 6 ++++++ gpu/include/GrGpu.h | 8 +------- gpu/include/GrInOrderDrawBuffer.h | 10 ++++++++++ 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 038e776..1be2601 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 1966f22..19f3746 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 c80afd9..03a2f2d 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 fDraws; GrTAllocator fStates; + GrTAllocator fClears; GrTAllocator fClips; bool fClipSet; @@ -163,11 +171,13 @@ private: kDrawPreallocCnt = 8, kStatePreallocCnt = 8, kClipPreallocCnt = 8, + kClearPreallocCnt = 4, }; GrAlignedSTStorage fDrawStorage; GrAlignedSTStorage fStateStorage; GrAlignedSTStorage fClipStorage; + GrAlignedSTStorage fClearStorage; typedef GrDrawTarget INHERITED; }; diff --git a/gpu/src/GrInOrderDrawBuffer.cpp b/gpu/src/GrInOrderDrawBuffer.cpp index eebae00..93acc12 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, -- 2.7.4