| 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" |
| 11 | 11 |
| 12 #include "GrGeometryProcessor.h" | 12 #include "GrGeometryProcessor.h" |
| 13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "gl/builders/GrGLFullProgramBuilder.h" |
| 14 #include "gl/GrGLProcessor.h" | 14 #include "gl/GrGLProcessor.h" |
| 15 #include "gl/GrGLGeometryProcessor.h" | 15 #include "gl/GrGLGeometryProcessor.h" |
| 16 #include "gl/GrGLSL.h" | 16 #include "gl/GrGLSL.h" |
| 17 #include "GrContext.h" | 17 #include "GrContext.h" |
| 18 #include "GrCoordTransform.h" | 18 #include "GrCoordTransform.h" |
| 19 #include "GrDrawTarget.h" | 19 #include "GrDrawTarget.h" |
| 20 #include "GrDrawTargetCaps.h" | 20 #include "GrDrawTargetCaps.h" |
| 21 #include "GrProcessor.h" | 21 #include "GrProcessor.h" |
| 22 #include "GrGpu.h" | 22 #include "GrGpu.h" |
| 23 #include "GrStrokeInfo.h" | 23 #include "GrStrokeInfo.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 475 |
| 476 typedef GrGeometryProcessor INHERITED; | 476 typedef GrGeometryProcessor INHERITED; |
| 477 }; | 477 }; |
| 478 | 478 |
| 479 ////////////////////////////////////////////////////////////////////////////// | 479 ////////////////////////////////////////////////////////////////////////////// |
| 480 | 480 |
| 481 class GLDashingCircleEffect : public GrGLGeometryProcessor { | 481 class GLDashingCircleEffect : public GrGLGeometryProcessor { |
| 482 public: | 482 public: |
| 483 GLDashingCircleEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 483 GLDashingCircleEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
| 484 | 484 |
| 485 virtual void emitCode(GrGLGPBuilder* builder, | 485 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 486 const GrGeometryProcessor& geometryProcessor, | 486 const GrGeometryProcessor& geometryProcessor, |
| 487 const GrProcessorKey& key, | 487 const GrProcessorKey& key, |
| 488 const char* outputColor, | 488 const char* outputColor, |
| 489 const char* inputColor, | 489 const char* inputColor, |
| 490 const TransformedCoordsArray&, | 490 const TransformedCoordsArray&, |
| 491 const TextureSamplerArray&) SK_OVERRIDE; | 491 const TextureSamplerArray&) SK_OVERRIDE; |
| 492 | 492 |
| 493 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 493 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 494 | 494 |
| 495 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 495 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 496 | 496 |
| 497 private: | 497 private: |
| 498 GrGLProgramDataManager::UniformHandle fParamUniform; | 498 GrGLProgramDataManager::UniformHandle fParamUniform; |
| 499 SkScalar fPrevRadius; | 499 SkScalar fPrevRadius; |
| 500 SkScalar fPrevCenterX; | 500 SkScalar fPrevCenterX; |
| 501 SkScalar fPrevIntervalLength; | 501 SkScalar fPrevIntervalLength; |
| 502 typedef GrGLGeometryProcessor INHERITED; | 502 typedef GrGLGeometryProcessor INHERITED; |
| 503 }; | 503 }; |
| 504 | 504 |
| 505 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendProcessorFactory& fa
ctory, | 505 GLDashingCircleEffect::GLDashingCircleEffect(const GrBackendProcessorFactory& fa
ctory, |
| 506 const GrProcessor&) | 506 const GrProcessor&) |
| 507 : INHERITED (factory) { | 507 : INHERITED (factory) { |
| 508 fPrevRadius = SK_ScalarMin; | 508 fPrevRadius = SK_ScalarMin; |
| 509 fPrevCenterX = SK_ScalarMin; | 509 fPrevCenterX = SK_ScalarMin; |
| 510 fPrevIntervalLength = SK_ScalarMax; | 510 fPrevIntervalLength = SK_ScalarMax; |
| 511 } | 511 } |
| 512 | 512 |
| 513 void GLDashingCircleEffect::emitCode(GrGLGPBuilder* builder, | 513 void GLDashingCircleEffect::emitCode(GrGLFullProgramBuilder* builder, |
| 514 const GrGeometryProcessor& geometryProcessor
, | 514 const GrGeometryProcessor& geometryProcessor
, |
| 515 const GrProcessorKey& key, | 515 const GrProcessorKey& key, |
| 516 const char* outputColor, | 516 const char* outputColor, |
| 517 const char* inputColor, | 517 const char* inputColor, |
| 518 const TransformedCoordsArray&, | 518 const TransformedCoordsArray&, |
| 519 const TextureSamplerArray& samplers) { | 519 const TextureSamplerArray& samplers) { |
| 520 const DashingCircleEffect& dce = geometryProcessor.cast<DashingCircleEffect>
(); | 520 const DashingCircleEffect& dce = geometryProcessor.cast<DashingCircleEffect>
(); |
| 521 const char *paramName; | 521 const char *paramName; |
| 522 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co
ord, and | 522 // The param uniforms, xyz, refer to circle radius - 0.5, cicles center x co
ord, and |
| 523 // the total interval length of the dash. | 523 // the total interval length of the dash. |
| 524 fParamUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, | 524 fParamUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, |
| 525 kVec3f_GrSLType, | 525 kVec3f_GrSLType, |
| 526 "params", | 526 "params", |
| 527 ¶mName); | 527 ¶mName); |
| 528 | 528 |
| 529 const char *vsCoordName, *fsCoordName; | 529 const char *vsCoordName, *fsCoordName; |
| 530 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); | 530 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); |
| 531 | 531 |
| 532 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 532 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 533 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dce.inCoord().c_str()); | 533 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, dce.inCoord().c_str()); |
| 534 | 534 |
| 535 // transforms all points so that we can compare them to our test circle | 535 // transforms all points so that we can compare them to our test circle |
| 536 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 536 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBu
ilder(); |
| 537 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", | 537 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", |
| 538 fsCoordName, fsCoordName, paramName, paramName); | 538 fsCoordName, fsCoordName, paramName, paramName); |
| 539 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); | 539 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); |
| 540 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); | 540 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); |
| 541 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; | 541 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; |
| 542 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { | 542 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { |
| 543 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); | 543 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); |
| 544 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); | 544 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); |
| 545 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); | 545 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); |
| 546 } else { | 546 } else { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 | 687 |
| 688 typedef GrGeometryProcessor INHERITED; | 688 typedef GrGeometryProcessor INHERITED; |
| 689 }; | 689 }; |
| 690 | 690 |
| 691 ////////////////////////////////////////////////////////////////////////////// | 691 ////////////////////////////////////////////////////////////////////////////// |
| 692 | 692 |
| 693 class GLDashingLineEffect : public GrGLGeometryProcessor { | 693 class GLDashingLineEffect : public GrGLGeometryProcessor { |
| 694 public: | 694 public: |
| 695 GLDashingLineEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 695 GLDashingLineEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
| 696 | 696 |
| 697 virtual void emitCode(GrGLGPBuilder* builder, | 697 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 698 const GrGeometryProcessor& geometryProcessor, | 698 const GrGeometryProcessor& geometryProcessor, |
| 699 const GrProcessorKey& key, | 699 const GrProcessorKey& key, |
| 700 const char* outputColor, | 700 const char* outputColor, |
| 701 const char* inputColor, | 701 const char* inputColor, |
| 702 const TransformedCoordsArray&, | 702 const TransformedCoordsArray&, |
| 703 const TextureSamplerArray&) SK_OVERRIDE; | 703 const TextureSamplerArray&) SK_OVERRIDE; |
| 704 | 704 |
| 705 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 705 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| 706 | 706 |
| 707 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 707 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 708 | 708 |
| 709 private: | 709 private: |
| 710 GrGLProgramDataManager::UniformHandle fRectUniform; | 710 GrGLProgramDataManager::UniformHandle fRectUniform; |
| 711 GrGLProgramDataManager::UniformHandle fIntervalUniform; | 711 GrGLProgramDataManager::UniformHandle fIntervalUniform; |
| 712 SkRect fPrevRect; | 712 SkRect fPrevRect; |
| 713 SkScalar fPrevIntervalLength; | 713 SkScalar fPrevIntervalLength; |
| 714 typedef GrGLGeometryProcessor INHERITED; | 714 typedef GrGLGeometryProcessor INHERITED; |
| 715 }; | 715 }; |
| 716 | 716 |
| 717 GLDashingLineEffect::GLDashingLineEffect(const GrBackendProcessorFactory& factor
y, | 717 GLDashingLineEffect::GLDashingLineEffect(const GrBackendProcessorFactory& factor
y, |
| 718 const GrProcessor&) | 718 const GrProcessor&) |
| 719 : INHERITED (factory) { | 719 : INHERITED (factory) { |
| 720 fPrevRect.fLeft = SK_ScalarNaN; | 720 fPrevRect.fLeft = SK_ScalarNaN; |
| 721 fPrevIntervalLength = SK_ScalarMax; | 721 fPrevIntervalLength = SK_ScalarMax; |
| 722 } | 722 } |
| 723 | 723 |
| 724 void GLDashingLineEffect::emitCode(GrGLGPBuilder* builder, | 724 void GLDashingLineEffect::emitCode(GrGLFullProgramBuilder* builder, |
| 725 const GrGeometryProcessor& geometryProcessor, | 725 const GrGeometryProcessor& geometryProcessor, |
| 726 const GrProcessorKey& key, | 726 const GrProcessorKey& key, |
| 727 const char* outputColor, | 727 const char* outputColor, |
| 728 const char* inputColor, | 728 const char* inputColor, |
| 729 const TransformedCoordsArray&, | 729 const TransformedCoordsArray&, |
| 730 const TextureSamplerArray& samplers) { | 730 const TextureSamplerArray& samplers) { |
| 731 const DashingLineEffect& de = geometryProcessor.cast<DashingLineEffect>(); | 731 const DashingLineEffect& de = geometryProcessor.cast<DashingLineEffect>(); |
| 732 const char *rectName; | 732 const char *rectName; |
| 733 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 733 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
| 734 // respectively. | 734 // respectively. |
| 735 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 735 fRectUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 736 kVec4f_GrSLType, | 736 kVec4f_GrSLType, |
| 737 "rect", | 737 "rect", |
| 738 &rectName); | 738 &rectName); |
| 739 const char *intervalName; | 739 const char *intervalName; |
| 740 // The interval uniform's refers to the total length of the interval (on + o
ff) | 740 // The interval uniform's refers to the total length of the interval (on + o
ff) |
| 741 fIntervalUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 741 fIntervalUniform = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, |
| 742 kFloat_GrSLType, | 742 kFloat_GrSLType, |
| 743 "interval", | 743 "interval", |
| 744 &intervalName); | 744 &intervalName); |
| 745 | 745 |
| 746 const char *vsCoordName, *fsCoordName; | 746 const char *vsCoordName, *fsCoordName; |
| 747 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); | 747 builder->addVarying(kVec2f_GrSLType, "Coord", &vsCoordName, &fsCoordName); |
| 748 GrGLVertexBuilder* vsBuilder = builder->getVertexShaderBuilder(); | 748 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 749 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, de.inCoord().c_str()); | 749 vsBuilder->codeAppendf("\t%s = %s;\n", vsCoordName, de.inCoord().c_str()); |
| 750 | 750 |
| 751 // transforms all points so that we can compare them to our test rect | 751 // transforms all points so that we can compare them to our test rect |
| 752 GrGLGPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 752 GrGLProcessorFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBu
ilder(); |
| 753 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", | 753 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", |
| 754 fsCoordName, fsCoordName, intervalName, intervalName)
; | 754 fsCoordName, fsCoordName, intervalName, intervalName)
; |
| 755 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); | 755 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
fsCoordName); |
| 756 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { | 756 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { |
| 757 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 757 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
| 758 // numbers, xSub and ySub. | 758 // numbers, xSub and ySub. |
| 759 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); | 759 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); |
| 760 fsBuilder->codeAppendf("\t\txSub = min(fragPosShifted.x - %s.x, 0.0);\n"
, rectName); | 760 fsBuilder->codeAppendf("\t\txSub = min(fragPosShifted.x - %s.x, 0.0);\n"
, rectName); |
| 761 fsBuilder->codeAppendf("\t\txSub += min(%s.z - fragPosShifted.x, 0.0);\n
", rectName); | 761 fsBuilder->codeAppendf("\t\txSub += min(%s.z - fragPosShifted.x, 0.0);\n
", rectName); |
| 762 fsBuilder->codeAppendf("\t\tySub = min(fragPosShifted.y - %s.y, 0.0);\n"
, rectName); | 762 fsBuilder->codeAppendf("\t\tySub = min(fragPosShifted.y - %s.y, 0.0);\n"
, rectName); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 switch (cap) { | 867 switch (cap) { |
| 868 case GrDashingEffect::kRound_DashCap: | 868 case GrDashingEffect::kRound_DashCap: |
| 869 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); | 869 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); |
| 870 case GrDashingEffect::kNonRound_DashCap: | 870 case GrDashingEffect::kNonRound_DashCap: |
| 871 return DashingLineEffect::Create(edgeType, info, strokeWidth); | 871 return DashingLineEffect::Create(edgeType, info, strokeWidth); |
| 872 default: | 872 default: |
| 873 SkFAIL("Unexpected dashed cap."); | 873 SkFAIL("Unexpected dashed cap."); |
| 874 } | 874 } |
| 875 return NULL; | 875 return NULL; |
| 876 } | 876 } |
| OLD | NEW |