| 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 "gl/GrGLGeometryProcessor.h" | 24 #include "gl/GrGLGeometryProcessor.h" |
| 25 #include "gl/GrGLFragmentProcessor.h" | 25 #include "gl/GrGLFragmentProcessor.h" |
| 26 #include "gl/builders/GrGLProgramBuilder.h" | 26 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 27 #include "glsl/GrGLSLProgramBuilder.h" |
| 27 #include "glsl/GrGLSLProgramDataManager.h" | 28 #include "glsl/GrGLSLProgramDataManager.h" |
| 29 #include "glsl/GrGLSLVertexShaderBuilder.h" |
| 28 | 30 |
| 29 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
| 30 | 32 |
| 31 // 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. |
| 32 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, | 34 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, |
| 33 const SkMatrix& viewMatrix) { | 35 const SkMatrix& viewMatrix) { |
| 34 // Pts must be either horizontal or vertical in src space | 36 // Pts must be either horizontal or vertical in src space |
| 35 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) { |
| 36 return false; | 38 return false; |
| 37 } | 39 } |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 GLDashingCircleEffect::GLDashingCircleEffect() { | 846 GLDashingCircleEffect::GLDashingCircleEffect() { |
| 845 fColor = GrColor_ILLEGAL; | 847 fColor = GrColor_ILLEGAL; |
| 846 fPrevRadius = SK_ScalarMin; | 848 fPrevRadius = SK_ScalarMin; |
| 847 fPrevCenterX = SK_ScalarMin; | 849 fPrevCenterX = SK_ScalarMin; |
| 848 fPrevIntervalLength = SK_ScalarMax; | 850 fPrevIntervalLength = SK_ScalarMax; |
| 849 } | 851 } |
| 850 | 852 |
| 851 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 853 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
| 852 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); | 854 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); |
| 853 GrGLSLGPBuilder* pb = args.fPB; | 855 GrGLSLGPBuilder* pb = args.fPB; |
| 854 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 856 GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 855 | 857 |
| 856 // emit attributes | 858 // emit attributes |
| 857 vsBuilder->emitAttributes(dce); | 859 vsBuilder->emitAttributes(dce); |
| 858 | 860 |
| 859 // XY are dashPos, Z is dashInterval | 861 // XY are dashPos, Z is dashInterval |
| 860 GrGLSLVertToFrag dashParams(kVec3f_GrSLType); | 862 GrGLSLVertToFrag dashParams(kVec3f_GrSLType); |
| 861 args.fPB->addVarying("DashParam", &dashParams); | 863 args.fPB->addVarying("DashParam", &dashParams); |
| 862 vsBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->f
Name); | 864 vsBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->f
Name); |
| 863 | 865 |
| 864 // x refers to circle radius - 0.5, y refers to cicle's center x coord | 866 // x refers to circle radius - 0.5, y refers to cicle's center x coord |
| 865 GrGLSLVertToFrag circleParams(kVec2f_GrSLType); | 867 GrGLSLVertToFrag circleParams(kVec2f_GrSLType); |
| 866 args.fPB->addVarying("CircleParams", &circleParams); | 868 args.fPB->addVarying("CircleParams", &circleParams); |
| 867 vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams(
)->fName); | 869 vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams(
)->fName); |
| 868 | 870 |
| 869 // Setup pass through color | 871 // Setup pass through color |
| 870 if (!dce.colorIgnored()) { | 872 if (!dce.colorIgnored()) { |
| 871 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 873 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 872 } | 874 } |
| 873 | 875 |
| 874 // Setup position | 876 // Setup position |
| 875 this->setupPosition(pb, gpArgs, dce.inPosition()->fName); | 877 this->setupPosition(pb, gpArgs, dce.inPosition()->fName); |
| 876 | 878 |
| 877 // emit transforms | 879 // emit transforms |
| 878 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName
, dce.localMatrix(), | 880 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName
, dce.localMatrix(), |
| 879 args.fTransformsIn, args.fTransformsOut); | 881 args.fTransformsIn, args.fTransformsOut); |
| 880 | 882 |
| 881 // transforms all points so that we can compare them to our test circle | 883 // transforms all points so that we can compare them to our test circle |
| 882 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 884 GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 883 fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;", | 885 fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;", |
| 884 dashParams.fsIn(), dashParams.fsIn(), dashParams.fsIn
(), | 886 dashParams.fsIn(), dashParams.fsIn(), dashParams.fsIn
(), |
| 885 dashParams.fsIn()); | 887 dashParams.fsIn()); |
| 886 fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dashPa
rams.fsIn()); | 888 fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dashPa
rams.fsIn()); |
| 887 fsBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn()
); | 889 fsBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn()
); |
| 888 fsBuilder->codeAppend("float dist = length(center - fragPosShifted);"); | 890 fsBuilder->codeAppend("float dist = length(center - fragPosShifted);"); |
| 889 if (dce.aaMode() != kBW_DashAAMode) { | 891 if (dce.aaMode() != kBW_DashAAMode) { |
| 890 fsBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn())
; | 892 fsBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn())
; |
| 891 fsBuilder->codeAppend("diff = 1.0 - diff;"); | 893 fsBuilder->codeAppend("diff = 1.0 - diff;"); |
| 892 fsBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); | 894 fsBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 }; | 1051 }; |
| 1050 | 1052 |
| 1051 GLDashingLineEffect::GLDashingLineEffect() { | 1053 GLDashingLineEffect::GLDashingLineEffect() { |
| 1052 fColor = GrColor_ILLEGAL; | 1054 fColor = GrColor_ILLEGAL; |
| 1053 } | 1055 } |
| 1054 | 1056 |
| 1055 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { | 1057 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { |
| 1056 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); | 1058 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); |
| 1057 GrGLSLGPBuilder* pb = args.fPB; | 1059 GrGLSLGPBuilder* pb = args.fPB; |
| 1058 | 1060 |
| 1059 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 1061 GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 1060 | 1062 |
| 1061 // emit attributes | 1063 // emit attributes |
| 1062 vsBuilder->emitAttributes(de); | 1064 vsBuilder->emitAttributes(de); |
| 1063 | 1065 |
| 1064 // XY refers to dashPos, Z is the dash interval length | 1066 // XY refers to dashPos, Z is the dash interval length |
| 1065 GrGLSLVertToFrag inDashParams(kVec3f_GrSLType); | 1067 GrGLSLVertToFrag inDashParams(kVec3f_GrSLType); |
| 1066 args.fPB->addVarying("DashParams", &inDashParams, GrSLPrecision::kHigh_GrSLP
recision); | 1068 args.fPB->addVarying("DashParams", &inDashParams, GrSLPrecision::kHigh_GrSLP
recision); |
| 1067 vsBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()->
fName); | 1069 vsBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()->
fName); |
| 1068 | 1070 |
| 1069 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), | 1071 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot
tom - 0.5), |
| 1070 // respectively. | 1072 // respectively. |
| 1071 GrGLSLVertToFrag inRectParams(kVec4f_GrSLType); | 1073 GrGLSLVertToFrag inRectParams(kVec4f_GrSLType); |
| 1072 args.fPB->addVarying("RectParams", &inRectParams, GrSLPrecision::kHigh_GrSLP
recision); | 1074 args.fPB->addVarying("RectParams", &inRectParams, GrSLPrecision::kHigh_GrSLP
recision); |
| 1073 vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()->
fName); | 1075 vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()->
fName); |
| 1074 | 1076 |
| 1075 // Setup pass through color | 1077 // Setup pass through color |
| 1076 if (!de.colorIgnored()) { | 1078 if (!de.colorIgnored()) { |
| 1077 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 1079 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
| 1078 } | 1080 } |
| 1079 | 1081 |
| 1080 | 1082 |
| 1081 // Setup position | 1083 // Setup position |
| 1082 this->setupPosition(pb, gpArgs, de.inPosition()->fName); | 1084 this->setupPosition(pb, gpArgs, de.inPosition()->fName); |
| 1083 | 1085 |
| 1084 // emit transforms | 1086 // emit transforms |
| 1085 this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName,
de.localMatrix(), | 1087 this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName,
de.localMatrix(), |
| 1086 args.fTransformsIn, args.fTransformsOut); | 1088 args.fTransformsIn, args.fTransformsOut); |
| 1087 | 1089 |
| 1088 // transforms all points so that we can compare them to our test rect | 1090 // transforms all points so that we can compare them to our test rect |
| 1089 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 1091 GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 1090 fsBuilder->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;", |
| 1091 inDashParams.fsIn(), inDashParams.fsIn(), inDashParam
s.fsIn(), | 1093 inDashParams.fsIn(), inDashParams.fsIn(), inDashParam
s.fsIn(), |
| 1092 inDashParams.fsIn()); | 1094 inDashParams.fsIn()); |
| 1093 fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDash
Params.fsIn()); | 1095 fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDash
Params.fsIn()); |
| 1094 if (de.aaMode() == kEdgeAA_DashAAMode) { | 1096 if (de.aaMode() == kEdgeAA_DashAAMode) { |
| 1095 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative | 1097 // The amount of coverage removed in x and y by the edges is computed as
a pair of negative |
| 1096 // numbers, xSub and ySub. | 1098 // numbers, xSub and ySub. |
| 1097 fsBuilder->codeAppend("float xSub, ySub;"); | 1099 fsBuilder->codeAppend("float xSub, ySub;"); |
| 1098 fsBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", inRe
ctParams.fsIn()); | 1100 fsBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", inRe
ctParams.fsIn()); |
| 1099 fsBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", inR
ectParams.fsIn()); | 1101 fsBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", inR
ectParams.fsIn()); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 info.fIntervals = intervals; | 1281 info.fIntervals = intervals; |
| 1280 info.fCount = 2; | 1282 info.fCount = 2; |
| 1281 info.fPhase = phase; | 1283 info.fPhase = phase; |
| 1282 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1284 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
| 1283 SkASSERT(success); | 1285 SkASSERT(success); |
| 1284 | 1286 |
| 1285 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1287 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
| 1286 } | 1288 } |
| 1287 | 1289 |
| 1288 #endif | 1290 #endif |
| OLD | NEW |