OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 "GrAAConvexPathRenderer.h" | 9 #include "GrAAConvexPathRenderer.h" |
10 | 10 |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 506 |
507 class QuadEdgeEffect : public GrGeometryProcessor { | 507 class QuadEdgeEffect : public GrGeometryProcessor { |
508 public: | 508 public: |
509 | 509 |
510 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& localMatri
x) { | 510 static GrGeometryProcessor* Create(GrColor color, const SkMatrix& localMatri
x) { |
511 return SkNEW_ARGS(QuadEdgeEffect, (color, localMatrix)); | 511 return SkNEW_ARGS(QuadEdgeEffect, (color, localMatrix)); |
512 } | 512 } |
513 | 513 |
514 virtual ~QuadEdgeEffect() {} | 514 virtual ~QuadEdgeEffect() {} |
515 | 515 |
516 const char* name() const SK_OVERRIDE { return "QuadEdge"; } | 516 const char* name() const override { return "QuadEdge"; } |
517 | 517 |
518 const Attribute* inPosition() const { return fInPosition; } | 518 const Attribute* inPosition() const { return fInPosition; } |
519 const Attribute* inQuadEdge() const { return fInQuadEdge; } | 519 const Attribute* inQuadEdge() const { return fInQuadEdge; } |
520 | 520 |
521 class GLProcessor : public GrGLGeometryProcessor { | 521 class GLProcessor : public GrGLGeometryProcessor { |
522 public: | 522 public: |
523 GLProcessor(const GrGeometryProcessor&, | 523 GLProcessor(const GrGeometryProcessor&, |
524 const GrBatchTracker&) | 524 const GrBatchTracker&) |
525 : fColor(GrColor_ILLEGAL) {} | 525 : fColor(GrColor_ILLEGAL) {} |
526 | 526 |
527 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE { | 527 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
528 const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>(); | 528 const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>(); |
529 GrGLGPBuilder* pb = args.fPB; | 529 GrGLGPBuilder* pb = args.fPB; |
530 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 530 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
531 | 531 |
532 // emit attributes | 532 // emit attributes |
533 vsBuilder->emitAttributes(qe); | 533 vsBuilder->emitAttributes(qe); |
534 | 534 |
535 GrGLVertToFrag v(kVec4f_GrSLType); | 535 GrGLVertToFrag v(kVec4f_GrSLType); |
536 args.fPB->addVarying("QuadEdge", &v); | 536 args.fPB->addVarying("QuadEdge", &v); |
537 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.inQuadEdge()->fName
); | 537 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.inQuadEdge()->fName
); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 GrProcessorKeyBuilder* b) { | 580 GrProcessorKeyBuilder* b) { |
581 const BatchTracker& local = bt.cast<BatchTracker>(); | 581 const BatchTracker& local = bt.cast<BatchTracker>(); |
582 uint32_t key = local.fInputColorType << 16; | 582 uint32_t key = local.fInputColorType << 16; |
583 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ?
0x1 : 0x0; | 583 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ?
0x1 : 0x0; |
584 key |= ComputePosKey(gp.viewMatrix()) << 1; | 584 key |= ComputePosKey(gp.viewMatrix()) << 1; |
585 b->add32(key); | 585 b->add32(key); |
586 } | 586 } |
587 | 587 |
588 virtual void setData(const GrGLProgramDataManager& pdman, | 588 virtual void setData(const GrGLProgramDataManager& pdman, |
589 const GrPrimitiveProcessor& gp, | 589 const GrPrimitiveProcessor& gp, |
590 const GrBatchTracker& bt) SK_OVERRIDE { | 590 const GrBatchTracker& bt) override { |
591 this->setUniformViewMatrix(pdman, gp.viewMatrix()); | 591 this->setUniformViewMatrix(pdman, gp.viewMatrix()); |
592 | 592 |
593 const BatchTracker& local = bt.cast<BatchTracker>(); | 593 const BatchTracker& local = bt.cast<BatchTracker>(); |
594 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { | 594 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { |
595 GrGLfloat c[4]; | 595 GrGLfloat c[4]; |
596 GrColorToRGBAFloat(local.fColor, c); | 596 GrColorToRGBAFloat(local.fColor, c); |
597 pdman.set4fv(fColorUniform, 1, c); | 597 pdman.set4fv(fColorUniform, 1, c); |
598 fColor = local.fColor; | 598 fColor = local.fColor; |
599 } | 599 } |
600 } | 600 } |
601 | 601 |
602 private: | 602 private: |
603 GrColor fColor; | 603 GrColor fColor; |
604 UniformHandle fColorUniform; | 604 UniformHandle fColorUniform; |
605 | 605 |
606 typedef GrGLGeometryProcessor INHERITED; | 606 typedef GrGLGeometryProcessor INHERITED; |
607 }; | 607 }; |
608 | 608 |
609 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 609 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
610 const GrGLCaps& caps, | 610 const GrGLCaps& caps, |
611 GrProcessorKeyBuilder* b) const SK_OVERRIDE { | 611 GrProcessorKeyBuilder* b) const override { |
612 GLProcessor::GenKey(*this, bt, caps, b); | 612 GLProcessor::GenKey(*this, bt, caps, b); |
613 } | 613 } |
614 | 614 |
615 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 615 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
616 const GrGLCaps&) const SK_O
VERRIDE { | 616 const GrGLCaps&) const over
ride { |
617 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 617 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
618 } | 618 } |
619 | 619 |
620 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
SK_OVERRIDE { | 620 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { |
621 BatchTracker* local = bt->cast<BatchTracker>(); | 621 BatchTracker* local = bt->cast<BatchTracker>(); |
622 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); | 622 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); |
623 local->fUsesLocalCoords = init.fUsesLocalCoords; | 623 local->fUsesLocalCoords = init.fUsesLocalCoords; |
624 } | 624 } |
625 | 625 |
626 bool onCanMakeEqual(const GrBatchTracker& m, | 626 bool onCanMakeEqual(const GrBatchTracker& m, |
627 const GrGeometryProcessor& that, | 627 const GrGeometryProcessor& that, |
628 const GrBatchTracker& t) const SK_OVERRIDE { | 628 const GrBatchTracker& t) const override { |
629 const BatchTracker& mine = m.cast<BatchTracker>(); | 629 const BatchTracker& mine = m.cast<BatchTracker>(); |
630 const BatchTracker& theirs = t.cast<BatchTracker>(); | 630 const BatchTracker& theirs = t.cast<BatchTracker>(); |
631 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, | 631 return CanCombineLocalMatrices(*this, mine.fUsesLocalCoords, |
632 that, theirs.fUsesLocalCoords) && | 632 that, theirs.fUsesLocalCoords) && |
633 CanCombineOutput(mine.fInputColorType, mine.fColor, | 633 CanCombineOutput(mine.fInputColorType, mine.fColor, |
634 theirs.fInputColorType, theirs.fColor); | 634 theirs.fInputColorType, theirs.fColor); |
635 } | 635 } |
636 | 636 |
637 private: | 637 private: |
638 QuadEdgeEffect(GrColor color, const SkMatrix& localMatrix) | 638 QuadEdgeEffect(GrColor color, const SkMatrix& localMatrix) |
639 : INHERITED(color, SkMatrix::I(), localMatrix) { | 639 : INHERITED(color, SkMatrix::I(), localMatrix) { |
640 this->initClassID<QuadEdgeEffect>(); | 640 this->initClassID<QuadEdgeEffect>(); |
641 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 641 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
642 fInQuadEdge = &this->addVertexAttrib(Attribute("inQuadEdge", kVec4f_GrVe
rtexAttribType)); | 642 fInQuadEdge = &this->addVertexAttrib(Attribute("inQuadEdge", kVec4f_GrVe
rtexAttribType)); |
643 } | 643 } |
644 | 644 |
645 bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE { | 645 bool onIsEqual(const GrGeometryProcessor& other) const override { |
646 return true; | 646 return true; |
647 } | 647 } |
648 | 648 |
649 void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERR
IDE { | 649 void onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const override
{ |
650 out->setUnknownSingleComponent(); | 650 out->setUnknownSingleComponent(); |
651 } | 651 } |
652 | 652 |
653 struct BatchTracker { | 653 struct BatchTracker { |
654 GrGPInput fInputColorType; | 654 GrGPInput fInputColorType; |
655 GrColor fColor; | 655 GrColor fColor; |
656 bool fUsesLocalCoords; | 656 bool fUsesLocalCoords; |
657 }; | 657 }; |
658 | 658 |
659 const Attribute* fInPosition; | 659 const Attribute* fInPosition; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 struct Geometry { | 693 struct Geometry { |
694 GrColor fColor; | 694 GrColor fColor; |
695 SkMatrix fViewMatrix; | 695 SkMatrix fViewMatrix; |
696 SkPath fPath; | 696 SkPath fPath; |
697 }; | 697 }; |
698 | 698 |
699 static GrBatch* Create(const Geometry& geometry) { | 699 static GrBatch* Create(const Geometry& geometry) { |
700 return SkNEW_ARGS(AAConvexPathBatch, (geometry)); | 700 return SkNEW_ARGS(AAConvexPathBatch, (geometry)); |
701 } | 701 } |
702 | 702 |
703 const char* name() const SK_OVERRIDE { return "AAConvexBatch"; } | 703 const char* name() const override { return "AAConvexBatch"; } |
704 | 704 |
705 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { | 705 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
706 // When this is called on a batch, there is only one geometry bundle | 706 // When this is called on a batch, there is only one geometry bundle |
707 out->setKnownFourComponents(fGeoData[0].fColor); | 707 out->setKnownFourComponents(fGeoData[0].fColor); |
708 } | 708 } |
709 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E { | 709 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
710 out->setUnknownSingleComponent(); | 710 out->setUnknownSingleComponent(); |
711 } | 711 } |
712 | 712 |
713 void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { | 713 void initBatchTracker(const GrPipelineInfo& init) override { |
714 // Handle any color overrides | 714 // Handle any color overrides |
715 if (init.fColorIgnored) { | 715 if (init.fColorIgnored) { |
716 fGeoData[0].fColor = GrColor_ILLEGAL; | 716 fGeoData[0].fColor = GrColor_ILLEGAL; |
717 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | 717 } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
718 fGeoData[0].fColor = init.fOverrideColor; | 718 fGeoData[0].fColor = init.fOverrideColor; |
719 } | 719 } |
720 | 720 |
721 // setup batch properties | 721 // setup batch properties |
722 fBatch.fColorIgnored = init.fColorIgnored; | 722 fBatch.fColorIgnored = init.fColorIgnored; |
723 fBatch.fColor = fGeoData[0].fColor; | 723 fBatch.fColor = fGeoData[0].fColor; |
724 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 724 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
725 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 725 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
726 } | 726 } |
727 | 727 |
728 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) SK_OVERRIDE { | 728 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
729 int instanceCount = fGeoData.count(); | 729 int instanceCount = fGeoData.count(); |
730 | 730 |
731 SkMatrix invert; | 731 SkMatrix invert; |
732 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { | 732 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { |
733 SkDebugf("Could not invert viewmatrix\n"); | 733 SkDebugf("Could not invert viewmatrix\n"); |
734 return; | 734 return; |
735 } | 735 } |
736 | 736 |
737 // Setup GrGeometryProcessor | 737 // Setup GrGeometryProcessor |
738 SkAutoTUnref<GrGeometryProcessor> quadProcessor(QuadEdgeEffect::Create(t
his->color(), | 738 SkAutoTUnref<GrGeometryProcessor> quadProcessor(QuadEdgeEffect::Create(t
his->color(), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 } | 826 } |
827 | 827 |
828 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 828 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
829 | 829 |
830 private: | 830 private: |
831 AAConvexPathBatch(const Geometry& geometry) { | 831 AAConvexPathBatch(const Geometry& geometry) { |
832 this->initClassID<AAConvexPathBatch>(); | 832 this->initClassID<AAConvexPathBatch>(); |
833 fGeoData.push_back(geometry); | 833 fGeoData.push_back(geometry); |
834 } | 834 } |
835 | 835 |
836 bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { | 836 bool onCombineIfPossible(GrBatch* t) override { |
837 AAConvexPathBatch* that = t->cast<AAConvexPathBatch>(); | 837 AAConvexPathBatch* that = t->cast<AAConvexPathBatch>(); |
838 | 838 |
839 if (this->color() != that->color()) { | 839 if (this->color() != that->color()) { |
840 return false; | 840 return false; |
841 } | 841 } |
842 | 842 |
843 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 843 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
844 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 844 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
845 return false; | 845 return false; |
846 } | 846 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
885 geometry.fColor = color; | 885 geometry.fColor = color; |
886 geometry.fViewMatrix = vm; | 886 geometry.fViewMatrix = vm; |
887 geometry.fPath = path; | 887 geometry.fPath = path; |
888 | 888 |
889 SkAutoTUnref<GrBatch> batch(AAConvexPathBatch::Create(geometry)); | 889 SkAutoTUnref<GrBatch> batch(AAConvexPathBatch::Create(geometry)); |
890 target->drawBatch(pipelineBuilder, batch, &devRect); | 890 target->drawBatch(pipelineBuilder, batch, &devRect); |
891 | 891 |
892 return true; | 892 return true; |
893 | 893 |
894 } | 894 } |
OLD | NEW |