Index: src/gpu/GrBatchBuffer.h |
diff --git a/src/gpu/GrBatchBuffer.h b/src/gpu/GrBatchBuffer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3ada38ceb959a52d35e52bdb26700816e1284735 |
--- /dev/null |
+++ b/src/gpu/GrBatchBuffer.h |
@@ -0,0 +1,74 @@ |
+/* |
+ * Copyright 2015 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef GrBatchBuffer_DEFINED |
+#define GrBatchBuffer_DEFINED |
+ |
+#include "GrPendingProgramElement.h" |
+#include "GrGpu.h" |
+#include "GrTRecorder.h" |
+ |
+/* |
+ * GrBatchBuffer is a simple class which lets GrDrawTarget subclasses defer flushing of batched |
+ * Geometry for performance reasons. |
+ */ |
+ |
+class GrBatchBuffer : public SkNoncopyable { |
+public: |
+ GrBatchBuffer(GrGpu* gpu, |
+ GrVertexBufferAllocPool* vpool, |
+ GrIndexBufferAllocPool* ipool) |
+ : fGpu(gpu) |
+ , fVertexPool(vpool) |
+ , fIndexPool(ipool) |
+ , fFlushBuffer(kFlushBufferInitialSizeInBytes) {} |
+ |
+ typedef GrDrawTarget::DrawInfo DrawInfo; |
+ void initDraw(const GrPrimitiveProcessor*, const GrOptDrawState*); |
+ void draw(const GrDrawTarget::DrawInfo&); |
+ void flush(); |
+ |
+ // TODO This goes away when everything uses batch |
+ GrBatchTracker* currentBatchTracker() { |
+ SkASSERT(!fFlushBuffer.empty()); |
+ return &fFlushBuffer.back().fBatchTracker; |
+ } |
+ |
+ GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } |
+ GrIndexBufferAllocPool* indexPool() { return fIndexPool; } |
+ |
+private: |
+ GrGpu* fGpu; |
+ GrVertexBufferAllocPool* fVertexPool; |
+ GrIndexBufferAllocPool* fIndexPool; |
+ |
+ typedef void* TBufferAlign; // This wouldn't be enough align if a command used long double. |
+ typedef GrTRecorder<GrDrawTarget::DrawInfo, TBufferAlign> DrawRecorder; |
+ |
+ struct BufferedFlush { |
+ BufferedFlush(const GrPrimitiveProcessor* primProc, const GrOptDrawState* optState) |
+ : fPrimitiveProcessor(primProc) |
+ , fOptState(optState) |
+ , fDraws(kDrawRecorderInitialSizeInBytes) {} |
+ typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimitiveProcessor; |
+ ProgramPrimitiveProcessor fPrimitiveProcessor; |
+ const GrOptDrawState* fOptState; |
+ GrBatchTracker fBatchTracker; |
+ DrawRecorder fDraws; |
+ }; |
+ |
+ enum { |
+ kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), |
+ kDrawRecorderInitialSizeInBytes = 8 * sizeof(DrawInfo), |
+ }; |
+ |
+ typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; |
+ |
+ FlushBuffer fFlushBuffer; |
+}; |
+ |
+#endif |