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

Side by Side Diff: src/gpu/GrAALinearizingConvexPathRenderer.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/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrAtlasTextContext.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 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAALinearizingConvexPathRenderer.h" 9 #include "GrAALinearizingConvexPathRenderer.h"
10 10
11 #include "GrAAConvexTessellator.h" 11 #include "GrAAConvexTessellator.h"
12 #include "GrBatchTarget.h" 12 #include "GrBatchFlushState.h"
13 #include "GrBatchTest.h" 13 #include "GrBatchTest.h"
14 #include "GrContext.h" 14 #include "GrContext.h"
15 #include "GrDefaultGeoProcFactory.h" 15 #include "GrDefaultGeoProcFactory.h"
16 #include "GrGeometryProcessor.h" 16 #include "GrGeometryProcessor.h"
17 #include "GrInvariantOutput.h" 17 #include "GrInvariantOutput.h"
18 #include "GrPathUtils.h" 18 #include "GrPathUtils.h"
19 #include "GrProcessor.h" 19 #include "GrProcessor.h"
20 #include "GrPipelineBuilder.h" 20 #include "GrPipelineBuilder.h"
21 #include "GrStrokeInfo.h" 21 #include "GrStrokeInfo.h"
22 #include "SkGeometry.h" 22 #include "SkGeometry.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 // setup batch properties 149 // setup batch properties
150 fBatch.fColorIgnored = !opt.readsColor(); 150 fBatch.fColorIgnored = !opt.readsColor();
151 fBatch.fColor = fGeoData[0].fColor; 151 fBatch.fColor = fGeoData[0].fColor;
152 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); 152 fBatch.fUsesLocalCoords = opt.readsLocalCoords();
153 fBatch.fCoverageIgnored = !opt.readsCoverage(); 153 fBatch.fCoverageIgnored = !opt.readsCoverage();
154 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks(); 154 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks();
155 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); 155 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage();
156 } 156 }
157 157
158 void draw(GrBatchTarget* batchTarget, const GrPipeline* pipeline, int vertex Count, 158 void draw(GrVertexBatch::Target* target, const GrPipeline* pipeline, int ver texCount,
159 size_t vertexStride, void* vertices, int indexCount, uint16_t* indic es) { 159 size_t vertexStride, void* vertices, int indexCount, uint16_t* indic es) {
160 if (vertexCount == 0 || indexCount == 0) { 160 if (vertexCount == 0 || indexCount == 0) {
161 return; 161 return;
162 } 162 }
163 const GrVertexBuffer* vertexBuffer; 163 const GrVertexBuffer* vertexBuffer;
164 GrVertices info; 164 GrVertices info;
165 int firstVertex; 165 int firstVertex;
166 void* verts = batchTarget->makeVertSpace(vertexStride, vertexCount, &ver texBuffer, 166 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex Buffer,
167 &firstVertex); 167 &firstVertex);
168 if (!verts) { 168 if (!verts) {
169 SkDebugf("Could not allocate vertices\n"); 169 SkDebugf("Could not allocate vertices\n");
170 return; 170 return;
171 } 171 }
172 memcpy(verts, vertices, vertexCount * vertexStride); 172 memcpy(verts, vertices, vertexCount * vertexStride);
173 173
174 const GrIndexBuffer* indexBuffer; 174 const GrIndexBuffer* indexBuffer;
175 int firstIndex; 175 int firstIndex;
176 uint16_t* idxs = batchTarget->makeIndexSpace(indexCount, &indexBuffer, & firstIndex); 176 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &first Index);
177 if (!idxs) { 177 if (!idxs) {
178 SkDebugf("Could not allocate indices\n"); 178 SkDebugf("Could not allocate indices\n");
179 return; 179 return;
180 } 180 }
181 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); 181 memcpy(idxs, indices, indexCount * sizeof(uint16_t));
182 info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex, 182 info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex,
183 firstIndex, vertexCount, indexCount); 183 firstIndex, vertexCount, indexCount);
184 batchTarget->draw(info); 184 target->draw(info);
185 } 185 }
186 186
187 void generateGeometry(GrBatchTarget* batchTarget) override { 187 void onPrepareDraws(Target* target) override {
188 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); 188 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
189 189
190 // Setup GrGeometryProcessor 190 // Setup GrGeometryProcessor
191 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage, 191 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage,
192 this->viewMatr ix(), 192 this->viewMatr ix(),
193 this->usesLoca lCoords(), 193 this->usesLoca lCoords(),
194 this->coverage Ignored())); 194 this->coverage Ignored()));
195 if (!gp) { 195 if (!gp) {
196 SkDebugf("Couldn't create a GrGeometryProcessor\n"); 196 SkDebugf("Couldn't create a GrGeometryProcessor\n");
197 return; 197 return;
198 } 198 }
199 199
200 batchTarget->initDraw(gp, this->pipeline()); 200 target->initDraw(gp, this->pipeline());
201 201
202 size_t vertexStride = gp->getVertexStride(); 202 size_t vertexStride = gp->getVertexStride();
203 203
204 SkASSERT(canTweakAlphaForCoverage ? 204 SkASSERT(canTweakAlphaForCoverage ?
205 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : 205 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) :
206 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); 206 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr));
207 207
208 int instanceCount = fGeoData.count(); 208 int instanceCount = fGeoData.count();
209 209
210 int vertexCount = 0; 210 int vertexCount = 0;
211 int indexCount = 0; 211 int indexCount = 0;
212 int maxVertices = DEFAULT_BUFFER_SIZE; 212 int maxVertices = DEFAULT_BUFFER_SIZE;
213 int maxIndices = DEFAULT_BUFFER_SIZE; 213 int maxIndices = DEFAULT_BUFFER_SIZE;
214 uint8_t* vertices = (uint8_t*) malloc(maxVertices * vertexStride); 214 uint8_t* vertices = (uint8_t*) malloc(maxVertices * vertexStride);
215 uint16_t* indices = (uint16_t*) malloc(maxIndices * sizeof(uint16_t)); 215 uint16_t* indices = (uint16_t*) malloc(maxIndices * sizeof(uint16_t));
216 for (int i = 0; i < instanceCount; i++) { 216 for (int i = 0; i < instanceCount; i++) {
217 Geometry& args = fGeoData[i]; 217 Geometry& args = fGeoData[i];
218 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite rLimit); 218 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite rLimit);
219 219
220 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { 220 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
221 continue; 221 continue;
222 } 222 }
223 223
224 int currentIndices = tess.numIndices(); 224 int currentIndices = tess.numIndices();
225 SkASSERT(currentIndices <= UINT16_MAX); 225 SkASSERT(currentIndices <= UINT16_MAX);
226 if (indexCount + currentIndices > UINT16_MAX) { 226 if (indexCount + currentIndices > UINT16_MAX) {
227 // if we added the current instance, we would overflow the indic es we can store in a 227 // if we added the current instance, we would overflow the indic es we can store in a
228 // uint16_t. Draw what we've got so far and reset. 228 // uint16_t. Draw what we've got so far and reset.
229 draw(batchTarget, this->pipeline(), vertexCount, vertexStride, v ertices, indexCount, 229 draw(target, this->pipeline(), vertexCount, vertexStride, vertic es, indexCount,
230 indices); 230 indices);
231 vertexCount = 0; 231 vertexCount = 0;
232 indexCount = 0; 232 indexCount = 0;
233 } 233 }
234 int currentVertices = tess.numPts(); 234 int currentVertices = tess.numPts();
235 if (vertexCount + currentVertices > maxVertices) { 235 if (vertexCount + currentVertices > maxVertices) {
236 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2); 236 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2);
237 vertices = (uint8_t*) realloc(vertices, maxVertices * vertexStri de); 237 vertices = (uint8_t*) realloc(vertices, maxVertices * vertexStri de);
238 } 238 }
239 if (indexCount + currentIndices > maxIndices) { 239 if (indexCount + currentIndices > maxIndices) {
240 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2) ; 240 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2) ;
241 indices = (uint16_t*) realloc(indices, maxIndices * sizeof(uint1 6_t)); 241 indices = (uint16_t*) realloc(indices, maxIndices * sizeof(uint1 6_t));
242 } 242 }
243 243
244 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr ide, args.fColor, 244 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr ide, args.fColor,
245 vertexCount, indices + indexCount, canTweakAlphaForCoverage) ; 245 vertexCount, indices + indexCount, canTweakAlphaForCoverage) ;
246 vertexCount += currentVertices; 246 vertexCount += currentVertices;
247 indexCount += currentIndices; 247 indexCount += currentIndices;
248 } 248 }
249 draw(batchTarget, this->pipeline(), vertexCount, vertexStride, vertices, indexCount, 249 draw(target, this->pipeline(), vertexCount, vertexStride, vertices, inde xCount,
250 indices); 250 indices);
251 free(vertices); 251 free(vertices);
252 free(indices); 252 free(indices);
253 } 253 }
254 254
255 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 255 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
256 256
257 private: 257 private:
258 AAFlatteningConvexPathBatch(const Geometry& geometry) { 258 AAFlatteningConvexPathBatch(const Geometry& geometry) {
259 this->initClassID<AAFlatteningConvexPathBatch>(); 259 this->initClassID<AAFlatteningConvexPathBatch>();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { 333 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) {
334 AAFlatteningConvexPathBatch::Geometry geometry; 334 AAFlatteningConvexPathBatch::Geometry geometry;
335 geometry.fColor = GrRandomColor(random); 335 geometry.fColor = GrRandomColor(random);
336 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); 336 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
337 geometry.fPath = GrTest::TestPathConvex(random); 337 geometry.fPath = GrTest::TestPathConvex(random);
338 338
339 return AAFlatteningConvexPathBatch::Create(geometry); 339 return AAFlatteningConvexPathBatch::Create(geometry);
340 } 340 }
341 341
342 #endif 342 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/GrAtlasTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698