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 23 matching lines...) Expand all Loading... |
34 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { | 34 if (pts[0].fX != pts[1].fX && pts[0].fY != pts[1].fY) { |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 // May be able to relax this to include skew. As of now cannot do perspectiv
e | 38 // May be able to relax this to include skew. As of now cannot do perspectiv
e |
39 // because of the non uniform scaling of bloating a rect | 39 // because of the non uniform scaling of bloating a rect |
40 if (!viewMatrix.preservesRightAngles()) { | 40 if (!viewMatrix.preservesRightAngles()) { |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 if (!strokeInfo.isDashed() || 2 != strokeInfo.dashCount()) { | 44 if (!strokeInfo.isDashed() || 2 != strokeInfo.getDashCount()) { |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
48 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); | 48 const SkScalar* intervals = strokeInfo.getDashIntervals(); |
49 if (0 == info.fIntervals[0] && 0 == info.fIntervals[1]) { | 49 if (0 == intervals[0] && 0 == intervals[1]) { |
50 return false; | 50 return false; |
51 } | 51 } |
52 | 52 |
53 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); | 53 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); |
54 // Current we do don't handle Round or Square cap dashes | 54 // Current we do don't handle Round or Square cap dashes |
55 if (SkPaint::kRound_Cap == cap && info.fIntervals[0] != 0.f) { | 55 if (SkPaint::kRound_Cap == cap && intervals[0] != 0.f) { |
56 return false; | 56 return false; |
57 } | 57 } |
58 | 58 |
59 return true; | 59 return true; |
60 } | 60 } |
61 | 61 |
62 namespace { | 62 namespace { |
63 struct DashLineVertex { | 63 struct DashLineVertex { |
64 SkPoint fPos; | 64 SkPoint fPos; |
65 SkPoint fDashPos; | 65 SkPoint fDashPos; |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 | 696 |
697 BatchTracker fBatch; | 697 BatchTracker fBatch; |
698 SkSTArray<1, Geometry, true> fGeoData; | 698 SkSTArray<1, Geometry, true> fGeoData; |
699 }; | 699 }; |
700 | 700 |
701 | 701 |
702 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, | 702 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, |
703 GrPipelineBuilder* pipelineBuilder, GrColor c
olor, | 703 GrPipelineBuilder* pipelineBuilder, GrColor c
olor, |
704 const SkMatrix& viewMatrix, const SkPoint pts
[2], | 704 const SkMatrix& viewMatrix, const SkPoint pts
[2], |
705 bool useAA, const GrStrokeInfo& strokeInfo) { | 705 bool useAA, const GrStrokeInfo& strokeInfo) { |
706 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); | 706 const SkScalar* intervals = strokeInfo.getDashIntervals(); |
| 707 SkScalar phase = strokeInfo.getDashPhase(); |
707 | 708 |
708 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); | 709 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); |
709 | 710 |
710 DashBatch::Geometry geometry; | 711 DashBatch::Geometry geometry; |
711 geometry.fSrcStrokeWidth = strokeInfo.getStrokeRec().getWidth(); | 712 geometry.fSrcStrokeWidth = strokeInfo.getStrokeRec().getWidth(); |
712 | 713 |
713 // the phase should be normalized to be [0, sum of all intervals) | 714 // the phase should be normalized to be [0, sum of all intervals) |
714 SkASSERT(info.fPhase >= 0 && info.fPhase < info.fIntervals[0] + info.fInterv
als[1]); | 715 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]); |
715 | 716 |
716 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[
1].fX | 717 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[
1].fX |
717 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) { | 718 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) { |
718 SkMatrix rotMatrix; | 719 SkMatrix rotMatrix; |
719 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot); | 720 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot); |
720 if(!rotMatrix.invert(&geometry.fSrcRotInv)) { | 721 if(!rotMatrix.invert(&geometry.fSrcRotInv)) { |
721 SkDebugf("Failed to create invertible rotation matrix!\n"); | 722 SkDebugf("Failed to create invertible rotation matrix!\n"); |
722 return false; | 723 return false; |
723 } | 724 } |
724 } else { | 725 } else { |
725 geometry.fSrcRotInv.reset(); | 726 geometry.fSrcRotInv.reset(); |
726 memcpy(geometry.fPtsRot, pts, 2 * sizeof(SkPoint)); | 727 memcpy(geometry.fPtsRot, pts, 2 * sizeof(SkPoint)); |
727 } | 728 } |
728 | 729 |
729 // Scale corrections of intervals and stroke from view matrix | 730 // Scale corrections of intervals and stroke from view matrix |
730 calc_dash_scaling(&geometry.fParallelScale, &geometry.fPerpendicularScale, v
iewMatrix, | 731 calc_dash_scaling(&geometry.fParallelScale, &geometry.fPerpendicularScale, v
iewMatrix, |
731 geometry.fPtsRot); | 732 geometry.fPtsRot); |
732 | 733 |
733 SkScalar offInterval = info.fIntervals[1] * geometry.fParallelScale; | 734 SkScalar offInterval = intervals[1] * geometry.fParallelScale; |
734 SkScalar strokeWidth = geometry.fSrcStrokeWidth * geometry.fPerpendicularSca
le; | 735 SkScalar strokeWidth = geometry.fSrcStrokeWidth * geometry.fPerpendicularSca
le; |
735 | 736 |
736 if (SkPaint::kSquare_Cap == cap && 0 != geometry.fSrcStrokeWidth) { | 737 if (SkPaint::kSquare_Cap == cap && 0 != geometry.fSrcStrokeWidth) { |
737 // add cap to on interveal and remove from off interval | 738 // add cap to on interveal and remove from off interval |
738 offInterval -= strokeWidth; | 739 offInterval -= strokeWidth; |
739 } | 740 } |
740 | 741 |
741 DashAAMode aaMode = pipelineBuilder->getRenderTarget()->isMultisampled() ? k
MSAA_DashAAMode : | 742 DashAAMode aaMode = pipelineBuilder->getRenderTarget()->isMultisampled() ? k
MSAA_DashAAMode : |
742 useAA ? kEdgeAA_DashAAMode : kBW_DashAAMode; | 743 useAA ? kEdgeAA_DashAAMode : kBW_DashAAMode; |
743 | 744 |
744 // TODO we can do a real rect call if not using fulldash(ie no off interval,
not using AA) | 745 // TODO we can do a real rect call if not using fulldash(ie no off interval,
not using AA) |
745 bool fullDash = offInterval > 0.f || aaMode != kBW_DashAAMode; | 746 bool fullDash = offInterval > 0.f || aaMode != kBW_DashAAMode; |
746 | 747 |
747 geometry.fColor = color; | 748 geometry.fColor = color; |
748 geometry.fViewMatrix = viewMatrix; | 749 geometry.fViewMatrix = viewMatrix; |
749 geometry.fPhase = info.fPhase; | 750 geometry.fPhase = phase; |
750 geometry.fIntervals[0] = info.fIntervals[0]; | 751 geometry.fIntervals[0] = intervals[0]; |
751 geometry.fIntervals[1] = info.fIntervals[1]; | 752 geometry.fIntervals[1] = intervals[1]; |
752 | 753 |
753 SkAutoTUnref<GrBatch> batch(DashBatch::Create(geometry, cap, aaMode, fullDas
h)); | 754 SkAutoTUnref<GrBatch> batch(DashBatch::Create(geometry, cap, aaMode, fullDas
h)); |
754 target->drawBatch(pipelineBuilder, batch); | 755 target->drawBatch(pipelineBuilder, batch); |
755 | 756 |
756 return true; | 757 return true; |
757 } | 758 } |
758 | 759 |
759 ////////////////////////////////////////////////////////////////////////////// | 760 ////////////////////////////////////////////////////////////////////////////// |
760 | 761 |
761 class GLDashingCircleEffect; | 762 class GLDashingCircleEffect; |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 switch (cap) { | 1273 switch (cap) { |
1273 case kRound_DashCap: | 1274 case kRound_DashCap: |
1274 return DashingCircleEffect::Create(color, dashAAMode, localMatrix); | 1275 return DashingCircleEffect::Create(color, dashAAMode, localMatrix); |
1275 case kNonRound_DashCap: | 1276 case kNonRound_DashCap: |
1276 return DashingLineEffect::Create(color, dashAAMode, localMatrix); | 1277 return DashingLineEffect::Create(color, dashAAMode, localMatrix); |
1277 default: | 1278 default: |
1278 SkFAIL("Unexpected dashed cap."); | 1279 SkFAIL("Unexpected dashed cap."); |
1279 } | 1280 } |
1280 return NULL; | 1281 return NULL; |
1281 } | 1282 } |
OLD | NEW |