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