Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1418)

Side by Side Diff: src/gpu/GrBatchTarget.h

Issue 1131553002: Isolate GrBufferAllocPools inside GrBatchTarget (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrBatch.cpp ('k') | src/gpu/GrBatchTarget.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "GrBatchAtlas.h"
12 #include "GrBufferAllocPool.h" 12 #include "GrBufferAllocPool.h"
13 #include "GrPendingProgramElement.h" 13 #include "GrPendingProgramElement.h"
14 #include "GrPipeline.h" 14 #include "GrPipeline.h"
15 #include "GrTRecorder.h" 15 #include "GrTRecorder.h"
16 #include "GrVertices.h" 16 #include "GrVertices.h"
17 17
18 /* 18 /*
19 * 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
20 * that render their batch. 20 * that render their batch.
21 */ 21 */
22
23 class GrIndexBufferAllocPool;
24 class GrVertexBufferAllocPool;
25
26 class GrBatchTarget : public SkNoncopyable { 22 class GrBatchTarget : public SkNoncopyable {
27 public: 23 public:
28 typedef GrBatchAtlas::BatchToken BatchToken; 24 typedef GrBatchAtlas::BatchToken BatchToken;
29 GrBatchTarget(GrGpu* gpu, 25 GrBatchTarget(GrGpu* gpu);
30 GrVertexBufferAllocPool* vpool,
31 GrIndexBufferAllocPool* ipool);
32 26
33 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) { 27 void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeli ne) {
34 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e)); 28 GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipelin e));
35 fNumberOfDraws++; 29 fNumberOfDraws++;
36 fCurrentToken++; 30 fCurrentToken++;
37 } 31 }
38 32
39 class TextureUploader { 33 class TextureUploader {
40 public: 34 public:
41 TextureUploader(GrGpu* gpu) : fGpu(gpu) { SkASSERT(gpu); } 35 TextureUploader(GrGpu* gpu) : fGpu(gpu) { SkASSERT(gpu); }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 81 }
88 82
89 bool isIssued(BatchToken token) const { return fLastFlushedToken >= token; } 83 bool isIssued(BatchToken token) const { return fLastFlushedToken >= token; }
90 BatchToken currentToken() const { return fCurrentToken; } 84 BatchToken currentToken() const { return fCurrentToken; }
91 BatchToken asapToken() const { return fLastFlushedToken + 1; } 85 BatchToken asapToken() const { return fLastFlushedToken + 1; }
92 86
93 // TODO much of this complexity goes away when batch is everywhere 87 // TODO much of this complexity goes away when batch is everywhere
94 void resetNumberOfDraws() { fNumberOfDraws = 0; } 88 void resetNumberOfDraws() { fNumberOfDraws = 0; }
95 int numberOfDraws() const { return fNumberOfDraws; } 89 int numberOfDraws() const { return fNumberOfDraws; }
96 void preFlush() { 90 void preFlush() {
91 this->unmapVertexAndIndexBuffers();
97 int updateCount = fAsapUploads.count(); 92 int updateCount = fAsapUploads.count();
98 for (int i = 0; i < updateCount; i++) { 93 for (int i = 0; i < updateCount; i++) {
99 fAsapUploads[i]->upload(TextureUploader(fGpu)); 94 fAsapUploads[i]->upload(TextureUploader(fGpu));
100 } 95 }
101 fInlineUpdatesIndex = 0; 96 fInlineUpdatesIndex = 0;
102 fIter = FlushBuffer::Iter(fFlushBuffer); 97 fIter = FlushBuffer::Iter(fFlushBuffer);
103 } 98 }
104 void flushNext(int n); 99 void flushNext(int n);
105 void postFlush() { 100 void postFlush() {
106 SkASSERT(!fIter.next()); 101 SkASSERT(!fIter.next());
107 fFlushBuffer.reset(); 102 fFlushBuffer.reset();
108 fAsapUploads.reset(); 103 fAsapUploads.reset();
109 fInlineUploads.reset(); 104 fInlineUploads.reset();
110 } 105 }
111 106
112 // TODO This goes away when everything uses batch 107 // TODO This goes away when everything uses batch
113 GrBatchTracker* currentBatchTracker() { 108 GrBatchTracker* currentBatchTracker() {
114 SkASSERT(!fFlushBuffer.empty()); 109 SkASSERT(!fFlushBuffer.empty());
115 return &fFlushBuffer.back().fBatchTracker; 110 return &fFlushBuffer.back().fBatchTracker;
116 } 111 }
117 112
118 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); } 113 const GrDrawTargetCaps& caps() const { return *fGpu->caps(); }
119 114
120 GrVertexBufferAllocPool* vertexPool() { return fVertexPool; } 115 GrResourceProvider* resourceProvider() const { return fGpu->getContext()->re sourceProvider(); }
121 GrIndexBufferAllocPool* indexPool() { return fIndexPool; }
122 116
123 GrResourceProvider* resourceProvider() const { return fGpu->getContext()->re sourceProvider(); } 117 void* makeVertSpace(size_t vertexSize, int vertexCount,
118 const GrVertexBuffer** buffer, int* startVertex);
119 uint16_t* makeIndexSpace(int indexCount,
120 const GrIndexBuffer** buffer, int* startIndex);
124 121
125 // A helper for draws which overallocate and then return data to the pool 122 // A helper for draws which overallocate and then return data to the pool
126 void putBackIndices(size_t indices) { fIndexPool->putBack(indices * sizeof(u int16_t)); } 123 void putBackIndices(size_t indices) { fIndexPool->putBack(indices * sizeof(u int16_t)); }
127 124
128 void putBackVertices(size_t vertices, size_t vertexStride) { 125 void putBackVertices(size_t vertices, size_t vertexStride) {
129 fVertexPool->putBack(vertices * vertexStride); 126 fVertexPool->putBack(vertices * vertexStride);
130 } 127 }
131 128
129 void reset() {
130 fVertexPool->reset();
131 fIndexPool->reset();
132 }
133
132 private: 134 private:
135 void unmapVertexAndIndexBuffers() {
136 fVertexPool->unmap();
137 fIndexPool->unmap();
138 }
139
133 GrGpu* fGpu; 140 GrGpu* fGpu;
134 GrVertexBufferAllocPool* fVertexPool; 141 SkAutoTDelete<GrVertexBufferAllocPool> fVertexPool;
135 GrIndexBufferAllocPool* fIndexPool; 142 SkAutoTDelete<GrIndexBufferAllocPool> fIndexPool;
136 143
137 typedef void* TBufferAlign; // This wouldn't be enough align if a command us ed long double. 144 typedef void* TBufferAlign; // This wouldn't be enough align if a command us ed long double.
138 145
139 struct BufferedFlush { 146 struct BufferedFlush {
140 BufferedFlush(const GrPrimitiveProcessor* primProc, const GrPipeline* pi peline) 147 BufferedFlush(const GrPrimitiveProcessor* primProc, const GrPipeline* pi peline)
141 : fPrimitiveProcessor(primProc) 148 : fPrimitiveProcessor(primProc)
142 , fPipeline(pipeline) {} 149 , fPipeline(pipeline) {}
143 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor; 150 typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimi tiveProcessor;
144 ProgramPrimitiveProcessor fPrimitiveProcessor; 151 ProgramPrimitiveProcessor fPrimitiveProcessor;
145 const GrPipeline* fPipeline; 152 const GrPipeline* fPipeline;
(...skipping 12 matching lines...) Expand all
158 FlushBuffer::Iter fIter; 165 FlushBuffer::Iter fIter;
159 int fNumberOfDraws; 166 int fNumberOfDraws;
160 BatchToken fCurrentToken; 167 BatchToken fCurrentToken;
161 BatchToken fLastFlushedToken; // The next token to be flushed 168 BatchToken fLastFlushedToken; // The next token to be flushed
162 SkTArray<SkAutoTUnref<Uploader>, true> fAsapUploads; 169 SkTArray<SkAutoTUnref<Uploader>, true> fAsapUploads;
163 SkTArray<SkAutoTUnref<Uploader>, true> fInlineUploads; 170 SkTArray<SkAutoTUnref<Uploader>, true> fInlineUploads;
164 int fInlineUpdatesIndex; 171 int fInlineUpdatesIndex;
165 }; 172 };
166 173
167 #endif 174 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrBatch.cpp ('k') | src/gpu/GrBatchTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698