| 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 }; | 463 }; |
| 464 | 464 |
| 465 ////////////////////////////////////////////////////////////////////////////// | 465 ////////////////////////////////////////////////////////////////////////////// |
| 466 | 466 |
| 467 class GLDashingCircleEffect : public GrGLVertexEffect { | 467 class GLDashingCircleEffect : public GrGLVertexEffect { |
| 468 public: | 468 public: |
| 469 GLDashingCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 469 GLDashingCircleEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 470 | 470 |
| 471 virtual void emitCode(GrGLFullShaderBuilder* builder, | 471 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 472 const GrDrawEffect& drawEffect, | 472 const GrDrawEffect& drawEffect, |
| 473 EffectKey key, | 473 const GrEffectKey& key, |
| 474 const char* outputColor, | 474 const char* outputColor, |
| 475 const char* inputColor, | 475 const char* inputColor, |
| 476 const TransformedCoordsArray&, | 476 const TransformedCoordsArray&, |
| 477 const TextureSamplerArray&) SK_OVERRIDE; | 477 const TextureSamplerArray&) SK_OVERRIDE; |
| 478 | 478 |
| 479 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 479 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
| 480 | 480 |
| 481 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 481 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
| 482 | 482 |
| 483 private: | 483 private: |
| 484 GrGLUniformManager::UniformHandle fParamUniform; | 484 GrGLUniformManager::UniformHandle fParamUniform; |
| 485 SkScalar fPrevRadius; | 485 SkScalar fPrevRadius; |
| 486 SkScalar fPrevCenterX; | 486 SkScalar fPrevCenterX; |
| 487 SkScalar fPrevIntervalLength; | 487 SkScalar fPrevIntervalLength; |
| 488 typedef GrGLVertexEffect INHERITED; | 488 typedef GrGLVertexEffect INHERITED; |
| 489 }; | 489 }; |
| 490 | 490 |
| 491 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& facto
ry, | 491 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendEffectFactory& facto
ry, |
| 492 const GrDrawEffect& drawEffect) | 492 const GrDrawEffect& drawEffect) |
| 493 : INHERITED (factory) { | 493 : INHERITED (factory) { |
| 494 fPrevRadius = SK_ScalarMin; | 494 fPrevRadius = SK_ScalarMin; |
| 495 fPrevCenterX = SK_ScalarMin; | 495 fPrevCenterX = SK_ScalarMin; |
| 496 fPrevIntervalLength = SK_ScalarMax; | 496 fPrevIntervalLength = SK_ScalarMax; |
| 497 } | 497 } |
| 498 | 498 |
| 499 void GLDashingCircleEffect::emitCode(GrGLFullShaderBuilder* builder, | 499 void GLDashingCircleEffect::emitCode(GrGLFullShaderBuilder* builder, |
| 500 const GrDrawEffect& drawEffect, | 500 const GrDrawEffect& drawEffect, |
| 501 EffectKey key, | 501 const GrEffectKey& key, |
| 502 const char* outputColor, | 502 const char* outputColor, |
| 503 const char* inputColor, | 503 const char* inputColor, |
| 504 const TransformedCoordsArray&, | 504 const TransformedCoordsArray&, |
| 505 const TextureSamplerArray& samplers) { | 505 const TextureSamplerArray& samplers) { |
| 506 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>(
); | 506 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>(
); |
| 507 const char *paramName; | 507 const char *paramName; |
| 508 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co
ord, and | 508 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co
ord, and |
| 509 // the total interval length of the dash. | 509 // the total interval length of the dash. |
| 510 fParamUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 510 fParamUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 511 kVec3f_GrSLType, | 511 kVec3f_GrSLType, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 542 SkScalar centerX = dce.getCenterX(); | 542 SkScalar centerX = dce.getCenterX(); |
| 543 SkScalar intervalLength = dce.getIntervalLength(); | 543 SkScalar intervalLength = dce.getIntervalLength(); |
| 544 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP
revIntervalLength) { | 544 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP
revIntervalLength) { |
| 545 uman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); | 545 uman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); |
| 546 fPrevRadius = radius; | 546 fPrevRadius = radius; |
| 547 fPrevCenterX = centerX; | 547 fPrevCenterX = centerX; |
| 548 fPrevIntervalLength = intervalLength; | 548 fPrevIntervalLength = intervalLength; |
| 549 } | 549 } |
| 550 } | 550 } |
| 551 | 551 |
| 552 GrGLEffect::EffectKey GLDashingCircleEffect::GenKey(const GrDrawEffect& drawEffe
ct, | 552 void GLDashingCircleEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCap
s&, |
| 553 const GrGLCaps&) { | 553 GrEffectKeyBuilder* b) { |
| 554 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>(
); | 554 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>(
); |
| 555 return dce.getEdgeType(); | 555 b->add32(dce.getEdgeType()); |
| 556 } | 556 } |
| 557 | 557 |
| 558 ////////////////////////////////////////////////////////////////////////////// | 558 ////////////////////////////////////////////////////////////////////////////// |
| 559 | 559 |
| 560 GrEffect* DashingCircleEffect::Create(GrEffectEdgeType edgeType, const DashInfo&
info, | 560 GrEffect* DashingCircleEffect::Create(GrEffectEdgeType edgeType, const DashInfo&
info, |
| 561 SkScalar radius) { | 561 SkScalar radius) { |
| 562 if (info.fCount != 2 || info.fIntervals[0] != 0) { | 562 if (info.fCount != 2 || info.fIntervals[0] != 0) { |
| 563 return NULL; | 563 return NULL; |
| 564 } | 564 } |
| 565 | 565 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 }; | 668 }; |
| 669 | 669 |
| 670 ////////////////////////////////////////////////////////////////////////////// | 670 ////////////////////////////////////////////////////////////////////////////// |
| 671 | 671 |
| 672 class GLDashingLineEffect : public GrGLVertexEffect { | 672 class GLDashingLineEffect : public GrGLVertexEffect { |
| 673 public: | 673 public: |
| 674 GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 674 GLDashingLineEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 675 | 675 |
| 676 virtual void emitCode(GrGLFullShaderBuilder* builder, | 676 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 677 const GrDrawEffect& drawEffect, | 677 const GrDrawEffect& drawEffect, |
| 678 EffectKey key, | 678 const GrEffectKey& key, |
| 679 const char* outputColor, | 679 const char* outputColor, |
| 680 const char* inputColor, | 680 const char* inputColor, |
| 681 const TransformedCoordsArray&, | 681 const TransformedCoordsArray&, |
| 682 const TextureSamplerArray&) SK_OVERRIDE; | 682 const TextureSamplerArray&) SK_OVERRIDE; |
| 683 | 683 |
| 684 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 684 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
| 685 | 685 |
| 686 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 686 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
| 687 | 687 |
| 688 private: | 688 private: |
| 689 GrGLUniformManager::UniformHandle fRectUniform; | 689 GrGLUniformManager::UniformHandle fRectUniform; |
| 690 GrGLUniformManager::UniformHandle fIntervalUniform; | 690 GrGLUniformManager::UniformHandle fIntervalUniform; |
| 691 SkRect fPrevRect; | 691 SkRect fPrevRect; |
| 692 SkScalar fPrevIntervalLength; | 692 SkScalar fPrevIntervalLength; |
| 693 typedef GrGLVertexEffect INHERITED; | 693 typedef GrGLVertexEffect INHERITED; |
| 694 }; | 694 }; |
| 695 | 695 |
| 696 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory, | 696 GLDashingLineEffect::GLDashingLineEffect(const GrBackendEffectFactory& factory, |
| 697 const GrDrawEffect& drawEffect) | 697 const GrDrawEffect& drawEffect) |
| 698 : INHERITED (factory) { | 698 : INHERITED (factory) { |
| 699 fPrevRect.fLeft = SK_ScalarNaN; | 699 fPrevRect.fLeft = SK_ScalarNaN; |
| 700 fPrevIntervalLength = SK_ScalarMax; | 700 fPrevIntervalLength = SK_ScalarMax; |
| 701 } | 701 } |
| 702 | 702 |
| 703 void GLDashingLineEffect::emitCode(GrGLFullShaderBuilder* builder, | 703 void GLDashingLineEffect::emitCode(GrGLFullShaderBuilder* builder, |
| 704 const GrDrawEffect& drawEffect, | 704 const GrDrawEffect& drawEffect, |
| 705 EffectKey key, | 705 const GrEffectKey& key, |
| 706 const char* outputColor, | 706 const char* outputColor, |
| 707 const char* inputColor, | 707 const char* inputColor, |
| 708 const TransformedCoordsArray&, | 708 const TransformedCoordsArray&, |
| 709 const TextureSamplerArray& samplers) { | 709 const TextureSamplerArray& samplers) { |
| 710 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); | 710 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); |
| 711 const char *rectName; | 711 const char *rectName; |
| 712 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 712 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
| 713 // respectively. | 713 // respectively. |
| 714 fRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 714 fRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 715 kVec4f_GrSLType, | 715 kVec4f_GrSLType, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 SkScalar intervalLength = de.getIntervalLength(); | 759 SkScalar intervalLength = de.getIntervalLength(); |
| 760 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { | 760 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { |
| 761 uman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, | 761 uman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, |
| 762 rect.fRight - 0.5f, rect.fBottom - 0.5f); | 762 rect.fRight - 0.5f, rect.fBottom - 0.5f); |
| 763 uman.set1f(fIntervalUniform, intervalLength); | 763 uman.set1f(fIntervalUniform, intervalLength); |
| 764 fPrevRect = rect; | 764 fPrevRect = rect; |
| 765 fPrevIntervalLength = intervalLength; | 765 fPrevIntervalLength = intervalLength; |
| 766 } | 766 } |
| 767 } | 767 } |
| 768 | 768 |
| 769 GrGLEffect::EffectKey GLDashingLineEffect::GenKey(const GrDrawEffect& drawEffect
, | 769 void GLDashingLineEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&
, |
| 770 const GrGLCaps&) { | 770 GrEffectKeyBuilder* b) { |
| 771 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); | 771 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); |
| 772 return de.getEdgeType(); | 772 b->add32(de.getEdgeType()); |
| 773 } | 773 } |
| 774 | 774 |
| 775 ////////////////////////////////////////////////////////////////////////////// | 775 ////////////////////////////////////////////////////////////////////////////// |
| 776 | 776 |
| 777 GrEffect* DashingLineEffect::Create(GrEffectEdgeType edgeType, const DashInfo& i
nfo, | 777 GrEffect* DashingLineEffect::Create(GrEffectEdgeType edgeType, const DashInfo& i
nfo, |
| 778 SkScalar strokeWidth) { | 778 SkScalar strokeWidth) { |
| 779 if (info.fCount != 2) { | 779 if (info.fCount != 2) { |
| 780 return NULL; | 780 return NULL; |
| 781 } | 781 } |
| 782 | 782 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 switch (cap) { | 842 switch (cap) { |
| 843 case GrDashingEffect::kRound_DashCap: | 843 case GrDashingEffect::kRound_DashCap: |
| 844 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); | 844 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); |
| 845 case GrDashingEffect::kNonRound_DashCap: | 845 case GrDashingEffect::kNonRound_DashCap: |
| 846 return DashingLineEffect::Create(edgeType, info, strokeWidth); | 846 return DashingLineEffect::Create(edgeType, info, strokeWidth); |
| 847 default: | 847 default: |
| 848 SkFAIL("Unexpected dashed cap."); | 848 SkFAIL("Unexpected dashed cap."); |
| 849 } | 849 } |
| 850 return NULL; | 850 return NULL; |
| 851 } | 851 } |
| OLD | NEW |