| 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 "gl/builders/GrGLProgramBuilder.h" |
| 27 #include "glsl/GrGLSLProgramDataManager.h" |
| 27 | 28 |
| 28 /////////////////////////////////////////////////////////////////////////////// | 29 /////////////////////////////////////////////////////////////////////////////// |
| 29 | 30 |
| 30 // Returns whether or not the gpu can fast path the dash line effect. | 31 // Returns whether or not the gpu can fast path the dash line effect. |
| 31 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, | 32 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, |
| 32 const SkMatrix& viewMatrix) { | 33 const SkMatrix& viewMatrix) { |
| 33 // Pts must be either horizontal or vertical in src space | 34 // Pts must be either horizontal or vertical in src space |
| 34 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { | 35 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { |
| 35 return false; | 36 return false; |
| 36 } | 37 } |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 class GLDashingCircleEffect : public GrGLGeometryProcessor { | 815 class GLDashingCircleEffect : public GrGLGeometryProcessor { |
| 815 public: | 816 public: |
| 816 GLDashingCircleEffect(); | 817 GLDashingCircleEffect(); |
| 817 | 818 |
| 818 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 819 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
| 819 | 820 |
| 820 static inline void GenKey(const GrGeometryProcessor&, | 821 static inline void GenKey(const GrGeometryProcessor&, |
| 821 const GrGLSLCaps&, | 822 const GrGLSLCaps&, |
| 822 GrProcessorKeyBuilder*); | 823 GrProcessorKeyBuilder*); |
| 823 | 824 |
| 824 void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) ove
rride; | 825 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) o
verride; |
| 825 | 826 |
| 826 void setTransformData(const GrPrimitiveProcessor& primProc, | 827 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 827 const GrGLProgramDataManager& pdman, | 828 const GrGLSLProgramDataManager& pdman, |
| 828 int index, | 829 int index, |
| 829 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | 830 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
| 830 this->setTransformDataHelper<DashingCircleEffect>(primProc, pdman, index
, transforms); | 831 this->setTransformDataHelper<DashingCircleEffect>(primProc, pdman, index
, transforms); |
| 831 } | 832 } |
| 832 | 833 |
| 833 private: | 834 private: |
| 834 UniformHandle fParamUniform; | 835 UniformHandle fParamUniform; |
| 835 UniformHandle fColorUniform; | 836 UniformHandle fColorUniform; |
| 836 GrColor fColor; | 837 GrColor fColor; |
| 837 SkScalar fPrevRadius; | 838 SkScalar fPrevRadius; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 fsBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn())
; | 890 fsBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn())
; |
| 890 fsBuilder->codeAppend("diff = 1.0 - diff;"); | 891 fsBuilder->codeAppend("diff = 1.0 - diff;"); |
| 891 fsBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); | 892 fsBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); |
| 892 } else { | 893 } else { |
| 893 fsBuilder->codeAppendf("float alpha = 1.0;"); | 894 fsBuilder->codeAppendf("float alpha = 1.0;"); |
| 894 fsBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", circl
eParams.fsIn()); | 895 fsBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", circl
eParams.fsIn()); |
| 895 } | 896 } |
| 896 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 897 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
| 897 } | 898 } |
| 898 | 899 |
| 899 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, | 900 void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman, |
| 900 const GrPrimitiveProcessor& processor) { | 901 const GrPrimitiveProcessor& processor) { |
| 901 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); | 902 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); |
| 902 if (dce.color() != fColor) { | 903 if (dce.color() != fColor) { |
| 903 GrGLfloat c[4]; | 904 float c[4]; |
| 904 GrColorToRGBAFloat(dce.color(), c); | 905 GrColorToRGBAFloat(dce.color(), c); |
| 905 pdman.set4fv(fColorUniform, 1, c); | 906 pdman.set4fv(fColorUniform, 1, c); |
| 906 fColor = dce.color(); | 907 fColor = dce.color(); |
| 907 } | 908 } |
| 908 } | 909 } |
| 909 | 910 |
| 910 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp, | 911 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp, |
| 911 const GrGLSLCaps&, | 912 const GrGLSLCaps&, |
| 912 GrProcessorKeyBuilder* b) { | 913 GrProcessorKeyBuilder* b) { |
| 913 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>(); | 914 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 class GLDashingLineEffect : public GrGLGeometryProcessor { | 1026 class GLDashingLineEffect : public GrGLGeometryProcessor { |
| 1026 public: | 1027 public: |
| 1027 GLDashingLineEffect(); | 1028 GLDashingLineEffect(); |
| 1028 | 1029 |
| 1029 void onEmitCode(EmitArgs&, GrGPArgs*) override; | 1030 void onEmitCode(EmitArgs&, GrGPArgs*) override; |
| 1030 | 1031 |
| 1031 static inline void GenKey(const GrGeometryProcessor&, | 1032 static inline void GenKey(const GrGeometryProcessor&, |
| 1032 const GrGLSLCaps&, | 1033 const GrGLSLCaps&, |
| 1033 GrProcessorKeyBuilder*); | 1034 GrProcessorKeyBuilder*); |
| 1034 | 1035 |
| 1035 void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) ove
rride; | 1036 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) o
verride; |
| 1036 | 1037 |
| 1037 void setTransformData(const GrPrimitiveProcessor& primProc, | 1038 void setTransformData(const GrPrimitiveProcessor& primProc, |
| 1038 const GrGLProgramDataManager& pdman, | 1039 const GrGLSLProgramDataManager& pdman, |
| 1039 int index, | 1040 int index, |
| 1040 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { | 1041 const SkTArray<const GrCoordTransform*, true>& transfo
rms) override { |
| 1041 this->setTransformDataHelper<DashingLineEffect>(primProc, pdman, index,
transforms); | 1042 this->setTransformDataHelper<DashingLineEffect>(primProc, pdman, index,
transforms); |
| 1042 } | 1043 } |
| 1043 | 1044 |
| 1044 private: | 1045 private: |
| 1045 GrColor fColor; | 1046 GrColor fColor; |
| 1046 UniformHandle fColorUniform; | 1047 UniformHandle fColorUniform; |
| 1047 typedef GrGLGeometryProcessor INHERITED; | 1048 typedef GrGLGeometryProcessor INHERITED; |
| 1048 }; | 1049 }; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 // Assuming the bounding geometry is tight so no need to check y values | 1114 // Assuming the bounding geometry is tight so no need to check y values |
| 1114 fsBuilder->codeAppendf("float alpha = 1.0;"); | 1115 fsBuilder->codeAppendf("float alpha = 1.0;"); |
| 1115 fsBuilder->codeAppendf("alpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0
: 0.0;", | 1116 fsBuilder->codeAppendf("alpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1.0
: 0.0;", |
| 1116 inRectParams.fsIn()); | 1117 inRectParams.fsIn()); |
| 1117 fsBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0
: 0.0;", | 1118 fsBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0
: 0.0;", |
| 1118 inRectParams.fsIn()); | 1119 inRectParams.fsIn()); |
| 1119 } | 1120 } |
| 1120 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 1121 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
| 1121 } | 1122 } |
| 1122 | 1123 |
| 1123 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, | 1124 void GLDashingLineEffect::setData(const GrGLSLProgramDataManager& pdman, |
| 1124 const GrPrimitiveProcessor& processor) { | 1125 const GrPrimitiveProcessor& processor) { |
| 1125 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); | 1126 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); |
| 1126 if (de.color() != fColor) { | 1127 if (de.color() != fColor) { |
| 1127 GrGLfloat c[4]; | 1128 float c[4]; |
| 1128 GrColorToRGBAFloat(de.color(), c); | 1129 GrColorToRGBAFloat(de.color(), c); |
| 1129 pdman.set4fv(fColorUniform, 1, c); | 1130 pdman.set4fv(fColorUniform, 1, c); |
| 1130 fColor = de.color(); | 1131 fColor = de.color(); |
| 1131 } | 1132 } |
| 1132 } | 1133 } |
| 1133 | 1134 |
| 1134 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp, | 1135 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp, |
| 1135 const GrGLSLCaps&, | 1136 const GrGLSLCaps&, |
| 1136 GrProcessorKeyBuilder* b) { | 1137 GrProcessorKeyBuilder* b) { |
| 1137 const DashingLineEffect& de = gp.cast<DashingLineEffect>(); | 1138 const DashingLineEffect& de = gp.cast<DashingLineEffect>(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 info.fIntervals = intervals; | 1279 info.fIntervals = intervals; |
| 1279 info.fCount = 2; | 1280 info.fCount = 2; |
| 1280 info.fPhase = phase; | 1281 info.fPhase = phase; |
| 1281 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1282 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
| 1282 SkASSERT(success); | 1283 SkASSERT(success); |
| 1283 | 1284 |
| 1284 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1285 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
| 1285 } | 1286 } |
| 1286 | 1287 |
| 1287 #endif | 1288 #endif |
| OLD | NEW |