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 "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 viewMatrix.mapVectors(&vecSrcPerp, 1); | 96 viewMatrix.mapVectors(&vecSrcPerp, 1); |
97 | 97 |
98 // parallelScale tells how much to scale along the line parallel to the dash
line | 98 // parallelScale tells how much to scale along the line parallel to the dash
line |
99 // perpScale tells how much to scale in the direction perpendicular to the d
ash line | 99 // perpScale tells how much to scale in the direction perpendicular to the d
ash line |
100 *parallelScale = vecSrc.length(); | 100 *parallelScale = vecSrc.length(); |
101 *perpScale = vecSrcPerp.length(); | 101 *perpScale = vecSrcPerp.length(); |
102 } | 102 } |
103 | 103 |
104 // calculates the rotation needed to aligned pts to the x axis with pts[0] < pts
[1] | 104 // calculates the rotation needed to aligned pts to the x axis with pts[0] < pts
[1] |
105 // Stores the rotation matrix in rotMatrix, and the mapped points in ptsRot | 105 // Stores the rotation matrix in rotMatrix, and the mapped points in ptsRot |
106 static void align_to_x_axis(const SkPoint pts[2], SkMatrix* rotMatrix, SkPoint p
tsRot[2] = NULL) { | 106 static void align_to_x_axis(const SkPoint pts[2], SkMatrix* rotMatrix, SkPoint p
tsRot[2] = nullptr) { |
107 SkVector vec = pts[1] - pts[0]; | 107 SkVector vec = pts[1] - pts[0]; |
108 SkScalar mag = vec.length(); | 108 SkScalar mag = vec.length(); |
109 SkScalar inv = mag ? SkScalarInvert(mag) : 0; | 109 SkScalar inv = mag ? SkScalarInvert(mag) : 0; |
110 | 110 |
111 vec.scale(inv); | 111 vec.scale(inv); |
112 rotMatrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); | 112 rotMatrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY); |
113 if (ptsRot) { | 113 if (ptsRot) { |
114 rotMatrix->mapPoints(ptsRot, pts, 2); | 114 rotMatrix->mapPoints(ptsRot, pts, 2); |
115 // correction for numerical issues if map doesn't make ptsRot exactly ho
rizontal | 115 // correction for numerical issues if map doesn't make ptsRot exactly ho
rizontal |
116 ptsRot[1].fY = pts[0].fY; | 116 ptsRot[1].fY = pts[0].fY; |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 | 688 |
689 // the phase should be normalized to be [0, sum of all intervals) | 689 // the phase should be normalized to be [0, sum of all intervals) |
690 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]); | 690 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]); |
691 | 691 |
692 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[
1].fX | 692 // Rotate the src pts so they are aligned horizontally with pts[0].fX < pts[
1].fX |
693 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) { | 693 if (pts[0].fY != pts[1].fY || pts[0].fX > pts[1].fX) { |
694 SkMatrix rotMatrix; | 694 SkMatrix rotMatrix; |
695 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot); | 695 align_to_x_axis(pts, &rotMatrix, geometry.fPtsRot); |
696 if(!rotMatrix.invert(&geometry.fSrcRotInv)) { | 696 if(!rotMatrix.invert(&geometry.fSrcRotInv)) { |
697 SkDebugf("Failed to create invertible rotation matrix!\n"); | 697 SkDebugf("Failed to create invertible rotation matrix!\n"); |
698 return NULL; | 698 return nullptr; |
699 } | 699 } |
700 } else { | 700 } else { |
701 geometry.fSrcRotInv.reset(); | 701 geometry.fSrcRotInv.reset(); |
702 memcpy(geometry.fPtsRot, pts, 2 * sizeof(SkPoint)); | 702 memcpy(geometry.fPtsRot, pts, 2 * sizeof(SkPoint)); |
703 } | 703 } |
704 | 704 |
705 // Scale corrections of intervals and stroke from view matrix | 705 // Scale corrections of intervals and stroke from view matrix |
706 calc_dash_scaling(&geometry.fParallelScale, &geometry.fPerpendicularScale, v
iewMatrix, | 706 calc_dash_scaling(&geometry.fParallelScale, &geometry.fPerpendicularScale, v
iewMatrix, |
707 geometry.fPtsRot); | 707 geometry.fPtsRot); |
708 | 708 |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 ////////////////////////////////////////////////////////////////////////////// | 1205 ////////////////////////////////////////////////////////////////////////////// |
1206 | 1206 |
1207 static GrGeometryProcessor* create_dash_gp(GrColor color, | 1207 static GrGeometryProcessor* create_dash_gp(GrColor color, |
1208 DashAAMode dashAAMode, | 1208 DashAAMode dashAAMode, |
1209 DashCap cap, | 1209 DashCap cap, |
1210 const SkMatrix& viewMatrix, | 1210 const SkMatrix& viewMatrix, |
1211 bool usesLocalCoords) { | 1211 bool usesLocalCoords) { |
1212 SkMatrix invert; | 1212 SkMatrix invert; |
1213 if (usesLocalCoords && !viewMatrix.invert(&invert)) { | 1213 if (usesLocalCoords && !viewMatrix.invert(&invert)) { |
1214 SkDebugf("Failed to invert\n"); | 1214 SkDebugf("Failed to invert\n"); |
1215 return NULL; | 1215 return nullptr; |
1216 } | 1216 } |
1217 | 1217 |
1218 switch (cap) { | 1218 switch (cap) { |
1219 case kRound_DashCap: | 1219 case kRound_DashCap: |
1220 return DashingCircleEffect::Create(color, dashAAMode, invert, usesLo
calCoords); | 1220 return DashingCircleEffect::Create(color, dashAAMode, invert, usesLo
calCoords); |
1221 case kNonRound_DashCap: | 1221 case kNonRound_DashCap: |
1222 return DashingLineEffect::Create(color, dashAAMode, invert, usesLoca
lCoords); | 1222 return DashingLineEffect::Create(color, dashAAMode, invert, usesLoca
lCoords); |
1223 } | 1223 } |
1224 return NULL; | 1224 return nullptr; |
1225 } | 1225 } |
1226 | 1226 |
1227 ////////////////////////////////////////////////////////////////////////////////
///////////////// | 1227 ////////////////////////////////////////////////////////////////////////////////
///////////////// |
1228 | 1228 |
1229 #ifdef GR_TEST_UTILS | 1229 #ifdef GR_TEST_UTILS |
1230 | 1230 |
1231 DRAW_BATCH_TEST_DEFINE(DashBatch) { | 1231 DRAW_BATCH_TEST_DEFINE(DashBatch) { |
1232 GrColor color = GrRandomColor(random); | 1232 GrColor color = GrRandomColor(random); |
1233 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); | 1233 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); |
1234 bool useAA = random->nextBool(); | 1234 bool useAA = random->nextBool(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 info.fIntervals = intervals; | 1297 info.fIntervals = intervals; |
1298 info.fCount = 2; | 1298 info.fCount = 2; |
1299 info.fPhase = phase; | 1299 info.fPhase = phase; |
1300 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1300 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
1301 SkASSERT(success); | 1301 SkASSERT(success); |
1302 | 1302 |
1303 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1303 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
1304 } | 1304 } |
1305 | 1305 |
1306 #endif | 1306 #endif |
OLD | NEW |