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

Side by Side Diff: src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp

Issue 1835283002: Simplify GrDrawBatch uploads and token uage. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 8 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/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/batches/GrAAStrokeRectBatch.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 "GrAALinearizingConvexPathRenderer.h" 8 #include "GrAALinearizingConvexPathRenderer.h"
9 9
10 #include "GrAAConvexTessellator.h" 10 #include "GrAAConvexTessellator.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 151
152 // setup batch properties 152 // setup batch properties
153 fBatch.fColorIgnored = !overrides.readsColor(); 153 fBatch.fColorIgnored = !overrides.readsColor();
154 fBatch.fColor = fGeoData[0].fColor; 154 fBatch.fColor = fGeoData[0].fColor;
155 fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); 155 fBatch.fUsesLocalCoords = overrides.readsLocalCoords();
156 fBatch.fCoverageIgnored = !overrides.readsCoverage(); 156 fBatch.fCoverageIgnored = !overrides.readsCoverage();
157 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks(); 157 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe gmentMasks();
158 fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage(); 158 fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage();
159 } 159 }
160 160
161 void draw(GrVertexBatch::Target* target, const GrPipeline* pipeline, int ver texCount, 161 void draw(GrVertexBatch::Target* target, const GrGeometryProcessor* gp, int vertexCount,
162 size_t vertexStride, void* vertices, int indexCount, uint16_t* ind ices) const { 162 size_t vertexStride, void* vertices, int indexCount, uint16_t* ind ices) const {
163 if (vertexCount == 0 || indexCount == 0) { 163 if (vertexCount == 0 || indexCount == 0) {
164 return; 164 return;
165 } 165 }
166 const GrBuffer* vertexBuffer; 166 const GrBuffer* vertexBuffer;
167 GrMesh mesh; 167 GrMesh mesh;
168 int firstVertex; 168 int firstVertex;
169 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex Buffer, 169 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex Buffer,
170 &firstVertex); 170 &firstVertex);
171 if (!verts) { 171 if (!verts) {
172 SkDebugf("Could not allocate vertices\n"); 172 SkDebugf("Could not allocate vertices\n");
173 return; 173 return;
174 } 174 }
175 memcpy(verts, vertices, vertexCount * vertexStride); 175 memcpy(verts, vertices, vertexCount * vertexStride);
176 176
177 const GrBuffer* indexBuffer; 177 const GrBuffer* indexBuffer;
178 int firstIndex; 178 int firstIndex;
179 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &first Index); 179 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &first Index);
180 if (!idxs) { 180 if (!idxs) {
181 SkDebugf("Could not allocate indices\n"); 181 SkDebugf("Could not allocate indices\n");
182 return; 182 return;
183 } 183 }
184 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); 184 memcpy(idxs, indices, indexCount * sizeof(uint16_t));
185 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex, 185 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex,
186 firstIndex, vertexCount, indexCount); 186 firstIndex, vertexCount, indexCount);
187 target->draw(mesh); 187 target->draw(gp, mesh);
188 } 188 }
189 189
190 void onPrepareDraws(Target* target) const override { 190 void onPrepareDraws(Target* target) const override {
191 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); 191 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
192 192
193 // Setup GrGeometryProcessor 193 // Setup GrGeometryProcessor
194 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage, 194 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF orCoverage,
195 this->viewMatr ix(), 195 this->viewMatr ix(),
196 this->usesLoca lCoords(), 196 this->usesLoca lCoords(),
197 this->coverage Ignored())); 197 this->coverage Ignored()));
198 if (!gp) { 198 if (!gp) {
199 SkDebugf("Couldn't create a GrGeometryProcessor\n"); 199 SkDebugf("Couldn't create a GrGeometryProcessor\n");
200 return; 200 return;
201 } 201 }
202 202
203 target->initDraw(gp);
204
205 size_t vertexStride = gp->getVertexStride(); 203 size_t vertexStride = gp->getVertexStride();
206 204
207 SkASSERT(canTweakAlphaForCoverage ? 205 SkASSERT(canTweakAlphaForCoverage ?
208 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) : 206 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt tr) :
209 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr)); 207 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo verageAttr));
210 208
211 int instanceCount = fGeoData.count(); 209 int instanceCount = fGeoData.count();
212 210
213 int vertexCount = 0; 211 int vertexCount = 0;
214 int indexCount = 0; 212 int indexCount = 0;
215 int maxVertices = DEFAULT_BUFFER_SIZE; 213 int maxVertices = DEFAULT_BUFFER_SIZE;
216 int maxIndices = DEFAULT_BUFFER_SIZE; 214 int maxIndices = DEFAULT_BUFFER_SIZE;
217 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStrid e); 215 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStrid e);
218 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint 16_t)); 216 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint 16_t));
219 for (int i = 0; i < instanceCount; i++) { 217 for (int i = 0; i < instanceCount; i++) {
220 const Geometry& args = fGeoData[i]; 218 const Geometry& args = fGeoData[i];
221 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite rLimit); 219 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite rLimit);
222 220
223 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { 221 if (!tess.tessellate(args.fViewMatrix, args.fPath)) {
224 continue; 222 continue;
225 } 223 }
226 224
227 int currentIndices = tess.numIndices(); 225 int currentIndices = tess.numIndices();
228 SkASSERT(currentIndices <= UINT16_MAX); 226 SkASSERT(currentIndices <= UINT16_MAX);
229 if (indexCount + currentIndices > UINT16_MAX) { 227 if (indexCount + currentIndices > UINT16_MAX) {
230 // if we added the current instance, we would overflow the indic es we can store in a 228 // if we added the current instance, we would overflow the indic es we can store in a
231 // uint16_t. Draw what we've got so far and reset. 229 // uint16_t. Draw what we've got so far and reset.
232 this->draw(target, this->pipeline(), vertexCount, vertexStride, vertices, 230 this->draw(target, gp, vertexCount, vertexStride, vertices, inde xCount, indices);
233 indexCount, indices);
234 vertexCount = 0; 231 vertexCount = 0;
235 indexCount = 0; 232 indexCount = 0;
236 } 233 }
237 int currentVertices = tess.numPts(); 234 int currentVertices = tess.numPts();
238 if (vertexCount + currentVertices > maxVertices) { 235 if (vertexCount + currentVertices > maxVertices) {
239 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2); 236 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices * 2);
240 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * v ertexStride); 237 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * v ertexStride);
241 } 238 }
242 if (indexCount + currentIndices > maxIndices) { 239 if (indexCount + currentIndices > maxIndices) {
243 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2) ; 240 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2) ;
244 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * siz eof(uint16_t)); 241 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * siz eof(uint16_t));
245 } 242 }
246 243
247 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr ide, args.fColor, 244 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr ide, args.fColor,
248 vertexCount, indices + indexCount, canTweakAlphaForCoverage) ; 245 vertexCount, indices + indexCount, canTweakAlphaForCoverage) ;
249 vertexCount += currentVertices; 246 vertexCount += currentVertices;
250 indexCount += currentIndices; 247 indexCount += currentIndices;
251 } 248 }
252 this->draw(target, this->pipeline(), vertexCount, vertexStride, vertices , indexCount, 249 this->draw(target, gp, vertexCount, vertexStride, vertices, indexCount, indices);
253 indices);
254 sk_free(vertices); 250 sk_free(vertices);
255 sk_free(indices); 251 sk_free(indices);
256 } 252 }
257 253
258 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 254 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
259 255
260 AAFlatteningConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) { 256 AAFlatteningConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID()) {
261 fGeoData.push_back(geometry); 257 fGeoData.push_back(geometry);
262 258
263 // compute bounds 259 // compute bounds
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { 343 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) {
348 AAFlatteningConvexPathBatch::Geometry geometry; 344 AAFlatteningConvexPathBatch::Geometry geometry;
349 geometry.fColor = GrRandomColor(random); 345 geometry.fColor = GrRandomColor(random);
350 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); 346 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
351 geometry.fPath = GrTest::TestPathConvex(random); 347 geometry.fPath = GrTest::TestPathConvex(random);
352 348
353 return AAFlatteningConvexPathBatch::Create(geometry); 349 return AAFlatteningConvexPathBatch::Create(geometry);
354 } 350 }
355 351
356 #endif 352 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrAAHairLinePathRenderer.cpp ('k') | src/gpu/batches/GrAAStrokeRectBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698