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

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

Issue 1139723004: Preliminary attempt to remove batch tracker (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup5
Patch Set: tweaks 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
« no previous file with comments | « src/gpu/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/effects/GrDistanceFieldGeoProc.h » ('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 "GrBatch.h" 10 #include "GrBatch.h"
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 /** 235 /**
236 * An GrGeometryProcessor that renders a dashed line. 236 * An GrGeometryProcessor that renders a dashed line.
237 * This GrGeometryProcessor is meant for dashed lines that only have a single on /off interval pair. 237 * This GrGeometryProcessor is meant for dashed lines that only have a single on /off interval pair.
238 * Bounding geometry is rendered and the effect computes coverage based on the f ragment's 238 * Bounding geometry is rendered and the effect computes coverage based on the f ragment's
239 * position relative to the dashed line. 239 * position relative to the dashed line.
240 */ 240 */
241 static GrGeometryProcessor* create_dash_gp(GrColor, 241 static GrGeometryProcessor* create_dash_gp(GrColor,
242 DashAAMode aaMode, 242 DashAAMode aaMode,
243 DashCap cap, 243 DashCap cap,
244 const SkMatrix& localMatrix); 244 const SkMatrix& localMatrix,
245 bool usesLocalCoords);
245 246
246 class DashBatch : public GrBatch { 247 class DashBatch : public GrBatch {
247 public: 248 public:
248 struct Geometry { 249 struct Geometry {
249 GrColor fColor; 250 GrColor fColor;
250 SkMatrix fViewMatrix; 251 SkMatrix fViewMatrix;
251 SkMatrix fSrcRotInv; 252 SkMatrix fSrcRotInv;
252 SkPoint fPtsRot[2]; 253 SkPoint fPtsRot[2];
253 SkScalar fSrcStrokeWidth; 254 SkScalar fSrcStrokeWidth;
254 SkScalar fPhase; 255 SkScalar fPhase;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return; 309 return;
309 } 310 }
310 311
311 SkPaint::Cap cap = this->cap(); 312 SkPaint::Cap cap = this->cap();
312 313
313 SkAutoTUnref<const GrGeometryProcessor> gp; 314 SkAutoTUnref<const GrGeometryProcessor> gp;
314 315
315 bool isRoundCap = SkPaint::kRound_Cap == cap; 316 bool isRoundCap = SkPaint::kRound_Cap == cap;
316 DashCap capType = isRoundCap ? kRound_DashCap : kNonRound_DashCap; 317 DashCap capType = isRoundCap ? kRound_DashCap : kNonRound_DashCap;
317 if (this->fullDash()) { 318 if (this->fullDash()) {
318 gp.reset(create_dash_gp(this->color(), this->aaMode(), capType, inve rt)); 319 gp.reset(create_dash_gp(this->color(), this->aaMode(), capType, inve rt,
320 this->usesLocalCoords()));
319 } else { 321 } else {
320 // Set up the vertex data for the line and start/end dashes 322 // Set up the vertex data for the line and start/end dashes
321 gp.reset(GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kP osition_GPType, 323 gp.reset(GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kP osition_GPType,
322 this->color(), 324 this->color(),
325 this->usesLocalCoords(),
326 this->coverageIgnored(),
323 SkMatrix::I(), 327 SkMatrix::I(),
324 invert)); 328 invert));
325 } 329 }
326 330
327 batchTarget->initDraw(gp, pipeline); 331 batchTarget->initDraw(gp, pipeline);
328 332
329 // TODO remove this when batch is everywhere
330 GrPipelineInfo init;
331 init.fColorIgnored = fBatch.fColorIgnored;
332 init.fOverrideColor = GrColor_ILLEGAL;
333 init.fCoverageIgnored = fBatch.fCoverageIgnored;
334 init.fUsesLocalCoords = this->usesLocalCoords();
335 gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
336
337 // useAA here means Edge AA or MSAA 333 // useAA here means Edge AA or MSAA
338 bool useAA = this->aaMode() != kBW_DashAAMode; 334 bool useAA = this->aaMode() != kBW_DashAAMode;
339 bool fullDash = this->fullDash(); 335 bool fullDash = this->fullDash();
340 336
341 // We do two passes over all of the dashes. First we setup the start, e nd, and bounds, 337 // We do two passes over all of the dashes. First we setup the start, e nd, and bounds,
342 // rectangles. We preserve all of this work in the rects / draws arrays below. Then we 338 // rectangles. We preserve all of this work in the rects / draws arrays below. Then we
343 // iterate again over these decomposed dashes to generate vertices 339 // iterate again over these decomposed dashes to generate vertices
344 SkSTArray<128, SkRect, true> rects; 340 SkSTArray<128, SkRect, true> rects;
345 SkSTArray<128, DashDraw, true> draws; 341 SkSTArray<128, DashDraw, true> draws;
346 342
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 this->joinBounds(that->bounds()); 650 this->joinBounds(that->bounds());
655 return true; 651 return true;
656 } 652 }
657 653
658 GrColor color() const { return fBatch.fColor; } 654 GrColor color() const { return fBatch.fColor; }
659 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 655 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
660 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } 656 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
661 DashAAMode aaMode() const { return fBatch.fAAMode; } 657 DashAAMode aaMode() const { return fBatch.fAAMode; }
662 bool fullDash() const { return fBatch.fFullDash; } 658 bool fullDash() const { return fBatch.fFullDash; }
663 SkPaint::Cap cap() const { return fBatch.fCap; } 659 SkPaint::Cap cap() const { return fBatch.fCap; }
660 bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
664 661
665 struct BatchTracker { 662 struct BatchTracker {
666 GrColor fColor; 663 GrColor fColor;
667 bool fUsesLocalCoords; 664 bool fUsesLocalCoords;
668 bool fColorIgnored; 665 bool fColorIgnored;
669 bool fCoverageIgnored; 666 bool fCoverageIgnored;
670 SkPaint::Cap fCap; 667 SkPaint::Cap fCap;
671 DashAAMode fAAMode; 668 DashAAMode fAAMode;
672 bool fFullDash; 669 bool fFullDash;
673 }; 670 };
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } 740 }
744 741
745 target->drawBatch(pipelineBuilder, batch); 742 target->drawBatch(pipelineBuilder, batch);
746 return true; 743 return true;
747 } 744 }
748 745
749 ////////////////////////////////////////////////////////////////////////////// 746 //////////////////////////////////////////////////////////////////////////////
750 747
751 class GLDashingCircleEffect; 748 class GLDashingCircleEffect;
752 749
753 struct DashingCircleBatchTracker {
754 GrGPInput fInputColorType;
755 GrColor fColor;
756 bool fUsesLocalCoords;
757 };
758
759 /* 750 /*
760 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on 751 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on
761 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo. 752 * interval). The radius of the dots is given by the strokeWidth and the spacing by the DashInfo.
762 * Both of the previous two parameters are in device space. This effect also req uires the setting of 753 * Both of the previous two parameters are in device space. This effect also req uires the setting of
763 * a vec2 vertex attribute for the the four corners of the bounding rect. This a ttribute is the 754 * a vec2 vertex attribute for the the four corners of the bounding rect. This a ttribute is the
764 * "dash position" of each vertex. In other words it is the vertex coords (in de vice space) if we 755 * "dash position" of each vertex. In other words it is the vertex coords (in de vice space) if we
765 * transform the line to be horizontal, with the start of line at the origin the n shifted to the 756 * transform the line to be horizontal, with the start of line at the origin the n shifted to the
766 * right by half the off interval. The line then goes in the positive x directio n. 757 * right by half the off interval. The line then goes in the positive x directio n.
767 */ 758 */
768 class DashingCircleEffect : public GrGeometryProcessor { 759 class DashingCircleEffect : public GrGeometryProcessor {
769 public: 760 public:
770 typedef SkPathEffect::DashInfo DashInfo; 761 typedef SkPathEffect::DashInfo DashInfo;
771 762
772 static GrGeometryProcessor* Create(GrColor, 763 static GrGeometryProcessor* Create(GrColor,
773 DashAAMode aaMode, 764 DashAAMode aaMode,
774 const SkMatrix& localMatrix); 765 const SkMatrix& localMatrix,
766 bool usesLocalCoords);
775 767
776 const char* name() const override { return "DashingCircleEffect"; } 768 const char* name() const override { return "DashingCircleEffect"; }
777 769
778 const Attribute* inPosition() const { return fInPosition; } 770 const Attribute* inPosition() const { return fInPosition; }
779 771
780 const Attribute* inDashParams() const { return fInDashParams; } 772 const Attribute* inDashParams() const { return fInDashParams; }
781 773
782 const Attribute* inCircleParams() const { return fInCircleParams; } 774 const Attribute* inCircleParams() const { return fInCircleParams; }
783 775
784 DashAAMode aaMode() const { return fAAMode; } 776 DashAAMode aaMode() const { return fAAMode; }
785 777
786 GrColor color() const { return fColor; } 778 GrColor color() const { return fColor; }
787 779
780 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
781
788 const SkMatrix& localMatrix() const { return fLocalMatrix; } 782 const SkMatrix& localMatrix() const { return fLocalMatrix; }
789 783
784 bool usesLocalCoords() const { return fUsesLocalCoords; }
785
790 virtual void getGLProcessorKey(const GrBatchTracker&, 786 virtual void getGLProcessorKey(const GrBatchTracker&,
791 const GrGLSLCaps&, 787 const GrGLSLCaps&,
792 GrProcessorKeyBuilder* b) const override; 788 GrProcessorKeyBuilder* b) const override;
793 789
794 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker&, 790 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker&,
795 const GrGLSLCaps&) const ov erride; 791 const GrGLSLCaps&) const ov erride;
796 792
797 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override;
798
799 private: 793 private:
800 DashingCircleEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix) ; 794 DashingCircleEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix,
795 bool usesLocalCoords);
801 796
802 GrColor fColor; 797 GrColor fColor;
803 SkMatrix fLocalMatrix; 798 SkMatrix fLocalMatrix;
799 bool fUsesLocalCoords;
804 DashAAMode fAAMode; 800 DashAAMode fAAMode;
805 const Attribute* fInPosition; 801 const Attribute* fInPosition;
806 const Attribute* fInDashParams; 802 const Attribute* fInDashParams;
807 const Attribute* fInCircleParams; 803 const Attribute* fInCircleParams;
808 804
809 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; 805 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
810 806
811 typedef GrGeometryProcessor INHERITED; 807 typedef GrGeometryProcessor INHERITED;
812 }; 808 };
813 809
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&, 844 GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&,
849 const GrBatchTracker&) { 845 const GrBatchTracker&) {
850 fColor = GrColor_ILLEGAL; 846 fColor = GrColor_ILLEGAL;
851 fPrevRadius = SK_ScalarMin; 847 fPrevRadius = SK_ScalarMin;
852 fPrevCenterX = SK_ScalarMin; 848 fPrevCenterX = SK_ScalarMin;
853 fPrevIntervalLength = SK_ScalarMax; 849 fPrevIntervalLength = SK_ScalarMax;
854 } 850 }
855 851
856 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { 852 void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
857 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>(); 853 const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>();
858 const DashingCircleBatchTracker local = args.fBT.cast<DashingCircleBatchTrac ker>();
859 GrGLGPBuilder* pb = args.fPB; 854 GrGLGPBuilder* pb = args.fPB;
860 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 855 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
861 856
862 // emit attributes 857 // emit attributes
863 vsBuilder->emitAttributes(dce); 858 vsBuilder->emitAttributes(dce);
864 859
865 // XY are dashPos, Z is dashInterval 860 // XY are dashPos, Z is dashInterval
866 GrGLVertToFrag dashParams(kVec3f_GrSLType); 861 GrGLVertToFrag dashParams(kVec3f_GrSLType);
867 args.fPB->addVarying("DashParam", &dashParams); 862 args.fPB->addVarying("DashParam", &dashParams);
868 vsBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->f Name); 863 vsBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->f Name);
869 864
870 // x refers to circle radius - 0.5, y refers to cicle's center x coord 865 // x refers to circle radius - 0.5, y refers to cicle's center x coord
871 GrGLVertToFrag circleParams(kVec2f_GrSLType); 866 GrGLVertToFrag circleParams(kVec2f_GrSLType);
872 args.fPB->addVarying("CircleParams", &circleParams); 867 args.fPB->addVarying("CircleParams", &circleParams);
873 vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams( )->fName); 868 vsBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams( )->fName);
874 869
875 // Setup pass through color 870 // Setup pass through color
876 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform); 871 if (!dce.colorIgnored()) {
872 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform);
873 }
877 874
878 // Setup position 875 // Setup position
879 this->setupPosition(pb, gpArgs, dce.inPosition()->fName); 876 this->setupPosition(pb, gpArgs, dce.inPosition()->fName);
880 877
881 // emit transforms 878 // emit transforms
882 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName , dce.localMatrix(), 879 this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName , dce.localMatrix(),
883 args.fTransformsIn, args.fTransformsOut); 880 args.fTransformsIn, args.fTransformsOut);
884 881
885 // transforms all points so that we can compare them to our test circle 882 // transforms all points so that we can compare them to our test circle
886 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 883 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
(...skipping 10 matching lines...) Expand all
897 } else { 894 } else {
898 fsBuilder->codeAppendf("float alpha = 1.0;"); 895 fsBuilder->codeAppendf("float alpha = 1.0;");
899 fsBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", circl eParams.fsIn()); 896 fsBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", circl eParams.fsIn());
900 } 897 }
901 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 898 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
902 } 899 }
903 900
904 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, 901 void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman,
905 const GrPrimitiveProcessor& processor, 902 const GrPrimitiveProcessor& processor,
906 const GrBatchTracker& bt) { 903 const GrBatchTracker& bt) {
907 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( ); 904 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
908 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { 905 if (dce.color() != fColor) {
909 GrGLfloat c[4]; 906 GrGLfloat c[4];
910 GrColorToRGBAFloat(local.fColor, c); 907 GrColorToRGBAFloat(dce.color(), c);
911 pdman.set4fv(fColorUniform, 1, c); 908 pdman.set4fv(fColorUniform, 1, c);
912 fColor = local.fColor; 909 fColor = dce.color();
913 } 910 }
914 } 911 }
915 912
916 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp, 913 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp,
917 const GrBatchTracker& bt, 914 const GrBatchTracker& bt,
918 const GrGLSLCaps&, 915 const GrGLSLCaps&,
919 GrProcessorKeyBuilder* b) { 916 GrProcessorKeyBuilder* b) {
920 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( );
921 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>(); 917 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>();
922 uint32_t key = 0; 918 uint32_t key = 0;
923 key |= local.fUsesLocalCoords && dce.localMatrix().hasPerspective() ? 0x1 : 0x0; 919 key |= dce.usesLocalCoords() && dce.localMatrix().hasPerspective() ? 0x1 : 0 x0;
920 key |= dce.colorIgnored() ? 0x2 : 0x0;
924 key |= dce.aaMode() << 8; 921 key |= dce.aaMode() << 8;
925 b->add32(key << 16 | local.fInputColorType); 922 b->add32(key);
926 } 923 }
927 924
928 ////////////////////////////////////////////////////////////////////////////// 925 //////////////////////////////////////////////////////////////////////////////
929 926
930 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, 927 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color,
931 DashAAMode aaMode, 928 DashAAMode aaMode,
932 const SkMatrix& localMatrix) { 929 const SkMatrix& localMatrix,
933 return SkNEW_ARGS(DashingCircleEffect, (color, aaMode, localMatrix)); 930 bool usesLocalCoords) {
931 return SkNEW_ARGS(DashingCircleEffect, (color, aaMode, localMatrix, usesLoca lCoords));
934 } 932 }
935 933
936 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, 934 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt,
937 const GrGLSLCaps& caps, 935 const GrGLSLCaps& caps,
938 GrProcessorKeyBuilder* b) const { 936 GrProcessorKeyBuilder* b) const {
939 GLDashingCircleEffect::GenKey(*this, bt, caps, b); 937 GLDashingCircleEffect::GenKey(*this, bt, caps, b);
940 } 938 }
941 939
942 GrGLPrimitiveProcessor* DashingCircleEffect::createGLInstance(const GrBatchTrack er& bt, 940 GrGLPrimitiveProcessor* DashingCircleEffect::createGLInstance(const GrBatchTrack er& bt,
943 const GrGLSLCaps&) const { 941 const GrGLSLCaps&) const {
944 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt)); 942 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt));
945 } 943 }
946 944
947 DashingCircleEffect::DashingCircleEffect(GrColor color, 945 DashingCircleEffect::DashingCircleEffect(GrColor color,
948 DashAAMode aaMode, 946 DashAAMode aaMode,
949 const SkMatrix& localMatrix) 947 const SkMatrix& localMatrix,
948 bool usesLocalCoords)
950 : fColor(color) 949 : fColor(color)
951 , fLocalMatrix(localMatrix) 950 , fLocalMatrix(localMatrix)
951 , fUsesLocalCoords(usesLocalCoords)
952 , fAAMode(aaMode) { 952 , fAAMode(aaMode) {
953 this->initClassID<DashingCircleEffect>(); 953 this->initClassID<DashingCircleEffect>();
954 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 954 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
955 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType)); 955 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType));
956 fInCircleParams = &this->addVertexAttrib(Attribute("inCircleParams", 956 fInCircleParams = &this->addVertexAttrib(Attribute("inCircleParams",
957 kVec2f_GrVertexAttribType )); 957 kVec2f_GrVertexAttribType ));
958 } 958 }
959 959
960 void DashingCircleEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineI nfo& init) const {
961 DashingCircleBatchTracker* local = bt->cast<DashingCircleBatchTracker>();
962 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, false);
963 local->fUsesLocalCoords = init.fUsesLocalCoords;
964 }
965
966 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); 960 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect);
967 961
968 GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random, 962 GrGeometryProcessor* DashingCircleEffect::TestCreate(SkRandom* random,
969 GrContext*, 963 GrContext*,
970 const GrDrawTargetCaps& cap s, 964 const GrDrawTargetCaps& cap s,
971 GrTexture*[]) { 965 GrTexture*[]) {
972 DashAAMode aaMode = static_cast<DashAAMode>(random->nextULessThan(kDashAAMod eCount)); 966 DashAAMode aaMode = static_cast<DashAAMode>(random->nextULessThan(kDashAAMod eCount));
973 return DashingCircleEffect::Create(GrRandomColor(random), 967 return DashingCircleEffect::Create(GrRandomColor(random),
974 aaMode, GrTest::TestMatrix(random)); 968 aaMode, GrTest::TestMatrix(random),
969 random->nextBool());
975 } 970 }
976 971
977 ////////////////////////////////////////////////////////////////////////////// 972 //////////////////////////////////////////////////////////////////////////////
978 973
979 class GLDashingLineEffect; 974 class GLDashingLineEffect;
980 975
981 struct DashingLineBatchTracker {
982 GrGPInput fInputColorType;
983 GrColor fColor;
984 bool fUsesLocalCoords;
985 };
986
987 /* 976 /*
988 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the 977 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the
989 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space. 978 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space.
990 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the 979 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the
991 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the 980 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the
992 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of 981 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of
993 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the 982 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the
994 * positive x direction. 983 * positive x direction.
995 */ 984 */
996 class DashingLineEffect : public GrGeometryProcessor { 985 class DashingLineEffect : public GrGeometryProcessor {
997 public: 986 public:
998 typedef SkPathEffect::DashInfo DashInfo; 987 typedef SkPathEffect::DashInfo DashInfo;
999 988
1000 static GrGeometryProcessor* Create(GrColor, 989 static GrGeometryProcessor* Create(GrColor,
1001 DashAAMode aaMode, 990 DashAAMode aaMode,
1002 const SkMatrix& localMatrix); 991 const SkMatrix& localMatrix,
992 bool usesLocalCoords);
1003 993
1004 const char* name() const override { return "DashingEffect"; } 994 const char* name() const override { return "DashingEffect"; }
1005 995
1006 const Attribute* inPosition() const { return fInPosition; } 996 const Attribute* inPosition() const { return fInPosition; }
1007 997
1008 const Attribute* inDashParams() const { return fInDashParams; } 998 const Attribute* inDashParams() const { return fInDashParams; }
1009 999
1010 const Attribute* inRectParams() const { return fInRectParams; } 1000 const Attribute* inRectParams() const { return fInRectParams; }
1011 1001
1012 DashAAMode aaMode() const { return fAAMode; } 1002 DashAAMode aaMode() const { return fAAMode; }
1013 1003
1014 GrColor color() const { return fColor; } 1004 GrColor color() const { return fColor; }
1015 1005
1006 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
1007
1016 const SkMatrix& localMatrix() const { return fLocalMatrix; } 1008 const SkMatrix& localMatrix() const { return fLocalMatrix; }
1017 1009
1010 bool usesLocalCoords() const { return fUsesLocalCoords; }
1011
1018 virtual void getGLProcessorKey(const GrBatchTracker& bt, 1012 virtual void getGLProcessorKey(const GrBatchTracker& bt,
1019 const GrGLSLCaps& caps, 1013 const GrGLSLCaps& caps,
1020 GrProcessorKeyBuilder* b) const override; 1014 GrProcessorKeyBuilder* b) const override;
1021 1015
1022 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt, 1016 virtual GrGLPrimitiveProcessor* createGLInstance(const GrBatchTracker& bt,
1023 const GrGLSLCaps&) const ov erride; 1017 const GrGLSLCaps&) const ov erride;
1024 1018
1025 void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override;
1026
1027 private: 1019 private:
1028 DashingLineEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix); 1020 DashingLineEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix,
1021 bool usesLocalCoords);
1029 1022
1030 GrColor fColor; 1023 GrColor fColor;
1031 SkMatrix fLocalMatrix; 1024 SkMatrix fLocalMatrix;
1025 bool fUsesLocalCoords;
1032 DashAAMode fAAMode; 1026 DashAAMode fAAMode;
1033 const Attribute* fInPosition; 1027 const Attribute* fInPosition;
1034 const Attribute* fInDashParams; 1028 const Attribute* fInDashParams;
1035 const Attribute* fInRectParams; 1029 const Attribute* fInRectParams;
1036 1030
1037 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; 1031 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
1038 1032
1039 typedef GrGeometryProcessor INHERITED; 1033 typedef GrGeometryProcessor INHERITED;
1040 }; 1034 };
1041 1035
(...skipping 27 matching lines...) Expand all
1069 typedef GrGLGeometryProcessor INHERITED; 1063 typedef GrGLGeometryProcessor INHERITED;
1070 }; 1064 };
1071 1065
1072 GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&, 1066 GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&,
1073 const GrBatchTracker&) { 1067 const GrBatchTracker&) {
1074 fColor = GrColor_ILLEGAL; 1068 fColor = GrColor_ILLEGAL;
1075 } 1069 }
1076 1070
1077 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { 1071 void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
1078 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>(); 1072 const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>();
1079 const DashingLineBatchTracker& local = args.fBT.cast<DashingLineBatchTracker >();
1080 GrGLGPBuilder* pb = args.fPB; 1073 GrGLGPBuilder* pb = args.fPB;
1081 1074
1082 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); 1075 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
1083 1076
1084 // emit attributes 1077 // emit attributes
1085 vsBuilder->emitAttributes(de); 1078 vsBuilder->emitAttributes(de);
1086 1079
1087 // XY refers to dashPos, Z is the dash interval length 1080 // XY refers to dashPos, Z is the dash interval length
1088 GrGLVertToFrag inDashParams(kVec3f_GrSLType); 1081 GrGLVertToFrag inDashParams(kVec3f_GrSLType);
1089 args.fPB->addVarying("DashParams", &inDashParams); 1082 args.fPB->addVarying("DashParams", &inDashParams);
1090 vsBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()-> fName); 1083 vsBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()-> fName);
1091 1084
1092 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5), 1085 // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bot tom - 0.5),
1093 // respectively. 1086 // respectively.
1094 GrGLVertToFrag inRectParams(kVec4f_GrSLType); 1087 GrGLVertToFrag inRectParams(kVec4f_GrSLType);
1095 args.fPB->addVarying("RectParams", &inRectParams); 1088 args.fPB->addVarying("RectParams", &inRectParams);
1096 vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()-> fName); 1089 vsBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()-> fName);
1097 1090
1098 // Setup pass through color 1091 // Setup pass through color
1099 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NU LL, &fColorUniform); 1092 if (!de.colorIgnored()) {
1093 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform);
1094 }
1095
1100 1096
1101 // Setup position 1097 // Setup position
1102 this->setupPosition(pb, gpArgs, de.inPosition()->fName); 1098 this->setupPosition(pb, gpArgs, de.inPosition()->fName);
1103 1099
1104 // emit transforms 1100 // emit transforms
1105 this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName, de.localMatrix(), 1101 this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName, de.localMatrix(),
1106 args.fTransformsIn, args.fTransformsOut); 1102 args.fTransformsIn, args.fTransformsOut);
1107 1103
1108 // transforms all points so that we can compare them to our test rect 1104 // transforms all points so that we can compare them to our test rect
1109 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); 1105 GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
(...skipping 27 matching lines...) Expand all
1137 inRectParams.fsIn()); 1133 inRectParams.fsIn());
1138 fsBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;", 1134 fsBuilder->codeAppendf("alpha *= (%s.z - fragPosShifted.x) >= -0.5 ? 1.0 : 0.0;",
1139 inRectParams.fsIn()); 1135 inRectParams.fsIn());
1140 } 1136 }
1141 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 1137 fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
1142 } 1138 }
1143 1139
1144 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, 1140 void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman,
1145 const GrPrimitiveProcessor& processor, 1141 const GrPrimitiveProcessor& processor,
1146 const GrBatchTracker& bt) { 1142 const GrBatchTracker& bt) {
1147 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); 1143 const DashingLineEffect& de = processor.cast<DashingLineEffect>();
1148 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { 1144 if (de.color() != fColor) {
1149 GrGLfloat c[4]; 1145 GrGLfloat c[4];
1150 GrColorToRGBAFloat(local.fColor, c); 1146 GrColorToRGBAFloat(de.color(), c);
1151 pdman.set4fv(fColorUniform, 1, c); 1147 pdman.set4fv(fColorUniform, 1, c);
1152 fColor = local.fColor; 1148 fColor = de.color();
1153 } 1149 }
1154 } 1150 }
1155 1151
1156 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp, 1152 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp,
1157 const GrBatchTracker& bt, 1153 const GrBatchTracker& bt,
1158 const GrGLSLCaps&, 1154 const GrGLSLCaps&,
1159 GrProcessorKeyBuilder* b) { 1155 GrProcessorKeyBuilder* b) {
1160 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>();
1161 const DashingLineEffect& de = gp.cast<DashingLineEffect>(); 1156 const DashingLineEffect& de = gp.cast<DashingLineEffect>();
1162 uint32_t key = 0; 1157 uint32_t key = 0;
1163 key |= local.fUsesLocalCoords && de.localMatrix().hasPerspective() ? 0x1 : 0 x0; 1158 key |= de.usesLocalCoords() && de.localMatrix().hasPerspective() ? 0x1 : 0x0 ;
1159 key |= de.colorIgnored() ? 0x2 : 0x0;
1164 key |= de.aaMode() << 8; 1160 key |= de.aaMode() << 8;
1165 b->add32(key << 16 | local.fInputColorType); 1161 b->add32(key);
1166 } 1162 }
1167 1163
1168 ////////////////////////////////////////////////////////////////////////////// 1164 //////////////////////////////////////////////////////////////////////////////
1169 1165
1170 GrGeometryProcessor* DashingLineEffect::Create(GrColor color, 1166 GrGeometryProcessor* DashingLineEffect::Create(GrColor color,
1171 DashAAMode aaMode, 1167 DashAAMode aaMode,
1172 const SkMatrix& localMatrix) { 1168 const SkMatrix& localMatrix,
1173 return SkNEW_ARGS(DashingLineEffect, (color, aaMode, localMatrix)); 1169 bool usesLocalCoords) {
1170 return SkNEW_ARGS(DashingLineEffect, (color, aaMode, localMatrix, usesLocalC oords));
1174 } 1171 }
1175 1172
1176 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, 1173 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt,
1177 const GrGLSLCaps& caps, 1174 const GrGLSLCaps& caps,
1178 GrProcessorKeyBuilder* b) const { 1175 GrProcessorKeyBuilder* b) const {
1179 GLDashingLineEffect::GenKey(*this, bt, caps, b); 1176 GLDashingLineEffect::GenKey(*this, bt, caps, b);
1180 } 1177 }
1181 1178
1182 GrGLPrimitiveProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker & bt, 1179 GrGLPrimitiveProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker & bt,
1183 const GrGLSLCaps&) c onst { 1180 const GrGLSLCaps&) c onst {
1184 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt)); 1181 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt));
1185 } 1182 }
1186 1183
1187 DashingLineEffect::DashingLineEffect(GrColor color, 1184 DashingLineEffect::DashingLineEffect(GrColor color,
1188 DashAAMode aaMode, 1185 DashAAMode aaMode,
1189 const SkMatrix& localMatrix) 1186 const SkMatrix& localMatrix,
1187 bool usesLocalCoords)
1190 : fColor(color) 1188 : fColor(color)
1191 , fLocalMatrix(localMatrix) 1189 , fLocalMatrix(localMatrix)
1190 , fUsesLocalCoords(usesLocalCoords)
1192 , fAAMode(aaMode) { 1191 , fAAMode(aaMode) {
1193 this->initClassID<DashingLineEffect>(); 1192 this->initClassID<DashingLineEffect>();
1194 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 1193 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
1195 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType)); 1194 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType));
1196 fInRectParams = &this->addVertexAttrib(Attribute("inRect", kVec4f_GrVertexAt tribType)); 1195 fInRectParams = &this->addVertexAttrib(Attribute("inRect", kVec4f_GrVertexAt tribType));
1197 } 1196 }
1198 1197
1199 void DashingLineEffect::initBatchTracker(GrBatchTracker* bt, const GrPipelineInf o& init) const {
1200 DashingLineBatchTracker* local = bt->cast<DashingLineBatchTracker>();
1201 local->fInputColorType = GetColorInputType(&local->fColor, this->color(), in it, false);
1202 local->fUsesLocalCoords = init.fUsesLocalCoords;
1203 }
1204
1205 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); 1198 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect);
1206 1199
1207 GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random, 1200 GrGeometryProcessor* DashingLineEffect::TestCreate(SkRandom* random,
1208 GrContext*, 1201 GrContext*,
1209 const GrDrawTargetCaps& caps, 1202 const GrDrawTargetCaps& caps,
1210 GrTexture*[]) { 1203 GrTexture*[]) {
1211 DashAAMode aaMode = static_cast<DashAAMode>(random->nextULessThan(kDashAAMod eCount)); 1204 DashAAMode aaMode = static_cast<DashAAMode>(random->nextULessThan(kDashAAMod eCount));
1212 return DashingLineEffect::Create(GrRandomColor(random), 1205 return DashingLineEffect::Create(GrRandomColor(random),
1213 aaMode, GrTest::TestMatrix(random)); 1206 aaMode, GrTest::TestMatrix(random), random- >nextBool());
1214 } 1207 }
1215 1208
1216 ////////////////////////////////////////////////////////////////////////////// 1209 //////////////////////////////////////////////////////////////////////////////
1217 1210
1218 static GrGeometryProcessor* create_dash_gp(GrColor color, 1211 static GrGeometryProcessor* create_dash_gp(GrColor color,
1219 DashAAMode dashAAMode, 1212 DashAAMode dashAAMode,
1220 DashCap cap, 1213 DashCap cap,
1221 const SkMatrix& localMatrix) { 1214 const SkMatrix& localMatrix,
1215 bool usesLocalCoords) {
1222 switch (cap) { 1216 switch (cap) {
1223 case kRound_DashCap: 1217 case kRound_DashCap:
1224 return DashingCircleEffect::Create(color, dashAAMode, localMatrix); 1218 return DashingCircleEffect::Create(color, dashAAMode, localMatrix, u sesLocalCoords);
1225 case kNonRound_DashCap: 1219 case kNonRound_DashCap:
1226 return DashingLineEffect::Create(color, dashAAMode, localMatrix); 1220 return DashingLineEffect::Create(color, dashAAMode, localMatrix, use sLocalCoords);
1227 default: 1221 default:
1228 SkFAIL("Unexpected dashed cap."); 1222 SkFAIL("Unexpected dashed cap.");
1229 } 1223 }
1230 return NULL; 1224 return NULL;
1231 } 1225 }
1232 1226
1233 //////////////////////////////////////////////////////////////////////////////// ///////////////// 1227 //////////////////////////////////////////////////////////////////////////////// /////////////////
1234 1228
1235 #ifdef GR_TEST_UTILS 1229 #ifdef GR_TEST_UTILS
1236 1230
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 info.fIntervals = intervals; 1297 info.fIntervals = intervals;
1304 info.fCount = 2; 1298 info.fCount = 2;
1305 info.fPhase = phase; 1299 info.fPhase = phase;
1306 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); 1300 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info);
1307 SkASSERT(success); 1301 SkASSERT(success);
1308 1302
1309 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); 1303 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT);
1310 } 1304 }
1311 1305
1312 #endif 1306 #endif
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBitmapTextGeoProc.cpp ('k') | src/gpu/effects/GrDistanceFieldGeoProc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698