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
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 @@
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 @@
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 @@
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 @@
int* vertexCount,
int* indexCount) const;
+ virtual void clear(GrColor color);
+
private:
struct Draw {
@@ -115,6 +117,11 @@
const GrIndexBuffer* fIndexBuffer;
};
+ struct Clear {
+ int fBeforeDrawIdx;
+ GrColor fColor;
+ };
+
virtual bool onAcquireGeometry(GrVertexLayout vertexLayout,
void** vertices,
void** indices);
@@ -135,6 +142,7 @@
GrTAllocator<Draw> fDraws;
GrTAllocator<SavedDrawState> fStates;
+ GrTAllocator<Clear> fClears;
GrTAllocator<GrClip> fClips;
bool fClipSet;
@@ -163,11 +171,13 @@
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 eebae00..93acc12 100644
--- a/gpu/src/GrInOrderDrawBuffer.cpp
+++ b/gpu/src/GrInOrderDrawBuffer.cpp
@@ -26,6 +26,7 @@
GrIndexBufferAllocPool* indexPool) :
fDraws(&fDrawStorage),
fStates(&fStateStorage),
+ fClears(&fClearStorage),
fClips(&fClipStorage),
fClipSet(true),
@@ -287,6 +288,16 @@
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 @@
fDraws.reset();
fStates.reset();
+ fClears.reset();
+
fVertexPool.reset();
fIndexPool.reset();
@@ -336,8 +349,15 @@
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 @@
draw.fVertexCount);
}
}
+ while (currClear < fClears.count()) {
+ GrAssert(fDraws.count() == fClears[currClear].fBeforeDrawIdx);
+ target->clear(fClears[currClear].fColor);
+ ++currClear;
+ }
}
bool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout,