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 |
18 class GrTextureUploader { | |
bsalomon
2015/03/11 13:34:12
Nest this and uploader in BatchTarget? They seem o
joshualitt
2015/03/11 16:03:27
Acknowledged.
| |
19 public: | |
20 GrTextureUploader(GrGpu* gpu) : fGpu(gpu) { SkASSERT(gpu); } | |
21 | |
22 /** | |
23 * Updates the pixels in a rectangle of a texture. | |
24 * | |
25 * @param left left edge of the rectangle to write (inclusive) | |
26 * @param top top edge of the rectangle to write (inclusive) | |
27 * @param width width of rectangle to write in pixels. | |
28 * @param height height of rectangle to write in pixels. | |
29 * @param config the pixel config of the source buffer | |
30 * @param buffer memory to read pixels from | |
31 * @param rowBytes number of bytes between consecutive rows. Zero | |
32 * means rows are tightly packed. | |
33 */ | |
34 bool writeTexturePixels(GrTexture* texture, | |
35 int left, int top, int width, int height, | |
36 GrPixelConfig config, const void* buffer, | |
37 size_t rowBytes) { | |
38 return fGpu->writeTexturePixels(texture, left, top, width, height, confi g, buffer, | |
39 rowBytes); | |
40 } | |
41 | |
42 private: | |
43 GrGpu* fGpu; | |
44 }; | |
45 | |
46 class GrUploader : public SkRefCnt { | |
47 public: | |
48 typedef GrDrawTarget::BatchToken BatchToken; | |
49 GrUploader(BatchToken lastUploadToken) : fLastUploadToken(lastUploadToken) { } | |
50 BatchToken lastUploadToken() const { return fLastUploadToken; } | |
51 virtual void upload(GrTextureUploader)=0; | |
52 | |
53 private: | |
54 BatchToken fLastUploadToken; | |
55 }; | |
56 | |
17 /* | 57 /* |
18 * GrBatch instances use this object to allocate space for their geometry and to issue the draws | 58 * GrBatch instances use this object to allocate space for their geometry and to issue the draws |
19 * that render their batch. | 59 * that render their batch. |
20 */ | 60 */ |
21 | 61 |
22 class GrIndexBufferAllocPool; | 62 class GrIndexBufferAllocPool; |
23 class GrVertexBufferAllocPool; | 63 class GrVertexBufferAllocPool; |
24 | 64 |
25 class GrBatchTarget : public SkNoncopyable { | 65 class GrBatchTarget : public SkNoncopyable { |
26 public: | 66 public: |
67 typedef GrDrawTarget::BatchToken BatchToken; | |
27 GrBatchTarget(GrGpu* gpu, | 68 GrBatchTarget(GrGpu* gpu, |
28 GrVertexBufferAllocPool* vpool, | 69 GrVertexBufferAllocPool* vpool, |
29 GrIndexBufferAllocPool* ipool) | 70 GrIndexBufferAllocPool* ipool); |
30 : fGpu(gpu) | |
31 , fVertexPool(vpool) | |
32 , fIndexPool(ipool) | |
33 , fFlushBuffer(kFlushBufferInitialSizeInBytes) | |
34 , fIter(fFlushBuffer) | |
35 , fNumberOfDraws(0) {} | |
36 | 71 |
37 typedef GrDrawTarget::DrawInfo DrawInfo; | 72 typedef GrDrawTarget::DrawInfo DrawInfo; |
38 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) { | 73 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) { |
39 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e)); | 74 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e)); |
40 fNumberOfDraws++; | 75 fNumberOfDraws++; |
76 fCurrentToken++; | |
77 } | |
78 | |
79 void upload(GrUploader* upload) { | |
80 if (this->asapToken() == upload->lastUploadToken()) { | |
81 fAsapUploads.push_back().reset(SkRef(upload)); | |
82 } else { | |
83 fInlineUploads.push_back().reset(SkRef(upload)); | |
84 } | |
41 } | 85 } |
42 | 86 |
43 void draw(const GrDrawTarget::DrawInfo& draw) { | 87 void draw(const GrDrawTarget::DrawInfo& draw) { |
44 fFlushBuffer.back().fDraws.push_back(draw); | 88 fFlushBuffer.back().fDraws.push_back(draw); |
45 } | 89 } |
46 | 90 |
47 // TODO this is temporary until batch is everywhere | 91 bool isIssued(BatchToken token) const { return fLastFlushedToken >= token; } |
48 //void flush(); | 92 BatchToken currentToken() const { return fCurrentToken; } |
93 BatchToken asapToken() const { return fLastFlushedToken + 1; } | |
94 | |
95 // TODO much of this complexity goes away when batch is everywhere | |
49 void resetNumberOfDraws() { fNumberOfDraws = 0; } | 96 void resetNumberOfDraws() { fNumberOfDraws = 0; } |
50 int numberOfDraws() const { return fNumberOfDraws; } | 97 int numberOfDraws() const { return fNumberOfDraws; } |
51 void preFlush() { fIter = FlushBuffer::Iter(fFlushBuffer); } | 98 void preFlush() { |
52 void flushNext(int n) { | 99 int updateCount = fAsapUploads.count(); |
53 for (; n > 0; n--) { | 100 for (int i = 0; i < updateCount; i++) { |
54 SkDEBUGCODE(bool verify =) fIter.next(); | 101 fAsapUploads[i]->upload(GrTextureUploader(fGpu)); |
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 } | 102 } |
103 fInlineUpdatesIndex = 0; | |
104 fIter = FlushBuffer::Iter(fFlushBuffer); | |
70 } | 105 } |
71 void postFlush() { SkASSERT(!fIter.next()); fFlushBuffer.reset(); } | 106 void flushNext(int n); |
107 void postFlush() { | |
108 SkASSERT(!fIter.next()); | |
109 fFlushBuffer.reset(); | |
110 fAsapUploads.reset(); | |
111 fInlineUploads.reset(); | |
112 } | |
72 | 113 |
73 // TODO This goes away when everything uses batch | 114 // TODO This goes away when everything uses batch |
74 GrBatchTracker* currentBatchTracker() { | 115 GrBatchTracker* currentBatchTracker() { |
75 SkASSERT(!fFlushBuffer.empty()); | 116 SkASSERT(!fFlushBuffer.empty()); |
76 return &fFlushBuffer.back().fBatchTracker; | 117 return &fFlushBuffer.back().fBatchTracker; |
77 } | 118 } |
78 | 119 |
79 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); } | 120 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); } |
80 | 121 |
81 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } | 122 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } |
82 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } | 123 GrIndexBufferAllocPool* indexPool() { return fIndexPool; } |
83 | 124 |
125 const static int kVertsPerRect = 4; | |
126 const static int kIndicesPerRect = 6; | |
84 const GrIndexBuffer* quadIndexBuffer() const { return fGpu->getQuadIndexBuff er(); } | 127 const GrIndexBuffer* quadIndexBuffer() const { return fGpu->getQuadIndexBuff er(); } |
85 | 128 |
86 // A helper for draws which overallocate and then return data to the pool | 129 // 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)); } | 130 void putBackIndices(size_t indices) { fIndexPool->putBack(indices * sizeof(u int16_t)); } |
88 | 131 |
89 void putBackVertices(size_t vertices, size_t vertexStride) { | 132 void putBackVertices(size_t vertices, size_t vertexStride) { |
90 fVertexPool->putBack(vertices * vertexStride); | 133 fVertexPool->putBack(vertices * vertexStride); |
91 } | 134 } |
92 | 135 |
93 private: | 136 private: |
(...skipping 17 matching lines...) Expand all Loading... | |
111 enum { | 154 enum { |
112 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), | 155 kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush), |
113 }; | 156 }; |
114 | 157 |
115 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; | 158 typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer; |
116 | 159 |
117 FlushBuffer fFlushBuffer; | 160 FlushBuffer fFlushBuffer; |
118 // TODO this is temporary | 161 // TODO this is temporary |
119 FlushBuffer::Iter fIter; | 162 FlushBuffer::Iter fIter; |
120 int fNumberOfDraws; | 163 int fNumberOfDraws; |
164 BatchToken fCurrentToken; | |
165 BatchToken fLastFlushedToken; // The next token to be flushed | |
166 SkTArray<SkAutoTUnref<GrUploader>, true> fAsapUploads; | |
167 SkTArray<SkAutoTUnref<GrUploader>, true> fInlineUploads; | |
168 int fInlineUpdatesIndex; | |
121 }; | 169 }; |
122 | 170 |
123 #endif | 171 #endif |
OLD | NEW |