| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 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 "SkStrokerPriv.h" | 8 #include "SkStrokerPriv.h" |
| 9 #include "SkGeometry.h" | 9 #include "SkGeometry.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| 11 | 11 |
| 12 #define kMaxQuadSubdivide 5 | 12 #define kMaxQuadSubdivide 5 |
| 13 #define kMaxCubicSubdivide 4 | 13 #define kMaxCubicSubdivide 7 |
| 14 | 14 |
| 15 static inline bool degenerate_vector(const SkVector& v) { | 15 static inline bool degenerate_vector(const SkVector& v) { |
| 16 return !SkPoint::CanNormalize(v.fX, v.fY); | 16 return !SkPoint::CanNormalize(v.fX, v.fY); |
| 17 } | 17 } |
| 18 | 18 |
| 19 static inline bool normals_too_curvy(const SkVector& norm0, SkVector& norm1) { | 19 static inline bool normals_too_curvy(const SkVector& norm0, SkVector& norm1) { |
| 20 /* root2/2 is a 45-degree angle | 20 /* root2/2 is a 45-degree angle |
| 21 make this constant bigger for more subdivisions (but not >= 1) | 21 make this constant bigger for more subdivisions (but not >= 1) |
| 22 */ | 22 */ |
| 23 static const SkScalar kFlatEnoughNormalDotProd = | 23 static const SkScalar kFlatEnoughNormalDotProd = |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 cd = pts[3] - pts[1]; | 297 cd = pts[3] - pts[1]; |
| 298 degenerateCD = degenerate_vector(cd); | 298 degenerateCD = degenerate_vector(cd); |
| 299 } | 299 } |
| 300 if (degenerateAB || degenerateCD) { | 300 if (degenerateAB || degenerateCD) { |
| 301 goto DRAW_LINE; | 301 goto DRAW_LINE; |
| 302 } | 302 } |
| 303 SkAssertResult(set_normal_unitnormal(cd, fRadius, normalCD, unitNormalCD)); | 303 SkAssertResult(set_normal_unitnormal(cd, fRadius, normalCD, unitNormalCD)); |
| 304 bool degenerateBC = !set_normal_unitnormal(pts[1], pts[2], fRadius, | 304 bool degenerateBC = !set_normal_unitnormal(pts[1], pts[2], fRadius, |
| 305 &normalBC, &unitNormalBC); | 305 &normalBC, &unitNormalBC); |
| 306 #ifndef SK_IGNORE_CUBIC_STROKE_FIX | 306 #ifndef SK_IGNORE_CUBIC_STROKE_FIX |
| 307 if (subDivide <= 0) { | 307 if (--subDivide < 0) { |
| 308 if (degenerateBC) { | 308 goto DRAW_LINE; |
| 309 goto DRAW_LINE; | |
| 310 } else { | |
| 311 goto DRAW_CUBIC; | |
| 312 } | |
| 313 } | 309 } |
| 314 #endif | 310 #endif |
| 315 if (degenerateBC || normals_too_curvy(unitNormalAB, unitNormalBC) || | 311 if (degenerateBC || normals_too_curvy(unitNormalAB, unitNormalBC) || |
| 316 normals_too_curvy(unitNormalBC, *unitNormalCD)) { | 312 normals_too_curvy(unitNormalBC, *unitNormalCD)) { |
| 317 #ifdef SK_IGNORE_CUBIC_STROKE_FIX | 313 #ifdef SK_IGNORE_CUBIC_STROKE_FIX |
| 318 // subdivide if we can | 314 // subdivide if we can |
| 319 if (--subDivide < 0) { | 315 if (--subDivide < 0) { |
| 320 goto DRAW_LINE; | 316 goto DRAW_LINE; |
| 321 } | 317 } |
| 322 #endif | 318 #endif |
| 323 SkPoint tmp[7]; | 319 SkPoint tmp[7]; |
| 324 SkVector norm, unit, dummy, unitDummy; | 320 SkVector norm, unit, dummy, unitDummy; |
| 325 | 321 |
| 326 SkChopCubicAtHalf(pts, tmp); | 322 SkChopCubicAtHalf(pts, tmp); |
| 327 this->cubic_to(&tmp[0], normalAB, unitNormalAB, &norm, &unit, | 323 this->cubic_to(&tmp[0], normalAB, unitNormalAB, &norm, &unit, |
| 328 subDivide); | 324 subDivide); |
| 329 // we use dummys since we already have a valid (and more accurate) | 325 // we use dummys since we already have a valid (and more accurate) |
| 330 // normals for CD | 326 // normals for CD |
| 331 this->cubic_to(&tmp[3], norm, unit, &dummy, &unitDummy, subDivide); | 327 this->cubic_to(&tmp[3], norm, unit, &dummy, &unitDummy, subDivide); |
| 332 } else { | 328 } else { |
| 333 #ifndef SK_IGNORE_CUBIC_STROKE_FIX | |
| 334 DRAW_CUBIC: | |
| 335 #endif | |
| 336 SkVector normalB, normalC; | 329 SkVector normalB, normalC; |
| 337 | 330 |
| 338 // need normals to inset/outset the off-curve pts B and C | 331 // need normals to inset/outset the off-curve pts B and C |
| 339 | 332 |
| 340 SkVector unitBC = pts[2] - pts[1]; | 333 SkVector unitBC = pts[2] - pts[1]; |
| 341 unitBC.normalize(); | 334 unitBC.normalize(); |
| 342 unitBC.rotateCCW(); | 335 unitBC.rotateCCW(); |
| 343 | 336 |
| 344 normalB = unitNormalAB + unitBC; | 337 normalB = unitNormalAB + unitBC; |
| 345 normalC = *unitNormalCD + unitBC; | 338 normalC = *unitNormalCD + unitBC; |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 default: | 757 default: |
| 765 break; | 758 break; |
| 766 } | 759 } |
| 767 | 760 |
| 768 if (fWidth < SkMinScalar(rw, rh) && !fDoFill) { | 761 if (fWidth < SkMinScalar(rw, rh) && !fDoFill) { |
| 769 r = rect; | 762 r = rect; |
| 770 r.inset(radius, radius); | 763 r.inset(radius, radius); |
| 771 dst->addRect(r, reverse_direction(dir)); | 764 dst->addRect(r, reverse_direction(dir)); |
| 772 } | 765 } |
| 773 } | 766 } |
| OLD | NEW |