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

Side by Side Diff: src/gpu/batches/GrAAStrokeRectBatch.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/batches/GrAAStrokeRectBatch.h ('k') | src/gpu/batches/GrBWFillRectBatch.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 #include "GrAAStrokeRectBatch.h" 8 #include "GrAAStrokeRectBatch.h"
9 9
10 #include "GrBatchFlushState.h"
10 #include "GrDefaultGeoProcFactory.h" 11 #include "GrDefaultGeoProcFactory.h"
11 #include "GrResourceKey.h" 12 #include "GrResourceKey.h"
12 #include "GrResourceProvider.h" 13 #include "GrResourceProvider.h"
13 14
14 GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); 15 GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey);
15 GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); 16 GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey);
16 17
17 static void set_inset_fan(SkPoint* pts, size_t stride, 18 static void set_inset_fan(SkPoint* pts, size_t stride,
18 const SkRect& r, SkScalar dx, SkScalar dy) { 19 const SkRect& r, SkScalar dx, SkScalar dy) {
19 pts->setRectFan(r.fLeft + dx, r.fTop + dy, 20 pts->setRectFan(r.fLeft + dx, r.fTop + dy,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 53
53 // setup batch properties 54 // setup batch properties
54 fBatch.fColorIgnored = !opt.readsColor(); 55 fBatch.fColorIgnored = !opt.readsColor();
55 fBatch.fColor = fGeoData[0].fColor; 56 fBatch.fColor = fGeoData[0].fColor;
56 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); 57 fBatch.fUsesLocalCoords = opt.readsLocalCoords();
57 fBatch.fCoverageIgnored = !opt.readsCoverage(); 58 fBatch.fCoverageIgnored = !opt.readsCoverage();
58 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; 59 fBatch.fMiterStroke = fGeoData[0].fMiterStroke;
59 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); 60 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage();
60 } 61 }
61 62
62 void GrAAStrokeRectBatch::generateGeometry(GrBatchTarget* batchTarget) { 63 void GrAAStrokeRectBatch::onPrepareDraws(Target* target) {
63 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); 64 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
64 65
65 SkAutoTUnref<const GrGeometryProcessor> gp(create_stroke_rect_gp(canTweakAlp haForCoverage, 66 SkAutoTUnref<const GrGeometryProcessor> gp(create_stroke_rect_gp(canTweakAlp haForCoverage,
66 this->viewM atrix(), 67 this->viewM atrix(),
67 this->usesL ocalCoords(), 68 this->usesL ocalCoords(),
68 this->cover ageIgnored())); 69 this->cover ageIgnored()));
69 if (!gp) { 70 if (!gp) {
70 SkDebugf("Couldn't create GrGeometryProcessor\n"); 71 SkDebugf("Couldn't create GrGeometryProcessor\n");
71 return; 72 return;
72 } 73 }
73 74
74 batchTarget->initDraw(gp, this->pipeline()); 75 target->initDraw(gp, this->pipeline());
75 76
76 size_t vertexStride = gp->getVertexStride(); 77 size_t vertexStride = gp->getVertexStride();
77 78
78 SkASSERT(canTweakAlphaForCoverage ? 79 SkASSERT(canTweakAlphaForCoverage ?
79 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) : 80 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
80 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCovera geAttr)); 81 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCovera geAttr));
81 int innerVertexNum = 4; 82 int innerVertexNum = 4;
82 int outerVertexNum = this->miterStroke() ? 4 : 8; 83 int outerVertexNum = this->miterStroke() ? 4 : 8;
83 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; 84 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2;
84 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexC nt; 85 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexC nt;
85 int instanceCount = fGeoData.count(); 86 int instanceCount = fGeoData.count();
86 87
87 const SkAutoTUnref<const GrIndexBuffer> indexBuffer( 88 const SkAutoTUnref<const GrIndexBuffer> indexBuffer(
88 GetIndexBuffer(batchTarget->resourceProvider(), this->miterStroke())); 89 GetIndexBuffer(target->resourceProvider(), this->miterStroke()));
89 InstancedHelper helper; 90 InstancedHelper helper;
90 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, vertex Stride, 91 void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStrid e,
91 indexBuffer, verticesPerInstance, indicesPerIn stance, 92 indexBuffer, verticesPerInstance, indicesPerIn stance,
92 instanceCount); 93 instanceCount);
93 if (!vertices || !indexBuffer) { 94 if (!vertices || !indexBuffer) {
94 SkDebugf("Could not allocate vertices\n"); 95 SkDebugf("Could not allocate vertices\n");
95 return; 96 return;
96 } 97 }
97 98
98 for (int i = 0; i < instanceCount; i++) { 99 for (int i = 0; i < instanceCount; i++) {
99 const Geometry& args = fGeoData[i]; 100 const Geometry& args = fGeoData[i];
100 this->generateAAStrokeRectGeometry(vertices, 101 this->generateAAStrokeRectGeometry(vertices,
101 i * verticesPerInstance * vertexStrid e, 102 i * verticesPerInstance * vertexStrid e,
102 vertexStride, 103 vertexStride,
103 outerVertexNum, 104 outerVertexNum,
104 innerVertexNum, 105 innerVertexNum,
105 args.fColor, 106 args.fColor,
106 args.fDevOutside, 107 args.fDevOutside,
107 args.fDevOutsideAssist, 108 args.fDevOutsideAssist,
108 args.fDevInside, 109 args.fDevInside,
109 args.fMiterStroke, 110 args.fMiterStroke,
110 canTweakAlphaForCoverage); 111 canTweakAlphaForCoverage);
111 } 112 }
112 helper.issueDraw(batchTarget); 113 helper.recordDraw(target);
113 } 114 }
114 115
115 const GrIndexBuffer* GrAAStrokeRectBatch::GetIndexBuffer(GrResourceProvider* res ourceProvider, 116 const GrIndexBuffer* GrAAStrokeRectBatch::GetIndexBuffer(GrResourceProvider* res ourceProvider,
116 bool miterStroke) { 117 bool miterStroke) {
117 118
118 if (miterStroke) { 119 if (miterStroke) {
119 static const uint16_t gMiterIndices[] = { 120 static const uint16_t gMiterIndices[] = {
120 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0, 121 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0,
121 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0, 122 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0,
122 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0, 123 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0,
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 geo.fColor = GrRandomColor(random); 373 geo.fColor = GrRandomColor(random);
373 geo.fDevOutside = outside; 374 geo.fDevOutside = outside;
374 geo.fDevOutsideAssist = outsideAssist; 375 geo.fDevOutsideAssist = outsideAssist;
375 geo.fDevInside = inside; 376 geo.fDevInside = inside;
376 geo.fMiterStroke = miterStroke; 377 geo.fMiterStroke = miterStroke;
377 378
378 return GrAAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); 379 return GrAAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random));
379 } 380 }
380 381
381 #endif 382 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrAAStrokeRectBatch.h ('k') | src/gpu/batches/GrBWFillRectBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698