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

Side by Side Diff: src/gpu/batches/GrBatch.h

Issue 1296483002: Split GrDrawBatch and GrVertexBatch into their own files (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add new files to git Created 5 years, 4 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/batches/GrBWFillRectBatch.cpp ('k') | src/gpu/batches/GrBatch.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 GrBatch_DEFINED 8 #ifndef GrBatch_DEFINED
9 #define GrBatch_DEFINED 9 #define GrBatch_DEFINED
10 10
11 #include <new> 11 #include <new>
12 #include "GrBatchTarget.h"
13 #include "GrGeometryProcessor.h"
14 #include "GrNonAtomicRef.h" 12 #include "GrNonAtomicRef.h"
15 #include "GrVertices.h"
16 #include "SkAtomics.h"
17 #include "SkTypes.h"
18 13
19 class GrGpu; 14 #include "SkRect.h"
20 class GrPipeline;
21 15
22 struct GrInitInvariantOutput; 16 class GrCaps;
23 17
24 /** 18 /**
25 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa cilitate 19 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa cilitate
26 * reorderable batching, Ganesh does not generate geometry inline with draw call s. Instead, it 20 * reorderable batching, Ganesh does not generate geometry inline with draw call s. Instead, it
27 * captures the arguments to the draw and then generates the geometry on demand. This gives GrBatch 21 * captures the arguments to the draw and then generates the geometry on demand. This gives GrBatch
28 * subclasses complete freedom to decide how / what they can batch. 22 * subclasses complete freedom to decide how / what they can batch.
29 * 23 *
30 * Batches are created when GrContext processes a draw call. Batches of the same subclass may be 24 * Batches are created when GrContext processes a draw call. Batches of the same subclass may be
31 * merged using combineIfPossible. When two batches merge, one takes on the unio n of the data 25 * merged using combineIfPossible. When two batches merge, one takes on the unio n of the data
32 * and the other is left empty. The merged batch becomes responsible for drawing the data from both 26 * and the other is left empty. The merged batch becomes responsible for drawing the data from both
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 uint32_t fClassID; 117 uint32_t fClassID;
124 SkDEBUGCODE(bool fUsed;) 118 SkDEBUGCODE(bool fUsed;)
125 #if GR_BATCH_SPEW 119 #if GR_BATCH_SPEW
126 uint32_t fUniqueID; 120 uint32_t fUniqueID;
127 static int32_t gCurrBatchUniqueID; 121 static int32_t gCurrBatchUniqueID;
128 #endif 122 #endif
129 static int32_t gCurrBatchClassID; 123 static int32_t gCurrBatchClassID;
130 typedef GrNonAtomicRef INHERITED; 124 typedef GrNonAtomicRef INHERITED;
131 }; 125 };
132 126
133 /**
134 * Base class for GrBatches that draw. These batches have a GrPipeline installed by GrDrawTarget.
135 */
136 class GrDrawBatch : public GrBatch {
137 public:
138 GrDrawBatch();
139 ~GrDrawBatch() override;
140
141 virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0;
142 virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0;
143
144 const GrPipeline* pipeline() const {
145 SkASSERT(fPipelineInstalled);
146 return reinterpret_cast<const GrPipeline*>(fPipelineStorage.get());
147 }
148
149 bool installPipeline(const GrPipeline::CreateArgs&);
150
151 // TODO no GrPrimitiveProcessors yet read fragment position
152 bool willReadFragmentPosition() const { return false; }
153
154 private:
155 /**
156 * initBatchTracker is a hook for the some additional overrides / optimizati on possibilities
157 * from the GrXferProcessor.
158 */
159 virtual void initBatchTracker(const GrPipelineOptimizations&) = 0;
160
161 SkAlignedSTStorage<1, GrPipeline> fPipelineStorage;
162 bool fPipelineInstalled;
163 typedef GrBatch INHERITED;
164 };
165
166 /**
167 * Base class for vertex-based GrBatches.
168 */
169 class GrVertexBatch : public GrDrawBatch {
170 public:
171 GrVertexBatch();
172
173 virtual void generateGeometry(GrBatchTarget*) = 0;
174
175 // TODO this goes away when batches are everywhere
176 void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; }
177 int numberOfDraws() const { return fNumberOfDraws; }
178
179 protected:
180 /** Helper for rendering instances using an instanced index index buffer. Th is class creates the
181 space for the vertices and flushes the draws to the batch target. */
182 class InstancedHelper {
183 public:
184 InstancedHelper() {}
185 /** Returns the allocated storage for the vertices. The caller should po pulate the before
186 vertices before calling issueDraws(). */
187 void* init(GrBatchTarget* batchTarget, GrPrimitiveType, size_t vertexStr ide,
188 const GrIndexBuffer*, int verticesPerInstance, int indicesPer Instance,
189 int instancesToDraw);
190
191 /** Call after init() to issue draws to the batch target.*/
192 void issueDraw(GrBatchTarget* batchTarget) {
193 SkASSERT(fVertices.instanceCount());
194 batchTarget->draw(fVertices);
195 }
196 private:
197 GrVertices fVertices;
198 };
199
200 static const int kVerticesPerQuad = 4;
201 static const int kIndicesPerQuad = 6;
202
203 /** A specialization of InstanceHelper for quad rendering. */
204 class QuadHelper : private InstancedHelper {
205 public:
206 QuadHelper() : INHERITED() {}
207 /** Finds the cached quad index buffer and reserves vertex space. Return s NULL on failure
208 and on sucess a pointer to the vertex data that the caller should po pulate before
209 calling issueDraws(). */
210 void* init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToD raw);
211
212 using InstancedHelper::issueDraw;
213
214 private:
215 typedef InstancedHelper INHERITED;
216 };
217
218 private:
219 int fNumberOfDraws;
220 typedef GrDrawBatch INHERITED;
221 };
222
223 #endif 127 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrBWFillRectBatch.cpp ('k') | src/gpu/batches/GrBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698