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

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

Issue 1110093002: Avoid using SkPathEffect::DashInfo in GrStrokeInfo (Closed) Base URL: https://skia.googlesource.com/skia.git@dashing-nvpr
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrStrokeInfo.cpp ('k') | no next file » | 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 25 matching lines...) Expand all
36 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { 36 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) {
37 return false; 37 return false;
38 } 38 }
39 39
40 // May be able to relax this to include skew. As of now cannot do perspectiv e 40 // May be able to relax this to include skew. As of now cannot do perspectiv e
41 // because of the non uniform scaling of bloating a rect 41 // because of the non uniform scaling of bloating a rect
42 if (!viewMatrix.preservesRightAngles()) { 42 if (!viewMatrix.preservesRightAngles()) {
43 return false; 43 return false;
44 } 44 }
45 45
46 if (!strokeInfo.isDashed() || 2 != strokeInfo.dashCount()) { 46 if (!strokeInfo.isDashed() || 2 != strokeInfo.getDashCount()) {
47 return false; 47 return false;
48 } 48 }
49 49
50 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); 50 const SkScalar* intervals = strokeInfo.getDashIntervals();
51 if (0 == info.fIntervals[0] && 0 == info.fIntervals[1]) { 51 if (0 == intervals[0] && 0 == intervals[1]) {
52 return false; 52 return false;
53 } 53 }
54 54
55 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); 55 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap();
56 // Current we do don't handle Round or Square cap dashes 56 // Current we do don't handle Round or Square cap dashes
57 if (SkPaint::kRound_Cap == cap && info.fIntervals[0] != 0.f) { 57 if (SkPaint::kRound_Cap == cap && intervals[0] != 0.f) {
58 return false; 58 return false;
59 } 59 }
60 60
61 return true; 61 return true;
62 } 62 }
63 63
64 namespace { 64 namespace {
65 struct DashLineVertex { 65 struct DashLineVertex {
66 SkPoint fPos; 66 SkPoint fPos;
67 SkPoint fDashPos; 67 SkPoint fDashPos;
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 704
705 static const int kVertsPerDash = 4; 705 static const int kVertsPerDash = 4;
706 static const int kIndicesPerDash = 6; 706 static const int kIndicesPerDash = 6;
707 707
708 BatchTracker fBatch; 708 BatchTracker fBatch;
709 SkSTArray<1, Geometry, true> fGeoData; 709 SkSTArray<1, Geometry, true> fGeoData;
710 }; 710 };
711 711
712 static GrBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, const Sk Point pts[2], 712 static GrBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, const Sk Point pts[2],
713 bool useAA, const GrStrokeInfo& strokeInfo, bool ms aaRT) { 713 bool useAA, const GrStrokeInfo& strokeInfo, bool ms aaRT) {
714 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); 714 const SkScalar* intervals = strokeInfo.getDashIntervals();
715 SkScalar phase = strokeInfo.getDashPhase();
715 716
716 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); 717 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap();
717 718
718 DashBatch::Geometry geometry; 719 DashBatch::Geometry geometry;
719 geometry.fSrcStrokeWidth = strokeInfo.getStrokeRec().getWidth(); 720 geometry.fSrcStrokeWidth = strokeInfo.getStrokeRec().getWidth();
720 721
721 // the phase should be normalized to be [0, sum of all intervals) 722 // the phase should be normalized to be [0, sum of all intervals)
722 SkASSERT(info.fPhase >= 0 && info.fPhase < info.fIntervals[0] + info.fInterv als[1]); 723 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]);
723 724
724 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[ 1].fX 725 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[ 1].fX
725 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) { 726 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) {
726 SkMatrix rotMatrix; 727 SkMatrix rotMatrix;
727 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot); 728 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot);
728 if(!rotMatrix.invert(&geometry.fSrcRotInv)) { 729 if(!rotMatrix.invert(&geometry.fSrcRotInv)) {
729 SkDebugf("Failed to create invertible rotation matrix!\n"); 730 SkDebugf("Failed to create invertible rotation matrix!\n");
730 return NULL; 731 return NULL;
731 } 732 }
732 } else { 733 } else {
733 geometry.fSrcRotInv.reset(); 734 geometry.fSrcRotInv.reset();
734 memcpy(geometry.fPtsRot, pts, 2 * sizeof(SkPoint)); 735 memcpy(geometry.fPtsRot, pts, 2 * sizeof(SkPoint));
735 } 736 }
736 737
737 // Scale corrections of intervals and stroke from view matrix 738 // Scale corrections of intervals and stroke from view matrix
738 calc_dash_scaling(&geometry.fParallelScale, &geometry.fPerpendicularScale, v iewMatrix, 739 calc_dash_scaling(&geometry.fParallelScale, &geometry.fPerpendicularScale, v iewMatrix,
739 geometry.fPtsRot); 740 geometry.fPtsRot);
740 741
741 SkScalar offInterval = info.fIntervals[1] * geometry.fParallelScale; 742 SkScalar offInterval = intervals[1] * geometry.fParallelScale;
742 SkScalar strokeWidth = geometry.fSrcStrokeWidth * geometry.fPerpendicularSca le; 743 SkScalar strokeWidth = geometry.fSrcStrokeWidth * geometry.fPerpendicularSca le;
743 744
744 if (SkPaint::kSquare_Cap == cap && 0 != geometry.fSrcStrokeWidth) { 745 if (SkPaint::kSquare_Cap == cap && 0 != geometry.fSrcStrokeWidth) {
745 // add cap to on interveal and remove from off interval 746 // add cap to on interveal and remove from off interval
746 offInterval -= strokeWidth; 747 offInterval -= strokeWidth;
747 } 748 }
748 749
749 DashAAMode aaMode = msaaRT ? kMSAA_DashAAMode : 750 DashAAMode aaMode = msaaRT ? kMSAA_DashAAMode :
750 useAA ? kEdgeAA_DashAAMode : kBW_DashAAMode; 751 useAA ? kEdgeAA_DashAAMode : kBW_DashAAMode;
751 752
752 // TODO we can do a real rect call if not using fulldash(ie no off interval, not using AA) 753 // TODO we can do a real rect call if not using fulldash(ie no off interval, not using AA)
753 bool fullDash = offInterval > 0.f || aaMode != kBW_DashAAMode; 754 bool fullDash = offInterval > 0.f || aaMode != kBW_DashAAMode;
754 755
755 geometry.fColor = color; 756 geometry.fColor = color;
756 geometry.fViewMatrix = viewMatrix; 757 geometry.fViewMatrix = viewMatrix;
757 geometry.fPhase = info.fPhase; 758 geometry.fPhase = phase;
758 geometry.fIntervals[0] = info.fIntervals[0]; 759 geometry.fIntervals[0] = intervals[0];
759 geometry.fIntervals[1] = info.fIntervals[1]; 760 geometry.fIntervals[1] = intervals[1];
760 761
761 return DashBatch::Create(geometry, cap, aaMode, fullDash); 762 return DashBatch::Create(geometry, cap, aaMode, fullDash);
762 } 763 }
763 764
764 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, 765 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target,
765 GrPipelineBuilder* pipelineBuilder, GrColor c olor, 766 GrPipelineBuilder* pipelineBuilder, GrColor c olor,
766 const SkMatrix& viewMatrix, const SkPoint pts [2], 767 const SkMatrix& viewMatrix, const SkPoint pts [2],
767 bool useAA, const GrStrokeInfo& strokeInfo) { 768 bool useAA, const GrStrokeInfo& strokeInfo) {
768 SkAutoTUnref<GrBatch> batch(create_batch(color, viewMatrix, pts, useAA, stro keInfo, 769 SkAutoTUnref<GrBatch> batch(create_batch(color, viewMatrix, pts, useAA, stro keInfo,
769 pipelineBuilder->getRenderTarget()- >isMultisampled())); 770 pipelineBuilder->getRenderTarget()- >isMultisampled()));
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 info.fIntervals = intervals; 1373 info.fIntervals = intervals;
1373 info.fCount = 2; 1374 info.fCount = 2;
1374 info.fPhase = phase; 1375 info.fPhase = phase;
1375 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); 1376 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info);
1376 SkASSERT(success); 1377 SkASSERT(success);
1377 1378
1378 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); 1379 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT);
1379 } 1380 }
1380 1381
1381 #endif 1382 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrStrokeInfo.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698