| 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" | 26 #include "glsl/GrGLSLProgramBuilder.h" |
| 27 #include "glsl/GrGLSLProgramDataManager.h" | 27 #include "glsl/GrGLSLProgramDataManager.h" |
| 28 #include "glsl/GrGLSLVarying.h" |
| 28 #include "glsl/GrGLSLVertexShaderBuilder.h" | 29 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 29 | 30 |
| 30 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
| 31 | 32 |
| 32 // 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. |
| 33 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, | 34 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, |
| 34 const SkMatrix& viewMatrix) { | 35 const SkMatrix& viewMatrix) { |
| 35 // Pts must be either horizontal or vertical in src space | 36 // Pts must be either horizontal or vertical in src space |
| 36 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) { |
| 37 return false; | 38 return false; |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 fColor = GrColor_ILLEGAL; | 847 fColor = GrColor_ILLEGAL; |
| 847 fPrevRadius = SK_ScalarMin; | 848 fPrevRadius = SK_ScalarMin; |
| 848 fPrevCenterX = SK_ScalarMin; | 849 fPrevCenterX = SK_ScalarMin; |
| 849 fPrevIntervalLength = SK_ScalarMax; | 850 fPrevIntervalLength = SK_ScalarMax; |
| 850 } | 851 } |
| 851 | 852 |
| 852 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 853 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
| 853 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); | 854 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); |
| 854 GrGLSLGPBuilder* pb = args.fPB; | 855 GrGLSLGPBuilder* pb = args.fPB; |
| 855 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 856 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
| 857 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
| 856 | 858 |
| 857 // emit attributes | 859 // emit attributes |
| 858 vertBuilder->emitAttributes(dce); | 860 varyingHandler->emitAttributes(dce); |
| 859 | 861 |
| 860 // XY are dashPos, Z is dashInterval | 862 // XY are dashPos, Z is dashInterval |
| 861 GrGLSLVertToFrag dashParams(kVec3f_GrSLType); | 863 GrGLSLVertToFrag dashParams(kVec3f_GrSLType); |
| 862 args.fPB->addVarying("DashParam", &dashParams); | 864 varyingHandler->addVarying("DashParam", &dashParams); |
| 863 vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()-
>fName); | 865 vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()-
>fName); |
| 864 | 866 |
| 865 // x refers to circle radius - 0.5, y refers to cicle's center x coord | 867 // x refers to circle radius - 0.5, y refers to cicle's center x coord |
| 866 GrGLSLVertToFrag circleParams(kVec2f_GrSLType); | 868 GrGLSLVertToFrag circleParams(kVec2f_GrSLType); |
| 867 args.fPB->addVarying("CircleParams", &circleParams); | 869 varyingHandler->addVarying("CircleParams", &circleParams); |
| 868 vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParam
s()->fName); | 870 vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParam
s()->fName); |
| 869 | 871 |
| 870 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 872 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 871 // Setup pass through color | 873 // Setup pass through color |
| 872 if (!dce.colorIgnored()) { | 874 if (!dce.colorIgnored()) { |
| 873 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUnifo
rm); | 875 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUnifo
rm); |
| 874 } | 876 } |
| 875 | 877 |
| 876 // Setup position | 878 // Setup position |
| 877 this->setupPosition(pb, vertBuilder, gpArgs, dce.inPosition()->fName); | 879 this->setupPosition(pb, vertBuilder, gpArgs, dce.inPosition()->fName); |
| 878 | 880 |
| 879 // emit transforms | 881 // emit transforms |
| 880 this->emitTransforms(args.fPB, | 882 this->emitTransforms(args.fPB, |
| 881 vertBuilder, | 883 vertBuilder, |
| 884 varyingHandler, |
| 882 gpArgs->fPositionVar, | 885 gpArgs->fPositionVar, |
| 883 dce.inPosition()->fName, | 886 dce.inPosition()->fName, |
| 884 dce.localMatrix(), | 887 dce.localMatrix(), |
| 885 args.fTransformsIn, | 888 args.fTransformsIn, |
| 886 args.fTransformsOut); | 889 args.fTransformsOut); |
| 887 | 890 |
| 888 // transforms all points so that we can compare them to our test circle | 891 // transforms all points so that we can compare them to our test circle |
| 889 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", | 892 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", |
| 890 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs
In(), | 893 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs
In(), |
| 891 dashParams.fsIn()); | 894 dashParams.fsIn()); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 | 1060 |
| 1058 GLDashingLineEffect::GLDashingLineEffect() { | 1061 GLDashingLineEffect::GLDashingLineEffect() { |
| 1059 fColor = GrColor_ILLEGAL; | 1062 fColor = GrColor_ILLEGAL; |
| 1060 } | 1063 } |
| 1061 | 1064 |
| 1062 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 1065 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
| 1063 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); | 1066 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); |
| 1064 GrGLSLGPBuilder* pb = args.fPB; | 1067 GrGLSLGPBuilder* pb = args.fPB; |
| 1065 | 1068 |
| 1066 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; | 1069 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
| 1070 GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler; |
| 1067 | 1071 |
| 1068 // emit attributes | 1072 // emit attributes |
| 1069 vertBuilder->emitAttributes(de); | 1073 varyingHandler->emitAttributes(de); |
| 1070 | 1074 |
| 1071 // XY refers to dashPos, Z is the dash interval length | 1075 // XY refers to dashPos, Z is the dash interval length |
| 1072 GrGLSLVertToFrag inDashParams(kVec3f_GrSLType); | 1076 GrGLSLVertToFrag inDashParams(kVec3f_GrSLType); |
| 1073 args.fPB->addVarying("DashParams", &inDashParams, GrSLPrecision::kHigh_GrSLP
recision); | 1077 varyingHandler->addVarying("DashParams", &inDashParams, GrSLPrecision::kHigh
_GrSLPrecision); |
| 1074 vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()
->fName); | 1078 vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()
->fName); |
| 1075 | 1079 |
| 1076 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 1080 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
| 1077 // respectively. | 1081 // respectively. |
| 1078 GrGLSLVertToFrag inRectParams(kVec4f_GrSLType); | 1082 GrGLSLVertToFrag inRectParams(kVec4f_GrSLType); |
| 1079 args.fPB->addVarying("RectParams", &inRectParams, GrSLPrecision::kHigh_GrSLP
recision); | 1083 varyingHandler->addVarying("RectParams", &inRectParams, GrSLPrecision::kHigh
_GrSLPrecision); |
| 1080 vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()
->fName); | 1084 vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()
->fName); |
| 1081 | 1085 |
| 1082 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 1086 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 1083 // Setup pass through color | 1087 // Setup pass through color |
| 1084 if (!de.colorIgnored()) { | 1088 if (!de.colorIgnored()) { |
| 1085 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUnifo
rm); | 1089 this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUnifo
rm); |
| 1086 } | 1090 } |
| 1087 | 1091 |
| 1088 // Setup position | 1092 // Setup position |
| 1089 this->setupPosition(pb, vertBuilder, gpArgs, de.inPosition()->fName); | 1093 this->setupPosition(pb, vertBuilder, gpArgs, de.inPosition()->fName); |
| 1090 | 1094 |
| 1091 // emit transforms | 1095 // emit transforms |
| 1092 this->emitTransforms(args.fPB, | 1096 this->emitTransforms(args.fPB, |
| 1093 vertBuilder, | 1097 vertBuilder, |
| 1098 varyingHandler, |
| 1094 gpArgs->fPositionVar, | 1099 gpArgs->fPositionVar, |
| 1095 de.inPosition()->fName, | 1100 de.inPosition()->fName, |
| 1096 de.localMatrix(), | 1101 de.localMatrix(), |
| 1097 args.fTransformsIn, | 1102 args.fTransformsIn, |
| 1098 args.fTransformsOut); | 1103 args.fTransformsOut); |
| 1099 | 1104 |
| 1100 // transforms all points so that we can compare them to our test rect | 1105 // transforms all points so that we can compare them to our test rect |
| 1101 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", | 1106 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;
", |
| 1102 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar
ams.fsIn(), | 1107 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar
ams.fsIn(), |
| 1103 inDashParams.fsIn()); | 1108 inDashParams.fsIn()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 info.fIntervals = intervals; | 1296 info.fIntervals = intervals; |
| 1292 info.fCount = 2; | 1297 info.fCount = 2; |
| 1293 info.fPhase = phase; | 1298 info.fPhase = phase; |
| 1294 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1299 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
| 1295 SkASSERT(success); | 1300 SkASSERT(success); |
| 1296 | 1301 |
| 1297 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1302 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
| 1298 } | 1303 } |
| 1299 | 1304 |
| 1300 #endif | 1305 #endif |
| OLD | NEW |