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 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 virtual void emitCode(GrGLFullShaderBuilder* builder, | 471 virtual void emitCode(GrGLFullShaderBuilder* builder, |
472 const GrDrawEffect& drawEffect, | 472 const GrDrawEffect& drawEffect, |
473 const GrEffectKey& 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 void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder*); | 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 GrGLProgramResourceManager&, const GrDrawEffect&) SK_OVERRIDE; |
482 | 482 |
483 private: | 483 private: |
484 GrGLUniformManager::UniformHandle fParamUniform; | 484 GrGLProgramResourceManager::UniformHandle fParamUniform; |
bsalomon
2014/07/29 13:08:17
align
| |
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; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 builder->fsCodeAppend("\t\tdiff = 1.0 - diff;\n"); | 529 builder->fsCodeAppend("\t\tdiff = 1.0 - diff;\n"); |
530 builder->fsCodeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); | 530 builder->fsCodeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); |
531 } else { | 531 } else { |
532 builder->fsCodeAppendf("\t\tfloat alpha = 1.0;\n"); | 532 builder->fsCodeAppendf("\t\tfloat alpha = 1.0;\n"); |
533 builder->fsCodeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName); | 533 builder->fsCodeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n", paramName); |
534 } | 534 } |
535 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, | 535 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
536 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); | 536 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); |
537 } | 537 } |
538 | 538 |
539 void GLDashingCircleEffect::setData(const GrGLUniformManager& uman, const GrDraw Effect& drawEffect) { | 539 void GLDashingCircleEffect::setData(const GrGLProgramResourceManager& prman, con st GrDrawEffect& drawEffect) { |
540 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>( ); | 540 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>( ); |
541 SkScalar radius = dce.getRadius(); | 541 SkScalar radius = dce.getRadius(); |
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 prman.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 void GLDashingCircleEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&, | 552 void GLDashingCircleEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCap s&, |
553 GrEffectKeyBuilder* b) { | 553 GrEffectKeyBuilder* b) { |
554 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>( ); | 554 const DashingCircleEffect& dce = drawEffect.castEffect<DashingCircleEffect>( ); |
555 b->add32(dce.getEdgeType()); | 555 b->add32(dce.getEdgeType()); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 virtual void emitCode(GrGLFullShaderBuilder* builder, | 676 virtual void emitCode(GrGLFullShaderBuilder* builder, |
677 const GrDrawEffect& drawEffect, | 677 const GrDrawEffect& drawEffect, |
678 const GrEffectKey& 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 void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder*); | 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 GrGLProgramResourceManager&, const GrDrawEffect&) SK_OVERRIDE; |
687 | 687 |
688 private: | 688 private: |
689 GrGLUniformManager::UniformHandle fRectUniform; | 689 GrGLProgramResourceManager::UniformHandle fRectUniform; |
690 GrGLUniformManager::UniformHandle fIntervalUniform; | 690 GrGLProgramResourceManager::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; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 } else { | 746 } else { |
747 // Assuming the bounding geometry is tight so no need to check y values | 747 // Assuming the bounding geometry is tight so no need to check y values |
748 builder->fsCodeAppendf("\t\tfloat alpha = 1.0;\n"); | 748 builder->fsCodeAppendf("\t\tfloat alpha = 1.0;\n"); |
749 builder->fsCodeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0 : 0.0;\n", rectName); | 749 builder->fsCodeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0 : 0.0;\n", rectName); |
750 builder->fsCodeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;\n", rectName); | 750 builder->fsCodeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;\n", rectName); |
751 } | 751 } |
752 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, | 752 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
753 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); | 753 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("alpha")).c_st r()); |
754 } | 754 } |
755 | 755 |
756 void GLDashingLineEffect::setData(const GrGLUniformManager& uman, const GrDrawEf fect& drawEffect) { | 756 void GLDashingLineEffect::setData(const GrGLProgramResourceManager& prman, const GrDrawEffect& drawEffect) { |
757 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); | 757 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); |
758 const SkRect& rect = de.getRect(); | 758 const SkRect& rect = de.getRect(); |
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 prman.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 prman.set1f(fIntervalUniform, intervalLength); |
764 fPrevRect = rect; | 764 fPrevRect = rect; |
765 fPrevIntervalLength = intervalLength; | 765 fPrevIntervalLength = intervalLength; |
766 } | 766 } |
767 } | 767 } |
768 | 768 |
769 void GLDashingLineEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps& , | 769 void GLDashingLineEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps& , |
770 GrEffectKeyBuilder* b) { | 770 GrEffectKeyBuilder* b) { |
771 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); | 771 const DashingLineEffect& de = drawEffect.castEffect<DashingLineEffect>(); |
772 b->add32(de.getEdgeType()); | 772 b->add32(de.getEdgeType()); |
773 } | 773 } |
(...skipping 68 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 |