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

Side by Side Diff: src/gpu/GrAADistanceFieldPathRenderer.cpp

Issue 1124633003: Revert of Start on simplifying generateGeometry() overrides (Closed) Base URL: https://skia.googlesource.com/skia.git@ibcache
Patch Set: Created 5 years, 7 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/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrAAHairLinePathRenderer.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 2014 Google Inc. 3 * Copyright 2014 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 "GrAADistanceFieldPathRenderer.h" 9 #include "GrAADistanceFieldPathRenderer.h"
10 10
11 #include "GrBatch.h" 11 #include "GrBatch.h"
12 #include "GrBatchTarget.h" 12 #include "GrBatchTarget.h"
13 #include "GrBufferAllocPool.h" 13 #include "GrBufferAllocPool.h"
14 #include "GrContext.h" 14 #include "GrContext.h"
15 #include "GrPipelineBuilder.h" 15 #include "GrPipelineBuilder.h"
16 #include "GrResourceProvider.h"
17 #include "GrSurfacePriv.h" 16 #include "GrSurfacePriv.h"
18 #include "GrSWMaskHelper.h" 17 #include "GrSWMaskHelper.h"
18 #include "GrResourceProvider.h"
19 #include "GrTexturePriv.h" 19 #include "GrTexturePriv.h"
20 #include "GrVertexBuffer.h" 20 #include "GrVertexBuffer.h"
21 #include "effects/GrDistanceFieldGeoProc.h" 21 #include "effects/GrDistanceFieldGeoProc.h"
22 22
23 #include "SkDistanceFieldGen.h" 23 #include "SkDistanceFieldGen.h"
24 #include "SkRTConf.h" 24 #include "SkRTConf.h"
25 25
26 #define ATLAS_TEXTURE_WIDTH 1024 26 #define ATLAS_TEXTURE_WIDTH 1024
27 #define ATLAS_TEXTURE_HEIGHT 2048 27 #define ATLAS_TEXTURE_HEIGHT 2048
28 #define PLOT_WIDTH 256 28 #define PLOT_WIDTH 256
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } else if (GrColor_ILLEGAL != init.fOverrideColor) { 162 } else if (GrColor_ILLEGAL != init.fOverrideColor) {
163 fBatch.fColor = init.fOverrideColor; 163 fBatch.fColor = init.fOverrideColor;
164 } 164 }
165 165
166 // setup batch properties 166 // setup batch properties
167 fBatch.fColorIgnored = init.fColorIgnored; 167 fBatch.fColorIgnored = init.fColorIgnored;
168 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; 168 fBatch.fUsesLocalCoords = init.fUsesLocalCoords;
169 fBatch.fCoverageIgnored = init.fCoverageIgnored; 169 fBatch.fCoverageIgnored = init.fCoverageIgnored;
170 } 170 }
171 171
172 struct FlushInfo {
173 SkAutoTUnref<const GrVertexBuffer> fVertexBuffer;
174 SkAutoTUnref<const GrIndexBuffer> fIndexBuffer;
175 int fVertexOffset;
176 int fInstancesToFlush;
177 };
178
179 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override { 172 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline ) override {
180 int instanceCount = fGeoData.count(); 173 int instanceCount = fGeoData.count();
181 174
182 SkMatrix invert; 175 SkMatrix invert;
183 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { 176 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
184 SkDebugf("Could not invert viewmatrix\n"); 177 SkDebugf("Could not invert viewmatrix\n");
185 return; 178 return;
186 } 179 }
187 180
188 uint32_t flags = 0; 181 uint32_t flags = 0;
189 flags |= this->viewMatrix().isSimilarity() ? kSimilarity_DistanceFieldEf fectFlag : 0; 182 flags |= this->viewMatrix().isSimilarity() ? kSimilarity_DistanceFieldEf fectFlag : 0;
190 183
191 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil erp_FilterMode); 184 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil erp_FilterMode);
192 185
193 // Setup GrGeometryProcessor 186 // Setup GrGeometryProcessor
194 GrBatchAtlas* atlas = fAtlas; 187 GrBatchAtlas* atlas = fAtlas;
195 SkAutoTUnref<GrGeometryProcessor> dfProcessor( 188 SkAutoTUnref<GrGeometryProcessor> dfProcessor(
196 GrDistanceFieldPathGeoProc::Create(this->color(), 189 GrDistanceFieldPathGeoProc::Create(this->color(),
197 this->viewMatrix(), 190 this->viewMatrix(),
198 atlas->getTexture(), 191 atlas->getTexture(),
199 params, 192 params,
200 flags, 193 flags,
201 false)); 194 false));
202 195
203 this->initDraw(batchTarget, dfProcessor, pipeline); 196 this->initDraw(batchTarget, dfProcessor, pipeline);
204 197
205 FlushInfo flushInfo; 198 static const int kVertsPerQuad = 4;
199 static const int kIndicesPerQuad = 6;
200
201 SkAutoTUnref<const GrIndexBuffer> indexBuffer(
202 batchTarget->resourceProvider()->refQuadIndexBuffer());
206 203
207 // allocate vertices 204 // allocate vertices
208 size_t vertexStride = dfProcessor->getVertexStride(); 205 size_t vertexStride = dfProcessor->getVertexStride();
209 SkASSERT(vertexStride == 2 * sizeof(SkPoint)); 206 SkASSERT(vertexStride == 2 * sizeof(SkPoint));
207 const GrVertexBuffer* vertexBuffer;
208 int vertexCount = kVertsPerQuad * instanceCount;
209 int firstVertex;
210 210
211 const GrVertexBuffer* vertexBuffer;
212 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 211 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
213 kVerticesPerQuad * instanceCount, 212 vertexCount,
214 &vertexBuffer, 213 &vertexBuffer,
215 &flushInfo.fVertex Offset); 214 &firstVertex);
216 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); 215
217 flushInfo.fIndexBuffer.reset(batchTarget->resourceProvider()->refQuadInd exBuffer()); 216 if (!vertices || !indexBuffer) {
218 if (!vertices || !flushInfo.fIndexBuffer) {
219 SkDebugf("Could not allocate vertices\n"); 217 SkDebugf("Could not allocate vertices\n");
220 return; 218 return;
221 } 219 }
222 220
223 flushInfo.fInstancesToFlush = 0; 221 // We may have to flush while uploading path data to the atlas, so we se t up the draw here
222 int maxInstancesPerDraw = indexBuffer->maxQuads();
223
224 GrDrawTarget::DrawInfo drawInfo;
225 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType);
226 drawInfo.setStartVertex(0);
227 drawInfo.setStartIndex(0);
228 drawInfo.setVerticesPerInstance(kVertsPerQuad);
229 drawInfo.setIndicesPerInstance(kIndicesPerQuad);
230 drawInfo.adjustStartVertex(firstVertex);
231 drawInfo.setVertexBuffer(vertexBuffer);
232 drawInfo.setIndexBuffer(indexBuffer);
233
234 int instancesToFlush = 0;
224 for (int i = 0; i < instanceCount; i++) { 235 for (int i = 0; i < instanceCount; i++) {
225 Geometry& args = fGeoData[i]; 236 Geometry& args = fGeoData[i];
226 237
227 // get mip level 238 // get mip level
228 SkScalar maxScale = this->viewMatrix().getMaxScale(); 239 SkScalar maxScale = this->viewMatrix().getMaxScale();
229 const SkRect& bounds = args.fPath.getBounds(); 240 const SkRect& bounds = args.fPath.getBounds();
230 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); 241 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height());
231 SkScalar size = maxScale * maxDim; 242 SkScalar size = maxScale * maxDim;
232 uint32_t desiredDimension; 243 uint32_t desiredDimension;
233 if (size <= kSmallMIP) { 244 if (size <= kSmallMIP) {
(...skipping 13 matching lines...) Expand all
247 if (args.fPathData) { 258 if (args.fPathData) {
248 fPathCache->remove(args.fPathData->fKey); 259 fPathCache->remove(args.fPathData->fKey);
249 fPathList->remove(args.fPathData); 260 fPathList->remove(args.fPathData);
250 SkDELETE(args.fPathData); 261 SkDELETE(args.fPathData);
251 } 262 }
252 SkScalar scale = desiredDimension/maxDim; 263 SkScalar scale = desiredDimension/maxDim;
253 args.fPathData = SkNEW(PathData); 264 args.fPathData = SkNEW(PathData);
254 if (!this->addPathToAtlas(batchTarget, 265 if (!this->addPathToAtlas(batchTarget,
255 dfProcessor, 266 dfProcessor,
256 pipeline, 267 pipeline,
257 &flushInfo, 268 &drawInfo,
269 &instancesToFlush,
270 maxInstancesPerDraw,
258 atlas, 271 atlas,
259 args.fPathData, 272 args.fPathData,
260 args.fPath, 273 args.fPath,
261 args.fStroke, 274 args.fStroke,
262 args.fAntiAlias, 275 args.fAntiAlias,
263 desiredDimension, 276 desiredDimension,
264 scale)) { 277 scale)) {
265 SkDebugf("Can't rasterize path\n"); 278 SkDebugf("Can't rasterize path\n");
266 return; 279 return;
267 } 280 }
268 } 281 }
269 282
270 atlas->setLastUseToken(args.fPathData->fID, batchTarget->currentToke n()); 283 atlas->setLastUseToken(args.fPathData->fID, batchTarget->currentToke n());
271 284
272 // Now set vertices 285 // Now set vertices
273 intptr_t offset = reinterpret_cast<intptr_t>(vertices); 286 intptr_t offset = reinterpret_cast<intptr_t>(vertices);
274 offset += i * kVerticesPerQuad * vertexStride; 287 offset += i * kVertsPerQuad * vertexStride;
275 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); 288 SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
276 this->writePathVertices(batchTarget, 289 this->drawPath(batchTarget,
277 atlas, 290 atlas,
278 pipeline, 291 pipeline,
279 dfProcessor, 292 dfProcessor,
280 positions, 293 positions,
281 vertexStride, 294 vertexStride,
282 this->viewMatrix(), 295 this->viewMatrix(),
283 args.fPath, 296 args.fPath,
284 args.fPathData); 297 args.fPathData);
285 flushInfo.fInstancesToFlush++; 298 instancesToFlush++;
286 } 299 }
287 300
288 this->flush(batchTarget, &flushInfo); 301 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra w);
289 } 302 }
290 303
291 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 304 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
292 305
293 private: 306 private:
294 AADistanceFieldPathBatch(const Geometry& geometry, GrColor color, const SkMa trix& viewMatrix, 307 AADistanceFieldPathBatch(const Geometry& geometry, GrColor color, const SkMa trix& viewMatrix,
295 GrBatchAtlas* atlas, 308 GrBatchAtlas* atlas,
296 PathCache* pathCache, PathDataList* pathList) { 309 PathCache* pathCache, PathDataList* pathList) {
297 this->initClassID<AADistanceFieldPathBatch>(); 310 this->initClassID<AADistanceFieldPathBatch>();
298 fBatch.fColor = color; 311 fBatch.fColor = color;
299 fBatch.fViewMatrix = viewMatrix; 312 fBatch.fViewMatrix = viewMatrix;
300 fGeoData.push_back(geometry); 313 fGeoData.push_back(geometry);
301 fGeoData.back().fPathData = NULL; 314 fGeoData.back().fPathData = NULL;
302 315
303 fAtlas = atlas; 316 fAtlas = atlas;
304 fPathCache = pathCache; 317 fPathCache = pathCache;
305 fPathList = pathList; 318 fPathList = pathList;
306 319
307 // Compute bounds 320 // Compute bounds
308 fBounds = geometry.fPath.getBounds(); 321 fBounds = geometry.fPath.getBounds();
309 viewMatrix.mapRect(&fBounds); 322 viewMatrix.mapRect(&fBounds);
310 } 323 }
311 324
312 bool addPathToAtlas(GrBatchTarget* batchTarget, 325 bool addPathToAtlas(GrBatchTarget* batchTarget,
313 const GrGeometryProcessor* dfProcessor, 326 const GrGeometryProcessor* dfProcessor,
314 const GrPipeline* pipeline, 327 const GrPipeline* pipeline,
315 FlushInfo* flushInfo, 328 GrDrawTarget::DrawInfo* drawInfo,
329 int* instancesToFlush,
330 int maxInstancesPerDraw,
316 GrBatchAtlas* atlas, 331 GrBatchAtlas* atlas,
317 PathData* pathData, 332 PathData* pathData,
318 const SkPath& path, 333 const SkPath& path,
319 const SkStrokeRec& 334 const SkStrokeRec&
320 stroke, bool antiAlias, 335 stroke, bool antiAlias,
321 uint32_t dimension, 336 uint32_t dimension,
322 SkScalar scale) { 337 SkScalar scale) {
323 const SkRect& bounds = path.getBounds(); 338 const SkRect& bounds = path.getBounds();
324 339
325 // generate bounding rect for bitmap draw 340 // generate bounding rect for bitmap draw
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 (const unsigned char*)bmp.getPixe ls(), 422 (const unsigned char*)bmp.getPixe ls(),
408 bmp.width(), bmp.height(), bmp.ro wBytes()); 423 bmp.width(), bmp.height(), bmp.ro wBytes());
409 } 424 }
410 425
411 // add to atlas 426 // add to atlas
412 SkIPoint16 atlasLocation; 427 SkIPoint16 atlasLocation;
413 GrBatchAtlas::AtlasID id; 428 GrBatchAtlas::AtlasID id;
414 bool success = atlas->addToAtlas(&id, batchTarget, width, height, dfStor age.get(), 429 bool success = atlas->addToAtlas(&id, batchTarget, width, height, dfStor age.get(),
415 &atlasLocation); 430 &atlasLocation);
416 if (!success) { 431 if (!success) {
417 this->flush(batchTarget, flushInfo); 432 this->flush(batchTarget, drawInfo, *instancesToFlush, maxInstancesPe rDraw);
418 this->initDraw(batchTarget, dfProcessor, pipeline); 433 this->initDraw(batchTarget, dfProcessor, pipeline);
434 *instancesToFlush = 0;
419 435
420 SkDEBUGCODE(success =) atlas->addToAtlas(&id, batchTarget, width, he ight, 436 SkDEBUGCODE(success =) atlas->addToAtlas(&id, batchTarget, width, he ight,
421 dfStorage.get(), &atlasLoca tion); 437 dfStorage.get(), &atlasLoca tion);
422 SkASSERT(success); 438 SkASSERT(success);
423 439
424 } 440 }
425 441
426 // add to cache 442 // add to cache
427 pathData->fKey.fGenID = path.getGenerationID(); 443 pathData->fKey.fGenID = path.getGenerationID();
428 pathData->fKey.fDimension = dimension; 444 pathData->fKey.fDimension = dimension;
(...skipping 15 matching lines...) Expand all
444 pathData->fAtlasLocation = atlasLocation; 460 pathData->fAtlasLocation = atlasLocation;
445 461
446 fPathCache->add(pathData); 462 fPathCache->add(pathData);
447 fPathList->addToTail(pathData); 463 fPathList->addToTail(pathData);
448 #ifdef DF_PATH_TRACKING 464 #ifdef DF_PATH_TRACKING
449 ++g_NumCachedPaths; 465 ++g_NumCachedPaths;
450 #endif 466 #endif
451 return true; 467 return true;
452 } 468 }
453 469
454 void writePathVertices(GrBatchTarget* target, 470 void drawPath(GrBatchTarget* target,
455 GrBatchAtlas* atlas, 471 GrBatchAtlas* atlas,
456 const GrPipeline* pipeline, 472 const GrPipeline* pipeline,
457 const GrGeometryProcessor* gp, 473 const GrGeometryProcessor* gp,
458 SkPoint* positions, 474 SkPoint* positions,
459 size_t vertexStride, 475 size_t vertexStride,
460 const SkMatrix& viewMatrix, 476 const SkMatrix& viewMatrix,
461 const SkPath& path, 477 const SkPath& path,
462 const PathData* pathData) { 478 const PathData* pathData) {
463 GrTexture* texture = atlas->getTexture(); 479 GrTexture* texture = atlas->getTexture();
464 480
465 SkScalar dx = pathData->fBounds.fLeft; 481 SkScalar dx = pathData->fBounds.fLeft;
466 SkScalar dy = pathData->fBounds.fTop; 482 SkScalar dy = pathData->fBounds.fTop;
467 SkScalar width = pathData->fBounds.width(); 483 SkScalar width = pathData->fBounds.width();
468 SkScalar height = pathData->fBounds.height(); 484 SkScalar height = pathData->fBounds.height();
469 485
470 SkScalar invScale = 1.0f / pathData->fScale; 486 SkScalar invScale = 1.0f / pathData->fScale;
471 dx *= invScale; 487 dx *= invScale;
472 dy *= invScale; 488 dy *= invScale;
(...skipping 26 matching lines...) Expand all
499 515
500 // TODO remove this when batch is everywhere 516 // TODO remove this when batch is everywhere
501 GrPipelineInfo init; 517 GrPipelineInfo init;
502 init.fColorIgnored = fBatch.fColorIgnored; 518 init.fColorIgnored = fBatch.fColorIgnored;
503 init.fOverrideColor = GrColor_ILLEGAL; 519 init.fOverrideColor = GrColor_ILLEGAL;
504 init.fCoverageIgnored = fBatch.fCoverageIgnored; 520 init.fCoverageIgnored = fBatch.fCoverageIgnored;
505 init.fUsesLocalCoords = this->usesLocalCoords(); 521 init.fUsesLocalCoords = this->usesLocalCoords();
506 dfProcessor->initBatchTracker(batchTarget->currentBatchTracker(), init); 522 dfProcessor->initBatchTracker(batchTarget->currentBatchTracker(), init);
507 } 523 }
508 524
509 void flush(GrBatchTarget* batchTarget, FlushInfo* flushInfo) { 525 void flush(GrBatchTarget* batchTarget,
510 GrDrawTarget::DrawInfo drawInfo; 526 GrDrawTarget::DrawInfo* drawInfo,
511 int instancesToFlush = flushInfo->fInstancesToFlush; 527 int instanceCount,
512 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); 528 int maxInstancesPerDraw) {
513 drawInfo.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuf fer, 529 while (instanceCount) {
514 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, 530 drawInfo->setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw ));
515 kIndicesPerQuad, &instancesToFlush, maxInstancesPerDraw); 531 drawInfo->setVertexCount(drawInfo->instanceCount() * drawInfo->verti cesPerInstance());
516 do { 532 drawInfo->setIndexCount(drawInfo->instanceCount() * drawInfo->indice sPerInstance());
517 batchTarget->draw(drawInfo); 533
518 } while (drawInfo.nextInstances(&instancesToFlush, maxInstancesPerDraw)) ; 534 batchTarget->draw(*drawInfo);
519 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl ush; 535
520 flushInfo->fInstancesToFlush = 0; 536 drawInfo->setStartVertex(drawInfo->startVertex() + drawInfo->vertexC ount());
537 instanceCount -= drawInfo->instanceCount();
538 }
521 } 539 }
522 540
523 GrColor color() const { return fBatch.fColor; } 541 GrColor color() const { return fBatch.fColor; }
524 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } 542 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; }
525 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 543 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
526 544
527 bool onCombineIfPossible(GrBatch* t) override { 545 bool onCombineIfPossible(GrBatch* t) override {
528 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); 546 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>();
529 547
530 // TODO we could actually probably do a bunch of this work on the CPU, i e map viewMatrix, 548 // TODO we could actually probably do a bunch of this work on the CPU, i e map viewMatrix,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 geometry.fPath = path; 614 geometry.fPath = path;
597 geometry.fAntiAlias = antiAlias; 615 geometry.fAntiAlias = antiAlias;
598 616
599 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color , viewMatrix, 617 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color , viewMatrix,
600 fAtlas, &fPathC ache, &fPathList)); 618 fAtlas, &fPathC ache, &fPathList));
601 target->drawBatch(pipelineBuilder, batch); 619 target->drawBatch(pipelineBuilder, batch);
602 620
603 return true; 621 return true;
604 } 622 }
605 623
OLDNEW
« no previous file with comments | « src/gpu/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrAAHairLinePathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698