| 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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 args.fPB->addVarying("Coord", &v); | 576 args.fPB->addVarying("Coord", &v); |
| 577 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dce.inCoord()->fName); | 577 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), dce.inCoord()->fName); |
| 578 | 578 |
| 579 // Setup pass through color | 579 // Setup pass through color |
| 580 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU
LL, &fColorUniform); | 580 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU
LL, &fColorUniform); |
| 581 | 581 |
| 582 // setup coord outputs | 582 // setup coord outputs |
| 583 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), dce.inPositi
on()->fName); | 583 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), dce.inPositi
on()->fName); |
| 584 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), dce.inPosition(
)->fName); | 584 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), dce.inPosition(
)->fName); |
| 585 | 585 |
| 586 // setup uniform viewMatrix |
| 587 this->addUniformViewMatrix(pb); |
| 588 |
| 586 // setup position varying | 589 // setup position varying |
| 587 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 590 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), th
is->uViewM(), |
| 588 dce.inPosition()->fName); | 591 dce.inPosition()->fName); |
| 589 | 592 |
| 590 // transforms all points so that we can compare them to our test circle | 593 // transforms all points so that we can compare them to our test circle |
| 591 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 594 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 592 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", | 595 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s.z) * %s.
z;\n", |
| 593 v.fsIn(), v.fsIn(), paramName, paramName); | 596 v.fsIn(), v.fsIn(), paramName, paramName); |
| 594 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); | 597 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); |
| 595 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); | 598 fsBuilder->codeAppendf("\t\tvec2 center = vec2(%s.y, 0.0);\n", paramName); |
| 596 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; | 599 fsBuilder->codeAppend("\t\tfloat dist = length(center - fragPosShifted);\n")
; |
| 597 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { | 600 if (GrProcessorEdgeTypeIsAA(dce.getEdgeType())) { |
| 598 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); | 601 fsBuilder->codeAppendf("\t\tfloat diff = dist - %s.x;\n", paramName); |
| 599 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); | 602 fsBuilder->codeAppend("\t\tdiff = 1.0 - diff;\n"); |
| 600 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); | 603 fsBuilder->codeAppend("\t\tfloat alpha = clamp(diff, 0.0, 1.0);\n"); |
| 601 } else { | 604 } else { |
| 602 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); | 605 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); |
| 603 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n",
paramName); | 606 fsBuilder->codeAppendf("\t\talpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;\n",
paramName); |
| 604 } | 607 } |
| 605 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 608 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
| 606 } | 609 } |
| 607 | 610 |
| 608 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, | 611 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, |
| 609 const GrPrimitiveProcessor& processor, | 612 const GrPrimitiveProcessor& processor, |
| 610 const GrBatchTracker& bt) { | 613 const GrBatchTracker& bt) { |
| 614 this->setUniformViewMatrix(pdman, processor.viewMatrix()); |
| 615 |
| 611 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); | 616 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); |
| 612 SkScalar radius = dce.getRadius(); | 617 SkScalar radius = dce.getRadius(); |
| 613 SkScalar centerX = dce.getCenterX(); | 618 SkScalar centerX = dce.getCenterX(); |
| 614 SkScalar intervalLength = dce.getIntervalLength(); | 619 SkScalar intervalLength = dce.getIntervalLength(); |
| 615 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP
revIntervalLength) { | 620 if (radius != fPrevRadius || centerX != fPrevCenterX || intervalLength != fP
revIntervalLength) { |
| 616 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); | 621 pdman.set3f(fParamUniform, radius - 0.5f, centerX, intervalLength); |
| 617 fPrevRadius = radius; | 622 fPrevRadius = radius; |
| 618 fPrevCenterX = centerX; | 623 fPrevCenterX = centerX; |
| 619 fPrevIntervalLength = intervalLength; | 624 fPrevIntervalLength = intervalLength; |
| 620 } | 625 } |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 args.fPB->addVarying("Coord", &v); | 869 args.fPB->addVarying("Coord", &v); |
| 865 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), de.inCoord()->fName); | 870 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), de.inCoord()->fName); |
| 866 | 871 |
| 867 // Setup pass through color | 872 // Setup pass through color |
| 868 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU
LL, &fColorUniform); | 873 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU
LL, &fColorUniform); |
| 869 | 874 |
| 870 // setup coord outputs | 875 // setup coord outputs |
| 871 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), de.inPositio
n()->fName); | 876 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), de.inPositio
n()->fName); |
| 872 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), de.inPosition()
->fName); | 877 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), de.inPosition()
->fName); |
| 873 | 878 |
| 879 // setup uniform viewMatrix |
| 880 this->addUniformViewMatrix(pb); |
| 881 |
| 874 // setup position varying | 882 // setup position varying |
| 875 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), vs
Builder->uViewM(), | 883 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition(), th
is->uViewM(), |
| 876 de.inPosition()->fName); | 884 de.inPosition()->fName); |
| 877 | 885 |
| 878 // transforms all points so that we can compare them to our test rect | 886 // transforms all points so that we can compare them to our test rect |
| 879 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 887 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 880 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", | 888 fsBuilder->codeAppendf("\t\tfloat xShifted = %s.x - floor(%s.x / %s) * %s;\n
", |
| 881 v.fsIn(), v.fsIn(), intervalName, intervalName); | 889 v.fsIn(), v.fsIn(), intervalName, intervalName); |
| 882 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); | 890 fsBuilder->codeAppendf("\t\tvec2 fragPosShifted = vec2(xShifted, %s.y);\n",
v.fsIn()); |
| 883 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { | 891 if (GrProcessorEdgeTypeIsAA(de.getEdgeType())) { |
| 884 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 892 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
| 885 // numbers, xSub and ySub. | 893 // numbers, xSub and ySub. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 896 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); | 904 fsBuilder->codeAppendf("\t\tfloat alpha = 1.0;\n"); |
| 897 fsBuilder->codeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ?
1.0 : 0.0;\n", rectName); | 905 fsBuilder->codeAppendf("\t\talpha *= (fragPosShifted.x - %s.x) > -0.5 ?
1.0 : 0.0;\n", rectName); |
| 898 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ?
1.0 : 0.0;\n", rectName); | 906 fsBuilder->codeAppendf("\t\talpha *= (%s.z - fragPosShifted.x) >= -0.5 ?
1.0 : 0.0;\n", rectName); |
| 899 } | 907 } |
| 900 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 908 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
| 901 } | 909 } |
| 902 | 910 |
| 903 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, | 911 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, |
| 904 const GrPrimitiveProcessor& processor, | 912 const GrPrimitiveProcessor& processor, |
| 905 const GrBatchTracker& bt) { | 913 const GrBatchTracker& bt) { |
| 914 this->setUniformViewMatrix(pdman, processor.viewMatrix()); |
| 915 |
| 906 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); | 916 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); |
| 907 const SkRect& rect = de.getRect(); | 917 const SkRect& rect = de.getRect(); |
| 908 SkScalar intervalLength = de.getIntervalLength(); | 918 SkScalar intervalLength = de.getIntervalLength(); |
| 909 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { | 919 if (rect != fPrevRect || intervalLength != fPrevIntervalLength) { |
| 910 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, | 920 pdman.set4f(fRectUniform, rect.fLeft + 0.5f, rect.fTop + 0.5f, |
| 911 rect.fRight - 0.5f, rect.fBottom - 0.5f); | 921 rect.fRight - 0.5f, rect.fBottom - 0.5f); |
| 912 pdman.set1f(fIntervalUniform, intervalLength); | 922 pdman.set1f(fIntervalUniform, intervalLength); |
| 913 fPrevRect = rect; | 923 fPrevRect = rect; |
| 914 fPrevIntervalLength = intervalLength; | 924 fPrevIntervalLength = intervalLength; |
| 915 } | 925 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 return DashingCircleEffect::Create(color, edgeType, info, | 1049 return DashingCircleEffect::Create(color, edgeType, info, |
| 1040 SkScalarHalf(strokeWidth), | 1050 SkScalarHalf(strokeWidth), |
| 1041 localMatrix); | 1051 localMatrix); |
| 1042 case GrDashingEffect::kNonRound_DashCap: | 1052 case GrDashingEffect::kNonRound_DashCap: |
| 1043 return DashingLineEffect::Create(color, edgeType, info, strokeWidth,
localMatrix); | 1053 return DashingLineEffect::Create(color, edgeType, info, strokeWidth,
localMatrix); |
| 1044 default: | 1054 default: |
| 1045 SkFAIL("Unexpected dashed cap."); | 1055 SkFAIL("Unexpected dashed cap."); |
| 1046 } | 1056 } |
| 1047 return NULL; | 1057 return NULL; |
| 1048 } | 1058 } |
| OLD | NEW |