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 "GrPendingProgramElement.h" | 11 #include "GrPendingProgramElement.h" |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "GrTRecorder.h" | 13 #include "GrTRecorder.h" |
14 | 14 |
15 /* | 15 /* |
16 * GrBatch instances use this object to allocate space for their geometry and to
issue the draws | 16 * GrBatch instances use this object to allocate space for their geometry and to
issue the draws |
17 * that render their batch. | 17 * that render their batch. |
18 */ | 18 */ |
19 | 19 |
20 class GrIndexBufferAllocPool; | |
21 class GrVertexBufferAllocPool; | |
22 | |
23 class GrBatchTarget : public SkNoncopyable { | 20 class GrBatchTarget : public SkNoncopyable { |
24 public: | 21 public: |
25 GrBatchTarget(GrGpu* gpu, | 22 GrBatchTarget(GrGpu* gpu, |
26 GrVertexBufferAllocPool* vpool, | 23 GrVertexBufferAllocPool* vpool, |
27 GrIndexBufferAllocPool* ipool) | 24 GrIndexBufferAllocPool* ipool) |
28 : fGpu(gpu) | 25 : fGpu(gpu) |
29 , fVertexPool(vpool) | 26 , fVertexPool(vpool) |
30 , fIndexPool(ipool) | 27 , fIndexPool(ipool) |
31 , fFlushBuffer(kFlushBufferInitialSizeInBytes) | 28 , fFlushBuffer(kFlushBufferInitialSizeInBytes) |
32 , fIter(fFlushBuffer) | 29 , fIter(fFlushBuffer) {} |
33 , fNumberOfDraws(0) {} | |
34 | 30 |
35 typedef GrDrawTarget::DrawInfo DrawInfo; | 31 typedef GrDrawTarget::DrawInfo DrawInfo; |
36 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli
ne) { | 32 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli
ne) { |
37 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin
e)); | 33 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin
e)); |
38 fNumberOfDraws++; | |
39 } | 34 } |
40 | 35 |
41 void draw(const GrDrawTarget::DrawInfo& draw) { | 36 void draw(const GrDrawTarget::DrawInfo& draw) { |
42 fFlushBuffer.back().fDraws.push_back(draw); | 37 fFlushBuffer.back().fDraws.push_back(draw); |
43 } | 38 } |
44 | 39 |
45 // TODO this is temporary until batch is everywhere | 40 // TODO this is temporary until batch is everywhere |
46 //void flush(); | 41 //void flush(); |
47 void resetNumberOfDraws() { fNumberOfDraws = 0; } | |
48 int numberOfDraws() const { return fNumberOfDraws; } | |
49 void preFlush() { fIter = FlushBuffer::Iter(fFlushBuffer); } | 42 void preFlush() { fIter = FlushBuffer::Iter(fFlushBuffer); } |
50 void flushNext(int n); | 43 void flushNext(); |
51 void postFlush() { SkASSERT(!fIter.next()); fFlushBuffer.reset(); } | 44 void postFlush() { SkASSERT(!fIter.next()); fFlushBuffer.reset(); } |
52 | 45 |
53 // TODO This goes away when everything uses batch | 46 // TODO This goes away when everything uses batch |
54 GrBatchTracker* currentBatchTracker() { | 47 GrBatchTracker* currentBatchTracker() { |
55 SkASSERT(!fFlushBuffer.empty()); | 48 SkASSERT(!fFlushBuffer.empty()); |
56 return &fFlushBuffer.back().fBatchTracker; | 49 return &fFlushBuffer.back().fBatchTracker; |
57 } | 50 } |
58 | 51 |
59 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); } | |
60 | |
61 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } | 52 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } |
62 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } | 53 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } |
63 | 54 |
64 private: | 55 private: |
65 GrGpu* fGpu; | 56 GrGpu* fGpu; |
66 GrVertexBufferAllocPool* fVertexPool; | 57 GrVertexBufferAllocPool* fVertexPool; |
67 GrIndexBufferAllocPool* fIndexPool; | 58 GrIndexBufferAllocPool* fIndexPool; |
68 | 59 |
69 typedef void* TBufferAlign; // This wouldn't be enough align if a command us
ed long double. | 60 typedef void* TBufferAlign; // This wouldn't be enough align if a command us
ed long double. |
70 | 61 |
71 struct BufferedFlush { | 62 struct BufferedFlush { |
72 BufferedFlush(const GrPrimitiveProcessor* primProc, const GrPipeline* pi
peline) | 63 BufferedFlush(const GrPrimitiveProcessor* primProc, const GrPipeline* pi
peline) |
73 : fPrimitiveProcessor(primProc) | 64 : fPrimitiveProcessor(primProc) |
74 , fPipeline(pipeline) {} | 65 , fPipeline(pipeline) |
| 66 , fDraws(kDrawRecorderInitialSizeInBytes) {} |
75 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; | 67 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi
tiveProcessor; |
76 ProgramPrimitiveProcessor fPrimitiveProcessor; | 68 ProgramPrimitiveProcessor fPrimitiveProcessor; |
77 const GrPipeline* fPipeline; | 69 const GrPipeline* fPipeline; |
78 GrBatchTracker fBatchTracker; | 70 GrBatchTracker fBatchTracker; |
79 SkSTArray<4, DrawInfo, true> fDraws; | 71 SkSTArray<4, DrawInfo, true> fDraws; |
80 }; | 72 }; |
81 | 73 |
82 enum { | 74 enum { |
83 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), | 75 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), |
| 76 kDrawRecorderInitialSizeInBytes = 8 * sizeof(DrawInfo), |
84 }; | 77 }; |
85 | 78 |
86 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; | 79 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; |
87 | 80 |
88 FlushBuffer fFlushBuffer; | 81 FlushBuffer fFlushBuffer; |
89 // TODO this is temporary | 82 // TODO this is temporary |
90 FlushBuffer::Iter fIter; | 83 FlushBuffer::Iter fIter; |
91 int fNumberOfDraws; | |
92 }; | 84 }; |
93 | 85 |
94 #endif | 86 #endif |
OLD | NEW |