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

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

Powered by Google App Engine
This is Rietveld 408576698