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

Side by Side Diff: src/gpu/GrInOrderDrawBuffer.cpp

Issue 1122673002: Start on simplifying generateGeometry() overrides (Closed) Base URL: https://skia.googlesource.com/skia.git@ibcache
Patch Set: drawinfo changes 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 #include "GrInOrderDrawBuffer.h" 8 #include "GrInOrderDrawBuffer.h"
9 9
10 #include "GrDefaultGeoProcFactory.h" 10 #include "GrDefaultGeoProcFactory.h"
11 #include "GrResourceProvider.h"
12 #include "GrTemplates.h" 11 #include "GrTemplates.h"
13 12
14 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context, 13 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context,
15 GrVertexBufferAllocPool* vertexPool, 14 GrVertexBufferAllocPool* vertexPool,
16 GrIndexBufferAllocPool* indexPool) 15 GrIndexBufferAllocPool* indexPool)
17 : INHERITED(context, vertexPool, indexPool) 16 : INHERITED(context, vertexPool, indexPool)
18 , fCommands(context->getGpu(), vertexPool, indexPool) 17 , fCommands(context->getGpu(), vertexPool, indexPool)
19 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) 18 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) 19 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
21 , fDrawID(0) { 20 , fDrawID(0) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // TODO this is hacky, but the only way we have to initialize the GP is to use the 123 // TODO this is hacky, but the only way we have to initialize the GP is to use the
125 // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch 124 // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
126 // everywhere we can remove this nastiness 125 // everywhere we can remove this nastiness
127 GrPipelineInfo init; 126 GrPipelineInfo init;
128 init.fColorIgnored = fBatch.fColorIgnored; 127 init.fColorIgnored = fBatch.fColorIgnored;
129 init.fOverrideColor = GrColor_ILLEGAL; 128 init.fOverrideColor = GrColor_ILLEGAL;
130 init.fCoverageIgnored = fBatch.fCoverageIgnored; 129 init.fCoverageIgnored = fBatch.fCoverageIgnored;
131 init.fUsesLocalCoords = this->usesLocalCoords(); 130 init.fUsesLocalCoords = this->usesLocalCoords();
132 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); 131 gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
133 132
133 int instanceCount = fGeoData.count();
134 size_t vertexStride = gp->getVertexStride(); 134 size_t vertexStride = gp->getVertexStride();
135
136 SkASSERT(hasExplicitLocalCoords ? 135 SkASSERT(hasExplicitLocalCoords ?
137 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo calCoordAttr) : 136 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo calCoordAttr) :
138 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr)); 137 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr));
138 QuadHelper helper;
139 void* vertices = helper.init(batchTarget, vertexStride, instanceCount);
139 140
140 int instanceCount = fGeoData.count(); 141 if (!vertices) {
141 SkAutoTUnref<const GrIndexBuffer> indexBuffer(
142 batchTarget->resourceProvider()->refQuadIndexBuffer());
143
144 int vertexCount = kVertsPerRect * instanceCount;
145 const GrVertexBuffer* vertexBuffer;
146 int firstVertex;
147 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
148 vertexCount,
149 &vertexBuffer,
150 &firstVertex);
151
152 if (!vertices || !indexBuffer) {
153 SkDebugf("Could not allocate buffers\n");
154 return; 142 return;
155 } 143 }
156 144
145
157 for (int i = 0; i < instanceCount; i++) { 146 for (int i = 0; i < instanceCount; i++) {
158 const Geometry& args = fGeoData[i]; 147 const Geometry& geom = fGeoData[i];
159 148
160 intptr_t offset = GrTCast<intptr_t>(vertices) + kVertsPerRect * i * vertexStride; 149 intptr_t offset = GrTCast<intptr_t>(vertices) + kVerticesPerQuad * i * vertexStride;
161 SkPoint* positions = GrTCast<SkPoint*>(offset); 150 SkPoint* positions = GrTCast<SkPoint*>(offset);
162 151
163 positions->setRectFan(args.fRect.fLeft, args.fRect.fTop, 152 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop,
164 args.fRect.fRight, args.fRect.fBottom, vertexS tride); 153 geom.fRect.fRight, geom.fRect.fBottom, vertexS tride);
165 args.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerts PerRect); 154 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti cesPerQuad);
166 155
167 if (args.fHasLocalRect) { 156 if (geom.fHasLocalRect) {
168 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor ); 157 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor );
169 SkPoint* coords = GrTCast<SkPoint*>(offset + kLocalOffset); 158 SkPoint* coords = GrTCast<SkPoint*>(offset + kLocalOffset);
170 coords->setRectFan(args.fLocalRect.fLeft, args.fLocalRect.fTop, 159 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop,
171 args.fLocalRect.fRight, args.fLocalRect.fBott om, 160 geom.fLocalRect.fRight, geom.fLocalRect.fBott om,
172 vertexStride); 161 vertexStride);
173 if (args.fHasLocalMatrix) { 162 if (geom.fHasLocalMatrix) {
174 args.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVertsPerRect); 163 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVerticesPerQuad);
175 } 164 }
176 } 165 }
177 166
178 static const int kColorOffset = sizeof(SkPoint); 167 static const int kColorOffset = sizeof(SkPoint);
179 GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset); 168 GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset);
180 for (int j = 0; j < 4; ++j) { 169 for (int j = 0; j < 4; ++j) {
181 *vertColor = args.fColor; 170 *vertColor = geom.fColor;
182 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); 171 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride);
183 } 172 }
184 } 173 }
185 174
186 GrDrawTarget::DrawInfo drawInfo; 175 helper.issueDraws(batchTarget);
187 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType);
188 drawInfo.setStartVertex(0);
189 drawInfo.setStartIndex(0);
190 drawInfo.setVerticesPerInstance(kVertsPerRect);
191 drawInfo.setIndicesPerInstance(kIndicesPerRect);
192 drawInfo.adjustStartVertex(firstVertex);
193 drawInfo.setVertexBuffer(vertexBuffer);
194 drawInfo.setIndexBuffer(indexBuffer);
195
196 int maxInstancesPerDraw = indexBuffer->maxQuads();
197 while (instanceCount) {
198 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw) );
199 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices PerInstance());
200 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe rInstance());
201
202 batchTarget->draw(drawInfo);
203
204 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun t());
205 instanceCount -= drawInfo.instanceCount();
206 }
207 } 176 }
208 177
209 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 178 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
210 179
211 private: 180 private:
212 RectBatch(const Geometry& geometry) { 181 RectBatch(const Geometry& geometry) {
213 this->initClassID<RectBatch>(); 182 this->initClassID<RectBatch>();
214 fGeoData.push_back(geometry); 183 fGeoData.push_back(geometry);
215 184
216 fBounds = geometry.fRect; 185 fBounds = geometry.fRect;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return true; 224 return true;
256 } 225 }
257 226
258 struct BatchTracker { 227 struct BatchTracker {
259 GrColor fColor; 228 GrColor fColor;
260 bool fUsesLocalCoords; 229 bool fUsesLocalCoords;
261 bool fColorIgnored; 230 bool fColorIgnored;
262 bool fCoverageIgnored; 231 bool fCoverageIgnored;
263 }; 232 };
264 233
265 const static int kVertsPerRect = 4;
266 const static int kIndicesPerRect = 6;
267
268 BatchTracker fBatch; 234 BatchTracker fBatch;
269 SkSTArray<1, Geometry, true> fGeoData; 235 SkSTArray<1, Geometry, true> fGeoData;
270 }; 236 };
271 237
272 void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder, 238 void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder,
273 GrColor color, 239 GrColor color,
274 const SkMatrix& viewMatrix, 240 const SkMatrix& viewMatrix,
275 const SkRect& rect, 241 const SkRect& rect,
276 const SkRect* localRect, 242 const SkRect* localRect,
277 const SkMatrix* localMatrix) { 243 const SkMatrix* localMatrix) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); 359 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
394 if (activeTraceMarkers.count() > 0) { 360 if (activeTraceMarkers.count() > 0) {
395 if (cmd->isTraced()) { 361 if (cmd->isTraced()) {
396 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); 362 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers);
397 } else { 363 } else {
398 cmd->setMarkerID(fGpuCmdMarkers.count()); 364 cmd->setMarkerID(fGpuCmdMarkers.count());
399 fGpuCmdMarkers.push_back(activeTraceMarkers); 365 fGpuCmdMarkers.push_back(activeTraceMarkers);
400 } 366 }
401 } 367 }
402 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698