Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #ifndef GrBatchBuffer_DEFINED | |
| 9 #define GrBatchBuffer_DEFINED | |
| 10 | |
| 11 #include "GrPendingProgramElement.h" | |
| 12 #include "GrGpu.h" | |
| 13 #include "GrTRecorder.h" | |
| 14 | |
| 15 /* | |
| 16 * GrBatchBuffer is a simple class which lets GrDrawTarget subclasses defer flus hing of batched | |
|
bsalomon
2015/01/21 21:39:29
I'm not crazy about this name
GrBatchTarget?
Pro
| |
| 17 * Geometry for performance reasons. | |
| 18 */ | |
| 19 | |
| 20 class GrBatchBuffer : public SkNoncopyable { | |
| 21 public: | |
| 22 GrBatchBuffer(GrGpu* gpu, | |
| 23 GrVertexBufferAllocPool* vpool, | |
| 24 GrIndexBufferAllocPool* ipool) | |
| 25 : fGpu(gpu) | |
| 26 , fVertexPool(vpool) | |
| 27 , fIndexPool(ipool) | |
| 28 , fFlushBuffer(kFlushBufferInitialSizeInBytes) {} | |
| 29 | |
| 30 typedef GrDrawTarget::DrawInfo DrawInfo; | |
| 31 void initDraw(const GrPrimitiveProcessor* primProc, const GrOptDrawState* op tState) { | |
| 32 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, optStat e)); | |
| 33 } | |
| 34 | |
| 35 void draw(const GrDrawTarget::DrawInfo& draw) { | |
| 36 fFlushBuffer.back().fDraws.push_back(draw); | |
| 37 } | |
| 38 void flush(); | |
| 39 | |
| 40 // TODO This goes away when everything uses batch | |
| 41 GrBatchTracker* currentBatchTracker() { | |
| 42 SkASSERT(!fFlushBuffer.empty()); | |
| 43 return &fFlushBuffer.back().fBatchTracker; | |
| 44 } | |
| 45 | |
| 46 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } | |
| 47 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } | |
| 48 | |
| 49 private: | |
| 50 GrGpu* fGpu; | |
| 51 GrVertexBufferAllocPool* fVertexPool; | |
| 52 GrIndexBufferAllocPool* fIndexPool; | |
| 53 | |
| 54 typedef void* TBufferAlign; // This wouldn't be enough align if a command us ed long double. | |
| 55 | |
| 56 struct BufferedFlush { | |
| 57 BufferedFlush(const GrPrimitiveProcessor* primProc, const GrOptDrawState * optState) | |
| 58 : fPrimitiveProcessor(primProc) | |
| 59 , fOptState(optState) | |
| 60 , fDraws(kDrawRecorderInitialSizeInBytes) {} | |
| 61 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor; | |
| 62 ProgramPrimitiveProcessor fPrimitiveProcessor; | |
| 63 const GrOptDrawState* fOptState; | |
| 64 GrBatchTracker fBatchTracker; | |
| 65 SkSTArray<4, DrawInfo, true> fDraws; | |
| 66 }; | |
| 67 | |
| 68 enum { | |
| 69 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), | |
| 70 kDrawRecorderInitialSizeInBytes = 8 * sizeof(DrawInfo), | |
| 71 }; | |
| 72 | |
| 73 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; | |
| 74 | |
| 75 FlushBuffer fFlushBuffer; | |
| 76 }; | |
| 77 | |
| 78 #endif | |
| OLD | NEW |