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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 return SkNEW_ARGS(QuadEdgeEffect, (color, localMatrix)); | 529 return SkNEW_ARGS(QuadEdgeEffect, (color, localMatrix)); |
530 } | 530 } |
531 | 531 |
532 virtual ~QuadEdgeEffect() {} | 532 virtual ~QuadEdgeEffect() {} |
533 | 533 |
534 const char* name() const override { return "QuadEdge"; } | 534 const char* name() const override { return "QuadEdge"; } |
535 | 535 |
536 const Attribute* inPosition() const { return fInPosition; } | 536 const Attribute* inPosition() const { return fInPosition; } |
537 const Attribute* inQuadEdge() const { return fInQuadEdge; } | 537 const Attribute* inQuadEdge() const { return fInQuadEdge; } |
538 GrColor color() const { return fColor; } | 538 GrColor color() const { return fColor; } |
| 539 const SkMatrix& localMatrix() const { return fLocalMatrix; } |
539 | 540 |
540 class GLProcessor : public GrGLGeometryProcessor { | 541 class GLProcessor : public GrGLGeometryProcessor { |
541 public: | 542 public: |
542 GLProcessor(const GrGeometryProcessor&, | 543 GLProcessor(const GrGeometryProcessor&, |
543 const GrBatchTracker&) | 544 const GrBatchTracker&) |
544 : fColor(GrColor_ILLEGAL) {} | 545 : fColor(GrColor_ILLEGAL) {} |
545 | 546 |
546 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 547 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
547 const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>(); | 548 const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>(); |
548 GrGLGPBuilder* pb = args.fPB; | 549 GrGLGPBuilder* pb = args.fPB; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);}"); | 592 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0
);}"); |
592 | 593 |
593 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); | 594 fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage
); |
594 } | 595 } |
595 | 596 |
596 static inline void GenKey(const GrGeometryProcessor& gp, | 597 static inline void GenKey(const GrGeometryProcessor& gp, |
597 const GrBatchTracker& bt, | 598 const GrBatchTracker& bt, |
598 const GrGLSLCaps&, | 599 const GrGLSLCaps&, |
599 GrProcessorKeyBuilder* b) { | 600 GrProcessorKeyBuilder* b) { |
600 const BatchTracker& local = bt.cast<BatchTracker>(); | 601 const BatchTracker& local = bt.cast<BatchTracker>(); |
| 602 const QuadEdgeEffect& qee = gp.cast<QuadEdgeEffect>(); |
601 uint32_t key = local.fInputColorType << 16; | 603 uint32_t key = local.fInputColorType << 16; |
602 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ?
0x1 : 0x0; | 604 key |= local.fUsesLocalCoords && qee.localMatrix().hasPerspective()
? 0x1 : 0x0; |
603 b->add32(key); | 605 b->add32(key); |
604 } | 606 } |
605 | 607 |
606 virtual void setData(const GrGLProgramDataManager& pdman, | 608 virtual void setData(const GrGLProgramDataManager& pdman, |
607 const GrPrimitiveProcessor& gp, | 609 const GrPrimitiveProcessor& gp, |
608 const GrBatchTracker& bt) override { | 610 const GrBatchTracker& bt) override { |
609 const BatchTracker& local = bt.cast<BatchTracker>(); | 611 const BatchTracker& local = bt.cast<BatchTracker>(); |
610 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { | 612 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != f
Color) { |
611 GrGLfloat c[4]; | 613 GrGLfloat c[4]; |
612 GrColorToRGBAFloat(local.fColor, c); | 614 GrColorToRGBAFloat(local.fColor, c); |
613 pdman.set4fv(fColorUniform, 1, c); | 615 pdman.set4fv(fColorUniform, 1, c); |
614 fColor = local.fColor; | 616 fColor = local.fColor; |
615 } | 617 } |
616 } | 618 } |
617 | 619 |
| 620 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 621 const GrGLProgramDataManager& pdman, |
| 622 int index, |
| 623 const SkTArray<const GrCoordTransform*, true>& tra
nsforms) override { |
| 624 this->setTransformDataHelper<QuadEdgeEffect>(primProc, pdman, index,
transforms); |
| 625 } |
| 626 |
618 private: | 627 private: |
619 GrColor fColor; | 628 GrColor fColor; |
620 UniformHandle fColorUniform; | 629 UniformHandle fColorUniform; |
621 | 630 |
622 typedef GrGLGeometryProcessor INHERITED; | 631 typedef GrGLGeometryProcessor INHERITED; |
623 }; | 632 }; |
624 | 633 |
625 virtual void getGLProcessorKey(const GrBatchTracker& bt, | 634 virtual void getGLProcessorKey(const GrBatchTracker& bt, |
626 const GrGLSLCaps& caps, | 635 const GrGLSLCaps& caps, |
627 GrProcessorKeyBuilder* b) const override { | 636 GrProcessorKeyBuilder* b) const override { |
628 GLProcessor::GenKey(*this, bt, caps, b); | 637 GLProcessor::GenKey(*this, bt, caps, b); |
629 } | 638 } |
630 | 639 |
631 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, | 640 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, |
632 const GrGLSLCaps&) const ov
erride { | 641 const GrGLSLCaps&) const ov
erride { |
633 return SkNEW_ARGS(GLProcessor, (*this, bt)); | 642 return SkNEW_ARGS(GLProcessor, (*this, bt)); |
634 } | 643 } |
635 | 644 |
636 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { | 645 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const
override { |
637 BatchTracker* local = bt->cast<BatchTracker>(); | 646 BatchTracker* local = bt->cast<BatchTracker>(); |
638 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); | 647 local->fInputColorType = GetColorInputType(&local->fColor, this->color()
, init, false); |
639 local->fUsesLocalCoords = init.fUsesLocalCoords; | 648 local->fUsesLocalCoords = init.fUsesLocalCoords; |
640 } | 649 } |
641 | 650 |
642 private: | 651 private: |
643 QuadEdgeEffect(GrColor color, const SkMatrix& localMatrix) | 652 QuadEdgeEffect(GrColor color, const SkMatrix& localMatrix) |
644 : INHERITED(localMatrix) | 653 : fColor(color) |
645 , fColor(color) { | 654 , fLocalMatrix(localMatrix) { |
646 this->initClassID<QuadEdgeEffect>(); | 655 this->initClassID<QuadEdgeEffect>(); |
647 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); | 656 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType)); |
648 fInQuadEdge = &this->addVertexAttrib(Attribute("inQuadEdge", kVec4f_GrVe
rtexAttribType)); | 657 fInQuadEdge = &this->addVertexAttrib(Attribute("inQuadEdge", kVec4f_GrVe
rtexAttribType)); |
649 } | 658 } |
650 | 659 |
651 struct BatchTracker { | 660 struct BatchTracker { |
652 GrGPInput fInputColorType; | 661 GrGPInput fInputColorType; |
653 GrColor fColor; | 662 GrColor fColor; |
654 bool fUsesLocalCoords; | 663 bool fUsesLocalCoords; |
655 }; | 664 }; |
656 | 665 |
657 const Attribute* fInPosition; | 666 const Attribute* fInPosition; |
658 const Attribute* fInQuadEdge; | 667 const Attribute* fInQuadEdge; |
659 GrColor fColor; | 668 GrColor fColor; |
| 669 SkMatrix fLocalMatrix; |
660 | 670 |
661 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 671 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
662 | 672 |
663 typedef GrGeometryProcessor INHERITED; | 673 typedef GrGeometryProcessor INHERITED; |
664 }; | 674 }; |
665 | 675 |
666 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); | 676 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); |
667 | 677 |
668 GrGeometryProcessor* QuadEdgeEffect::TestCreate(SkRandom* random, | 678 GrGeometryProcessor* QuadEdgeEffect::TestCreate(SkRandom* random, |
669 GrContext*, | 679 GrContext*, |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 BATCH_TEST_DEFINE(AAConvexPath) { | 1035 BATCH_TEST_DEFINE(AAConvexPath) { |
1026 AAConvexPathBatch::Geometry geometry; | 1036 AAConvexPathBatch::Geometry geometry; |
1027 geometry.fColor = GrRandomColor(random); | 1037 geometry.fColor = GrRandomColor(random); |
1028 geometry.fViewMatrix = GrTest::TestMatrix(random); | 1038 geometry.fViewMatrix = GrTest::TestMatrix(random); |
1029 geometry.fPath = GrTest::TestPathConvex(random); | 1039 geometry.fPath = GrTest::TestPathConvex(random); |
1030 | 1040 |
1031 return AAConvexPathBatch::Create(geometry); | 1041 return AAConvexPathBatch::Create(geometry); |
1032 } | 1042 } |
1033 | 1043 |
1034 #endif | 1044 #endif |
OLD | NEW |