OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GrMSAAPathRenderer.h" | 8 #include "GrMSAAPathRenderer.h" |
9 | 9 |
10 #include "GrAuditTrail.h" | 10 #include "GrAuditTrail.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 SkMatrix fViewMatrix; | 217 SkMatrix fViewMatrix; |
218 | 218 |
219 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 219 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
220 | 220 |
221 typedef GrGeometryProcessor INHERITED; | 221 typedef GrGeometryProcessor INHERITED; |
222 }; | 222 }; |
223 | 223 |
224 class MSAAPathBatch : public GrVertexBatch { | 224 class MSAAPathBatch : public GrVertexBatch { |
225 public: | 225 public: |
226 DEFINE_BATCH_CLASS_ID | 226 DEFINE_BATCH_CLASS_ID |
227 | 227 |
robertphillips
2016/06/30 17:10:41
The usage of 'tolerance', 'kTolerance' & 'fToleran
| |
228 struct Geometry { | 228 MSAAPathBatch(GrColor color, const SkPath& path, SkScalar tolerance, const S kMatrix& viewMatrix, |
229 GrColor fColor; | 229 const SkRect& devBounds) |
230 SkPath fPath; | 230 : INHERITED(ClassID()) |
231 SkScalar fTolerance; | 231 , fViewMatrix(viewMatrix) { |
232 }; | 232 fPaths.emplace_back(PathInfo{color, path, tolerance}); |
233 | 233 this->setBounds(devBounds); |
234 static MSAAPathBatch* Create(const Geometry& geometry, const SkMatrix& viewM atrix, | 234 int contourCount; |
235 const SkRect& devBounds) { | 235 this->computeWorstCasePointCount(path, &contourCount, kTolerance, |
236 return new MSAAPathBatch(geometry, viewMatrix, devBounds); | 236 &fMaxLineVertices, &fMaxQuadVertices); |
237 fMaxLineIndices = fMaxLineVertices * 3; | |
238 fMaxQuadIndices = fMaxQuadVertices * 3; | |
239 fIsIndexed = contourCount > 1; | |
237 } | 240 } |
238 | 241 |
239 const char* name() const override { return "MSAAPathBatch"; } | 242 const char* name() const override { return "MSAAPathBatch"; } |
240 | 243 |
241 void computePipelineOptimizations(GrInitInvariantOutput* color, | 244 void computePipelineOptimizations(GrInitInvariantOutput* color, |
242 GrInitInvariantOutput* coverage, | 245 GrInitInvariantOutput* coverage, |
243 GrBatchToXPOverrides* overrides) const ove rride { | 246 GrBatchToXPOverrides* overrides) const ove rride { |
244 // When this is called on a batch, there is only one geometry bundle | 247 // When this is called on a batch, there is only one path |
245 color->setKnownFourComponents(fGeoData[0].fColor); | 248 color->setKnownFourComponents(fPaths[0].fColor); |
246 coverage->setKnownSingleComponent(0xff); | 249 coverage->setKnownSingleComponent(0xff); |
247 } | 250 } |
248 | 251 |
249 bool isValid() const { | 252 bool isValid() const { |
250 return !fIsIndexed || fMaxLineIndices <= SK_MaxU16; | 253 return !fIsIndexed || fMaxLineIndices <= SK_MaxU16; |
251 } | 254 } |
252 | 255 |
253 private: | 256 private: |
254 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { | 257 void initBatchTracker(const GrXPOverridesForBatch& overrides) override { |
255 // Handle any color overrides | 258 // Handle any color overrides |
256 if (!overrides.readsColor()) { | 259 if (!overrides.readsColor()) { |
257 fGeoData[0].fColor = GrColor_ILLEGAL; | 260 fPaths[0].fColor = GrColor_ILLEGAL; |
258 } | 261 } |
259 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); | 262 overrides.getOverrideColorIfSet(&fPaths[0].fColor); |
260 } | 263 } |
261 | 264 |
262 void computeWorstCasePointCount(const SkPath& path, int* subpaths, SkScalar tol, | 265 void computeWorstCasePointCount(const SkPath& path, int* subpaths, SkScalar tol, |
263 int* outLinePointCount, int* outQuadPointCou nt) const { | 266 int* outLinePointCount, int* outQuadPointCou nt) const { |
264 int linePointCount = 0; | 267 int linePointCount = 0; |
265 int quadPointCount = 0; | 268 int quadPointCount = 0; |
266 *subpaths = 1; | 269 *subpaths = 1; |
267 | 270 |
268 bool first = true; | 271 bool first = true; |
269 | 272 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 if (fIsIndexed) { | 366 if (fIsIndexed) { |
364 quads.indices = (uint16_t*) sk_malloc_throw(fMaxQuadIndices * sizeof (uint16_t)); | 367 quads.indices = (uint16_t*) sk_malloc_throw(fMaxQuadIndices * sizeof (uint16_t)); |
365 quadIndexPtr.set(quads.indices); | 368 quadIndexPtr.set(quads.indices); |
366 quads.nextIndex = quads.indices; | 369 quads.nextIndex = quads.indices; |
367 } else { | 370 } else { |
368 quads.indices = nullptr; | 371 quads.indices = nullptr; |
369 quads.nextIndex = nullptr; | 372 quads.nextIndex = nullptr; |
370 } | 373 } |
371 | 374 |
372 // fill buffers | 375 // fill buffers |
373 for (int i = 0; i < fGeoData.count(); i++) { | 376 for (int i = 0; i < fPaths.count(); i++) { |
374 const Geometry& args = fGeoData[i]; | 377 const PathInfo& pathInfo = fPaths[i]; |
375 | 378 |
376 if (!this->createGeom(lines, | 379 if (!this->createGeom(lines, |
377 quads, | 380 quads, |
378 args.fPath, | 381 pathInfo.fPath, |
379 args.fTolerance, | 382 pathInfo.fTolerance, |
380 fViewMatrix, | 383 fViewMatrix, |
381 args.fColor, | 384 pathInfo.fColor, |
382 fIsIndexed)) { | 385 fIsIndexed)) { |
383 return; | 386 return; |
384 } | 387 } |
385 } | 388 } |
386 int lineVertexOffset = (int) (lines.nextVertex - lines.vertices); | 389 int lineVertexOffset = (int) (lines.nextVertex - lines.vertices); |
387 int lineIndexOffset = (int) (lines.nextIndex - lines.indices); | 390 int lineIndexOffset = (int) (lines.nextIndex - lines.indices); |
388 SkASSERT(lineVertexOffset <= fMaxLineVertices && lineIndexOffset <= fMax LineIndices); | 391 SkASSERT(lineVertexOffset <= fMaxLineVertices && lineIndexOffset <= fMax LineIndices); |
389 int quadVertexOffset = (int) (quads.nextVertex - quads.vertices); | 392 int quadVertexOffset = (int) (quads.nextVertex - quads.vertices); |
390 int quadIndexOffset = (int) (quads.nextIndex - quads.indices); | 393 int quadIndexOffset = (int) (quads.nextIndex - quads.indices); |
391 SkASSERT(quadVertexOffset <= fMaxQuadVertices && quadIndexOffset <= fMax QuadIndices); | 394 SkASSERT(quadVertexOffset <= fMaxQuadVertices && quadIndexOffset <= fMax QuadIndices); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 quadIndexBuffer, firstQuadVertex, firstQu adIndex, | 438 quadIndexBuffer, firstQuadVertex, firstQu adIndex, |
436 quadVertexOffset, quadIndexOffset); | 439 quadVertexOffset, quadIndexOffset); |
437 } else { | 440 } else { |
438 quadMeshes.init(kTriangles_GrPrimitiveType, quadVertexBuffer, fi rstQuadVertex, | 441 quadMeshes.init(kTriangles_GrPrimitiveType, quadVertexBuffer, fi rstQuadVertex, |
439 quadVertexOffset); | 442 quadVertexOffset); |
440 } | 443 } |
441 target->draw(quadGP, quadMeshes); | 444 target->draw(quadGP, quadMeshes); |
442 } | 445 } |
443 } | 446 } |
444 | 447 |
445 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | |
446 | |
447 MSAAPathBatch(const Geometry& geometry, const SkMatrix& viewMatrix, const Sk Rect& devBounds) | |
448 : INHERITED(ClassID()) | |
449 , fViewMatrix(viewMatrix) { | |
450 fGeoData.push_back(geometry); | |
451 this->setBounds(devBounds); | |
452 int contourCount; | |
453 this->computeWorstCasePointCount(geometry.fPath, &contourCount, kToleran ce, | |
454 &fMaxLineVertices, &fMaxQuadVertices); | |
455 fMaxLineIndices = fMaxLineVertices * 3; | |
456 fMaxQuadIndices = fMaxQuadVertices * 3; | |
457 fIsIndexed = contourCount > 1; | |
458 } | |
459 | |
460 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 448 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
461 MSAAPathBatch* that = t->cast<MSAAPathBatch>(); | 449 MSAAPathBatch* that = t->cast<MSAAPathBatch>(); |
462 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), | 450 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), |
463 that->bounds(), caps)) { | 451 that->bounds(), caps)) { |
464 return false; | 452 return false; |
465 } | 453 } |
466 | 454 |
467 if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) { | 455 if (!fViewMatrix.cheapEqualTo(that->fViewMatrix)) { |
468 return false; | 456 return false; |
469 } | 457 } |
470 | 458 |
471 if ((fMaxLineIndices + that->fMaxLineIndices > SK_MaxU16) || | 459 if ((fMaxLineIndices + that->fMaxLineIndices > SK_MaxU16) || |
472 (fMaxQuadIndices + that->fMaxQuadIndices > SK_MaxU16)) { | 460 (fMaxQuadIndices + that->fMaxQuadIndices > SK_MaxU16)) { |
473 return false; | 461 return false; |
474 } | 462 } |
475 | 463 |
476 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; | 464 fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin()); |
477 this->joinBounds(that->bounds()); | 465 this->joinBounds(that->bounds()); |
478 fIsIndexed = true; | 466 fIsIndexed = true; |
479 fMaxLineVertices += that->fMaxLineVertices; | 467 fMaxLineVertices += that->fMaxLineVertices; |
480 fMaxQuadVertices += that->fMaxQuadVertices; | 468 fMaxQuadVertices += that->fMaxQuadVertices; |
481 fMaxLineIndices += that->fMaxLineIndices; | 469 fMaxLineIndices += that->fMaxLineIndices; |
482 fMaxQuadIndices += that->fMaxQuadIndices; | 470 fMaxQuadIndices += that->fMaxQuadIndices; |
483 return true; | 471 return true; |
484 } | 472 } |
485 | 473 |
486 bool createGeom(MSAALineVertices& lines, | 474 bool createGeom(MSAALineVertices& lines, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 break; | 536 break; |
549 case SkPath::kDone_Verb: | 537 case SkPath::kDone_Verb: |
550 done = true; | 538 done = true; |
551 } | 539 } |
552 first = false; | 540 first = false; |
553 } | 541 } |
554 } | 542 } |
555 return true; | 543 return true; |
556 } | 544 } |
557 | 545 |
558 SkSTArray<1, Geometry, true> fGeoData; | 546 struct PathInfo { |
547 GrColor fColor; | |
548 SkPath fPath; | |
549 SkScalar fTolerance; | |
550 }; | |
551 | |
552 SkSTArray<1, PathInfo, true> fPaths; | |
559 | 553 |
560 SkMatrix fViewMatrix; | 554 SkMatrix fViewMatrix; |
561 int fMaxLineVertices; | 555 int fMaxLineVertices; |
562 int fMaxQuadVertices; | 556 int fMaxQuadVertices; |
563 int fMaxLineIndices; | 557 int fMaxLineIndices; |
564 int fMaxQuadIndices; | 558 int fMaxQuadIndices; |
565 bool fIsIndexed; | 559 bool fIsIndexed; |
566 | 560 |
567 typedef GrVertexBatch INHERITED; | 561 typedef GrVertexBatch INHERITED; |
568 }; | 562 }; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(pa int)); | 667 GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(pa int)); |
674 pipelineBuilder.setDrawFace(drawFace[p]); | 668 pipelineBuilder.setDrawFace(drawFace[p]); |
675 if (passes[p]) { | 669 if (passes[p]) { |
676 pipelineBuilder.setUserStencil(passes[p]); | 670 pipelineBuilder.setUserStencil(passes[p]); |
677 } else { | 671 } else { |
678 pipelineBuilder.setUserStencil(userStencilSettings); | 672 pipelineBuilder.setUserStencil(userStencilSettings); |
679 } | 673 } |
680 | 674 |
681 drawContext->drawBatch(pipelineBuilder, clip, batch); | 675 drawContext->drawBatch(pipelineBuilder, clip, batch); |
682 } else { | 676 } else { |
683 MSAAPathBatch::Geometry geometry; | 677 SkAutoTUnref<MSAAPathBatch> batch(new MSAAPathBatch(color, path, kTo lerance, viewMatrix, |
684 geometry.fColor = color; | 678 devBounds)); |
685 geometry.fPath = path; | |
686 geometry.fTolerance = kTolerance; | |
687 | |
688 SkAutoTUnref<MSAAPathBatch> batch(MSAAPathBatch::Create(geometry, vi ewMatrix, | |
689 devBounds)); | |
690 if (!batch->isValid()) { | 679 if (!batch->isValid()) { |
691 return false; | 680 return false; |
692 } | 681 } |
693 | 682 |
694 GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(pa int)); | 683 GrPipelineBuilder pipelineBuilder(paint, drawContext->mustUseHWAA(pa int)); |
695 pipelineBuilder.setDrawFace(drawFace[p]); | 684 pipelineBuilder.setDrawFace(drawFace[p]); |
696 if (passes[p]) { | 685 if (passes[p]) { |
697 pipelineBuilder.setUserStencil(passes[p]); | 686 pipelineBuilder.setUserStencil(passes[p]); |
698 } else { | 687 } else { |
699 pipelineBuilder.setUserStencil(userStencilSettings); | 688 pipelineBuilder.setUserStencil(userStencilSettings); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
743 | 732 |
744 GrPaint paint; | 733 GrPaint paint; |
745 paint.setXPFactory(GrDisableColorXPFactory::Make()); | 734 paint.setXPFactory(GrDisableColorXPFactory::Make()); |
746 paint.setAntiAlias(args.fIsAA); | 735 paint.setAntiAlias(args.fIsAA); |
747 | 736 |
748 this->internalDrawPath(args.fDrawContext, paint, &GrUserStencilSettings::kUn used, *args.fClip, | 737 this->internalDrawPath(args.fDrawContext, paint, &GrUserStencilSettings::kUn used, *args.fClip, |
749 GrColor_WHITE, *args.fViewMatrix, *args.fShape, true) ; | 738 GrColor_WHITE, *args.fViewMatrix, *args.fShape, true) ; |
750 } | 739 } |
751 | 740 |
752 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 741 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
OLD | NEW |