OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrPathUtils.h" | 8 #include "GrPathUtils.h" |
9 | 9 |
10 #include "GrTypes.h" | 10 #include "GrTypes.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 // take worst case mapRadius amoung four corners. | 22 // take worst case mapRadius amoung four corners. |
23 // (less than perfect) | 23 // (less than perfect) |
24 for (int i = 0; i < 4; ++i) { | 24 for (int i = 0; i < 4; ++i) { |
25 SkMatrix mat; | 25 SkMatrix mat; |
26 mat.setTranslate((i % 2) ? pathBounds.fLeft : pathBounds.fRight, | 26 mat.setTranslate((i % 2) ? pathBounds.fLeft : pathBounds.fRight, |
27 (i < 2) ? pathBounds.fTop : pathBounds.fBottom); | 27 (i < 2) ? pathBounds.fTop : pathBounds.fBottom); |
28 mat.postConcat(viewM); | 28 mat.postConcat(viewM); |
29 stretch = SkMaxScalar(stretch, mat.mapRadius(SK_Scalar1)); | 29 stretch = SkMaxScalar(stretch, mat.mapRadius(SK_Scalar1)); |
30 } | 30 } |
31 } | 31 } |
32 srcTol = SkScalarDiv(srcTol, stretch); | 32 return srcTol / stretch; |
33 return srcTol; | |
34 } | 33 } |
35 | 34 |
36 static const int MAX_POINTS_PER_CURVE = 1 << 10; | 35 static const int MAX_POINTS_PER_CURVE = 1 << 10; |
37 static const SkScalar gMinCurveTol = 0.0001f; | 36 static const SkScalar gMinCurveTol = 0.0001f; |
38 | 37 |
39 uint32_t GrPathUtils::quadraticPointCount(const SkPoint points[], | 38 uint32_t GrPathUtils::quadraticPointCount(const SkPoint points[], |
40 SkScalar tol) { | 39 SkScalar tol) { |
41 if (tol < gMinCurveTol) { | 40 if (tol < gMinCurveTol) { |
42 tol = gMinCurveTol; | 41 tol = gMinCurveTol; |
43 } | 42 } |
44 SkASSERT(tol > 0); | 43 SkASSERT(tol > 0); |
45 | 44 |
46 SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); | 45 SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); |
47 if (d <= tol) { | 46 if (d <= tol) { |
48 return 1; | 47 return 1; |
49 } else { | 48 } else { |
50 // Each time we subdivide, d should be cut in 4. So we need to | 49 // Each time we subdivide, d should be cut in 4. So we need to |
51 // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x) | 50 // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x) |
52 // points. | 51 // points. |
53 // 2^(log4(x)) = sqrt(x); | 52 // 2^(log4(x)) = sqrt(x); |
54 SkScalar divSqrt = SkScalarSqrt(SkScalarDiv(d, tol)); | 53 SkScalar divSqrt = SkScalarSqrt(d / tol); |
55 if (((SkScalar)SK_MaxS32) <= divSqrt) { | 54 if (((SkScalar)SK_MaxS32) <= divSqrt) { |
56 return MAX_POINTS_PER_CURVE; | 55 return MAX_POINTS_PER_CURVE; |
57 } else { | 56 } else { |
58 int temp = SkScalarCeilToInt(divSqrt); | 57 int temp = SkScalarCeilToInt(divSqrt); |
59 int pow2 = GrNextPow2(temp); | 58 int pow2 = GrNextPow2(temp); |
60 // Because of NaNs & INFs we can wind up with a degenerate temp | 59 // Because of NaNs & INFs we can wind up with a degenerate temp |
61 // such that pow2 comes out negative. Also, our point generator | 60 // such that pow2 comes out negative. Also, our point generator |
62 // will always output at least one pt. | 61 // will always output at least one pt. |
63 if (pow2 < 1) { | 62 if (pow2 < 1) { |
64 pow2 = 1; | 63 pow2 = 1; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 99 } |
101 SkASSERT(tol > 0); | 100 SkASSERT(tol > 0); |
102 | 101 |
103 SkScalar d = SkTMax( | 102 SkScalar d = SkTMax( |
104 points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), | 103 points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), |
105 points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); | 104 points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); |
106 d = SkScalarSqrt(d); | 105 d = SkScalarSqrt(d); |
107 if (d <= tol) { | 106 if (d <= tol) { |
108 return 1; | 107 return 1; |
109 } else { | 108 } else { |
110 SkScalar divSqrt = SkScalarSqrt(SkScalarDiv(d, tol)); | 109 SkScalar divSqrt = SkScalarSqrt(d / tol); |
111 if (((SkScalar)SK_MaxS32) <= divSqrt) { | 110 if (((SkScalar)SK_MaxS32) <= divSqrt) { |
112 return MAX_POINTS_PER_CURVE; | 111 return MAX_POINTS_PER_CURVE; |
113 } else { | 112 } else { |
114 int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); | 113 int temp = SkScalarCeilToInt(SkScalarSqrt(d / tol)); |
115 int pow2 = GrNextPow2(temp); | 114 int pow2 = GrNextPow2(temp); |
116 // Because of NaNs & INFs we can wind up with a degenerate temp | 115 // Because of NaNs & INFs we can wind up with a degenerate temp |
117 // such that pow2 comes out negative. Also, our point generator | 116 // such that pow2 comes out negative. Also, our point generator |
118 // will always output at least one pt. | 117 // will always output at least one pt. |
119 if (pow2 < 1) { | 118 if (pow2 < 1) { |
120 pow2 = 1; | 119 pow2 = 1; |
121 } | 120 } |
122 return SkTMin(pow2, MAX_POINTS_PER_CURVE); | 121 return SkTMin(pow2, MAX_POINTS_PER_CURVE); |
123 } | 122 } |
124 } | 123 } |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 set_loop_klm(d, controlK, controlL, controlM); | 807 set_loop_klm(d, controlK, controlL, controlM); |
809 } else if (kCusp_SkCubicType == cType) { | 808 } else if (kCusp_SkCubicType == cType) { |
810 SkASSERT(0.f == d[0]); | 809 SkASSERT(0.f == d[0]); |
811 set_cusp_klm(d, controlK, controlL, controlM); | 810 set_cusp_klm(d, controlK, controlL, controlM); |
812 } else if (kQuadratic_SkCubicType == cType) { | 811 } else if (kQuadratic_SkCubicType == cType) { |
813 set_quadratic_klm(d, controlK, controlL, controlM); | 812 set_quadratic_klm(d, controlK, controlL, controlM); |
814 } | 813 } |
815 | 814 |
816 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); | 815 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); |
817 } | 816 } |
OLD | NEW |