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" |
11 #include "GrBatchTest.h" | 11 #include "GrBatchTest.h" |
12 #include "GrCaps.h" | 12 #include "GrCaps.h" |
13 #include "GrGeometryProcessor.h" | 13 #include "GrGeometryProcessor.h" |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
15 #include "GrCoordTransform.h" | 15 #include "GrCoordTransform.h" |
16 #include "GrDefaultGeoProcFactory.h" | 16 #include "GrDefaultGeoProcFactory.h" |
17 #include "GrDrawTarget.h" | 17 #include "GrDrawTarget.h" |
18 #include "GrInvariantOutput.h" | 18 #include "GrInvariantOutput.h" |
19 #include "GrProcessor.h" | 19 #include "GrProcessor.h" |
20 #include "GrStrokeInfo.h" | 20 #include "GrStrokeInfo.h" |
21 #include "GrVertexBuffer.h" | 21 #include "GrVertexBuffer.h" |
22 #include "SkGr.h" | 22 #include "SkGr.h" |
23 #include "batches/GrVertexBatch.h" | 23 #include "batches/GrVertexBatch.h" |
24 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 24 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
25 #include "glsl/GrGLSLGeometryProcessor.h" | 25 #include "glsl/GrGLSLGeometryProcessor.h" |
26 #include "glsl/GrGLSLProgramBuilder.h" | |
27 #include "glsl/GrGLSLProgramDataManager.h" | 26 #include "glsl/GrGLSLProgramDataManager.h" |
| 27 #include "glsl/GrGLSLUniformHandler.h" |
28 #include "glsl/GrGLSLVarying.h" | 28 #include "glsl/GrGLSLVarying.h" |
29 #include "glsl/GrGLSLVertexShaderBuilder.h" | 29 #include "glsl/GrGLSLVertexShaderBuilder.h" |
30 | 30 |
31 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
32 | 32 |
33 // Returns whether or not the gpu can fast path the dash line effect. | 33 // Returns whether or not the gpu can fast path the dash line effect. |
34 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, | 34 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, |
35 const SkMatrix& viewMatrix) { | 35 const SkMatrix& viewMatrix) { |
36 // Pts must be either horizontal or vertical in src space | 36 // Pts must be either horizontal or vertical in src space |
37 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { | 37 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 | 856 |
857 GLDashingCircleEffect::GLDashingCircleEffect() { | 857 GLDashingCircleEffect::GLDashingCircleEffect() { |
858 fColor = GrColor_ILLEGAL; | 858 fColor = GrColor_ILLEGAL; |
859 fPrevRadius = SK_ScalarMin; | 859 fPrevRadius = SK_ScalarMin; |
860 fPrevCenterX = SK_ScalarMin; | 860 fPrevCenterX = SK_ScalarMin; |
861 fPrevIntervalLength = SK_ScalarMax; | 861 fPrevIntervalLength = SK_ScalarMax; |
862 } | 862 } |
863 | 863 |
864 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 864 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
865 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); | 865 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); |
866 GrGLSLGPBuilder* pb = args.fPB; | |
867 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 866 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
868 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 867 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
| 868 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
869 | 869 |
870 // emit attributes | 870 // emit attributes |
871 varyingHandler->emitAttributes(dce); | 871 varyingHandler->emitAttributes(dce); |
872 | 872 |
873 // XY are dashPos, Z is dashInterval | 873 // XY are dashPos, Z is dashInterval |
874 GrGLSLVertToFrag dashParams(kVec3f_GrSLType); | 874 GrGLSLVertToFrag dashParams(kVec3f_GrSLType); |
875 varyingHandler->addVarying("DashParam", &dashParams); | 875 varyingHandler->addVarying("DashParam", &dashParams); |
876 vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()-
>fName); | 876 vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()-
>fName); |
877 | 877 |
878 // x refers to circle radius - 0.5, y refers to cicle's center x coord | 878 // x refers to circle radius - 0.5, y refers to cicle's center x coord |
879 GrGLSLVertToFrag circleParams(kVec2f_GrSLType); | 879 GrGLSLVertToFrag circleParams(kVec2f_GrSLType); |
880 varyingHandler->addVarying("CircleParams", &circleParams); | 880 varyingHandler->addVarying("CircleParams", &circleParams); |
881 vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParam
s()->fName); | 881 vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParam
s()->fName); |
882 | 882 |
883 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 883 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
884 // Setup pass through color | 884 // Setup pass through color |
885 if (!dce.colorIgnored()) { | 885 if (!dce.colorIgnored()) { |
886 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUnifo
rm); | 886 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
&fColorUniform); |
887 } | 887 } |
888 | 888 |
889 // Setup position | 889 // Setup position |
890 this->setupPosition(pb, vertBuilder, gpArgs, dce.inPosition()->fName); | 890 this->setupPosition(vertBuilder, gpArgs, dce.inPosition()->fName); |
891 | 891 |
892 // emit transforms | 892 // emit transforms |
893 this->emitTransforms(args.fPB, | 893 this->emitTransforms(vertBuilder, |
894 vertBuilder, | |
895 varyingHandler, | 894 varyingHandler, |
| 895 uniformHandler, |
896 gpArgs->fPositionVar, | 896 gpArgs->fPositionVar, |
897 dce.inPosition()->fName, | 897 dce.inPosition()->fName, |
898 dce.localMatrix(), | 898 dce.localMatrix(), |
899 args.fTransformsIn, | 899 args.fTransformsIn, |
900 args.fTransformsOut); | 900 args.fTransformsOut); |
901 | 901 |
902 // transforms all points so that we can compare them to our test circle | 902 // transforms all points so that we can compare them to our test circle |
903 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", | 903 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", |
904 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs
In(), | 904 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs
In(), |
905 dashParams.fsIn()); | 905 dashParams.fsIn()); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 UniformHandle fColorUniform; | 1068 UniformHandle fColorUniform; |
1069 typedef GrGLSLGeometryProcessor INHERITED; | 1069 typedef GrGLSLGeometryProcessor INHERITED; |
1070 }; | 1070 }; |
1071 | 1071 |
1072 GLDashingLineEffect::GLDashingLineEffect() { | 1072 GLDashingLineEffect::GLDashingLineEffect() { |
1073 fColor = GrColor_ILLEGAL; | 1073 fColor = GrColor_ILLEGAL; |
1074 } | 1074 } |
1075 | 1075 |
1076 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 1076 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
1077 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); | 1077 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); |
1078 GrGLSLGPBuilder* pb = args.fPB; | |
1079 | 1078 |
1080 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 1079 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
1081 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; | 1080 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
| 1081 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
1082 | 1082 |
1083 // emit attributes | 1083 // emit attributes |
1084 varyingHandler->emitAttributes(de); | 1084 varyingHandler->emitAttributes(de); |
1085 | 1085 |
1086 // XY refers to dashPos, Z is the dash interval length | 1086 // XY refers to dashPos, Z is the dash interval length |
1087 GrGLSLVertToFrag inDashParams(kVec3f_GrSLType); | 1087 GrGLSLVertToFrag inDashParams(kVec3f_GrSLType); |
1088 varyingHandler->addVarying("DashParams", &inDashParams, GrSLPrecision::kHigh
_GrSLPrecision); | 1088 varyingHandler->addVarying("DashParams", &inDashParams, GrSLPrecision::kHigh
_GrSLPrecision); |
1089 vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()
->fName); | 1089 vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()
->fName); |
1090 | 1090 |
1091 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 1091 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
1092 // respectively. | 1092 // respectively. |
1093 GrGLSLVertToFrag inRectParams(kVec4f_GrSLType); | 1093 GrGLSLVertToFrag inRectParams(kVec4f_GrSLType); |
1094 varyingHandler->addVarying("RectParams", &inRectParams, GrSLPrecision::kHigh
_GrSLPrecision); | 1094 varyingHandler->addVarying("RectParams", &inRectParams, GrSLPrecision::kHigh
_GrSLPrecision); |
1095 vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()
->fName); | 1095 vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()
->fName); |
1096 | 1096 |
1097 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 1097 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
1098 // Setup pass through color | 1098 // Setup pass through color |
1099 if (!de.colorIgnored()) { | 1099 if (!de.colorIgnored()) { |
1100 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUnifo
rm); | 1100 this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
&fColorUniform); |
1101 } | 1101 } |
1102 | 1102 |
1103 // Setup position | 1103 // Setup position |
1104 this->setupPosition(pb, vertBuilder, gpArgs, de.inPosition()->fName); | 1104 this->setupPosition(vertBuilder, gpArgs, de.inPosition()->fName); |
1105 | 1105 |
1106 // emit transforms | 1106 // emit transforms |
1107 this->emitTransforms(args.fPB, | 1107 this->emitTransforms(vertBuilder, |
1108 vertBuilder, | |
1109 varyingHandler, | 1108 varyingHandler, |
| 1109 uniformHandler, |
1110 gpArgs->fPositionVar, | 1110 gpArgs->fPositionVar, |
1111 de.inPosition()->fName, | 1111 de.inPosition()->fName, |
1112 de.localMatrix(), | 1112 de.localMatrix(), |
1113 args.fTransformsIn, | 1113 args.fTransformsIn, |
1114 args.fTransformsOut); | 1114 args.fTransformsOut); |
1115 | 1115 |
1116 // transforms all points so that we can compare them to our test rect | 1116 // transforms all points so that we can compare them to our test rect |
1117 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", | 1117 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", |
1118 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar
ams.fsIn(), | 1118 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar
ams.fsIn(), |
1119 inDashParams.fsIn()); | 1119 inDashParams.fsIn()); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 info.fIntervals = intervals; | 1307 info.fIntervals = intervals; |
1308 info.fCount = 2; | 1308 info.fCount = 2; |
1309 info.fPhase = phase; | 1309 info.fPhase = phase; |
1310 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1310 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
1311 SkASSERT(success); | 1311 SkASSERT(success); |
1312 | 1312 |
1313 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1313 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
1314 } | 1314 } |
1315 | 1315 |
1316 #endif | 1316 #endif |
OLD | NEW |