Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: src/gpu/effects/GrDashingEffect.cpp

Issue 2339203002: Stop flattening GrCoordTransforms in parent GrFragmentProcessors. (Closed)
Patch Set: Fix issue of taking ref to a temporary Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/effects/GrDistanceFieldGeoProc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 class GLDashingCircleEffect : public GrGLSLGeometryProcessor { 810 class GLDashingCircleEffect : public GrGLSLGeometryProcessor {
811 public: 811 public:
812 GLDashingCircleEffect(); 812 GLDashingCircleEffect();
813 813
814 void onEmitCode(EmitArgs&, GrGPArgs*) override; 814 void onEmitCode(EmitArgs&, GrGPArgs*) override;
815 815
816 static inline void GenKey(const GrGeometryProcessor&, 816 static inline void GenKey(const GrGeometryProcessor&,
817 const GrGLSLCaps&, 817 const GrGLSLCaps&,
818 GrProcessorKeyBuilder*); 818 GrProcessorKeyBuilder*);
819 819
820 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) o verride; 820 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&,
821 821 FPCoordTransformIter&& transformIter) override;
822 void setTransformData(const GrPrimitiveProcessor& primProc,
823 const GrGLSLProgramDataManager& pdman,
824 int index,
825 const SkTArray<const GrCoordTransform*, true>& transfo rms) override {
826 this->setTransformDataHelper(primProc.cast<DashingCircleEffect>().localM atrix(), pdman,
827 index, transforms);
828 }
829
830 private: 822 private:
831 UniformHandle fParamUniform; 823 UniformHandle fParamUniform;
832 UniformHandle fColorUniform; 824 UniformHandle fColorUniform;
833 GrColor fColor; 825 GrColor fColor;
834 SkScalar fPrevRadius; 826 SkScalar fPrevRadius;
835 SkScalar fPrevCenterX; 827 SkScalar fPrevCenterX;
836 SkScalar fPrevIntervalLength; 828 SkScalar fPrevIntervalLength;
837 typedef GrGLSLGeometryProcessor INHERITED; 829 typedef GrGLSLGeometryProcessor INHERITED;
838 }; 830 };
839 831
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 // Setup position 864 // Setup position
873 this->setupPosition(vertBuilder, gpArgs, dce.inPosition()->fName); 865 this->setupPosition(vertBuilder, gpArgs, dce.inPosition()->fName);
874 866
875 // emit transforms 867 // emit transforms
876 this->emitTransforms(vertBuilder, 868 this->emitTransforms(vertBuilder,
877 varyingHandler, 869 varyingHandler,
878 uniformHandler, 870 uniformHandler,
879 gpArgs->fPositionVar, 871 gpArgs->fPositionVar,
880 dce.inPosition()->fName, 872 dce.inPosition()->fName,
881 dce.localMatrix(), 873 dce.localMatrix(),
882 args.fTransformsIn, 874 args.fFPCoordTransformHandler);
883 args.fTransformsOut);
884 875
885 // transforms all points so that we can compare them to our test circle 876 // transforms all points so that we can compare them to our test circle
886 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z; ", 877 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z; ",
887 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs In(), 878 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs In(),
888 dashParams.fsIn()); 879 dashParams.fsIn());
889 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dash Params.fsIn()); 880 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dash Params.fsIn());
890 fragBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn ()); 881 fragBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn ());
891 fragBuilder->codeAppend("float dist = length(center - fragPosShifted);"); 882 fragBuilder->codeAppend("float dist = length(center - fragPosShifted);");
892 if (dce.aaMode() != AAMode::kNone) { 883 if (dce.aaMode() != AAMode::kNone) {
893 fragBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn( )); 884 fragBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn( ));
894 fragBuilder->codeAppend("diff = 1.0 - diff;"); 885 fragBuilder->codeAppend("diff = 1.0 - diff;");
895 fragBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); 886 fragBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);");
896 } else { 887 } else {
897 fragBuilder->codeAppendf("float alpha = 1.0;"); 888 fragBuilder->codeAppendf("float alpha = 1.0;");
898 fragBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", cir cleParams.fsIn()); 889 fragBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", cir cleParams.fsIn());
899 } 890 }
900 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 891 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
901 } 892 }
902 893
903 void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman, 894 void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman,
904 const GrPrimitiveProcessor& processor) { 895 const GrPrimitiveProcessor& processor,
896 FPCoordTransformIter&& transformIter) {
905 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); 897 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
906 if (dce.color() != fColor) { 898 if (dce.color() != fColor) {
907 float c[4]; 899 float c[4];
908 GrColorToRGBAFloat(dce.color(), c); 900 GrColorToRGBAFloat(dce.color(), c);
909 pdman.set4fv(fColorUniform, 1, c); 901 pdman.set4fv(fColorUniform, 1, c);
910 fColor = dce.color(); 902 fColor = dce.color();
911 } 903 }
904 this->setTransformDataHelper(dce.localMatrix(), pdman, &transformIter);
912 } 905 }
913 906
914 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp, 907 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp,
915 const GrGLSLCaps&, 908 const GrGLSLCaps&,
916 GrProcessorKeyBuilder* b) { 909 GrProcessorKeyBuilder* b) {
917 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>(); 910 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>();
918 uint32_t key = 0; 911 uint32_t key = 0;
919 key |= dce.usesLocalCoords() && dce.localMatrix().hasPerspective() ? 0x1 : 0 x0; 912 key |= dce.usesLocalCoords() && dce.localMatrix().hasPerspective() ? 0x1 : 0 x0;
920 key |= dce.colorIgnored() ? 0x2 : 0x0; 913 key |= dce.colorIgnored() ? 0x2 : 0x0;
921 key |= static_cast<uint32_t>(dce.aaMode()) << 8; 914 key |= static_cast<uint32_t>(dce.aaMode()) << 8;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 class GLDashingLineEffect : public GrGLSLGeometryProcessor { 1023 class GLDashingLineEffect : public GrGLSLGeometryProcessor {
1031 public: 1024 public:
1032 GLDashingLineEffect(); 1025 GLDashingLineEffect();
1033 1026
1034 void onEmitCode(EmitArgs&, GrGPArgs*) override; 1027 void onEmitCode(EmitArgs&, GrGPArgs*) override;
1035 1028
1036 static inline void GenKey(const GrGeometryProcessor&, 1029 static inline void GenKey(const GrGeometryProcessor&,
1037 const GrGLSLCaps&, 1030 const GrGLSLCaps&,
1038 GrProcessorKeyBuilder*); 1031 GrProcessorKeyBuilder*);
1039 1032
1040 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) o verride; 1033 void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&,
1041 1034 FPCoordTransformIter&& iter) override;
1042 void setTransformData(const GrPrimitiveProcessor& primProc,
1043 const GrGLSLProgramDataManager& pdman,
1044 int index,
1045 const SkTArray<const GrCoordTransform*, true>& transfo rms) override {
1046 this->setTransformDataHelper(primProc.cast<DashingLineEffect>().localMat rix(), pdman, index,
1047 transforms);
1048 }
1049 1035
1050 private: 1036 private:
1051 GrColor fColor; 1037 GrColor fColor;
1052 UniformHandle fColorUniform; 1038 UniformHandle fColorUniform;
1053 typedef GrGLSLGeometryProcessor INHERITED; 1039 typedef GrGLSLGeometryProcessor INHERITED;
1054 }; 1040 };
1055 1041
1056 GLDashingLineEffect::GLDashingLineEffect() { 1042 GLDashingLineEffect::GLDashingLineEffect() {
1057 fColor = GrColor_ILLEGAL; 1043 fColor = GrColor_ILLEGAL;
1058 } 1044 }
(...skipping 28 matching lines...) Expand all
1087 // Setup position 1073 // Setup position
1088 this->setupPosition(vertBuilder, gpArgs, de.inPosition()->fName); 1074 this->setupPosition(vertBuilder, gpArgs, de.inPosition()->fName);
1089 1075
1090 // emit transforms 1076 // emit transforms
1091 this->emitTransforms(vertBuilder, 1077 this->emitTransforms(vertBuilder,
1092 varyingHandler, 1078 varyingHandler,
1093 uniformHandler, 1079 uniformHandler,
1094 gpArgs->fPositionVar, 1080 gpArgs->fPositionVar,
1095 de.inPosition()->fName, 1081 de.inPosition()->fName,
1096 de.localMatrix(), 1082 de.localMatrix(),
1097 args.fTransformsIn, 1083 args.fFPCoordTransformHandler);
1098 args.fTransformsOut);
1099 1084
1100 // transforms all points so that we can compare them to our test rect 1085 // 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; ", 1086 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z; ",
1102 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar ams.fsIn(), 1087 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar ams.fsIn(),
1103 inDashParams.fsIn()); 1088 inDashParams.fsIn());
1104 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDa shParams.fsIn()); 1089 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDa shParams.fsIn());
1105 if (de.aaMode() == AAMode::kCoverage) { 1090 if (de.aaMode() == AAMode::kCoverage) {
1106 // The amount of coverage removed in x and y by the edges is computed as a pair of negative 1091 // The amount of coverage removed in x and y by the edges is computed as a pair of negative
1107 // numbers, xSub and ySub. 1092 // numbers, xSub and ySub.
1108 fragBuilder->codeAppend("float xSub, ySub;"); 1093 fragBuilder->codeAppend("float xSub, ySub;");
(...skipping 18 matching lines...) Expand all
1127 fragBuilder->codeAppendf("float alpha = 1.0;"); 1112 fragBuilder->codeAppendf("float alpha = 1.0;");
1128 fragBuilder->codeAppendf("alpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1. 0 : 0.0;", 1113 fragBuilder->codeAppendf("alpha *= (fragPosShifted.x - %s.x) > -0.5 ? 1. 0 : 0.0;",
1129 inRectParams.fsIn()); 1114 inRectParams.fsIn());
1130 fragBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1 .0 : 0.0;", 1115 fragBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1 .0 : 0.0;",
1131 inRectParams.fsIn()); 1116 inRectParams.fsIn());
1132 } 1117 }
1133 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 1118 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
1134 } 1119 }
1135 1120
1136 void GLDashingLineEffect::setData(const GrGLSLProgramDataManager& pdman, 1121 void GLDashingLineEffect::setData(const GrGLSLProgramDataManager& pdman,
1137 const GrPrimitiveProcessor& processor) { 1122 const GrPrimitiveProcessor& processor,
1123 FPCoordTransformIter&& transformIter) {
1138 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); 1124 const DashingLineEffect& de = processor.cast<DashingLineEffect>();
1139 if (de.color() != fColor) { 1125 if (de.color() != fColor) {
1140 float c[4]; 1126 float c[4];
1141 GrColorToRGBAFloat(de.color(), c); 1127 GrColorToRGBAFloat(de.color(), c);
1142 pdman.set4fv(fColorUniform, 1, c); 1128 pdman.set4fv(fColorUniform, 1, c);
1143 fColor = de.color(); 1129 fColor = de.color();
1144 } 1130 }
1131 this->setTransformDataHelper(de.localMatrix(), pdman, &transformIter);
1145 } 1132 }
1146 1133
1147 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp, 1134 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp,
1148 const GrGLSLCaps&, 1135 const GrGLSLCaps&,
1149 GrProcessorKeyBuilder* b) { 1136 GrProcessorKeyBuilder* b) {
1150 const DashingLineEffect& de = gp.cast<DashingLineEffect>(); 1137 const DashingLineEffect& de = gp.cast<DashingLineEffect>();
1151 uint32_t key = 0; 1138 uint32_t key = 0;
1152 key |= de.usesLocalCoords() && de.localMatrix().hasPerspective() ? 0x1 : 0x0 ; 1139 key |= de.usesLocalCoords() && de.localMatrix().hasPerspective() ? 0x1 : 0x0 ;
1153 key |= de.colorIgnored() ? 0x2 : 0x0; 1140 key |= de.colorIgnored() ? 0x2 : 0x0;
1154 key |= static_cast<int>(de.aaMode()) << 8; 1141 key |= static_cast<int>(de.aaMode()) << 8;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 p.setStrokeWidth(SkIntToScalar(1)); 1272 p.setStrokeWidth(SkIntToScalar(1));
1286 p.setStrokeCap(cap); 1273 p.setStrokeCap(cap);
1287 p.setPathEffect(GrTest::TestDashPathEffect::Make(intervals, 2, phase)); 1274 p.setPathEffect(GrTest::TestDashPathEffect::Make(intervals, 2, phase));
1288 1275
1289 GrStyle style(p); 1276 GrStyle style(p);
1290 1277
1291 return GrDashingEffect::CreateDashLineBatch(color, viewMatrix, pts, aaMode, style); 1278 return GrDashingEffect::CreateDashLineBatch(color, viewMatrix, pts, aaMode, style);
1292 } 1279 }
1293 1280
1294 #endif 1281 #endif
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/effects/GrDistanceFieldGeoProc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698