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 "GrDashingEffect.h" | 8 #include "GrDashingEffect.h" |
9 | 9 |
10 #include "../GrAARectRenderer.h" | 10 #include "../GrAARectRenderer.h" |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 * Both of the previous two parameters are in device space. This effect also req
uires the setting of | 419 * Both of the previous two parameters are in device space. This effect also req
uires the setting of |
420 * a vec2 vertex attribute for the the four corners of the bounding rect. This a
ttribute is the | 420 * a vec2 vertex attribute for the the four corners of the bounding rect. This a
ttribute is the |
421 * "dash position" of each vertex. In other words it is the vertex coords (in de
vice space) if we | 421 * "dash position" of each vertex. In other words it is the vertex coords (in de
vice space) if we |
422 * transform the line to be horizontal, with the start of line at the origin the
n shifted to the | 422 * transform the line to be horizontal, with the start of line at the origin the
n shifted to the |
423 * right by half the off interval. The line then goes in the positive x directio
n. | 423 * right by half the off interval. The line then goes in the positive x directio
n. |
424 */ | 424 */ |
425 class DashingCircleEffect : public GrVertexEffect { | 425 class DashingCircleEffect : public GrVertexEffect { |
426 public: | 426 public: |
427 typedef SkPathEffect::DashInfo DashInfo; | 427 typedef SkPathEffect::DashInfo DashInfo; |
428 | 428 |
429 static GrEffectRef* Create(GrEffectEdgeType edgeType, const DashInfo& info, | 429 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS
calar radius); |
430 SkScalar radius); | |
431 | 430 |
432 virtual ~DashingCircleEffect(); | 431 virtual ~DashingCircleEffect(); |
433 | 432 |
434 static const char* Name() { return "DashingCircleEffect"; } | 433 static const char* Name() { return "DashingCircleEffect"; } |
435 | 434 |
436 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 435 GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
437 | 436 |
438 SkScalar getRadius() const { return fRadius; } | 437 SkScalar getRadius() const { return fRadius; } |
439 | 438 |
440 SkScalar getCenterX() const { return fCenterX; } | 439 SkScalar getCenterX() const { return fCenterX; } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 } | 549 } |
551 | 550 |
552 GrGLEffect::EffectKey GLDashingCircleEffect::GenKey(const GrDrawEffect& drawEffe
ct, | 551 GrGLEffect::EffectKey GLDashingCircleEffect::GenKey(const GrDrawEffect& drawEffe
ct, |
553 const GrGLCaps&) { | 552 const GrGLCaps&) { |
554 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>(
); | 553 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>(
); |
555 return dce.getEdgeType(); | 554 return dce.getEdgeType(); |
556 } | 555 } |
557 | 556 |
558 ////////////////////////////////////////////////////////////////////////////// | 557 ////////////////////////////////////////////////////////////////////////////// |
559 | 558 |
560 GrEffectRef* DashingCircleEffect::Create(GrEffectEdgeType edgeType, const DashIn
fo& info, | 559 GrEffect* DashingCircleEffect::Create(GrEffectEdgeType edgeType, const DashInfo&
info, |
561 SkScalar radius) { | 560 SkScalar radius) { |
562 if (info.fCount != 2 || info.fIntervals[0] != 0) { | 561 if (info.fCount != 2 || info.fIntervals[0] != 0) { |
563 return NULL; | 562 return NULL; |
564 } | 563 } |
565 | 564 |
566 return SkNEW_ARGS(DashingCircleEffect, (edgeType, info, radius)); | 565 return SkNEW_ARGS(DashingCircleEffect, (edgeType, info, radius)); |
567 } | 566 } |
568 | 567 |
569 DashingCircleEffect::~DashingCircleEffect() {} | 568 DashingCircleEffect::~DashingCircleEffect() {} |
570 | 569 |
571 void DashingCircleEffect::getConstantColorComponents(GrColor* color, uint32_t* v
alidFlags) const { | 570 void DashingCircleEffect::getConstantColorComponents(GrColor* color, uint32_t* v
alidFlags) const { |
(...skipping 19 matching lines...) Expand all Loading... |
591 bool DashingCircleEffect::onIsEqual(const GrEffect& other) const { | 590 bool DashingCircleEffect::onIsEqual(const GrEffect& other) const { |
592 const DashingCircleEffect& dce = CastEffect<DashingCircleEffect>(other); | 591 const DashingCircleEffect& dce = CastEffect<DashingCircleEffect>(other); |
593 return (fEdgeType == dce.fEdgeType && | 592 return (fEdgeType == dce.fEdgeType && |
594 fIntervalLength == dce.fIntervalLength && | 593 fIntervalLength == dce.fIntervalLength && |
595 fRadius == dce.fRadius && | 594 fRadius == dce.fRadius && |
596 fCenterX == dce.fCenterX); | 595 fCenterX == dce.fCenterX); |
597 } | 596 } |
598 | 597 |
599 GR_DEFINE_EFFECT_TEST(DashingCircleEffect); | 598 GR_DEFINE_EFFECT_TEST(DashingCircleEffect); |
600 | 599 |
601 GrEffectRef* DashingCircleEffect::TestCreate(SkRandom* random, | 600 GrEffect* DashingCircleEffect::TestCreate(SkRandom* random, |
602 GrContext*, | 601 GrContext*, |
603 const GrDrawTargetCaps& caps, | 602 const GrDrawTargetCaps& caps, |
604 GrTexture*[]) { | 603 GrTexture*[]) { |
605 GrEffectRef* effect; | 604 GrEffect* effect; |
606 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextULessT
han( | 605 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextULessT
han( |
607 kGrEffectEdgeTypeCnt)); | 606 kGrEffectEdgeTypeCnt)); |
608 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); | 607 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); |
609 DashInfo info; | 608 DashInfo info; |
610 info.fCount = 2; | 609 info.fCount = 2; |
611 SkAutoTArray<SkScalar> intervals(info.fCount); | 610 SkAutoTArray<SkScalar> intervals(info.fCount); |
612 info.fIntervals = intervals.get(); | 611 info.fIntervals = intervals.get(); |
613 info.fIntervals[0] = 0; | 612 info.fIntervals[0] = 0; |
614 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); | 613 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); |
615 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); | 614 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); |
(...skipping 12 matching lines...) Expand all Loading... |
628 * This effect also requires the setting of a vec2 vertex attribute for the the
four corners of the | 627 * This effect also requires the setting of a vec2 vertex attribute for the the
four corners of the |
629 * bounding rect. This attribute is the "dash position" of each vertex. In other
words it is the | 628 * bounding rect. This attribute is the "dash position" of each vertex. In other
words it is the |
630 * vertex coords (in device space) if we transform the line to be horizontal, wi
th the start of | 629 * vertex coords (in device space) if we transform the line to be horizontal, wi
th the start of |
631 * line at the origin then shifted to the right by half the off interval. The li
ne then goes in the | 630 * line at the origin then shifted to the right by half the off interval. The li
ne then goes in the |
632 * positive x direction. | 631 * positive x direction. |
633 */ | 632 */ |
634 class DashingLineEffect : public GrVertexEffect { | 633 class DashingLineEffect : public GrVertexEffect { |
635 public: | 634 public: |
636 typedef SkPathEffect::DashInfo DashInfo; | 635 typedef SkPathEffect::DashInfo DashInfo; |
637 | 636 |
638 static GrEffectRef* Create(GrEffectEdgeType edgeType, const DashInfo& info, | 637 static GrEffect* Create(GrEffectEdgeType edgeType, const DashInfo& info, SkS
calar strokeWidth); |
639 SkScalar strokeWidth); | |
640 | 638 |
641 virtual ~DashingLineEffect(); | 639 virtual ~DashingLineEffect(); |
642 | 640 |
643 static const char* Name() { return "DashingEffect"; } | 641 static const char* Name() { return "DashingEffect"; } |
644 | 642 |
645 GrEffectEdgeType getEdgeType() const { return fEdgeType; } | 643 GrEffectEdgeType getEdgeType() const { return fEdgeType; } |
646 | 644 |
647 const SkRect& getRect() const { return fRect; } | 645 const SkRect& getRect() const { return fRect; } |
648 | 646 |
649 SkScalar getIntervalLength() const { return fIntervalLength; } | 647 SkScalar getIntervalLength() const { return fIntervalLength; } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 } | 766 } |
769 | 767 |
770 GrGLEffect::EffectKey GLDashingLineEffect::GenKey(const GrDrawEffect& drawEffect
, | 768 GrGLEffect::EffectKey GLDashingLineEffect::GenKey(const GrDrawEffect& drawEffect
, |
771 const GrGLCaps&) { | 769 const GrGLCaps&) { |
772 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); | 770 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); |
773 return de.getEdgeType(); | 771 return de.getEdgeType(); |
774 } | 772 } |
775 | 773 |
776 ////////////////////////////////////////////////////////////////////////////// | 774 ////////////////////////////////////////////////////////////////////////////// |
777 | 775 |
778 GrEffectRef* DashingLineEffect::Create(GrEffectEdgeType edgeType, const DashInfo
& info, | 776 GrEffect* DashingLineEffect::Create(GrEffectEdgeType edgeType, const DashInfo& i
nfo, |
779 SkScalar strokeWidth) { | 777 SkScalar strokeWidth) { |
780 if (info.fCount != 2) { | 778 if (info.fCount != 2) { |
781 return NULL; | 779 return NULL; |
782 } | 780 } |
783 | 781 |
784 return SkNEW_ARGS(DashingLineEffect, (edgeType, info, strokeWidth)); | 782 return SkNEW_ARGS(DashingLineEffect, (edgeType, info, strokeWidth)); |
785 } | 783 } |
786 | 784 |
787 DashingLineEffect::~DashingLineEffect() {} | 785 DashingLineEffect::~DashingLineEffect() {} |
788 | 786 |
789 void DashingLineEffect::getConstantColorComponents(GrColor* color, uint32_t* val
idFlags) const { | 787 void DashingLineEffect::getConstantColorComponents(GrColor* color, uint32_t* val
idFlags) const { |
(...skipping 19 matching lines...) Expand all Loading... |
809 | 807 |
810 bool DashingLineEffect::onIsEqual(const GrEffect& other) const { | 808 bool DashingLineEffect::onIsEqual(const GrEffect& other) const { |
811 const DashingLineEffect& de = CastEffect<DashingLineEffect>(other); | 809 const DashingLineEffect& de = CastEffect<DashingLineEffect>(other); |
812 return (fEdgeType == de.fEdgeType && | 810 return (fEdgeType == de.fEdgeType && |
813 fRect == de.fRect && | 811 fRect == de.fRect && |
814 fIntervalLength == de.fIntervalLength); | 812 fIntervalLength == de.fIntervalLength); |
815 } | 813 } |
816 | 814 |
817 GR_DEFINE_EFFECT_TEST(DashingLineEffect); | 815 GR_DEFINE_EFFECT_TEST(DashingLineEffect); |
818 | 816 |
819 GrEffectRef* DashingLineEffect::TestCreate(SkRandom* random, | 817 GrEffect* DashingLineEffect::TestCreate(SkRandom* random, |
820 GrContext*, | 818 GrContext*, |
821 const GrDrawTargetCaps& caps, | 819 const GrDrawTargetCaps& caps, |
822 GrTexture*[]) { | 820 GrTexture*[]) { |
823 GrEffectRef* effect; | 821 GrEffect* effect; |
824 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextULessT
han( | 822 GrEffectEdgeType edgeType = static_cast<GrEffectEdgeType>(random->nextULessT
han( |
825 kGrEffectEdgeTypeCnt)); | 823 kGrEffectEdgeTypeCnt)); |
826 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); | 824 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); |
827 DashInfo info; | 825 DashInfo info; |
828 info.fCount = 2; | 826 info.fCount = 2; |
829 SkAutoTArray<SkScalar> intervals(info.fCount); | 827 SkAutoTArray<SkScalar> intervals(info.fCount); |
830 info.fIntervals = intervals.get(); | 828 info.fIntervals = intervals.get(); |
831 info.fIntervals[0] = random->nextRangeScalar(0, 10.f); | 829 info.fIntervals[0] = random->nextRangeScalar(0, 10.f); |
832 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); | 830 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); |
833 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval
s[1]); | 831 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval
s[1]); |
834 | 832 |
835 effect = DashingLineEffect::Create(edgeType, info, strokeWidth); | 833 effect = DashingLineEffect::Create(edgeType, info, strokeWidth); |
836 return effect; | 834 return effect; |
837 } | 835 } |
838 | 836 |
839 ////////////////////////////////////////////////////////////////////////////// | 837 ////////////////////////////////////////////////////////////////////////////// |
840 | 838 |
841 GrEffectRef* GrDashingEffect::Create(GrEffectEdgeType edgeType, const SkPathEffe
ct::DashInfo& info, | 839 GrEffect* GrDashingEffect::Create(GrEffectEdgeType edgeType, const SkPathEffect:
:DashInfo& info, |
842 SkScalar strokeWidth, GrDashingEffect::Dash
Cap cap) { | 840 SkScalar strokeWidth, GrDashingEffect::DashCap
cap) { |
843 switch (cap) { | 841 switch (cap) { |
844 case GrDashingEffect::kRound_DashCap: | 842 case GrDashingEffect::kRound_DashCap: |
845 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); | 843 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); |
846 case GrDashingEffect::kNonRound_DashCap: | 844 case GrDashingEffect::kNonRound_DashCap: |
847 return DashingLineEffect::Create(edgeType, info, strokeWidth); | 845 return DashingLineEffect::Create(edgeType, info, strokeWidth); |
848 default: | 846 default: |
849 SkFAIL("Unexpected dashed cap."); | 847 SkFAIL("Unexpected dashed cap."); |
850 } | 848 } |
851 return NULL; | 849 return NULL; |
852 } | 850 } |
OLD | NEW |