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

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

Issue 1127953003: Remove viewmatrix from GrGeometryProcessor base class (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup3
Patch Set: Created 5 years, 7 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
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 "GrBatch.h" 10 #include "GrBatch.h"
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 859
860 // x refers to circle radius - 0.5, y refers to cicle's center x coord 860 // x refers to circle radius - 0.5, y refers to cicle's center x coord
861 GrGLVertToFrag circleParams(kVec2f_GrSLType); 861 GrGLVertToFrag circleParams(kVec2f_GrSLType);
862 args.fPB->addVarying("CircleParams", &circleParams); 862 args.fPB->addVarying("CircleParams", &circleParams);
863 vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams( )->fName); 863 vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams( )->fName);
864 864
865 // Setup pass through color 865 // Setup pass through color
866 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform); 866 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform);
867 867
868 // Setup position 868 // Setup position
869 this->setupPosition(pb, gpArgs, dce.inPosition()->fName, dce.viewMatrix()); 869 this->setupPosition(pb, gpArgs, dce.inPosition()->fName);
870 870
871 // emit transforms 871 // emit transforms
872 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName , dce.localMatrix(), 872 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName , dce.localMatrix(),
873 args.fTransformsIn, args.fTransformsOut); 873 args.fTransformsIn, args.fTransformsOut);
874 874
875 // transforms all points so that we can compare them to our test circle 875 // transforms all points so that we can compare them to our test circle
876 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 876 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
877 fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;", 877 fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;",
878 dashParams.fsIn(), dashParams.fsIn(), dashParams.fsIn (), 878 dashParams.fsIn(), dashParams.fsIn(), dashParams.fsIn (),
879 dashParams.fsIn()); 879 dashParams.fsIn());
880 fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dashPa rams.fsIn()); 880 fsBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dashPa rams.fsIn());
881 fsBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn() ); 881 fsBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn() );
882 fsBuilder->codeAppend("float dist = length(center - fragPosShifted);"); 882 fsBuilder->codeAppend("float dist = length(center - fragPosShifted);");
883 if (dce.aaMode() != kBW_DashAAMode) { 883 if (dce.aaMode() != kBW_DashAAMode) {
884 fsBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn()) ; 884 fsBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn()) ;
885 fsBuilder->codeAppend("diff = 1.0 - diff;"); 885 fsBuilder->codeAppend("diff = 1.0 - diff;");
886 fsBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); 886 fsBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);");
887 } else { 887 } else {
888 fsBuilder->codeAppendf("float alpha = 1.0;"); 888 fsBuilder->codeAppendf("float alpha = 1.0;");
889 fsBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", circl eParams.fsIn()); 889 fsBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", circl eParams.fsIn());
890 } 890 }
891 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 891 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
892 } 892 }
893 893
894 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, 894 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman,
895 const GrPrimitiveProcessor& processor, 895 const GrPrimitiveProcessor& processor,
896 const GrBatchTracker& bt) { 896 const GrBatchTracker& bt) {
897 this->setUniformViewMatrix(pdman, processor.viewMatrix());
898
899 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( ); 897 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( );
900 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { 898 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) {
901 GrGLfloat c[4]; 899 GrGLfloat c[4];
902 GrColorToRGBAFloat(local.fColor, c); 900 GrColorToRGBAFloat(local.fColor, c);
903 pdman.set4fv(fColorUniform, 1, c); 901 pdman.set4fv(fColorUniform, 1, c);
904 fColor = local.fColor; 902 fColor = local.fColor;
905 } 903 }
906 } 904 }
907 905
908 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp, 906 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp,
909 const GrBatchTracker& bt, 907 const GrBatchTracker& bt,
910 const GrGLSLCaps&, 908 const GrGLSLCaps&,
911 GrProcessorKeyBuilder* b) { 909 GrProcessorKeyBuilder* b) {
912 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( ); 910 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( );
913 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>(); 911 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>();
914 uint32_t key = 0; 912 uint32_t key = 0;
915 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0 x0; 913 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0 x0;
916 key |= ComputePosKey(gp.viewMatrix()) << 1;
917 key |= dce.aaMode() << 8; 914 key |= dce.aaMode() << 8;
918 b->add32(key << 16 | local.fInputColorType); 915 b->add32(key << 16 | local.fInputColorType);
919 } 916 }
920 917
921 ////////////////////////////////////////////////////////////////////////////// 918 //////////////////////////////////////////////////////////////////////////////
922 919
923 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, 920 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color,
924 DashAAMode aaMode, 921 DashAAMode aaMode,
925 const SkMatrix& localMatrix) { 922 const SkMatrix& localMatrix) {
926 return SkNEW_ARGS(DashingCircleEffect, (color, aaMode, localMatrix)); 923 return SkNEW_ARGS(DashingCircleEffect, (color, aaMode, localMatrix));
927 } 924 }
928 925
929 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, 926 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt,
930 const GrGLSLCaps& caps, 927 const GrGLSLCaps& caps,
931 GrProcessorKeyBuilder* b) const { 928 GrProcessorKeyBuilder* b) const {
932 GLDashingCircleEffect::GenKey(*this, bt, caps, b); 929 GLDashingCircleEffect::GenKey(*this, bt, caps, b);
933 } 930 }
934 931
935 GrGLPrimitiveProcessor* DashingCircleEffect::createGLInstance(const GrBatchTrack er& bt, 932 GrGLPrimitiveProcessor* DashingCircleEffect::createGLInstance(const GrBatchTrack er& bt,
936 const GrGLSLCaps&) const { 933 const GrGLSLCaps&) const {
937 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt)); 934 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt));
938 } 935 }
939 936
940 DashingCircleEffect::DashingCircleEffect(GrColor color, 937 DashingCircleEffect::DashingCircleEffect(GrColor color,
941 DashAAMode aaMode, 938 DashAAMode aaMode,
942 const SkMatrix& localMatrix) 939 const SkMatrix& localMatrix)
943 : INHERITED(SkMatrix::I(), localMatrix) 940 : INHERITED(localMatrix)
944 , fColor(color) 941 , fColor(color)
945 , fAAMode(aaMode) { 942 , fAAMode(aaMode) {
946 this->initClassID<DashingCircleEffect>(); 943 this->initClassID<DashingCircleEffect>();
947 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 944 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
948 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType)); 945 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType));
949 fInCircleParams = &this->addVertexAttrib(Attribute("inCircleParams", 946 fInCircleParams = &this->addVertexAttrib(Attribute("inCircleParams",
950 kVec2f_GrVertexAttribType )); 947 kVec2f_GrVertexAttribType ));
951 } 948 }
952 949
953 void DashingCircleEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineI nfo& init) const { 950 void DashingCircleEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineI nfo& init) const {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5), 1072 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5),
1076 // respectively. 1073 // respectively.
1077 GrGLVertToFrag inRectParams(kVec4f_GrSLType); 1074 GrGLVertToFrag inRectParams(kVec4f_GrSLType);
1078 args.fPB->addVarying("RectParams", &inRectParams); 1075 args.fPB->addVarying("RectParams", &inRectParams);
1079 vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()-> fName); 1076 vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()-> fName);
1080 1077
1081 // Setup pass through color 1078 // Setup pass through color
1082 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform); 1079 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform);
1083 1080
1084 // Setup position 1081 // Setup position
1085 this->setupPosition(pb, gpArgs, de.inPosition()->fName, de.viewMatrix()); 1082 this->setupPosition(pb, gpArgs, de.inPosition()->fName);
1086 1083
1087 // emit transforms 1084 // emit transforms
1088 this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName, de.localMatrix(), 1085 this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName, de.localMatrix(),
1089 args.fTransformsIn, args.fTransformsOut); 1086 args.fTransformsIn, args.fTransformsOut);
1090 1087
1091 // transforms all points so that we can compare them to our test rect 1088 // transforms all points so that we can compare them to our test rect
1092 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 1089 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
1093 fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;", 1090 fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;",
1094 inDashParams.fsIn(), inDashParams.fsIn(), inDashParam s.fsIn(), 1091 inDashParams.fsIn(), inDashParams.fsIn(), inDashParam s.fsIn(),
1095 inDashParams.fsIn()); 1092 inDashParams.fsIn());
(...skipping 24 matching lines...) Expand all
1120 inRectParams.fsIn()); 1117 inRectParams.fsIn());
1121 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;",
1122 inRectParams.fsIn()); 1119 inRectParams.fsIn());
1123 } 1120 }
1124 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 1121 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
1125 } 1122 }
1126 1123
1127 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, 1124 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman,
1128 const GrPrimitiveProcessor& processor, 1125 const GrPrimitiveProcessor& processor,
1129 const GrBatchTracker& bt) { 1126 const GrBatchTracker& bt) {
1130 this->setUniformViewMatrix(pdman, processor.viewMatrix());
1131
1132 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); 1127 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>();
1133 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { 1128 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) {
1134 GrGLfloat c[4]; 1129 GrGLfloat c[4];
1135 GrColorToRGBAFloat(local.fColor, c); 1130 GrColorToRGBAFloat(local.fColor, c);
1136 pdman.set4fv(fColorUniform, 1, c); 1131 pdman.set4fv(fColorUniform, 1, c);
1137 fColor = local.fColor; 1132 fColor = local.fColor;
1138 } 1133 }
1139 } 1134 }
1140 1135
1141 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp, 1136 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp,
1142 const GrBatchTracker& bt, 1137 const GrBatchTracker& bt,
1143 const GrGLSLCaps&, 1138 const GrGLSLCaps&,
1144 GrProcessorKeyBuilder* b) { 1139 GrProcessorKeyBuilder* b) {
1145 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); 1140 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>();
1146 const DashingLineEffect& de = gp.cast<DashingLineEffect>(); 1141 const DashingLineEffect& de = gp.cast<DashingLineEffect>();
1147 uint32_t key = 0; 1142 uint32_t key = 0;
1148 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0 x0; 1143 key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0 x0;
1149 key |= ComputePosKey(gp.viewMatrix()) << 1;
1150 key |= de.aaMode() << 8; 1144 key |= de.aaMode() << 8;
1151 b->add32(key << 16 | local.fInputColorType); 1145 b->add32(key << 16 | local.fInputColorType);
1152 } 1146 }
1153 1147
1154 ////////////////////////////////////////////////////////////////////////////// 1148 //////////////////////////////////////////////////////////////////////////////
1155 1149
1156 GrGeometryProcessor* DashingLineEffect::Create(GrColor color, 1150 GrGeometryProcessor* DashingLineEffect::Create(GrColor color,
1157 DashAAMode aaMode, 1151 DashAAMode aaMode,
1158 const SkMatrix& localMatrix) { 1152 const SkMatrix& localMatrix) {
1159 return SkNEW_ARGS(DashingLineEffect, (color, aaMode, localMatrix)); 1153 return SkNEW_ARGS(DashingLineEffect, (color, aaMode, localMatrix));
1160 } 1154 }
1161 1155
1162 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, 1156 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt,
1163 const GrGLSLCaps& caps, 1157 const GrGLSLCaps& caps,
1164 GrProcessorKeyBuilder* b) const { 1158 GrProcessorKeyBuilder* b) const {
1165 GLDashingLineEffect::GenKey(*this, bt, caps, b); 1159 GLDashingLineEffect::GenKey(*this, bt, caps, b);
1166 } 1160 }
1167 1161
1168 GrGLPrimitiveProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker & bt, 1162 GrGLPrimitiveProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker & bt,
1169 const GrGLSLCaps&) c onst { 1163 const GrGLSLCaps&) c onst {
1170 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt)); 1164 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt));
1171 } 1165 }
1172 1166
1173 DashingLineEffect::DashingLineEffect(GrColor color, 1167 DashingLineEffect::DashingLineEffect(GrColor color,
1174 DashAAMode aaMode, 1168 DashAAMode aaMode,
1175 const SkMatrix& localMatrix) 1169 const SkMatrix& localMatrix)
1176 : INHERITED(SkMatrix::I(), localMatrix) 1170 : INHERITED(localMatrix)
1177 , fColor(color) 1171 , fColor(color)
1178 , fAAMode(aaMode) { 1172 , fAAMode(aaMode) {
1179 this->initClassID<DashingLineEffect>(); 1173 this->initClassID<DashingLineEffect>();
1180 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 1174 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
1181 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType)); 1175 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType));
1182 fInRectParams = &this->addVertexAttrib(Attribute("inRect", kVec4f_GrVertexAt tribType)); 1176 fInRectParams = &this->addVertexAttrib(Attribute("inRect", kVec4f_GrVertexAt tribType));
1183 } 1177 }
1184 1178
1185 void DashingLineEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInf o& init) const { 1179 void DashingLineEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInf o& init) const {
1186 DashingLineBatchTracker* local = bt->cast<DashingLineBatchTracker>(); 1180 DashingLineBatchTracker* local = bt->cast<DashingLineBatchTracker>();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 info.fIntervals = intervals; 1283 info.fIntervals = intervals;
1290 info.fCount = 2; 1284 info.fCount = 2;
1291 info.fPhase = phase; 1285 info.fPhase = phase;
1292 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); 1286 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info);
1293 SkASSERT(success); 1287 SkASSERT(success);
1294 1288
1295 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); 1289 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT);
1296 } 1290 }
1297 1291
1298 #endif 1292 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698