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 10 matching lines...) Expand all Loading... |
21 #include "GrStrokeInfo.h" | 21 #include "GrStrokeInfo.h" |
22 #include "SkGr.h" | 22 #include "SkGr.h" |
23 #include "gl/GrGLGeometryProcessor.h" | 23 #include "gl/GrGLGeometryProcessor.h" |
24 #include "gl/GrGLProcessor.h" | 24 #include "gl/GrGLProcessor.h" |
25 #include "gl/GrGLSL.h" | 25 #include "gl/GrGLSL.h" |
26 #include "gl/builders/GrGLProgramBuilder.h" | 26 #include "gl/builders/GrGLProgramBuilder.h" |
27 | 27 |
28 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
29 | 29 |
30 // Returns whether or not the gpu can fast path the dash line effect. | 30 // Returns whether or not the gpu can fast path the dash line effect. |
31 static bool can_fast_path_dash(const SkPoint pts[2], const GrStrokeInfo& strokeI
nfo, | 31 bool GrDashingEffect::CanDrawDashLine(const SkPoint pts[2], const GrStrokeInfo&
strokeInfo, |
32 const GrDrawTarget& target, const GrPipelineBuild
er& pipelineBuilder, | 32 const SkMatrix& viewMatrix) { |
33 const SkMatrix& viewMatrix) { | |
34 // Pts must be either horizontal or vertical in src space | 33 // Pts must be either horizontal or vertical in src space |
35 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) { |
36 return false; | 35 return false; |
37 } | 36 } |
38 | 37 |
39 // 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 |
40 // because of the non uniform scaling of bloating a rect | 39 // because of the non uniform scaling of bloating a rect |
41 if (!viewMatrix.preservesRightAngles()) { | 40 if (!viewMatrix.preservesRightAngles()) { |
42 return false; | 41 return false; |
43 } | 42 } |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 static const int kIndicesPerDash = 6; | 695 static const int kIndicesPerDash = 6; |
697 | 696 |
698 BatchTracker fBatch; | 697 BatchTracker fBatch; |
699 SkSTArray<1, Geometry, true> fGeoData; | 698 SkSTArray<1, Geometry, true> fGeoData; |
700 }; | 699 }; |
701 | 700 |
702 | 701 |
703 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, | 702 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, |
704 GrPipelineBuilder* pipelineBuilder, GrColor c
olor, | 703 GrPipelineBuilder* pipelineBuilder, GrColor c
olor, |
705 const SkMatrix& viewMatrix, const SkPoint pts
[2], | 704 const SkMatrix& viewMatrix, const SkPoint pts
[2], |
706 const GrPaint& paint, const GrStrokeInfo& str
okeInfo) { | 705 bool useAA, const GrStrokeInfo& strokeInfo) { |
707 if (!can_fast_path_dash(pts, strokeInfo, *target, *pipelineBuilder, viewMatr
ix)) { | |
708 return false; | |
709 } | |
710 | |
711 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); | 706 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
712 | 707 |
713 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); | 708 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); |
714 | 709 |
715 DashBatch::Geometry geometry; | 710 DashBatch::Geometry geometry; |
716 geometry.fSrcStrokeWidth = strokeInfo.getStrokeRec().getWidth(); | 711 geometry.fSrcStrokeWidth = strokeInfo.getStrokeRec().getWidth(); |
717 | 712 |
718 // the phase should be normalized to be [0, sum of all intervals) | 713 // the phase should be normalized to be [0, sum of all intervals) |
719 SkASSERT(info.fPhase >= 0 && info.fPhase < info.fIntervals[0] + info.fInterv
als[1]); | 714 SkASSERT(info.fPhase >= 0 && info.fPhase < info.fIntervals[0] + info.fInterv
als[1]); |
720 | 715 |
(...skipping 16 matching lines...) Expand all Loading... |
737 | 732 |
738 SkScalar offInterval = info.fIntervals[1] * geometry.fParallelScale; | 733 SkScalar offInterval = info.fIntervals[1] * geometry.fParallelScale; |
739 SkScalar strokeWidth = geometry.fSrcStrokeWidth * geometry.fPerpendicularSca
le; | 734 SkScalar strokeWidth = geometry.fSrcStrokeWidth * geometry.fPerpendicularSca
le; |
740 | 735 |
741 if (SkPaint::kSquare_Cap == cap && 0 != geometry.fSrcStrokeWidth) { | 736 if (SkPaint::kSquare_Cap == cap && 0 != geometry.fSrcStrokeWidth) { |
742 // add cap to on interveal and remove from off interval | 737 // add cap to on interveal and remove from off interval |
743 offInterval -= strokeWidth; | 738 offInterval -= strokeWidth; |
744 } | 739 } |
745 | 740 |
746 DashAAMode aaMode = pipelineBuilder->getRenderTarget()->isMultisampled() ? k
MSAA_DashAAMode : | 741 DashAAMode aaMode = pipelineBuilder->getRenderTarget()->isMultisampled() ? k
MSAA_DashAAMode : |
747 paint.isAntiAlias() ? kEdgeAA_DashAAMode : | 742 useAA ? kEdgeAA_DashAAMode : kBW_DashAAMode; |
748 kBW_DashAAMode; | |
749 | 743 |
750 // TODO we can do a real rect call if not using fulldash(ie no off interval,
not using AA) | 744 // TODO we can do a real rect call if not using fulldash(ie no off interval,
not using AA) |
751 bool fullDash = offInterval > 0.f || aaMode != kBW_DashAAMode; | 745 bool fullDash = offInterval > 0.f || aaMode != kBW_DashAAMode; |
752 | 746 |
753 geometry.fColor = color; | 747 geometry.fColor = color; |
754 geometry.fViewMatrix = viewMatrix; | 748 geometry.fViewMatrix = viewMatrix; |
755 geometry.fPhase = info.fPhase; | 749 geometry.fPhase = info.fPhase; |
756 geometry.fIntervals[0] = info.fIntervals[0]; | 750 geometry.fIntervals[0] = info.fIntervals[0]; |
757 geometry.fIntervals[1] = info.fIntervals[1]; | 751 geometry.fIntervals[1] = info.fIntervals[1]; |
758 | 752 |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 switch (cap) { | 1272 switch (cap) { |
1279 case kRound_DashCap: | 1273 case kRound_DashCap: |
1280 return DashingCircleEffect::Create(color, dashAAMode, localMatrix); | 1274 return DashingCircleEffect::Create(color, dashAAMode, localMatrix); |
1281 case kNonRound_DashCap: | 1275 case kNonRound_DashCap: |
1282 return DashingLineEffect::Create(color, dashAAMode, localMatrix); | 1276 return DashingLineEffect::Create(color, dashAAMode, localMatrix); |
1283 default: | 1277 default: |
1284 SkFAIL("Unexpected dashed cap."); | 1278 SkFAIL("Unexpected dashed cap."); |
1285 } | 1279 } |
1286 return NULL; | 1280 return NULL; |
1287 } | 1281 } |
OLD | NEW |