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

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

Issue 1116943004: Move instanced index buffer creation to flush time (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix missing assignment of keys to index buffers 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/GrGpu.cpp ('k') | src/gpu/GrOvalRenderer.h » ('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 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"
11 #include "GrTemplates.h" 12 #include "GrTemplates.h"
12 13
13 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context, 14 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context,
14 GrVertexBufferAllocPool* vertexPool, 15 GrVertexBufferAllocPool* vertexPool,
15 GrIndexBufferAllocPool* indexPool) 16 GrIndexBufferAllocPool* indexPool)
16 : INHERITED(context, vertexPool, indexPool) 17 : INHERITED(context, vertexPool, indexPool)
17 , fCommands(context->getGpu(), vertexPool, indexPool) 18 , fCommands(context->getGpu(), vertexPool, indexPool)
18 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) 19 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
19 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) 20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
20 , fDrawID(0) { 21 , fDrawID(0) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 init.fUsesLocalCoords = this->usesLocalCoords(); 131 init.fUsesLocalCoords = this->usesLocalCoords();
131 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); 132 gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
132 133
133 size_t vertexStride = gp->getVertexStride(); 134 size_t vertexStride = gp->getVertexStride();
134 135
135 SkASSERT(hasExplicitLocalCoords ? 136 SkASSERT(hasExplicitLocalCoords ?
136 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo calCoordAttr) : 137 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo calCoordAttr) :
137 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr)); 138 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr));
138 139
139 int instanceCount = fGeoData.count(); 140 int instanceCount = fGeoData.count();
141 SkAutoTUnref<const GrIndexBuffer> indexBuffer(
142 batchTarget->resourceProvider()->refQuadIndexBuffer());
143
140 int vertexCount = kVertsPerRect * instanceCount; 144 int vertexCount = kVertsPerRect * instanceCount;
141
142 const GrVertexBuffer* vertexBuffer; 145 const GrVertexBuffer* vertexBuffer;
143 int firstVertex; 146 int firstVertex;
144
145 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 147 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
146 vertexCount, 148 vertexCount,
147 &vertexBuffer, 149 &vertexBuffer,
148 &firstVertex); 150 &firstVertex);
149 151
150 if (!vertices || !batchTarget->quadIndexBuffer()) { 152 if (!vertices || !indexBuffer) {
151 SkDebugf("Could not allocate buffers\n"); 153 SkDebugf("Could not allocate buffers\n");
152 return; 154 return;
153 } 155 }
154 156
155 for (int i = 0; i < instanceCount; i++) { 157 for (int i = 0; i < instanceCount; i++) {
156 const Geometry& args = fGeoData[i]; 158 const Geometry& args = fGeoData[i];
157 159
158 intptr_t offset = GrTCast<intptr_t>(vertices) + kVertsPerRect * i * vertexStride; 160 intptr_t offset = GrTCast<intptr_t>(vertices) + kVertsPerRect * i * vertexStride;
159 SkPoint* positions = GrTCast<SkPoint*>(offset); 161 SkPoint* positions = GrTCast<SkPoint*>(offset);
160 162
(...skipping 13 matching lines...) Expand all
174 } 176 }
175 177
176 static const int kColorOffset = sizeof(SkPoint); 178 static const int kColorOffset = sizeof(SkPoint);
177 GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset); 179 GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset);
178 for (int j = 0; j < 4; ++j) { 180 for (int j = 0; j < 4; ++j) {
179 *vertColor = args.fColor; 181 *vertColor = args.fColor;
180 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); 182 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride);
181 } 183 }
182 } 184 }
183 185
184 const GrIndexBuffer* quadIndexBuffer = batchTarget->quadIndexBuffer();
185
186 GrDrawTarget::DrawInfo drawInfo; 186 GrDrawTarget::DrawInfo drawInfo;
187 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); 187 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType);
188 drawInfo.setStartVertex(0); 188 drawInfo.setStartVertex(0);
189 drawInfo.setStartIndex(0); 189 drawInfo.setStartIndex(0);
190 drawInfo.setVerticesPerInstance(kVertsPerRect); 190 drawInfo.setVerticesPerInstance(kVertsPerRect);
191 drawInfo.setIndicesPerInstance(kIndicesPerRect); 191 drawInfo.setIndicesPerInstance(kIndicesPerRect);
192 drawInfo.adjustStartVertex(firstVertex); 192 drawInfo.adjustStartVertex(firstVertex);
193 drawInfo.setVertexBuffer(vertexBuffer); 193 drawInfo.setVertexBuffer(vertexBuffer);
194 drawInfo.setIndexBuffer(quadIndexBuffer); 194 drawInfo.setIndexBuffer(indexBuffer);
195 195
196 int maxInstancesPerDraw = quadIndexBuffer->maxQuads(); 196 int maxInstancesPerDraw = indexBuffer->maxQuads();
197 while (instanceCount) { 197 while (instanceCount) {
198 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw) ); 198 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw) );
199 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices PerInstance()); 199 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices PerInstance());
200 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe rInstance()); 200 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe rInstance());
201 201
202 batchTarget->draw(drawInfo); 202 batchTarget->draw(drawInfo);
203 203
204 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun t()); 204 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun t());
205 instanceCount -= drawInfo.instanceCount(); 205 instanceCount -= drawInfo.instanceCount();
206 } 206 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); 393 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
394 if (activeTraceMarkers.count() > 0) { 394 if (activeTraceMarkers.count() > 0) {
395 if (cmd->isTraced()) { 395 if (cmd->isTraced()) {
396 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); 396 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers);
397 } else { 397 } else {
398 cmd->setMarkerID(fGpuCmdMarkers.count()); 398 cmd->setMarkerID(fGpuCmdMarkers.count());
399 fGpuCmdMarkers.push_back(activeTraceMarkers); 399 fGpuCmdMarkers.push_back(activeTraceMarkers);
400 } 400 }
401 } 401 }
402 } 402 }
OLDNEW
« no previous file with comments | « src/gpu/GrGpu.cpp ('k') | src/gpu/GrOvalRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698