| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrBatchBuffer_DEFINED | 8 #ifndef GrBatchBuffer_DEFINED |
| 9 #define GrBatchBuffer_DEFINED | 9 #define GrBatchBuffer_DEFINED |
| 10 | 10 |
| 11 #include "GrBatchAtlas.h" |
| 11 #include "GrBufferAllocPool.h" | 12 #include "GrBufferAllocPool.h" |
| 12 #include "GrPendingProgramElement.h" | 13 #include "GrPendingProgramElement.h" |
| 13 #include "GrPipeline.h" | 14 #include "GrPipeline.h" |
| 14 #include "GrGpu.h" | 15 #include "GrGpu.h" |
| 15 #include "GrTRecorder.h" | 16 #include "GrTRecorder.h" |
| 16 | 17 |
| 17 /* | 18 /* |
| 18 * GrBatch instances use this object to allocate space for their geometry and to
issue the draws | 19 * GrBatch instances use this object to allocate space for their geometry and to
issue the draws |
| 19 * that render their batch. | 20 * that render their batch. |
| 20 */ | 21 */ |
| 21 | 22 |
| 22 class GrIndexBufferAllocPool; | 23 class GrIndexBufferAllocPool; |
| 23 class GrVertexBufferAllocPool; | 24 class GrVertexBufferAllocPool; |
| 24 | 25 |
| 25 class GrBatchTarget : public SkNoncopyable { | 26 class GrBatchTarget : public SkNoncopyable { |
| 26 public: | 27 public: |
| 28 typedef GrDrawTarget::BatchToken BatchToken; |
| 27 GrBatchTarget(GrGpu* gpu, | 29 GrBatchTarget(GrGpu* gpu, |
| 28 GrVertexBufferAllocPool* vpool, | 30 GrVertexBufferAllocPool* vpool, |
| 29 GrIndexBufferAllocPool* ipool) | 31 GrIndexBufferAllocPool* ipool); |
| 30 : fGpu(gpu) | |
| 31 , fVertexPool(vpool) | |
| 32 , fIndexPool(ipool) | |
| 33 , fFlushBuffer(kFlushBufferInitialSizeInBytes) | |
| 34 , fIter(fFlushBuffer) | |
| 35 , fNumberOfDraws(0) {} | |
| 36 | 32 |
| 37 typedef GrDrawTarget::DrawInfo DrawInfo; | 33 typedef GrDrawTarget::DrawInfo DrawInfo; |
| 38 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli
ne) { | 34 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli
ne) { |
| 39 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin
e)); | 35 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin
e)); |
| 40 fNumberOfDraws++; | 36 fNumberOfDraws++; |
| 37 fCurrentToken++; |
| 38 } |
| 39 |
| 40 void update(GrPlotUpdater updater) { |
| 41 BatchToken updaterToken = updater.lastUploadToken(); |
| 42 if (this->asapToken() == updaterToken) { |
| 43 fAsapUpdates.push_back(updater); |
| 44 } else { |
| 45 fInlineUpdates.push_back(updater); |
| 46 } |
| 41 } | 47 } |
| 42 | 48 |
| 43 void draw(const GrDrawTarget::DrawInfo& draw) { | 49 void draw(const GrDrawTarget::DrawInfo& draw) { |
| 44 fFlushBuffer.back().fDraws.push_back(draw); | 50 fFlushBuffer.back().fDraws.push_back(draw); |
| 45 } | 51 } |
| 46 | 52 |
| 47 // TODO this is temporary until batch is everywhere | 53 bool isIssued(BatchToken token) const { return fLastFlushedToken >= token; } |
| 48 //void flush(); | 54 BatchToken currentToken() const { return fCurrentToken; } |
| 55 BatchToken asapToken() const { return fLastFlushedToken + 1; } |
| 56 |
| 57 // TODO much of this complexity goes away when batch is everywhere |
| 49 void resetNumberOfDraws() { fNumberOfDraws = 0; } | 58 void resetNumberOfDraws() { fNumberOfDraws = 0; } |
| 50 int numberOfDraws() const { return fNumberOfDraws; } | 59 int numberOfDraws() const { return fNumberOfDraws; } |
| 51 void preFlush() { fIter = FlushBuffer::Iter(fFlushBuffer); } | 60 void preFlush() { |
| 52 void flushNext(int n) { | 61 int updateCount = fAsapUpdates.count(); |
| 53 for (; n > 0; n--) { | 62 for (int i = 0; i < updateCount; i++) { |
| 54 SkDEBUGCODE(bool verify =) fIter.next(); | 63 fAsapUpdates[i].update(); |
| 55 SkASSERT(verify); | |
| 56 GrProgramDesc desc; | |
| 57 BufferedFlush* bf = fIter.get(); | |
| 58 const GrPipeline* pipeline = bf->fPipeline; | |
| 59 const GrPrimitiveProcessor* primProc = bf->fPrimitiveProcessor.get()
; | |
| 60 fGpu->buildProgramDesc(&desc, *primProc, *pipeline, bf->fBatchTracke
r); | |
| 61 | |
| 62 GrGpu::DrawArgs args(primProc, pipeline, &desc, &bf->fBatchTracker); | |
| 63 | |
| 64 int drawCount = bf->fDraws.count(); | |
| 65 const SkSTArray<1, DrawInfo, true>& draws = bf->fDraws; | |
| 66 for (int i = 0; i < drawCount; i++) { | |
| 67 fGpu->draw(args, draws[i]); | |
| 68 } | |
| 69 } | 64 } |
| 65 fInlineUpdatesIndex = 0; |
| 66 fIter = FlushBuffer::Iter(fFlushBuffer); |
| 70 } | 67 } |
| 71 void postFlush() { SkASSERT(!fIter.next()); fFlushBuffer.reset(); } | 68 void flushNext(int n); |
| 69 void postFlush() { |
| 70 SkASSERT(!fIter.next()); |
| 71 fFlushBuffer.reset(); |
| 72 fAsapUpdates.reset(); |
| 73 fInlineUpdates.reset(); |
| 74 } |
| 72 | 75 |
| 73 // TODO This goes away when everything uses batch | 76 // TODO This goes away when everything uses batch |
| 74 GrBatchTracker* currentBatchTracker() { | 77 GrBatchTracker* currentBatchTracker() { |
| 75 SkASSERT(!fFlushBuffer.empty()); | 78 SkASSERT(!fFlushBuffer.empty()); |
| 76 return &fFlushBuffer.back().fBatchTracker; | 79 return &fFlushBuffer.back().fBatchTracker; |
| 77 } | 80 } |
| 78 | 81 |
| 79 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); } | 82 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); } |
| 80 | 83 |
| 81 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } | 84 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } |
| 82 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } | 85 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } |
| 83 | 86 |
| 87 const static int kVertsPerRect = 4; |
| 88 const static int kIndicesPerRect = 6; |
| 84 const GrIndexBuffer* quadIndexBuffer() const { return fGpu->getQuadIndexBuff
er(); } | 89 const GrIndexBuffer* quadIndexBuffer() const { return fGpu->getQuadIndexBuff
er(); } |
| 85 | 90 |
| 86 // A helper for draws which overallocate and then return data to the pool | 91 // A helper for draws which overallocate and then return data to the pool |
| 87 void putBackIndices(size_t indices) { fIndexPool->putBack(indices * sizeof(u
int16_t)); } | 92 void putBackIndices(size_t indices) { fIndexPool->putBack(indices * sizeof(u
int16_t)); } |
| 88 | 93 |
| 89 void putBackVertices(size_t vertices, size_t vertexStride) { | 94 void putBackVertices(size_t vertices, size_t vertexStride) { |
| 90 fVertexPool->putBack(vertices * vertexStride); | 95 fVertexPool->putBack(vertices * vertexStride); |
| 91 } | 96 } |
| 92 | 97 |
| 93 private: | 98 private: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 111 enum { | 116 enum { |
| 112 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), | 117 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), |
| 113 }; | 118 }; |
| 114 | 119 |
| 115 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; | 120 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; |
| 116 | 121 |
| 117 FlushBuffer fFlushBuffer; | 122 FlushBuffer fFlushBuffer; |
| 118 // TODO this is temporary | 123 // TODO this is temporary |
| 119 FlushBuffer::Iter fIter; | 124 FlushBuffer::Iter fIter; |
| 120 int fNumberOfDraws; | 125 int fNumberOfDraws; |
| 126 BatchToken fCurrentToken; |
| 127 BatchToken fLastFlushedToken; // The next token to be flushed |
| 128 SkTArray<GrPlotUpdater, true> fAsapUpdates; |
| 129 SkTArray<GrPlotUpdater, true> fInlineUpdates; |
| 130 int fInlineUpdatesIndex; |
| 121 }; | 131 }; |
| 122 | 132 |
| 123 #endif | 133 #endif |
| OLD | NEW |