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 "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 GLDashingCircleEffect::GLDashingCircleEffect() { | 845 GLDashingCircleEffect::GLDashingCircleEffect() { |
846 fColor = GrColor_ILLEGAL; | 846 fColor = GrColor_ILLEGAL; |
847 fPrevRadius = SK_ScalarMin; | 847 fPrevRadius = SK_ScalarMin; |
848 fPrevCenterX = SK_ScalarMin; | 848 fPrevCenterX = SK_ScalarMin; |
849 fPrevIntervalLength = SK_ScalarMax; | 849 fPrevIntervalLength = SK_ScalarMax; |
850 } | 850 } |
851 | 851 |
852 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 852 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
853 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); | 853 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); |
854 GrGLSLGPBuilder* pb = args.fPB; | 854 GrGLSLGPBuilder* pb = args.fPB; |
855 GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 855 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
856 | 856 |
857 // emit attributes | 857 // emit attributes |
858 vsBuilder->emitAttributes(dce); | 858 vertBuilder->emitAttributes(dce); |
859 | 859 |
860 // XY are dashPos, Z is dashInterval | 860 // XY are dashPos, Z is dashInterval |
861 GrGLSLVertToFrag dashParams(kVec3f_GrSLType); | 861 GrGLSLVertToFrag dashParams(kVec3f_GrSLType); |
862 args.fPB->addVarying("DashParam", &dashParams); | 862 args.fPB->addVarying("DashParam", &dashParams); |
863 vsBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->f
Name); | 863 vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()-
>fName); |
864 | 864 |
865 // x refers to circle radius - 0.5, y refers to cicle's center x coord | 865 // x refers to circle radius - 0.5, y refers to cicle's center x coord |
866 GrGLSLVertToFrag circleParams(kVec2f_GrSLType); | 866 GrGLSLVertToFrag circleParams(kVec2f_GrSLType); |
867 args.fPB->addVarying("CircleParams", &circleParams); | 867 args.fPB->addVarying("CircleParams", &circleParams); |
868 vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams(
)->fName); | 868 vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParam
s()->fName); |
869 | 869 |
| 870 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
870 // Setup pass through color | 871 // Setup pass through color |
871 if (!dce.colorIgnored()) { | 872 if (!dce.colorIgnored()) { |
872 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 873 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUnifo
rm); |
873 } | 874 } |
874 | 875 |
875 // Setup position | 876 // Setup position |
876 this->setupPosition(pb, gpArgs, dce.inPosition()->fName); | 877 this->setupPosition(pb, vertBuilder, gpArgs, dce.inPosition()->fName); |
877 | 878 |
878 // emit transforms | 879 // emit transforms |
879 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName
, dce.localMatrix(), | 880 this->emitTransforms(args.fPB, |
880 args.fTransformsIn, args.fTransformsOut); | 881 vertBuilder, |
| 882 gpArgs->fPositionVar, |
| 883 dce.inPosition()->fName, |
| 884 dce.localMatrix(), |
| 885 args.fTransformsIn, |
| 886 args.fTransformsOut); |
881 | 887 |
882 // transforms all points so that we can compare them to our test circle | 888 // transforms all points so that we can compare them to our test circle |
883 GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 889 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", |
884 fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;", | 890 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs
In(), |
885 dashParams.fsIn(), dashParams.fsIn(), dashParams.fsIn
(), | 891 dashParams.fsIn()); |
886 dashParams.fsIn()); | 892 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dash
Params.fsIn()); |
887 fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dashPa
rams.fsIn()); | 893 fragBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn
()); |
888 fsBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn()
); | 894 fragBuilder->codeAppend("float dist = length(center - fragPosShifted);"); |
889 fsBuilder->codeAppend("float dist = length(center - fragPosShifted);"); | |
890 if (dce.aaMode() != kBW_DashAAMode) { | 895 if (dce.aaMode() != kBW_DashAAMode) { |
891 fsBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn())
; | 896 fragBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn(
)); |
892 fsBuilder->codeAppend("diff = 1.0 - diff;"); | 897 fragBuilder->codeAppend("diff = 1.0 - diff;"); |
893 fsBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); | 898 fragBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); |
894 } else { | 899 } else { |
895 fsBuilder->codeAppendf("float alpha = 1.0;"); | 900 fragBuilder->codeAppendf("float alpha = 1.0;"); |
896 fsBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", circl
eParams.fsIn()); | 901 fragBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", cir
cleParams.fsIn()); |
897 } | 902 } |
898 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 903 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
899 } | 904 } |
900 | 905 |
901 void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman, | 906 void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman, |
902 const GrPrimitiveProcessor& processor) { | 907 const GrPrimitiveProcessor& processor) { |
903 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); | 908 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); |
904 if (dce.color() != fColor) { | 909 if (dce.color() != fColor) { |
905 float c[4]; | 910 float c[4]; |
906 GrColorToRGBAFloat(dce.color(), c); | 911 GrColorToRGBAFloat(dce.color(), c); |
907 pdman.set4fv(fColorUniform, 1, c); | 912 pdman.set4fv(fColorUniform, 1, c); |
908 fColor = dce.color(); | 913 fColor = dce.color(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 }; | 1056 }; |
1052 | 1057 |
1053 GLDashingLineEffect::GLDashingLineEffect() { | 1058 GLDashingLineEffect::GLDashingLineEffect() { |
1054 fColor = GrColor_ILLEGAL; | 1059 fColor = GrColor_ILLEGAL; |
1055 } | 1060 } |
1056 | 1061 |
1057 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 1062 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
1058 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); | 1063 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); |
1059 GrGLSLGPBuilder* pb = args.fPB; | 1064 GrGLSLGPBuilder* pb = args.fPB; |
1060 | 1065 |
1061 GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 1066 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
1062 | 1067 |
1063 // emit attributes | 1068 // emit attributes |
1064 vsBuilder->emitAttributes(de); | 1069 vertBuilder->emitAttributes(de); |
1065 | 1070 |
1066 // XY refers to dashPos, Z is the dash interval length | 1071 // XY refers to dashPos, Z is the dash interval length |
1067 GrGLSLVertToFrag inDashParams(kVec3f_GrSLType); | 1072 GrGLSLVertToFrag inDashParams(kVec3f_GrSLType); |
1068 args.fPB->addVarying("DashParams", &inDashParams, GrSLPrecision::kHigh_GrSLP
recision); | 1073 args.fPB->addVarying("DashParams", &inDashParams, GrSLPrecision::kHigh_GrSLP
recision); |
1069 vsBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()->
fName); | 1074 vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()
->fName); |
1070 | 1075 |
1071 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 1076 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
1072 // respectively. | 1077 // respectively. |
1073 GrGLSLVertToFrag inRectParams(kVec4f_GrSLType); | 1078 GrGLSLVertToFrag inRectParams(kVec4f_GrSLType); |
1074 args.fPB->addVarying("RectParams", &inRectParams, GrSLPrecision::kHigh_GrSLP
recision); | 1079 args.fPB->addVarying("RectParams", &inRectParams, GrSLPrecision::kHigh_GrSLP
recision); |
1075 vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()->
fName); | 1080 vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()
->fName); |
1076 | 1081 |
| 1082 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
1077 // Setup pass through color | 1083 // Setup pass through color |
1078 if (!de.colorIgnored()) { | 1084 if (!de.colorIgnored()) { |
1079 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 1085 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUnifo
rm); |
1080 } | 1086 } |
1081 | 1087 |
1082 | |
1083 // Setup position | 1088 // Setup position |
1084 this->setupPosition(pb, gpArgs, de.inPosition()->fName); | 1089 this->setupPosition(pb, vertBuilder, gpArgs, de.inPosition()->fName); |
1085 | 1090 |
1086 // emit transforms | 1091 // emit transforms |
1087 this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName,
de.localMatrix(), | 1092 this->emitTransforms(args.fPB, |
1088 args.fTransformsIn, args.fTransformsOut); | 1093 vertBuilder, |
| 1094 gpArgs->fPositionVar, |
| 1095 de.inPosition()->fName, |
| 1096 de.localMatrix(), |
| 1097 args.fTransformsIn, |
| 1098 args.fTransformsOut); |
1089 | 1099 |
1090 // transforms all points so that we can compare them to our test rect | 1100 // transforms all points so that we can compare them to our test rect |
1091 GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 1101 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", |
1092 fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;", | 1102 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar
ams.fsIn(), |
1093 inDashParams.fsIn(), inDashParams.fsIn(), inDashParam
s.fsIn(), | 1103 inDashParams.fsIn()); |
1094 inDashParams.fsIn()); | 1104 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDa
shParams.fsIn()); |
1095 fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDash
Params.fsIn()); | |
1096 if (de.aaMode() == kEdgeAA_DashAAMode) { | 1105 if (de.aaMode() == kEdgeAA_DashAAMode) { |
1097 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 1106 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
1098 // numbers, xSub and ySub. | 1107 // numbers, xSub and ySub. |
1099 fsBuilder->codeAppend("float xSub, ySub;"); | 1108 fragBuilder->codeAppend("float xSub, ySub;"); |
1100 fsBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", inRe
ctParams.fsIn()); | 1109 fragBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", in
RectParams.fsIn()); |
1101 fsBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", inR
ectParams.fsIn()); | 1110 fragBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", i
nRectParams.fsIn()); |
1102 fsBuilder->codeAppendf("ySub = min(fragPosShifted.y - %s.y, 0.0);", inRe
ctParams.fsIn()); | 1111 fragBuilder->codeAppendf("ySub = min(fragPosShifted.y - %s.y, 0.0);", in
RectParams.fsIn()); |
1103 fsBuilder->codeAppendf("ySub += min(%s.w - fragPosShifted.y, 0.0);", inR
ectParams.fsIn()); | 1112 fragBuilder->codeAppendf("ySub += min(%s.w - fragPosShifted.y, 0.0);", i
nRectParams.fsIn()); |
1104 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel | 1113 // Now compute coverage in x and y and multiply them to get the fraction
of the pixel |
1105 // covered. | 1114 // covered. |
1106 fsBuilder->codeAppendf("float alpha = (1.0 + max(xSub, -1.0)) * (1.0 + m
ax(ySub, -1.0));"); | 1115 fragBuilder->codeAppendf( |
| 1116 "float alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));"); |
1107 } else if (de.aaMode() == kMSAA_DashAAMode) { | 1117 } else if (de.aaMode() == kMSAA_DashAAMode) { |
1108 // For MSAA, we don't modulate the alpha by the Y distance, since MSAA c
overage will handle | 1118 // For MSAA, we don't modulate the alpha by the Y distance, since MSAA c
overage will handle |
1109 // AA on the the top and bottom edges. The shader is only responsible fo
r intra-dash alpha. | 1119 // AA on the the top and bottom edges. The shader is only responsible fo
r intra-dash alpha. |
1110 fsBuilder->codeAppend("float xSub;"); | 1120 fragBuilder->codeAppend("float xSub;"); |
1111 fsBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", inRe
ctParams.fsIn()); | 1121 fragBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", in
RectParams.fsIn()); |
1112 fsBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", inR
ectParams.fsIn()); | 1122 fragBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", i
nRectParams.fsIn()); |
1113 // Now compute coverage in x to get the fraction of the pixel covered. | 1123 // Now compute coverage in x to get the fraction of the pixel covered. |
1114 fsBuilder->codeAppendf("float alpha = (1.0 + max(xSub, -1.0));"); | 1124 fragBuilder->codeAppendf("float alpha = (1.0 + max(xSub, -1.0));"); |
1115 } else { | 1125 } else { |
1116 // Assuming the bounding geometry is tight so no need to check y values | 1126 // Assuming the bounding geometry is tight so no need to check y values |
1117 fsBuilder->codeAppendf("float alpha = 1.0;"); | 1127 fragBuilder->codeAppendf("float alpha = 1.0;"); |
1118 fsBuilder->codeAppendf("alpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0
: 0.0;", | 1128 fragBuilder->codeAppendf("alpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.
0 : 0.0;", |
1119 inRectParams.fsIn()); | 1129 inRectParams.fsIn()); |
1120 fsBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0
: 0.0;", | 1130 fragBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1
.0 : 0.0;", |
1121 inRectParams.fsIn()); | 1131 inRectParams.fsIn()); |
1122 } | 1132 } |
1123 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 1133 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
1124 } | 1134 } |
1125 | 1135 |
1126 void GLDashingLineEffect::setData(const GrGLSLProgramDataManager& pdman, | 1136 void GLDashingLineEffect::setData(const GrGLSLProgramDataManager& pdman, |
1127 const GrPrimitiveProcessor& processor) { | 1137 const GrPrimitiveProcessor& processor) { |
1128 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); | 1138 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); |
1129 if (de.color() != fColor) { | 1139 if (de.color() != fColor) { |
1130 float c[4]; | 1140 float c[4]; |
1131 GrColorToRGBAFloat(de.color(), c); | 1141 GrColorToRGBAFloat(de.color(), c); |
1132 pdman.set4fv(fColorUniform, 1, c); | 1142 pdman.set4fv(fColorUniform, 1, c); |
1133 fColor = de.color(); | 1143 fColor = de.color(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 info.fIntervals = intervals; | 1291 info.fIntervals = intervals; |
1282 info.fCount = 2; | 1292 info.fCount = 2; |
1283 info.fPhase = phase; | 1293 info.fPhase = phase; |
1284 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1294 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
1285 SkASSERT(success); | 1295 SkASSERT(success); |
1286 | 1296 |
1287 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1297 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
1288 } | 1298 } |
1289 | 1299 |
1290 #endif | 1300 #endif |
OLD | NEW |