| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 44     SkASSERT(tol > 0); | 44     SkASSERT(tol > 0); | 
| 45 | 45 | 
| 46     SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); | 46     SkScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); | 
| 47     if (d <= tol) { | 47     if (d <= tol) { | 
| 48         return 1; | 48         return 1; | 
| 49     } else { | 49     } else { | 
| 50         // Each time we subdivide, d should be cut in 4. So we need to | 50         // 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) | 51         // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x) | 
| 52         // points. | 52         // points. | 
| 53         // 2^(log4(x)) = sqrt(x); | 53         // 2^(log4(x)) = sqrt(x); | 
| 54         int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); | 54         SkScalar divSqrt = SkScalarSqrt(SkScalarDiv(d, tol)); | 
| 55         int pow2 = GrNextPow2(temp); | 55         if (((SkScalar)SK_MaxS32) <= divSqrt) { | 
| 56         // Because of NaNs & INFs we can wind up with a degenerate temp | 56             return MAX_POINTS_PER_CURVE; | 
| 57         // such that pow2 comes out negative. Also, our point generator | 57         } else { | 
| 58         // will always output at least one pt. | 58             int temp = SkScalarCeilToInt(divSqrt); | 
| 59         if (pow2 < 1) { | 59             int pow2 = GrNextPow2(temp); | 
| 60             pow2 = 1; | 60             // Because of NaNs & INFs we can wind up with a degenerate temp | 
|  | 61             // such that pow2 comes out negative. Also, our point generator | 
|  | 62             // will always output at least one pt. | 
|  | 63             if (pow2 < 1) { | 
|  | 64                 pow2 = 1; | 
|  | 65             } | 
|  | 66             return SkTMin(pow2, MAX_POINTS_PER_CURVE); | 
| 61         } | 67         } | 
| 62         return SkTMin(pow2, MAX_POINTS_PER_CURVE); |  | 
| 63     } | 68     } | 
| 64 } | 69 } | 
| 65 | 70 | 
| 66 uint32_t GrPathUtils::generateQuadraticPoints(const SkPoint& p0, | 71 uint32_t GrPathUtils::generateQuadraticPoints(const SkPoint& p0, | 
| 67                                               const SkPoint& p1, | 72                                               const SkPoint& p1, | 
| 68                                               const SkPoint& p2, | 73                                               const SkPoint& p2, | 
| 69                                               SkScalar tolSqd, | 74                                               SkScalar tolSqd, | 
| 70                                               SkPoint** points, | 75                                               SkPoint** points, | 
| 71                                               uint32_t pointsLeft) { | 76                                               uint32_t pointsLeft) { | 
| 72     if (pointsLeft < 2 || | 77     if (pointsLeft < 2 || | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 95     } | 100     } | 
| 96     SkASSERT(tol > 0); | 101     SkASSERT(tol > 0); | 
| 97 | 102 | 
| 98     SkScalar d = SkTMax( | 103     SkScalar d = SkTMax( | 
| 99         points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), | 104         points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), | 
| 100         points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); | 105         points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); | 
| 101     d = SkScalarSqrt(d); | 106     d = SkScalarSqrt(d); | 
| 102     if (d <= tol) { | 107     if (d <= tol) { | 
| 103         return 1; | 108         return 1; | 
| 104     } else { | 109     } else { | 
| 105         int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); | 110         SkScalar divSqrt = SkScalarSqrt(SkScalarDiv(d, tol)); | 
| 106         int pow2 = GrNextPow2(temp); | 111         if (((SkScalar)SK_MaxS32) <= divSqrt) { | 
| 107         // Because of NaNs & INFs we can wind up with a degenerate temp | 112             return MAX_POINTS_PER_CURVE; | 
| 108         // such that pow2 comes out negative. Also, our point generator | 113         } else { | 
| 109         // will always output at least one pt. | 114             int temp = SkScalarCeilToInt(SkScalarSqrt(SkScalarDiv(d, tol))); | 
| 110         if (pow2 < 1) { | 115             int pow2 = GrNextPow2(temp); | 
| 111             pow2 = 1; | 116             // Because of NaNs & INFs we can wind up with a degenerate temp | 
|  | 117             // such that pow2 comes out negative. Also, our point generator | 
|  | 118             // will always output at least one pt. | 
|  | 119             if (pow2 < 1) { | 
|  | 120                 pow2 = 1; | 
|  | 121             } | 
|  | 122             return SkTMin(pow2, MAX_POINTS_PER_CURVE); | 
| 112         } | 123         } | 
| 113         return SkTMin(pow2, MAX_POINTS_PER_CURVE); |  | 
| 114     } | 124     } | 
| 115 } | 125 } | 
| 116 | 126 | 
| 117 uint32_t GrPathUtils::generateCubicPoints(const SkPoint& p0, | 127 uint32_t GrPathUtils::generateCubicPoints(const SkPoint& p0, | 
| 118                                           const SkPoint& p1, | 128                                           const SkPoint& p1, | 
| 119                                           const SkPoint& p2, | 129                                           const SkPoint& p2, | 
| 120                                           const SkPoint& p3, | 130                                           const SkPoint& p3, | 
| 121                                           SkScalar tolSqd, | 131                                           SkScalar tolSqd, | 
| 122                                           SkPoint** points, | 132                                           SkPoint** points, | 
| 123                                           uint32_t pointsLeft) { | 133                                           uint32_t pointsLeft) { | 
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 798         set_loop_klm(d, controlK, controlL, controlM); | 808         set_loop_klm(d, controlK, controlL, controlM); | 
| 799     } else if (kCusp_SkCubicType == cType) { | 809     } else if (kCusp_SkCubicType == cType) { | 
| 800         SkASSERT(0.f == d[0]); | 810         SkASSERT(0.f == d[0]); | 
| 801         set_cusp_klm(d, controlK, controlL, controlM); | 811         set_cusp_klm(d, controlK, controlL, controlM); | 
| 802     } else if (kQuadratic_SkCubicType == cType) { | 812     } else if (kQuadratic_SkCubicType == cType) { | 
| 803         set_quadratic_klm(d, controlK, controlL, controlM); | 813         set_quadratic_klm(d, controlK, controlL, controlM); | 
| 804     } | 814     } | 
| 805 | 815 | 
| 806     calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); | 816     calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); | 
| 807 } | 817 } | 
| OLD | NEW | 
|---|