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 2042923003: Make GrDashEffect take a AA mode enum. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: rm unneeded scoping Created 4 years, 6 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 "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
11 #include "GrBatchTest.h" 11 #include "GrBatchTest.h"
12 #include "GrCaps.h" 12 #include "GrCaps.h"
13 #include "GrGeometryProcessor.h" 13 #include "GrGeometryProcessor.h"
14 #include "GrContext.h" 14 #include "GrContext.h"
15 #include "GrCoordTransform.h" 15 #include "GrCoordTransform.h"
16 #include "GrDefaultGeoProcFactory.h" 16 #include "GrDefaultGeoProcFactory.h"
17 #include "GrInvariantOutput.h" 17 #include "GrInvariantOutput.h"
18 #include "GrProcessor.h" 18 #include "GrProcessor.h"
19 #include "GrStyle.h" 19 #include "GrStyle.h"
20 #include "SkGr.h" 20 #include "SkGr.h"
21 #include "batches/GrVertexBatch.h" 21 #include "batches/GrVertexBatch.h"
22 #include "glsl/GrGLSLFragmentShaderBuilder.h" 22 #include "glsl/GrGLSLFragmentShaderBuilder.h"
23 #include "glsl/GrGLSLGeometryProcessor.h" 23 #include "glsl/GrGLSLGeometryProcessor.h"
24 #include "glsl/GrGLSLProgramDataManager.h" 24 #include "glsl/GrGLSLProgramDataManager.h"
25 #include "glsl/GrGLSLUniformHandler.h" 25 #include "glsl/GrGLSLUniformHandler.h"
26 #include "glsl/GrGLSLVarying.h" 26 #include "glsl/GrGLSLVarying.h"
27 #include "glsl/GrGLSLVertexShaderBuilder.h" 27 #include "glsl/GrGLSLVertexShaderBuilder.h"
28 28
29 using AAMode = GrDashingEffect::AAMode;
30
29 /////////////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////////////
30 32
31 // Returns whether or not the gpu can fast path the dash line effect. 33 // Returns whether or not the gpu can fast path the dash line effect.
32 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStyle& style , 34 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStyle& style ,
33 const SkMatrix& viewMatrix) { 35 const SkMatrix& viewMatrix) {
34 // Pts must be either horizontal or vertical in src space 36 // Pts must be either horizontal or vertical in src space
35 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { 37 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) {
36 return false; 38 return false;
37 } 39 }
38 40
(...skipping 28 matching lines...) Expand all
67 SkScalar fIntervalLength; 69 SkScalar fIntervalLength;
68 SkRect fRect; 70 SkRect fRect;
69 }; 71 };
70 struct DashCircleVertex { 72 struct DashCircleVertex {
71 SkPoint fPos; 73 SkPoint fPos;
72 SkPoint fDashPos; 74 SkPoint fDashPos;
73 SkScalar fIntervalLength; 75 SkScalar fIntervalLength;
74 SkScalar fRadius; 76 SkScalar fRadius;
75 SkScalar fCenterX; 77 SkScalar fCenterX;
76 }; 78 };
77
78 enum DashAAMode {
79 kBW_DashAAMode,
80 kEdgeAA_DashAAMode,
81 kMSAA_DashAAMode,
82
83 kDashAAModeCount,
84 };
85 }; 79 };
86 80
87 static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale, 81 static void calc_dash_scaling(SkScalar* parallelScale, SkScalar* perpScale,
88 const SkMatrix& viewMatrix, const SkPoint pts[2]) { 82 const SkMatrix& viewMatrix, const SkPoint pts[2]) {
89 SkVector vecSrc = pts[1] - pts[0]; 83 SkVector vecSrc = pts[1] - pts[0];
90 SkScalar magSrc = vecSrc.length(); 84 SkScalar magSrc = vecSrc.length();
91 SkScalar invSrc = magSrc ? SkScalarInvert(magSrc) : 0; 85 SkScalar invSrc = magSrc ? SkScalarInvert(magSrc) : 0;
92 vecSrc.scale(invSrc); 86 vecSrc.scale(invSrc);
93 87
94 SkVector vecSrcPerp; 88 SkVector vecSrcPerp;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 226 }
233 227
234 228
235 /** 229 /**
236 * An GrGeometryProcessor that renders a dashed line. 230 * An GrGeometryProcessor that renders a dashed line.
237 * This GrGeometryProcessor is meant for dashed lines that only have a single on /off interval pair. 231 * 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 232 * Bounding geometry is rendered and the effect computes coverage based on the f ragment's
239 * position relative to the dashed line. 233 * position relative to the dashed line.
240 */ 234 */
241 static GrGeometryProcessor* create_dash_gp(GrColor, 235 static GrGeometryProcessor* create_dash_gp(GrColor,
242 DashAAMode aaMode, 236 AAMode aaMode,
243 DashCap cap, 237 DashCap cap,
244 const SkMatrix& localMatrix, 238 const SkMatrix& localMatrix,
245 bool usesLocalCoords); 239 bool usesLocalCoords);
246 240
247 class DashBatch : public GrVertexBatch { 241 class DashBatch : public GrVertexBatch {
248 public: 242 public:
249 DEFINE_BATCH_CLASS_ID 243 DEFINE_BATCH_CLASS_ID
250
251 struct Geometry { 244 struct Geometry {
252 SkMatrix fViewMatrix; 245 SkMatrix fViewMatrix;
253 SkMatrix fSrcRotInv; 246 SkMatrix fSrcRotInv;
254 SkPoint fPtsRot[2]; 247 SkPoint fPtsRot[2];
255 SkScalar fSrcStrokeWidth; 248 SkScalar fSrcStrokeWidth;
256 SkScalar fPhase; 249 SkScalar fPhase;
257 SkScalar fIntervals[2]; 250 SkScalar fIntervals[2];
258 SkScalar fParallelScale; 251 SkScalar fParallelScale;
259 SkScalar fPerpendicularScale; 252 SkScalar fPerpendicularScale;
260 GrColor fColor; 253 GrColor fColor;
261 }; 254 };
262 255
263 static GrDrawBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashA AMode aaMode, 256 static GrDrawBatch* Create(const Geometry& geometry, SkPaint::Cap cap, AAMod e aaMode,
264 bool fullDash) { 257 bool fullDash) {
265 return new DashBatch(geometry, cap, aaMode, fullDash); 258 return new DashBatch(geometry, cap, aaMode, fullDash);
266 } 259 }
267 260
268 const char* name() const override { return "DashBatch"; } 261 const char* name() const override { return "DashBatch"; }
269 262
270 void computePipelineOptimizations(GrInitInvariantOutput* color, 263 void computePipelineOptimizations(GrInitInvariantOutput* color,
271 GrInitInvariantOutput* coverage, 264 GrInitInvariantOutput* coverage,
272 GrBatchToXPOverrides* overrides) const ove rride { 265 GrBatchToXPOverrides* overrides) const ove rride {
273 // When this is called on a batch, there is only one geometry bundle 266 // When this is called on a batch, there is only one geometry bundle
274 color->setKnownFourComponents(fGeoData[0].fColor); 267 color->setKnownFourComponents(fGeoData[0].fColor);
275 coverage->setUnknownSingleComponent(); 268 coverage->setUnknownSingleComponent();
276 } 269 }
277 270
278 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 271 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
279 272
280 private: 273 private:
281 DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, boo l fullDash) 274 DashBatch(const Geometry& geometry, SkPaint::Cap cap, AAMode aaMode, bool fu llDash)
282 : INHERITED(ClassID()) { 275 : INHERITED(ClassID()) {
283 fGeoData.push_back(geometry); 276 fGeoData.push_back(geometry);
284 277
285 fBatch.fAAMode = aaMode; 278 fBatch.fAAMode = aaMode;
286 fBatch.fCap = cap; 279 fBatch.fCap = cap;
287 fBatch.fFullDash = fullDash; 280 fBatch.fFullDash = fullDash;
288 281
289 // compute bounds 282 // compute bounds
290 SkScalar halfStrokeWidth = 0.5f * geometry.fSrcStrokeWidth; 283 SkScalar halfStrokeWidth = 0.5f * geometry.fSrcStrokeWidth;
291 SkScalar xBloat = SkPaint::kButt_Cap == cap ? 0 : halfStrokeWidth; 284 SkScalar xBloat = SkPaint::kButt_Cap == cap ? 0 : halfStrokeWidth;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 LocalCoords::kUnus ed_Type); 345 LocalCoords::kUnus ed_Type);
353 gp.reset(CreateForDeviceSpace(color, coverage, localCoords, this->vi ewMatrix())); 346 gp.reset(CreateForDeviceSpace(color, coverage, localCoords, this->vi ewMatrix()));
354 } 347 }
355 348
356 if (!gp) { 349 if (!gp) {
357 SkDebugf("Could not create GrGeometryProcessor\n"); 350 SkDebugf("Could not create GrGeometryProcessor\n");
358 return; 351 return;
359 } 352 }
360 353
361 // useAA here means Edge AA or MSAA 354 // useAA here means Edge AA or MSAA
362 bool useAA = this->aaMode() != kBW_DashAAMode; 355 bool useAA = this->aaMode() != AAMode::kNone;
363 bool fullDash = this->fullDash(); 356 bool fullDash = this->fullDash();
364 357
365 // We do two passes over all of the dashes. First we setup the start, e nd, and bounds, 358 // We do two passes over all of the dashes. First we setup the start, e nd, and bounds,
366 // rectangles. We preserve all of this work in the rects / draws arrays below. Then we 359 // rectangles. We preserve all of this work in the rects / draws arrays below. Then we
367 // iterate again over these decomposed dashes to generate vertices 360 // iterate again over these decomposed dashes to generate vertices
368 static const int kNumStackDashes = 128; 361 static const int kNumStackDashes = 128;
369 SkSTArray<kNumStackDashes, SkRect, true> rects; 362 SkSTArray<kNumStackDashes, SkRect, true> rects;
370 SkSTArray<kNumStackDashes, DashDraw, true> draws; 363 SkSTArray<kNumStackDashes, DashDraw, true> draws;
371 364
372 int totalRectCount = 0; 365 int totalRectCount = 0;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 472
480 if (SkPaint::kSquare_Cap == cap && 0 != args.fSrcStrokeWidth) { 473 if (SkPaint::kSquare_Cap == cap && 0 != args.fSrcStrokeWidth) {
481 // add cap to on interval and remove from off interval 474 // add cap to on interval and remove from off interval
482 devIntervals[0] += strokeWidth; 475 devIntervals[0] += strokeWidth;
483 devIntervals[1] -= strokeWidth; 476 devIntervals[1] -= strokeWidth;
484 } 477 }
485 SkScalar startOffset = devIntervals[1] * 0.5f + devPhase; 478 SkScalar startOffset = devIntervals[1] * 0.5f + devPhase;
486 479
487 // For EdgeAA, we bloat in X & Y for both square and round caps. 480 // For EdgeAA, we bloat in X & Y for both square and round caps.
488 // For MSAA, we don't bloat at all for square caps, and bloat in Y o nly for round caps. 481 // For MSAA, we don't bloat at all for square caps, and bloat in Y o nly for round caps.
489 SkScalar devBloatX = this->aaMode() == kEdgeAA_DashAAMode ? 0.5f : 0 .0f; 482 SkScalar devBloatX = this->aaMode() == AAMode::kCoverage ? 0.5f : 0. 0f;
490 SkScalar devBloatY = (SkPaint::kRound_Cap == cap && this->aaMode() = = kMSAA_DashAAMode) 483 SkScalar devBloatY;
491 ? 0.5f : devBloatX; 484 if (SkPaint::kRound_Cap == cap && this->aaMode() == AAMode::kCoverag eWithMSAA) {
485 devBloatY = 0.5f;
486 } else {
487 devBloatY = devBloatX;
488 }
492 489
493 SkScalar bloatX = devBloatX / args.fParallelScale; 490 SkScalar bloatX = devBloatX / args.fParallelScale;
494 SkScalar bloatY = devBloatY / args.fPerpendicularScale; 491 SkScalar bloatY = devBloatY / args.fPerpendicularScale;
495 492
496 if (devIntervals[1] <= 0.f && useAA) { 493 if (devIntervals[1] <= 0.f && useAA) {
497 // Case when we end up drawing a solid AA rect 494 // Case when we end up drawing a solid AA rect
498 // Reset the start rect to draw this single solid rect 495 // Reset the start rect to draw this single solid rect
499 // but it requires to upload a new intervals uniform so we can m imic 496 // but it requires to upload a new intervals uniform so we can m imic
500 // one giant dash 497 // one giant dash
501 draw.fPtsRot[0].fX -= hasStartRect ? startAdj : 0; 498 draw.fPtsRot[0].fX -= hasStartRect ? startAdj : 0;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } 655 }
659 656
660 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; 657 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ;
661 this->joinBounds(that->bounds()); 658 this->joinBounds(that->bounds());
662 return true; 659 return true;
663 } 660 }
664 661
665 GrColor color() const { return fBatch.fColor; } 662 GrColor color() const { return fBatch.fColor; }
666 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 663 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
667 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } 664 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; }
668 DashAAMode aaMode() const { return fBatch.fAAMode; } 665 AAMode aaMode() const { return fBatch.fAAMode; }
669 bool fullDash() const { return fBatch.fFullDash; } 666 bool fullDash() const { return fBatch.fFullDash; }
670 SkPaint::Cap cap() const { return fBatch.fCap; } 667 SkPaint::Cap cap() const { return fBatch.fCap; }
671 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } 668 bool coverageIgnored() const { return fBatch.fCoverageIgnored; }
672 669
673 struct BatchTracker { 670 struct BatchTracker {
674 GrColor fColor; 671 GrColor fColor;
675 bool fUsesLocalCoords; 672 bool fUsesLocalCoords;
676 bool fColorIgnored; 673 bool fColorIgnored;
677 bool fCoverageIgnored; 674 bool fCoverageIgnored;
678 SkPaint::Cap fCap; 675 SkPaint::Cap fCap;
679 DashAAMode fAAMode; 676 AAMode fAAMode;
680 bool fFullDash; 677 bool fFullDash;
681 }; 678 };
682 679
683 static const int kVertsPerDash = 4; 680 static const int kVertsPerDash = 4;
684 static const int kIndicesPerDash = 6; 681 static const int kIndicesPerDash = 6;
685 682
686 BatchTracker fBatch; 683 BatchTracker fBatch;
687 SkSTArray<1, Geometry, true> fGeoData; 684 SkSTArray<1, Geometry, true> fGeoData;
688 685
689 typedef GrVertexBatch INHERITED; 686 typedef GrVertexBatch INHERITED;
690 }; 687 };
691 688
692 static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, cons t SkPoint pts[2], 689 GrDrawBatch* GrDashingEffect::CreateDashLineBatch(GrColor color,
693 bool useAA, const GrStyle& style, bool msaaRT) { 690 const SkMatrix& viewMatrix,
691 const SkPoint pts[2],
692 AAMode aaMode,
693 const GrStyle& style) {
694 SkASSERT(GrDashingEffect::CanDrawDashLine(pts, style, viewMatrix)); 694 SkASSERT(GrDashingEffect::CanDrawDashLine(pts, style, viewMatrix));
695 const SkScalar* intervals = style.dashIntervals(); 695 const SkScalar* intervals = style.dashIntervals();
696 SkScalar phase = style.dashPhase(); 696 SkScalar phase = style.dashPhase();
697 697
698 SkPaint::Cap cap = style.strokeRec().getCap(); 698 SkPaint::Cap cap = style.strokeRec().getCap();
699 699
700 DashBatch::Geometry geometry; 700 DashBatch::Geometry geometry;
701 geometry.fSrcStrokeWidth = style.strokeRec().getWidth(); 701 geometry.fSrcStrokeWidth = style.strokeRec().getWidth();
702 702
703 // the phase should be normalized to be [0, sum of all intervals) 703 // the phase should be normalized to be [0, sum of all intervals)
(...skipping 17 matching lines...) Expand all
721 geometry.fPtsRot); 721 geometry.fPtsRot);
722 722
723 SkScalar offInterval = intervals[1] * geometry.fParallelScale; 723 SkScalar offInterval = intervals[1] * geometry.fParallelScale;
724 SkScalar strokeWidth = geometry.fSrcStrokeWidth * geometry.fPerpendicularSca le; 724 SkScalar strokeWidth = geometry.fSrcStrokeWidth * geometry.fPerpendicularSca le;
725 725
726 if (SkPaint::kSquare_Cap == cap && 0 != geometry.fSrcStrokeWidth) { 726 if (SkPaint::kSquare_Cap == cap && 0 != geometry.fSrcStrokeWidth) {
727 // add cap to on interveal and remove from off interval 727 // add cap to on interveal and remove from off interval
728 offInterval -= strokeWidth; 728 offInterval -= strokeWidth;
729 } 729 }
730 730
731 DashAAMode aaMode = msaaRT ? kMSAA_DashAAMode :
732 useAA ? kEdgeAA_DashAAMode : kBW_DashAAMode;
733
734 // TODO we can do a real rect call if not using fulldash(ie no off interval, not using AA) 731 // TODO we can do a real rect call if not using fulldash(ie no off interval, not using AA)
735 bool fullDash = offInterval > 0.f || aaMode != kBW_DashAAMode; 732 bool fullDash = offInterval > 0.f || aaMode != AAMode::kNone;
736 733
737 geometry.fColor = color; 734 geometry.fColor = color;
738 geometry.fViewMatrix = viewMatrix; 735 geometry.fViewMatrix = viewMatrix;
739 geometry.fPhase = phase; 736 geometry.fPhase = phase;
740 geometry.fIntervals[0] = intervals[0]; 737 geometry.fIntervals[0] = intervals[0];
741 geometry.fIntervals[1] = intervals[1]; 738 geometry.fIntervals[1] = intervals[1];
742 739
743 return DashBatch::Create(geometry, cap, aaMode, fullDash); 740 return DashBatch::Create(geometry, cap, aaMode, fullDash);
744 } 741 }
745 742
746 GrDrawBatch* GrDashingEffect::CreateDashLineBatch(GrColor color,
747 const SkMatrix& viewMatrix,
748 const SkPoint pts[2],
749 bool useAA,
750 bool msaaIsEnabled,
751 const GrStyle& style) {
752 return create_batch(color, viewMatrix, pts, useAA, style, msaaIsEnabled);
753 }
754
755 ////////////////////////////////////////////////////////////////////////////// 743 //////////////////////////////////////////////////////////////////////////////
756 744
757 class GLDashingCircleEffect; 745 class GLDashingCircleEffect;
758 746
759 /* 747 /*
760 * This effect will draw a dotted line (defined as a dashed lined with round cap s and no on 748 * 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. 749 * 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 750 * 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 751 * 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 752 * "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 753 * 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. 754 * right by half the off interval. The line then goes in the positive x directio n.
767 */ 755 */
768 class DashingCircleEffect : public GrGeometryProcessor { 756 class DashingCircleEffect : public GrGeometryProcessor {
769 public: 757 public:
770 typedef SkPathEffect::DashInfo DashInfo; 758 typedef SkPathEffect::DashInfo DashInfo;
771 759
772 static GrGeometryProcessor* Create(GrColor, 760 static GrGeometryProcessor* Create(GrColor,
773 DashAAMode aaMode, 761 AAMode aaMode,
774 const SkMatrix& localMatrix, 762 const SkMatrix& localMatrix,
775 bool usesLocalCoords); 763 bool usesLocalCoords);
776 764
777 const char* name() const override { return "DashingCircleEffect"; } 765 const char* name() const override { return "DashingCircleEffect"; }
778 766
779 const Attribute* inPosition() const { return fInPosition; } 767 const Attribute* inPosition() const { return fInPosition; }
780 768
781 const Attribute* inDashParams() const { return fInDashParams; } 769 const Attribute* inDashParams() const { return fInDashParams; }
782 770
783 const Attribute* inCircleParams() const { return fInCircleParams; } 771 const Attribute* inCircleParams() const { return fInCircleParams; }
784 772
785 DashAAMode aaMode() const { return fAAMode; } 773 AAMode aaMode() const { return fAAMode; }
786 774
787 GrColor color() const { return fColor; } 775 GrColor color() const { return fColor; }
788 776
789 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } 777 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
790 778
791 const SkMatrix& localMatrix() const { return fLocalMatrix; } 779 const SkMatrix& localMatrix() const { return fLocalMatrix; }
792 780
793 bool usesLocalCoords() const { return fUsesLocalCoords; } 781 bool usesLocalCoords() const { return fUsesLocalCoords; }
794 782
795 void getGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder* b) const override; 783 void getGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder* b) const override;
796 784
797 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de; 785 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de;
798 786
799 private: 787 private:
800 DashingCircleEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix, 788 DashingCircleEffect(GrColor, AAMode aaMode, const SkMatrix& localMatrix,
801 bool usesLocalCoords); 789 bool usesLocalCoords);
802 790
803 GrColor fColor; 791 GrColor fColor;
804 SkMatrix fLocalMatrix; 792 SkMatrix fLocalMatrix;
805 bool fUsesLocalCoords; 793 bool fUsesLocalCoords;
806 DashAAMode fAAMode; 794 AAMode fAAMode;
807 const Attribute* fInPosition; 795 const Attribute* fInPosition;
808 const Attribute* fInDashParams; 796 const Attribute* fInDashParams;
809 const Attribute* fInCircleParams; 797 const Attribute* fInCircleParams;
810 798
811 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; 799 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
812 800
813 typedef GrGeometryProcessor INHERITED; 801 typedef GrGeometryProcessor INHERITED;
814 }; 802 };
815 803
816 ////////////////////////////////////////////////////////////////////////////// 804 //////////////////////////////////////////////////////////////////////////////
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 args.fTransformsIn, 877 args.fTransformsIn,
890 args.fTransformsOut); 878 args.fTransformsOut);
891 879
892 // transforms all points so that we can compare them to our test circle 880 // transforms all points so that we can compare them to our test circle
893 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z; ", 881 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z; ",
894 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs In(), 882 dashParams.fsIn(), dashParams.fsIn(), dashParams.fs In(),
895 dashParams.fsIn()); 883 dashParams.fsIn());
896 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dash Params.fsIn()); 884 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", dash Params.fsIn());
897 fragBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn ()); 885 fragBuilder->codeAppendf("vec2 center = vec2(%s.y, 0.0);", circleParams.fsIn ());
898 fragBuilder->codeAppend("float dist = length(center - fragPosShifted);"); 886 fragBuilder->codeAppend("float dist = length(center - fragPosShifted);");
899 if (dce.aaMode() != kBW_DashAAMode) { 887 if (dce.aaMode() != AAMode::kNone) {
900 fragBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn( )); 888 fragBuilder->codeAppendf("float diff = dist - %s.x;", circleParams.fsIn( ));
901 fragBuilder->codeAppend("diff = 1.0 - diff;"); 889 fragBuilder->codeAppend("diff = 1.0 - diff;");
902 fragBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);"); 890 fragBuilder->codeAppend("float alpha = clamp(diff, 0.0, 1.0);");
903 } else { 891 } else {
904 fragBuilder->codeAppendf("float alpha = 1.0;"); 892 fragBuilder->codeAppendf("float alpha = 1.0;");
905 fragBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", cir cleParams.fsIn()); 893 fragBuilder->codeAppendf("alpha *= dist < %s.x + 0.5 ? 1.0 : 0.0;", cir cleParams.fsIn());
906 } 894 }
907 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); 895 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage);
908 } 896 }
909 897
910 void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman, 898 void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman,
911 const GrPrimitiveProcessor& processor) { 899 const GrPrimitiveProcessor& processor) {
912 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); 900 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
913 if (dce.color() != fColor) { 901 if (dce.color() != fColor) {
914 float c[4]; 902 float c[4];
915 GrColorToRGBAFloat(dce.color(), c); 903 GrColorToRGBAFloat(dce.color(), c);
916 pdman.set4fv(fColorUniform, 1, c); 904 pdman.set4fv(fColorUniform, 1, c);
917 fColor = dce.color(); 905 fColor = dce.color();
918 } 906 }
919 } 907 }
920 908
921 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp, 909 void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp,
922 const GrGLSLCaps&, 910 const GrGLSLCaps&,
923 GrProcessorKeyBuilder* b) { 911 GrProcessorKeyBuilder* b) {
924 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>(); 912 const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>();
925 uint32_t key = 0; 913 uint32_t key = 0;
926 key |= dce.usesLocalCoords() && dce.localMatrix().hasPerspective() ? 0x1 : 0 x0; 914 key |= dce.usesLocalCoords() && dce.localMatrix().hasPerspective() ? 0x1 : 0 x0;
927 key |= dce.colorIgnored() ? 0x2 : 0x0; 915 key |= dce.colorIgnored() ? 0x2 : 0x0;
928 key |= dce.aaMode() << 8; 916 key |= static_cast<uint32_t>(dce.aaMode()) << 8;
929 b->add32(key); 917 b->add32(key);
930 } 918 }
931 919
932 ////////////////////////////////////////////////////////////////////////////// 920 //////////////////////////////////////////////////////////////////////////////
933 921
934 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, 922 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color,
935 DashAAMode aaMode, 923 AAMode aaMode,
936 const SkMatrix& localMatrix, 924 const SkMatrix& localMatrix,
937 bool usesLocalCoords) { 925 bool usesLocalCoords) {
938 return new DashingCircleEffect(color, aaMode, localMatrix, usesLocalCoords); 926 return new DashingCircleEffect(color, aaMode, localMatrix, usesLocalCoords);
939 } 927 }
940 928
941 void DashingCircleEffect::getGLSLProcessorKey(const GrGLSLCaps& caps, 929 void DashingCircleEffect::getGLSLProcessorKey(const GrGLSLCaps& caps,
942 GrProcessorKeyBuilder* b) const { 930 GrProcessorKeyBuilder* b) const {
943 GLDashingCircleEffect::GenKey(*this, caps, b); 931 GLDashingCircleEffect::GenKey(*this, caps, b);
944 } 932 }
945 933
946 GrGLSLPrimitiveProcessor* DashingCircleEffect::createGLSLInstance(const GrGLSLCa ps&) const { 934 GrGLSLPrimitiveProcessor* DashingCircleEffect::createGLSLInstance(const GrGLSLCa ps&) const {
947 return new GLDashingCircleEffect(); 935 return new GLDashingCircleEffect();
948 } 936 }
949 937
950 DashingCircleEffect::DashingCircleEffect(GrColor color, 938 DashingCircleEffect::DashingCircleEffect(GrColor color,
951 DashAAMode aaMode, 939 AAMode aaMode,
952 const SkMatrix& localMatrix, 940 const SkMatrix& localMatrix,
953 bool usesLocalCoords) 941 bool usesLocalCoords)
954 : fColor(color) 942 : fColor(color)
955 , fLocalMatrix(localMatrix) 943 , fLocalMatrix(localMatrix)
956 , fUsesLocalCoords(usesLocalCoords) 944 , fUsesLocalCoords(usesLocalCoords)
957 , fAAMode(aaMode) { 945 , fAAMode(aaMode) {
958 this->initClassID<DashingCircleEffect>(); 946 this->initClassID<DashingCircleEffect>();
959 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 947 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
960 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType)); 948 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType));
961 fInCircleParams = &this->addVertexAttrib(Attribute("inCircleParams", 949 fInCircleParams = &this->addVertexAttrib(Attribute("inCircleParams",
962 kVec2f_GrVertexAttribType )); 950 kVec2f_GrVertexAttribType ));
963 } 951 }
964 952
965 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); 953 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect);
966 954
967 const GrGeometryProcessor* DashingCircleEffect::TestCreate(GrProcessorTestData* d) { 955 const GrGeometryProcessor* DashingCircleEffect::TestCreate(GrProcessorTestData* d) {
968 DashAAMode aaMode = static_cast<DashAAMode>(d->fRandom->nextULessThan(kDashA AModeCount)); 956 AAMode aaMode = static_cast<AAMode>(d->fRandom->nextULessThan(GrDashingEffec t::kAAModeCnt));
969 return DashingCircleEffect::Create(GrRandomColor(d->fRandom), 957 return DashingCircleEffect::Create(GrRandomColor(d->fRandom),
970 aaMode, GrTest::TestMatrix(d->fRandom), 958 aaMode, GrTest::TestMatrix(d->fRandom),
971 d->fRandom->nextBool()); 959 d->fRandom->nextBool());
972 } 960 }
973 961
974 ////////////////////////////////////////////////////////////////////////////// 962 //////////////////////////////////////////////////////////////////////////////
975 963
976 class GLDashingLineEffect; 964 class GLDashingLineEffect;
977 965
978 /* 966 /*
979 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the 967 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the
980 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space. 968 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space.
981 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the 969 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the
982 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the 970 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the
983 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of 971 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of
984 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the 972 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the
985 * positive x direction. 973 * positive x direction.
986 */ 974 */
987 class DashingLineEffect : public GrGeometryProcessor { 975 class DashingLineEffect : public GrGeometryProcessor {
988 public: 976 public:
989 typedef SkPathEffect::DashInfo DashInfo; 977 typedef SkPathEffect::DashInfo DashInfo;
990 978
991 static GrGeometryProcessor* Create(GrColor, 979 static GrGeometryProcessor* Create(GrColor,
992 DashAAMode aaMode, 980 AAMode aaMode,
993 const SkMatrix& localMatrix, 981 const SkMatrix& localMatrix,
994 bool usesLocalCoords); 982 bool usesLocalCoords);
995 983
996 const char* name() const override { return "DashingEffect"; } 984 const char* name() const override { return "DashingEffect"; }
997 985
998 const Attribute* inPosition() const { return fInPosition; } 986 const Attribute* inPosition() const { return fInPosition; }
999 987
1000 const Attribute* inDashParams() const { return fInDashParams; } 988 const Attribute* inDashParams() const { return fInDashParams; }
1001 989
1002 const Attribute* inRectParams() const { return fInRectParams; } 990 const Attribute* inRectParams() const { return fInRectParams; }
1003 991
1004 DashAAMode aaMode() const { return fAAMode; } 992 AAMode aaMode() const { return fAAMode; }
1005 993
1006 GrColor color() const { return fColor; } 994 GrColor color() const { return fColor; }
1007 995
1008 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; } 996 bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
1009 997
1010 const SkMatrix& localMatrix() const { return fLocalMatrix; } 998 const SkMatrix& localMatrix() const { return fLocalMatrix; }
1011 999
1012 bool usesLocalCoords() const { return fUsesLocalCoords; } 1000 bool usesLocalCoords() const { return fUsesLocalCoords; }
1013 1001
1014 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override; 1002 void getGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c onst override;
1015 1003
1016 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de; 1004 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrGLSLCaps&) const overri de;
1017 1005
1018 private: 1006 private:
1019 DashingLineEffect(GrColor, DashAAMode aaMode, const SkMatrix& localMatrix, 1007 DashingLineEffect(GrColor, AAMode aaMode, const SkMatrix& localMatrix,
1020 bool usesLocalCoords); 1008 bool usesLocalCoords);
1021 1009
1022 GrColor fColor; 1010 GrColor fColor;
1023 SkMatrix fLocalMatrix; 1011 SkMatrix fLocalMatrix;
1024 bool fUsesLocalCoords; 1012 bool fUsesLocalCoords;
1025 DashAAMode fAAMode; 1013 AAMode fAAMode;
1026 const Attribute* fInPosition; 1014 const Attribute* fInPosition;
1027 const Attribute* fInDashParams; 1015 const Attribute* fInDashParams;
1028 const Attribute* fInRectParams; 1016 const Attribute* fInRectParams;
1029 1017
1030 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; 1018 GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
1031 1019
1032 typedef GrGeometryProcessor INHERITED; 1020 typedef GrGeometryProcessor INHERITED;
1033 }; 1021 };
1034 1022
1035 ////////////////////////////////////////////////////////////////////////////// 1023 //////////////////////////////////////////////////////////////////////////////
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 de.inPosition()->fName, 1089 de.inPosition()->fName,
1102 de.localMatrix(), 1090 de.localMatrix(),
1103 args.fTransformsIn, 1091 args.fTransformsIn,
1104 args.fTransformsOut); 1092 args.fTransformsOut);
1105 1093
1106 // transforms all points so that we can compare them to our test rect 1094 // transforms all points so that we can compare them to our test rect
1107 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z; ", 1095 fragBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z; ",
1108 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar ams.fsIn(), 1096 inDashParams.fsIn(), inDashParams.fsIn(), inDashPar ams.fsIn(),
1109 inDashParams.fsIn()); 1097 inDashParams.fsIn());
1110 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDa shParams.fsIn()); 1098 fragBuilder->codeAppendf("vec2 fragPosShifted = vec2(xShifted, %s.y);", inDa shParams.fsIn());
1111 if (de.aaMode() == kEdgeAA_DashAAMode) { 1099 if (de.aaMode() == AAMode::kCoverage) {
1112 // The amount of coverage removed in x and y by the edges is computed as a pair of negative 1100 // The amount of coverage removed in x and y by the edges is computed as a pair of negative
1113 // numbers, xSub and ySub. 1101 // numbers, xSub and ySub.
1114 fragBuilder->codeAppend("float xSub, ySub;"); 1102 fragBuilder->codeAppend("float xSub, ySub;");
1115 fragBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", in RectParams.fsIn()); 1103 fragBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", in RectParams.fsIn());
1116 fragBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", i nRectParams.fsIn()); 1104 fragBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", i nRectParams.fsIn());
1117 fragBuilder->codeAppendf("ySub = min(fragPosShifted.y - %s.y, 0.0);", in RectParams.fsIn()); 1105 fragBuilder->codeAppendf("ySub = min(fragPosShifted.y - %s.y, 0.0);", in RectParams.fsIn());
1118 fragBuilder->codeAppendf("ySub += min(%s.w - fragPosShifted.y, 0.0);", i nRectParams.fsIn()); 1106 fragBuilder->codeAppendf("ySub += min(%s.w - fragPosShifted.y, 0.0);", i nRectParams.fsIn());
1119 // Now compute coverage in x and y and multiply them to get the fraction of the pixel 1107 // Now compute coverage in x and y and multiply them to get the fraction of the pixel
1120 // covered. 1108 // covered.
1121 fragBuilder->codeAppendf( 1109 fragBuilder->codeAppendf(
1122 "float alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));"); 1110 "float alpha = (1.0 + max(xSub, -1.0)) * (1.0 + max(ySub, -1.0));");
1123 } else if (de.aaMode() == kMSAA_DashAAMode) { 1111 } else if (de.aaMode() == AAMode::kCoverageWithMSAA) {
1124 // For MSAA, we don't modulate the alpha by the Y distance, since MSAA c overage will handle 1112 // For MSAA, we don't modulate the alpha by the Y distance, since MSAA c overage will handle
1125 // AA on the the top and bottom edges. The shader is only responsible fo r intra-dash alpha. 1113 // AA on the the top and bottom edges. The shader is only responsible fo r intra-dash alpha.
1126 fragBuilder->codeAppend("float xSub;"); 1114 fragBuilder->codeAppend("float xSub;");
1127 fragBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", in RectParams.fsIn()); 1115 fragBuilder->codeAppendf("xSub = min(fragPosShifted.x - %s.x, 0.0);", in RectParams.fsIn());
1128 fragBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", i nRectParams.fsIn()); 1116 fragBuilder->codeAppendf("xSub += min(%s.z - fragPosShifted.x, 0.0);", i nRectParams.fsIn());
1129 // Now compute coverage in x to get the fraction of the pixel covered. 1117 // Now compute coverage in x to get the fraction of the pixel covered.
1130 fragBuilder->codeAppendf("float alpha = (1.0 + max(xSub, -1.0));"); 1118 fragBuilder->codeAppendf("float alpha = (1.0 + max(xSub, -1.0));");
1131 } else { 1119 } else {
1132 // Assuming the bounding geometry is tight so no need to check y values 1120 // Assuming the bounding geometry is tight so no need to check y values
1133 fragBuilder->codeAppendf("float alpha = 1.0;"); 1121 fragBuilder->codeAppendf("float alpha = 1.0;");
(...skipping 16 matching lines...) Expand all
1150 } 1138 }
1151 } 1139 }
1152 1140
1153 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp, 1141 void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp,
1154 const GrGLSLCaps&, 1142 const GrGLSLCaps&,
1155 GrProcessorKeyBuilder* b) { 1143 GrProcessorKeyBuilder* b) {
1156 const DashingLineEffect& de = gp.cast<DashingLineEffect>(); 1144 const DashingLineEffect& de = gp.cast<DashingLineEffect>();
1157 uint32_t key = 0; 1145 uint32_t key = 0;
1158 key |= de.usesLocalCoords() && de.localMatrix().hasPerspective() ? 0x1 : 0x0 ; 1146 key |= de.usesLocalCoords() && de.localMatrix().hasPerspective() ? 0x1 : 0x0 ;
1159 key |= de.colorIgnored() ? 0x2 : 0x0; 1147 key |= de.colorIgnored() ? 0x2 : 0x0;
1160 key |= de.aaMode() << 8; 1148 key |= static_cast<int>(de.aaMode()) << 8;
1161 b->add32(key); 1149 b->add32(key);
1162 } 1150 }
1163 1151
1164 ////////////////////////////////////////////////////////////////////////////// 1152 //////////////////////////////////////////////////////////////////////////////
1165 1153
1166 GrGeometryProcessor* DashingLineEffect::Create(GrColor color, 1154 GrGeometryProcessor* DashingLineEffect::Create(GrColor color,
1167 DashAAMode aaMode, 1155 AAMode aaMode,
1168 const SkMatrix& localMatrix, 1156 const SkMatrix& localMatrix,
1169 bool usesLocalCoords) { 1157 bool usesLocalCoords) {
1170 return new DashingLineEffect(color, aaMode, localMatrix, usesLocalCoords); 1158 return new DashingLineEffect(color, aaMode, localMatrix, usesLocalCoords);
1171 } 1159 }
1172 1160
1173 void DashingLineEffect::getGLSLProcessorKey(const GrGLSLCaps& caps, 1161 void DashingLineEffect::getGLSLProcessorKey(const GrGLSLCaps& caps,
1174 GrProcessorKeyBuilder* b) const { 1162 GrProcessorKeyBuilder* b) const {
1175 GLDashingLineEffect::GenKey(*this, caps, b); 1163 GLDashingLineEffect::GenKey(*this, caps, b);
1176 } 1164 }
1177 1165
1178 GrGLSLPrimitiveProcessor* DashingLineEffect::createGLSLInstance(const GrGLSLCaps &) const { 1166 GrGLSLPrimitiveProcessor* DashingLineEffect::createGLSLInstance(const GrGLSLCaps &) const {
1179 return new GLDashingLineEffect(); 1167 return new GLDashingLineEffect();
1180 } 1168 }
1181 1169
1182 DashingLineEffect::DashingLineEffect(GrColor color, 1170 DashingLineEffect::DashingLineEffect(GrColor color,
1183 DashAAMode aaMode, 1171 AAMode aaMode,
1184 const SkMatrix& localMatrix, 1172 const SkMatrix& localMatrix,
1185 bool usesLocalCoords) 1173 bool usesLocalCoords)
1186 : fColor(color) 1174 : fColor(color)
1187 , fLocalMatrix(localMatrix) 1175 , fLocalMatrix(localMatrix)
1188 , fUsesLocalCoords(usesLocalCoords) 1176 , fUsesLocalCoords(usesLocalCoords)
1189 , fAAMode(aaMode) { 1177 , fAAMode(aaMode) {
1190 this->initClassID<DashingLineEffect>(); 1178 this->initClassID<DashingLineEffect>();
1191 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType)); 1179 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertex AttribType));
1192 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType)); 1180 fInDashParams = &this->addVertexAttrib(Attribute("inDashParams", kVec3f_GrVe rtexAttribType));
1193 fInRectParams = &this->addVertexAttrib(Attribute("inRect", kVec4f_GrVertexAt tribType)); 1181 fInRectParams = &this->addVertexAttrib(Attribute("inRect", kVec4f_GrVertexAt tribType));
1194 } 1182 }
1195 1183
1196 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); 1184 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect);
1197 1185
1198 const GrGeometryProcessor* DashingLineEffect::TestCreate(GrProcessorTestData* d) { 1186 const GrGeometryProcessor* DashingLineEffect::TestCreate(GrProcessorTestData* d) {
1199 DashAAMode aaMode = static_cast<DashAAMode>(d->fRandom->nextULessThan(kDashA AModeCount)); 1187 AAMode aaMode = static_cast<AAMode>(d->fRandom->nextULessThan(GrDashingEffec t::kAAModeCnt));
1200 return DashingLineEffect::Create(GrRandomColor(d->fRandom), 1188 return DashingLineEffect::Create(GrRandomColor(d->fRandom),
1201 aaMode, GrTest::TestMatrix(d->fRandom), 1189 aaMode, GrTest::TestMatrix(d->fRandom),
1202 d->fRandom->nextBool()); 1190 d->fRandom->nextBool());
1203 } 1191 }
1204 1192
1205 ////////////////////////////////////////////////////////////////////////////// 1193 //////////////////////////////////////////////////////////////////////////////
1206 1194
1207 static GrGeometryProcessor* create_dash_gp(GrColor color, 1195 static GrGeometryProcessor* create_dash_gp(GrColor color,
1208 DashAAMode dashAAMode, 1196 AAMode aaMode,
1209 DashCap cap, 1197 DashCap cap,
1210 const SkMatrix& viewMatrix, 1198 const SkMatrix& viewMatrix,
1211 bool usesLocalCoords) { 1199 bool usesLocalCoords) {
1212 SkMatrix invert; 1200 SkMatrix invert;
1213 if (usesLocalCoords && !viewMatrix.invert(&invert)) { 1201 if (usesLocalCoords && !viewMatrix.invert(&invert)) {
1214 SkDebugf("Failed to invert\n"); 1202 SkDebugf("Failed to invert\n");
1215 return nullptr; 1203 return nullptr;
1216 } 1204 }
1217 1205
1218 switch (cap) { 1206 switch (cap) {
1219 case kRound_DashCap: 1207 case kRound_DashCap:
1220 return DashingCircleEffect::Create(color, dashAAMode, invert, usesLo calCoords); 1208 return DashingCircleEffect::Create(color, aaMode, invert, usesLocalC oords);
1221 case kNonRound_DashCap: 1209 case kNonRound_DashCap:
1222 return DashingLineEffect::Create(color, dashAAMode, invert, usesLoca lCoords); 1210 return DashingLineEffect::Create(color, aaMode, invert, usesLocalCoo rds);
1223 } 1211 }
1224 return nullptr; 1212 return nullptr;
1225 } 1213 }
1226 1214
1227 //////////////////////////////////////////////////////////////////////////////// ///////////////// 1215 //////////////////////////////////////////////////////////////////////////////// /////////////////
1228 1216
1229 #ifdef GR_TEST_UTILS 1217 #ifdef GR_TEST_UTILS
1230 1218
1231 DRAW_BATCH_TEST_DEFINE(DashBatch) { 1219 DRAW_BATCH_TEST_DEFINE(DashBatch) {
1232 GrColor color = GrRandomColor(random); 1220 GrColor color = GrRandomColor(random);
1233 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); 1221 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random);
1234 bool useAA = random->nextBool(); 1222 AAMode aaMode = static_cast<AAMode>(random->nextULessThan(GrDashingEffect::k AAModeCnt));
1235 bool msaaRT = random->nextBool();
1236 1223
1237 // We can only dash either horizontal or vertical lines 1224 // We can only dash either horizontal or vertical lines
1238 SkPoint pts[2]; 1225 SkPoint pts[2];
1239 if (random->nextBool()) { 1226 if (random->nextBool()) {
1240 // vertical 1227 // vertical
1241 pts[0].fX = 1.f; 1228 pts[0].fX = 1.f;
1242 pts[0].fY = random->nextF() * 10.f; 1229 pts[0].fY = random->nextF() * 10.f;
1243 pts[1].fX = 1.f; 1230 pts[1].fX = 1.f;
1244 pts[1].fY = random->nextF() * 10.f; 1231 pts[1].fY = random->nextF() * 10.f;
1245 } else { 1232 } else {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 SkScalar phase = random->nextRangeScalar(0, intervals[0] + intervals[1]); 1274 SkScalar phase = random->nextRangeScalar(0, intervals[0] + intervals[1]);
1288 1275
1289 SkPaint p; 1276 SkPaint p;
1290 p.setStyle(SkPaint::kStroke_Style); 1277 p.setStyle(SkPaint::kStroke_Style);
1291 p.setStrokeWidth(SkIntToScalar(1)); 1278 p.setStrokeWidth(SkIntToScalar(1));
1292 p.setStrokeCap(cap); 1279 p.setStrokeCap(cap);
1293 p.setPathEffect(GrTest::TestDashPathEffect::Make(intervals, 2, phase)); 1280 p.setPathEffect(GrTest::TestDashPathEffect::Make(intervals, 2, phase));
1294 1281
1295 GrStyle style(p); 1282 GrStyle style(p);
1296 1283
1297 return create_batch(color, viewMatrix, pts, useAA, style, msaaRT); 1284 return GrDashingEffect::CreateDashLineBatch(color, viewMatrix, pts, aaMode, style);
1298 } 1285 }
1299 1286
1300 #endif 1287 #endif
OLDNEW
« src/gpu/batches/GrDashLinePathRenderer.cpp ('K') | « src/gpu/effects/GrDashingEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698