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

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

Issue 1286043004: Make GrVertexBatch objects hold their own draws during GrDrawTarget flush (Closed) Base URL: https://skia.googlesource.com/skia.git@m
Patch Set: forward decl 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/GrContext.cpp ('k') | src/gpu/GrImmediateDrawTarget.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 "GrDefaultPathRenderer.h" 8 #include "GrDefaultPathRenderer.h"
9 9
10 #include "GrBatchTarget.h" 10 #include "GrBatchFlushState.h"
11 #include "GrBatchTest.h" 11 #include "GrBatchTest.h"
12 #include "GrContext.h" 12 #include "GrContext.h"
13 #include "GrDefaultGeoProcFactory.h" 13 #include "GrDefaultGeoProcFactory.h"
14 #include "GrPathUtils.h" 14 #include "GrPathUtils.h"
15 #include "GrPipelineBuilder.h" 15 #include "GrPipelineBuilder.h"
16 #include "GrVertices.h" 16 #include "GrVertices.h"
17 #include "SkGeometry.h" 17 #include "SkGeometry.h"
18 #include "SkString.h" 18 #include "SkString.h"
19 #include "SkStrokeRec.h" 19 #include "SkStrokeRec.h"
20 #include "SkTLazy.h" 20 #include "SkTLazy.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 241 }
242 opt.getOverrideColorIfSet(&fGeoData[0].fColor); 242 opt.getOverrideColorIfSet(&fGeoData[0].fColor);
243 243
244 // setup batch properties 244 // setup batch properties
245 fBatch.fColorIgnored = !opt.readsColor(); 245 fBatch.fColorIgnored = !opt.readsColor();
246 fBatch.fColor = fGeoData[0].fColor; 246 fBatch.fColor = fGeoData[0].fColor;
247 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); 247 fBatch.fUsesLocalCoords = opt.readsLocalCoords();
248 fBatch.fCoverageIgnored = !opt.readsCoverage(); 248 fBatch.fCoverageIgnored = !opt.readsCoverage();
249 } 249 }
250 250
251 void generateGeometry(GrBatchTarget* batchTarget) override { 251 void onPrepareDraws(Target* target) override {
252 SkAutoTUnref<const GrGeometryProcessor> gp; 252 SkAutoTUnref<const GrGeometryProcessor> gp;
253 { 253 {
254 using namespace GrDefaultGeoProcFactory; 254 using namespace GrDefaultGeoProcFactory;
255 Color color(this->color()); 255 Color color(this->color());
256 Coverage coverage(this->coverage()); 256 Coverage coverage(this->coverage());
257 if (this->coverageIgnored()) { 257 if (this->coverageIgnored()) {
258 coverage.fType = Coverage::kNone_Type; 258 coverage.fType = Coverage::kNone_Type;
259 } 259 }
260 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP osition_Type : 260 LocalCoords localCoords(this->usesLocalCoords() ? LocalCoords::kUseP osition_Type :
261 LocalCoords::kUnus ed_Type); 261 LocalCoords::kUnus ed_Type);
262 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s, 262 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s,
263 this->viewMatrix())); 263 this->viewMatrix()));
264 } 264 }
265 265
266 size_t vertexStride = gp->getVertexStride(); 266 size_t vertexStride = gp->getVertexStride();
267 SkASSERT(vertexStride == sizeof(SkPoint)); 267 SkASSERT(vertexStride == sizeof(SkPoint));
268 268
269 batchTarget->initDraw(gp, this->pipeline()); 269 target->initDraw(gp, this->pipeline());
270 270
271 int instanceCount = fGeoData.count(); 271 int instanceCount = fGeoData.count();
272 272
273 // compute number of vertices 273 // compute number of vertices
274 int maxVertices = 0; 274 int maxVertices = 0;
275 275
276 // We will use index buffers if we have multiple paths or one path with multiple contours 276 // We will use index buffers if we have multiple paths or one path with multiple contours
277 bool isIndexed = instanceCount > 1; 277 bool isIndexed = instanceCount > 1;
278 for (int i = 0; i < instanceCount; i++) { 278 for (int i = 0; i < instanceCount; i++) {
279 Geometry& args = fGeoData[i]; 279 Geometry& args = fGeoData[i];
(...skipping 26 matching lines...) Expand all
306 primitiveType = kTriangles_GrPrimitiveType; 306 primitiveType = kTriangles_GrPrimitiveType;
307 } else { 307 } else {
308 primitiveType = kTriangleFan_GrPrimitiveType; 308 primitiveType = kTriangleFan_GrPrimitiveType;
309 } 309 }
310 } 310 }
311 311
312 // allocate vertex / index buffers 312 // allocate vertex / index buffers
313 const GrVertexBuffer* vertexBuffer; 313 const GrVertexBuffer* vertexBuffer;
314 int firstVertex; 314 int firstVertex;
315 315
316 void* verts = batchTarget->makeVertSpace(vertexStride, maxVertices, 316 void* verts = target->makeVertexSpace(vertexStride, maxVertices,
317 &vertexBuffer, &firstVertex); 317 &vertexBuffer, &firstVertex);
318 318
319 if (!verts) { 319 if (!verts) {
320 SkDebugf("Could not allocate vertices\n"); 320 SkDebugf("Could not allocate vertices\n");
321 return; 321 return;
322 } 322 }
323 323
324 const GrIndexBuffer* indexBuffer = NULL; 324 const GrIndexBuffer* indexBuffer = NULL;
325 int firstIndex = 0; 325 int firstIndex = 0;
326 326
327 void* indices = NULL; 327 void* indices = NULL;
328 if (isIndexed) { 328 if (isIndexed) {
329 indices = batchTarget->makeIndexSpace(maxIndices, &indexBuffer, &fir stIndex); 329 indices = target->makeIndexSpace(maxIndices, &indexBuffer, &firstInd ex);
330 330
331 if (!indices) { 331 if (!indices) {
332 SkDebugf("Could not allocate indices\n"); 332 SkDebugf("Could not allocate indices\n");
333 return; 333 return;
334 } 334 }
335 } 335 }
336 336
337 // fill buffers 337 // fill buffers
338 int vertexOffset = 0; 338 int vertexOffset = 0;
339 int indexOffset = 0; 339 int indexOffset = 0;
(...skipping 19 matching lines...) Expand all
359 SkASSERT(vertexOffset <= maxVertices && indexOffset <= maxIndices); 359 SkASSERT(vertexOffset <= maxVertices && indexOffset <= maxIndices);
360 } 360 }
361 361
362 GrVertices vertices; 362 GrVertices vertices;
363 if (isIndexed) { 363 if (isIndexed) {
364 vertices.initIndexed(primitiveType, vertexBuffer, indexBuffer, first Vertex, firstIndex, 364 vertices.initIndexed(primitiveType, vertexBuffer, indexBuffer, first Vertex, firstIndex,
365 vertexOffset, indexOffset); 365 vertexOffset, indexOffset);
366 } else { 366 } else {
367 vertices.init(primitiveType, vertexBuffer, firstVertex, vertexOffset ); 367 vertices.init(primitiveType, vertexBuffer, firstVertex, vertexOffset );
368 } 368 }
369 batchTarget->draw(vertices); 369 target->draw(vertices);
370 370
371 // put back reserves 371 // put back reserves
372 batchTarget->putBackIndices((size_t)(maxIndices - indexOffset)); 372 target->putBackIndices((size_t)(maxIndices - indexOffset));
373 batchTarget->putBackVertices((size_t)(maxVertices - vertexOffset), (size _t)vertexStride); 373 target->putBackVertices((size_t)(maxVertices - vertexOffset), (size_t)ve rtexStride);
374 } 374 }
375 375
376 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 376 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
377 377
378 private: 378 private:
379 DefaultPathBatch(const Geometry& geometry, uint8_t coverage, const SkMatrix& viewMatrix, 379 DefaultPathBatch(const Geometry& geometry, uint8_t coverage, const SkMatrix& viewMatrix,
380 bool isHairline, const SkRect& devBounds) { 380 bool isHairline, const SkRect& devBounds) {
381 this->initClassID<DefaultPathBatch>(); 381 this->initClassID<DefaultPathBatch>();
382 fBatch.fCoverage = coverage; 382 fBatch.fCoverage = coverage;
383 fBatch.fIsHairline = isHairline; 383 fBatch.fIsHairline = isHairline;
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 geometry.fColor = color; 753 geometry.fColor = color;
754 geometry.fPath = path; 754 geometry.fPath = path;
755 geometry.fTolerance = srcSpaceTol; 755 geometry.fTolerance = srcSpaceTol;
756 756
757 viewMatrix.mapRect(&bounds); 757 viewMatrix.mapRect(&bounds);
758 uint8_t coverage = GrRandomCoverage(random); 758 uint8_t coverage = GrRandomCoverage(random);
759 return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds ); 759 return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds );
760 } 760 }
761 761
762 #endif 762 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrImmediateDrawTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698