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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 kVec3f_GrSLType, | 513 kVec3f_GrSLType, |
514 "params", | 514 "params", |
515 ¶mName); | 515 ¶mName); |
516 | 516 |
517 GrGLVertToFrag v(kVec2f_GrSLType); | 517 GrGLVertToFrag v(kVec2f_GrSLType); |
518 args.fPB->addVarying("Coord", &v); | 518 args.fPB->addVarying("Coord", &v); |
519 | 519 |
520 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 520 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
521 vsBuilder->codeAppendf("\t%s = %s;\n", v.vsOut(), dce.inCoord().c_str()); | 521 vsBuilder->codeAppendf("\t%s = %s;\n", v.vsOut(), dce.inCoord().c_str()); |
522 | 522 |
523 // setup position varying | |
524 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | |
525 vsBuilder->inPosition()); | |
526 | |
527 // transforms all points so that we can compare them to our test circle | 523 // transforms all points so that we can compare them to our test circle |
528 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 524 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
529 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", | 525 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", |
530 v.fsIn(), v.fsIn(), paramName, paramName); | 526 v.fsIn(), v.fsIn(), paramName, paramName); |
531 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); | 527 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); |
532 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); | 528 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); |
533 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; | 529 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; |
534 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { | 530 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { |
535 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); | 531 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); |
536 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); | 532 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 fIntervalUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, | 716 fIntervalUniform = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
721 kFloat_GrSLType, | 717 kFloat_GrSLType, |
722 "interval", | 718 "interval", |
723 &intervalName); | 719 &intervalName); |
724 | 720 |
725 GrGLVertToFrag v(kVec2f_GrSLType); | 721 GrGLVertToFrag v(kVec2f_GrSLType); |
726 args.fPB->addVarying("Coord", &v); | 722 args.fPB->addVarying("Coord", &v); |
727 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 723 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
728 vsBuilder->codeAppendf("\t%s = %s;\n", v.vsOut(), de.inCoord().c_str()); | 724 vsBuilder->codeAppendf("\t%s = %s;\n", v.vsOut(), de.inCoord().c_str()); |
729 | 725 |
730 // setup position varying | |
731 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | |
732 vsBuilder->inPosition()); | |
733 | |
734 // transforms all points so that we can compare them to our test rect | 726 // transforms all points so that we can compare them to our test rect |
735 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 727 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
736 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", | 728 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", |
737 v.fsIn(), v.fsIn(), intervalName, intervalName); | 729 v.fsIn(), v.fsIn(), intervalName, intervalName); |
738 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); | 730 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); |
739 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { | 731 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { |
740 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 732 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
741 // numbers, xSub and ySub. | 733 // numbers, xSub and ySub. |
742 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); | 734 fsBuilder->codeAppend("\t\tfloat xSub, ySub;\n"); |
743 fsBuilder->codeAppendf("\t\txSub = min(fragPosShifted.x - %s.x, 0.0);\n"
, rectName); | 735 fsBuilder->codeAppendf("\t\txSub = min(fragPosShifted.x - %s.x, 0.0);\n"
, rectName); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 switch (cap) { | 841 switch (cap) { |
850 case GrDashingEffect::kRound_DashCap: | 842 case GrDashingEffect::kRound_DashCap: |
851 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); | 843 return DashingCircleEffect::Create(edgeType, info, SkScalarHalf(stro
keWidth)); |
852 case GrDashingEffect::kNonRound_DashCap: | 844 case GrDashingEffect::kNonRound_DashCap: |
853 return DashingLineEffect::Create(edgeType, info, strokeWidth); | 845 return DashingLineEffect::Create(edgeType, info, strokeWidth); |
854 default: | 846 default: |
855 SkFAIL("Unexpected dashed cap."); | 847 SkFAIL("Unexpected dashed cap."); |
856 } | 848 } |
857 return NULL; | 849 return NULL; |
858 } | 850 } |
OLD | NEW |