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

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

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/GrDrawTarget.cpp ('k') | src/gpu/GrOvalRenderer.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 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // TODO this is hacky, but the only way we have to initialize the GP is to use the 124 // TODO this is hacky, but the only way we have to initialize the GP is to use the
124 // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch 125 // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
125 // everywhere we can remove this nastiness 126 // everywhere we can remove this nastiness
126 GrPipelineInfo init; 127 GrPipelineInfo init;
127 init.fColorIgnored = fBatch.fColorIgnored; 128 init.fColorIgnored = fBatch.fColorIgnored;
128 init.fOverrideColor = GrColor_ILLEGAL; 129 init.fOverrideColor = GrColor_ILLEGAL;
129 init.fCoverageIgnored = fBatch.fCoverageIgnored; 130 init.fCoverageIgnored = fBatch.fCoverageIgnored;
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 int instanceCount = fGeoData.count();
134 size_t vertexStride = gp->getVertexStride(); 134 size_t vertexStride = gp->getVertexStride();
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 QuadHelper helper;
139 void* vertices = helper.init(batchTarget, vertexStride, instanceCount);
140 139
141 if (!vertices) { 140 int instanceCount = fGeoData.count();
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");
142 return; 154 return;
143 } 155 }
144 156
157 for (int i = 0; i < instanceCount; i++) {
158 const Geometry& args = fGeoData[i];
145 159
146 for (int i = 0; i < instanceCount; i++) { 160 intptr_t offset = GrTCast<intptr_t>(vertices) + kVertsPerRect * i * vertexStride;
147 const Geometry& geom = fGeoData[i];
148
149 intptr_t offset = GrTCast<intptr_t>(vertices) + kVerticesPerQuad * i * vertexStride;
150 SkPoint* positions = GrTCast<SkPoint*>(offset); 161 SkPoint* positions = GrTCast<SkPoint*>(offset);
151 162
152 positions->setRectFan(geom.fRect.fLeft, geom.fRect.fTop, 163 positions->setRectFan(args.fRect.fLeft, args.fRect.fTop,
153 geom.fRect.fRight, geom.fRect.fBottom, vertexS tride); 164 args.fRect.fRight, args.fRect.fBottom, vertexS tride);
154 geom.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerti cesPerQuad); 165 args.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVerts PerRect);
155 166
156 if (geom.fHasLocalRect) { 167 if (args.fHasLocalRect) {
157 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor ); 168 static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor );
158 SkPoint* coords = GrTCast<SkPoint*>(offset + kLocalOffset); 169 SkPoint* coords = GrTCast<SkPoint*>(offset + kLocalOffset);
159 coords->setRectFan(geom.fLocalRect.fLeft, geom.fLocalRect.fTop, 170 coords->setRectFan(args.fLocalRect.fLeft, args.fLocalRect.fTop,
160 geom.fLocalRect.fRight, geom.fLocalRect.fBott om, 171 args.fLocalRect.fRight, args.fLocalRect.fBott om,
161 vertexStride); 172 vertexStride);
162 if (geom.fHasLocalMatrix) { 173 if (args.fHasLocalMatrix) {
163 geom.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVerticesPerQuad); 174 args.fLocalMatrix.mapPointsWithStride(coords, vertexStride, kVertsPerRect);
164 } 175 }
165 } 176 }
166 177
167 static const int kColorOffset = sizeof(SkPoint); 178 static const int kColorOffset = sizeof(SkPoint);
168 GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset); 179 GrColor* vertColor = GrTCast<GrColor*>(offset + kColorOffset);
169 for (int j = 0; j < 4; ++j) { 180 for (int j = 0; j < 4; ++j) {
170 *vertColor = geom.fColor; 181 *vertColor = args.fColor;
171 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); 182 vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride);
172 } 183 }
173 } 184 }
174 185
175 helper.issueDraws(batchTarget); 186 GrDrawTarget::DrawInfo drawInfo;
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 }
176 } 207 }
177 208
178 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 209 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
179 210
180 private: 211 private:
181 RectBatch(const Geometry& geometry) { 212 RectBatch(const Geometry& geometry) {
182 this->initClassID<RectBatch>(); 213 this->initClassID<RectBatch>();
183 fGeoData.push_back(geometry); 214 fGeoData.push_back(geometry);
184 215
185 fBounds = geometry.fRect; 216 fBounds = geometry.fRect;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return true; 255 return true;
225 } 256 }
226 257
227 struct BatchTracker { 258 struct BatchTracker {
228 GrColor fColor; 259 GrColor fColor;
229 bool fUsesLocalCoords; 260 bool fUsesLocalCoords;
230 bool fColorIgnored; 261 bool fColorIgnored;
231 bool fCoverageIgnored; 262 bool fCoverageIgnored;
232 }; 263 };
233 264
265 const static int kVertsPerRect = 4;
266 const static int kIndicesPerRect = 6;
267
234 BatchTracker fBatch; 268 BatchTracker fBatch;
235 SkSTArray<1, Geometry, true> fGeoData; 269 SkSTArray<1, Geometry, true> fGeoData;
236 }; 270 };
237 271
238 void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder, 272 void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder,
239 GrColor color, 273 GrColor color,
240 const SkMatrix& viewMatrix, 274 const SkMatrix& viewMatrix,
241 const SkRect& rect, 275 const SkRect& rect,
242 const SkRect* localRect, 276 const SkRect* localRect,
243 const SkMatrix* localMatrix) { 277 const SkMatrix* localMatrix) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); 393 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers();
360 if (activeTraceMarkers.count() > 0) { 394 if (activeTraceMarkers.count() > 0) {
361 if (cmd->isTraced()) { 395 if (cmd->isTraced()) {
362 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); 396 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers);
363 } else { 397 } else {
364 cmd->setMarkerID(fGpuCmdMarkers.count()); 398 cmd->setMarkerID(fGpuCmdMarkers.count());
365 fGpuCmdMarkers.push_back(activeTraceMarkers); 399 fGpuCmdMarkers.push_back(activeTraceMarkers);
366 } 400 }
367 } 401 }
368 } 402 }
OLDNEW
« no previous file with comments | « src/gpu/GrDrawTarget.cpp ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698