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

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

Issue 1124633003: Revert of Start on simplifying generateGeometry() overrides (Closed) Base URL: https://skia.googlesource.com/skia.git@ibcache
Patch Set: 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/GrAtlasTextContext.cpp ('k') | src/gpu/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 // TODO remove this header when we move entirely to batch 12 // TODO remove this header when we move entirely to batch
13 #include "GrDrawTarget.h" 13 #include "GrDrawTarget.h"
14 #include "GrBatchTarget.h"
15 #include "GrGeometryProcessor.h" 14 #include "GrGeometryProcessor.h"
16 #include "SkRefCnt.h" 15 #include "SkRefCnt.h"
17 #include "SkThread.h" 16 #include "SkThread.h"
18 #include "SkTypes.h" 17 #include "SkTypes.h"
19 18
19 class GrBatchTarget;
20 class GrGpu; 20 class GrGpu;
21 class GrIndexBufferAllocPool; 21 class GrIndexBufferAllocPool;
22 class GrPipeline; 22 class GrPipeline;
23 class GrVertexBufferAllocPool; 23 class GrVertexBufferAllocPool;
24 24
25 struct GrInitInvariantOutput; 25 struct GrInitInvariantOutput;
26 26
27 /* 27 /*
28 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa cilitate 28 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa cilitate
29 * reorderable batching, Ganesh does not generate geometry inline with draw call s. Instead, it 29 * reorderable batching, Ganesh does not generate geometry inline with draw call s. Instead, it
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 uint32_t fClassID; 106 uint32_t fClassID;
107 107
108 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL argest on the bounds 108 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL argest on the bounds
109 // rect because we outset it for dst copy textures 109 // rect because we outset it for dst copy textures
110 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } 110 void setBounds(const SkRect& newBounds) { fBounds = newBounds; }
111 111
112 void joinBounds(const SkRect& otherBounds) { 112 void joinBounds(const SkRect& otherBounds) {
113 return fBounds.joinPossiblyEmptyRect(otherBounds); 113 return fBounds.joinPossiblyEmptyRect(otherBounds);
114 } 114 }
115 115
116 /** Helper for rendering instances using an instanced index index buffer. Th is class creates the
117 space for the vertices and flushes the draws to the batch target.*/
118 class InstancedHelper {
119 public:
120 InstancedHelper() : fInstancesRemaining(0) {}
121 /** Returns the allocated storage for the vertices. The caller should po pulate the before
122 vertices before calling issueDraws(). */
123 void* init(GrBatchTarget* batchTarget, size_t vertexStride,
124 const GrIndexBuffer* indexBuffer, int verticesPerInstance,
125 int indicesPerInstance, int instancesToDraw);
126
127 /** Call after init() to issue draws to the batch target.*/
128 void issueDraws(GrBatchTarget* batchTarget) {
129 SkASSERT(fDrawInfo.instanceCount());
130 do {
131 batchTarget->draw(fDrawInfo);
132 } while (fDrawInfo.nextInstances(&fInstancesRemaining, fMaxInstances PerDraw));
133 }
134 private:
135 int fInstancesRemaining;
136 int fMaxInstancesPerDraw;
137 GrDrawTarget::DrawInfo fDrawInfo;
138 };
139
140 static const int kVerticesPerQuad = 4;
141 static const int kIndicesPerQuad = 6;
142
143 /** A specialization of InstanceHelper for quad rendering. */
144 class QuadHelper : private InstancedHelper {
145 public:
146 QuadHelper() : INHERITED() {}
147 /** Finds the cached quad index buffer and reserves vertex space. Return s NULL on failure
148 and on sucess a pointer to the vertex data that the caller should po pulate before
149 calling issueDraws(). */
150 void* init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToD raw);
151
152 using InstancedHelper::issueDraws;
153
154 private:
155 typedef InstancedHelper INHERITED;
156 };
157
158 SkRect fBounds; 116 SkRect fBounds;
159 117
160 private: 118 private:
161 static uint32_t GenClassID() { 119 static uint32_t GenClassID() {
162 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The 120 // fCurrProcessorClassID has been initialized to kIllegalProcessorClassI D. The
163 // atomic inc returns the old value not the incremented value. So we add 121 // atomic inc returns the old value not the incremented value. So we add
164 // 1 to the returned value. 122 // 1 to the returned value.
165 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) + 1; 123 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) + 1;
166 if (!id) { 124 if (!id) {
167 SkFAIL("This should never wrap as it should only be called once for each GrBatch " 125 SkFAIL("This should never wrap as it should only be called once for each GrBatch "
168 "subclass."); 126 "subclass.");
169 } 127 }
170 return id; 128 return id;
171 } 129 }
172 130
173 enum { 131 enum {
174 kIllegalBatchClassID = 0, 132 kIllegalBatchClassID = 0,
175 }; 133 };
176 static int32_t gCurrBatchClassID; 134 static int32_t gCurrBatchClassID;
177 135
178 SkDEBUGCODE(bool fUsed;) 136 SkDEBUGCODE(bool fUsed;)
179 137
180 int fNumberOfDraws; 138 int fNumberOfDraws;
181 139
182 typedef SkRefCnt INHERITED; 140 typedef SkRefCnt INHERITED;
183 }; 141 };
184 142
185 #endif 143 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/GrBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698