OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrAADistanceFieldPathRenderer.h" | 8 #include "GrAADistanceFieldPathRenderer.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 static const SkScalar kAntiAliasPad = 1.0f; | 121 static const SkScalar kAntiAliasPad = 1.0f; |
122 | 122 |
123 class AADistanceFieldPathBatch : public GrVertexBatch { | 123 class AADistanceFieldPathBatch : public GrVertexBatch { |
124 public: | 124 public: |
125 DEFINE_BATCH_CLASS_ID | 125 DEFINE_BATCH_CLASS_ID |
126 | 126 |
127 typedef GrAADistanceFieldPathRenderer::ShapeData ShapeData; | 127 typedef GrAADistanceFieldPathRenderer::ShapeData ShapeData; |
128 typedef SkTDynamicHash<ShapeData, ShapeData::Key> ShapeCache; | 128 typedef SkTDynamicHash<ShapeData, ShapeData::Key> ShapeCache; |
129 typedef GrAADistanceFieldPathRenderer::ShapeDataList ShapeDataList; | 129 typedef GrAADistanceFieldPathRenderer::ShapeDataList ShapeDataList; |
130 | 130 |
131 struct Geometry { | 131 AADistanceFieldPathBatch(GrColor color, |
132 GrShape fShape; | 132 const GrShape& shape, |
133 GrColor fColor; | 133 bool antiAlias, |
134 bool fAntiAlias; | 134 const SkMatrix& viewMatrix, |
135 }; | 135 GrBatchAtlas* atlas, |
| 136 ShapeCache* shapeCache, ShapeDataList* shapeList, |
| 137 bool gammaCorrect) |
| 138 : INHERITED(ClassID()) { |
| 139 SkASSERT(shape.hasUnstyledKey()); |
| 140 fBatch.fViewMatrix = viewMatrix; |
| 141 fGeoData.emplace_back(Geometry{color, shape, antiAlias}); |
136 | 142 |
137 static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMat
rix, | 143 fAtlas = atlas; |
138 GrBatchAtlas* atlas, ShapeCache* shapeCache, | 144 fShapeCache = shapeCache; |
139 ShapeDataList* shapeList, bool gammaCorrect) { | 145 fShapeList = shapeList; |
140 return new AADistanceFieldPathBatch(geometry, viewMatrix, atlas, shapeCa
che, shapeList, | 146 fGammaCorrect = gammaCorrect; |
141 gammaCorrect); | 147 |
| 148 // Compute bounds |
| 149 fBounds = shape.bounds(); |
| 150 viewMatrix.mapRect(&fBounds); |
142 } | 151 } |
143 | 152 |
144 const char* name() const override { return "AADistanceFieldPathBatch"; } | 153 const char* name() const override { return "AADistanceFieldPathBatch"; } |
145 | 154 |
146 void computePipelineOptimizations(GrInitInvariantOutput* color, | 155 void computePipelineOptimizations(GrInitInvariantOutput* color, |
147 GrInitInvariantOutput* coverage, | 156 GrInitInvariantOutput* coverage, |
148 GrBatchToXPOverrides* overrides) const ove
rride { | 157 GrBatchToXPOverrides* overrides) const ove
rride { |
149 color->setKnownFourComponents(fGeoData[0].fColor); | 158 color->setKnownFourComponents(fGeoData[0].fColor); |
150 coverage->setUnknownSingleComponent(); | 159 coverage->setUnknownSingleComponent(); |
151 } | 160 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 vertexStride, | 280 vertexStride, |
272 this->viewMatrix(), | 281 this->viewMatrix(), |
273 args.fShape, | 282 args.fShape, |
274 shapeData); | 283 shapeData); |
275 flushInfo.fInstancesToFlush++; | 284 flushInfo.fInstancesToFlush++; |
276 } | 285 } |
277 | 286 |
278 this->flush(target, &flushInfo); | 287 this->flush(target, &flushInfo); |
279 } | 288 } |
280 | 289 |
281 AADistanceFieldPathBatch(const Geometry& geometry, | |
282 const SkMatrix& viewMatrix, | |
283 GrBatchAtlas* atlas, | |
284 ShapeCache* shapeCache, ShapeDataList* shapeList, | |
285 bool gammaCorrect) | |
286 : INHERITED(ClassID()) { | |
287 SkASSERT(geometry.fShape.hasUnstyledKey()); | |
288 fBatch.fViewMatrix = viewMatrix; | |
289 fGeoData.push_back(geometry); | |
290 SkASSERT(fGeoData[0].fShape.hasUnstyledKey()); | |
291 | |
292 fAtlas = atlas; | |
293 fShapeCache = shapeCache; | |
294 fShapeList = shapeList; | |
295 fGammaCorrect = gammaCorrect; | |
296 | |
297 // Compute bounds | |
298 fBounds = geometry.fShape.bounds(); | |
299 viewMatrix.mapRect(&fBounds); | |
300 } | |
301 | |
302 bool addPathToAtlas(GrVertexBatch::Target* target, | 290 bool addPathToAtlas(GrVertexBatch::Target* target, |
303 FlushInfo* flushInfo, | 291 FlushInfo* flushInfo, |
304 GrBatchAtlas* atlas, | 292 GrBatchAtlas* atlas, |
305 ShapeData* shapeData, | 293 ShapeData* shapeData, |
306 const GrShape& shape, | 294 const GrShape& shape, |
307 bool antiAlias, | 295 bool antiAlias, |
308 uint32_t dimension, | 296 uint32_t dimension, |
309 SkScalar scale) const { | 297 SkScalar scale) const { |
310 const SkRect& bounds = shape.bounds(); | 298 const SkRect& bounds = shape.bounds(); |
311 | 299 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 return true; | 488 return true; |
501 } | 489 } |
502 | 490 |
503 struct BatchTracker { | 491 struct BatchTracker { |
504 SkMatrix fViewMatrix; | 492 SkMatrix fViewMatrix; |
505 bool fUsesLocalCoords; | 493 bool fUsesLocalCoords; |
506 bool fColorIgnored; | 494 bool fColorIgnored; |
507 bool fCoverageIgnored; | 495 bool fCoverageIgnored; |
508 }; | 496 }; |
509 | 497 |
| 498 struct Geometry { |
| 499 GrColor fColor; |
| 500 GrShape fShape; |
| 501 bool fAntiAlias; |
| 502 }; |
| 503 |
510 BatchTracker fBatch; | 504 BatchTracker fBatch; |
511 SkSTArray<1, Geometry> fGeoData; | 505 SkSTArray<1, Geometry> fGeoData; |
512 GrBatchAtlas* fAtlas; | 506 GrBatchAtlas* fAtlas; |
513 ShapeCache* fShapeCache; | 507 ShapeCache* fShapeCache; |
514 ShapeDataList* fShapeList; | 508 ShapeDataList* fShapeList; |
515 bool fGammaCorrect; | 509 bool fGammaCorrect; |
516 | 510 |
517 typedef GrVertexBatch INHERITED; | 511 typedef GrVertexBatch INHERITED; |
518 }; | 512 }; |
519 | 513 |
(...skipping 10 matching lines...) Expand all Loading... |
530 fAtlas = args.fResourceProvider->createAtlas(kAlpha_8_GrPixelConfig, | 524 fAtlas = args.fResourceProvider->createAtlas(kAlpha_8_GrPixelConfig, |
531 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, | 525 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, |
532 NUM_PLOTS_X, NUM_PLOTS_Y, | 526 NUM_PLOTS_X, NUM_PLOTS_Y, |
533 &GrAADistanceFieldPathRende
rer::HandleEviction, | 527 &GrAADistanceFieldPathRende
rer::HandleEviction, |
534 (void*)this); | 528 (void*)this); |
535 if (!fAtlas) { | 529 if (!fAtlas) { |
536 return false; | 530 return false; |
537 } | 531 } |
538 } | 532 } |
539 | 533 |
540 AADistanceFieldPathBatch::Geometry geometry; | 534 SkAutoTUnref<GrDrawBatch> batch(new AADistanceFieldPathBatch(args.fColor, *a
rgs.fShape, |
541 geometry.fShape = *args.fShape; | 535 args.fAntiAlias
, *args.fViewMatrix, |
542 geometry.fColor = args.fColor; | 536 fAtlas, &fShape
Cache, &fShapeList, |
543 geometry.fAntiAlias = args.fAntiAlias; | 537 args.fGammaCorr
ect)); |
544 | |
545 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, | |
546 *args.fView
Matrix, fAtlas, | |
547 &fShapeCach
e, &fShapeList, | |
548 args.fGamma
Correct)); | |
549 | 538 |
550 GrPipelineBuilder pipelineBuilder(*args.fPaint); | 539 GrPipelineBuilder pipelineBuilder(*args.fPaint); |
551 pipelineBuilder.setUserStencil(args.fUserStencilSettings); | 540 pipelineBuilder.setUserStencil(args.fUserStencilSettings); |
552 | 541 |
553 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); | 542 args.fDrawContext->drawBatch(pipelineBuilder, *args.fClip, batch); |
554 | 543 |
555 return true; | 544 return true; |
556 } | 545 } |
557 | 546 |
558 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 547 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, | 601 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, |
613 NUM_PLOTS_X, NUM_PLOTS_Y, | 602 NUM_PLOTS_X, NUM_PLOTS_Y, |
614 &PathTestStruct::HandleEvic
tion, | 603 &PathTestStruct::HandleEvic
tion, |
615 (void*)&gTestStruct); | 604 (void*)&gTestStruct); |
616 } | 605 } |
617 | 606 |
618 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 607 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
619 GrColor color = GrRandomColor(random); | 608 GrColor color = GrRandomColor(random); |
620 bool gammaCorrect = random->nextBool(); | 609 bool gammaCorrect = random->nextBool(); |
621 | 610 |
622 AADistanceFieldPathBatch::Geometry geometry; | |
623 // This path renderer only allows fill styles. | 611 // This path renderer only allows fill styles. |
624 GrShape shape(GrTest::TestPath(random), GrStyle::SimpleFill()); | 612 GrShape shape(GrTest::TestPath(random), GrStyle::SimpleFill()); |
625 geometry.fShape = shape; | 613 bool antiAlias = random->nextBool(); |
626 geometry.fColor = color; | |
627 geometry.fAntiAlias = random->nextBool(); | |
628 | 614 |
629 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, | 615 return new AADistanceFieldPathBatch(color, |
630 gTestStruct.fAtlas, | 616 shape, |
631 &gTestStruct.fShapeCache, | 617 antiAlias, |
632 &gTestStruct.fShapeList, | 618 viewMatrix, |
633 gammaCorrect); | 619 gTestStruct.fAtlas, |
| 620 &gTestStruct.fShapeCache, |
| 621 &gTestStruct.fShapeList, |
| 622 gammaCorrect); |
634 } | 623 } |
635 | 624 |
636 #endif | 625 #endif |
OLD | NEW |