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

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

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