| 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" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 const SkVector& normalAB, const SkVector& unitNormalAB
, | 264 const SkVector& normalAB, const SkVector& unitNormalAB
, |
| 265 SkVector* normalBC, SkVector* unitNormalBC); | 265 SkVector* normalBC, SkVector* unitNormalBC); |
| 266 void setRayPts(const SkPoint& tPt, SkVector* dxy, SkPoint* onPt, SkPoint* ta
ngent) const; | 266 void setRayPts(const SkPoint& tPt, SkVector* dxy, SkPoint* onPt, SkPoint* ta
ngent) const; |
| 267 static bool SlightAngle(SkQuadConstruct* ); | 267 static bool SlightAngle(SkQuadConstruct* ); |
| 268 ResultType strokeCloseEnough(const SkPoint stroke[3], const SkPoint ray[2], | 268 ResultType strokeCloseEnough(const SkPoint stroke[3], const SkPoint ray[2], |
| 269 SkQuadConstruct* STROKER_DEBUG_PARAMS(int dept
h) ) const; | 269 SkQuadConstruct* STROKER_DEBUG_PARAMS(int dept
h) ) const; |
| 270 ResultType tangentsMeet(const SkPoint cubic[4], SkQuadConstruct* ); | 270 ResultType tangentsMeet(const SkPoint cubic[4], SkQuadConstruct* ); |
| 271 #endif | 271 #endif |
| 272 | 272 |
| 273 void finishContour(bool close, bool isLine); | 273 void finishContour(bool close, bool isLine); |
| 274 void preJoinTo(const SkPoint&, SkVector* normal, SkVector* unitNormal, | 274 bool preJoinTo(const SkPoint&, SkVector* normal, SkVector* unitNormal, |
| 275 bool isLine); | 275 bool isLine); |
| 276 void postJoinTo(const SkPoint&, const SkVector& normal, | 276 void postJoinTo(const SkPoint&, const SkVector& normal, |
| 277 const SkVector& unitNormal); | 277 const SkVector& unitNormal); |
| 278 | 278 |
| 279 void line_to(const SkPoint& currPt, const SkVector& normal); | 279 void line_to(const SkPoint& currPt, const SkVector& normal); |
| 280 #ifdef SK_LEGACY_STROKE_CURVES | 280 #ifdef SK_LEGACY_STROKE_CURVES |
| 281 void quad_to(const SkPoint pts[3], | 281 void quad_to(const SkPoint pts[3], |
| 282 const SkVector& normalAB, const SkVector& unitNormalAB, | 282 const SkVector& normalAB, const SkVector& unitNormalAB, |
| 283 SkVector* normalBC, SkVector* unitNormalBC, | 283 SkVector* normalBC, SkVector* unitNormalBC, |
| 284 int subDivide); | 284 int subDivide); |
| 285 void cubic_to(const SkPoint pts[4], | 285 void cubic_to(const SkPoint pts[4], |
| 286 const SkVector& normalAB, const SkVector& unitNormalAB, | 286 const SkVector& normalAB, const SkVector& unitNormalAB, |
| 287 SkVector* normalCD, SkVector* unitNormalCD, | 287 SkVector* normalCD, SkVector* unitNormalCD, |
| 288 int subDivide); | 288 int subDivide); |
| 289 #endif | 289 #endif |
| 290 }; | 290 }; |
| 291 | 291 |
| 292 /////////////////////////////////////////////////////////////////////////////// | 292 /////////////////////////////////////////////////////////////////////////////// |
| 293 | 293 |
| 294 void SkPathStroker::preJoinTo(const SkPoint& currPt, SkVector* normal, | 294 bool SkPathStroker::preJoinTo(const SkPoint& currPt, SkVector* normal, |
| 295 SkVector* unitNormal, bool currIsLine) { | 295 SkVector* unitNormal, bool currIsLine) { |
| 296 SkASSERT(fSegmentCount >= 0); | 296 SkASSERT(fSegmentCount >= 0); |
| 297 | 297 |
| 298 SkScalar prevX = fPrevPt.fX; | 298 SkScalar prevX = fPrevPt.fX; |
| 299 SkScalar prevY = fPrevPt.fY; | 299 SkScalar prevY = fPrevPt.fY; |
| 300 | 300 |
| 301 SkAssertResult(set_normal_unitnormal(fPrevPt, currPt, fRadius, normal, | 301 if (!set_normal_unitnormal(fPrevPt, currPt, fRadius, normal, unitNormal)) { |
| 302 unitNormal)); | 302 return false; |
| 303 } |
| 303 | 304 |
| 304 if (fSegmentCount == 0) { | 305 if (fSegmentCount == 0) { |
| 305 fFirstNormal = *normal; | 306 fFirstNormal = *normal; |
| 306 fFirstUnitNormal = *unitNormal; | 307 fFirstUnitNormal = *unitNormal; |
| 307 fFirstOuterPt.set(prevX + normal->fX, prevY + normal->fY); | 308 fFirstOuterPt.set(prevX + normal->fX, prevY + normal->fY); |
| 308 | 309 |
| 309 fOuter.moveTo(fFirstOuterPt.fX, fFirstOuterPt.fY); | 310 fOuter.moveTo(fFirstOuterPt.fX, fFirstOuterPt.fY); |
| 310 fInner.moveTo(prevX - normal->fX, prevY - normal->fY); | 311 fInner.moveTo(prevX - normal->fX, prevY - normal->fY); |
| 311 } else { // we have a previous segment | 312 } else { // we have a previous segment |
| 312 fJoiner(&fOuter, &fInner, fPrevUnitNormal, fPrevPt, *unitNormal, | 313 fJoiner(&fOuter, &fInner, fPrevUnitNormal, fPrevPt, *unitNormal, |
| 313 fRadius, fInvMiterLimit, fPrevIsLine, currIsLine); | 314 fRadius, fInvMiterLimit, fPrevIsLine, currIsLine); |
| 314 } | 315 } |
| 315 fPrevIsLine = currIsLine; | 316 fPrevIsLine = currIsLine; |
| 317 return true; |
| 316 } | 318 } |
| 317 | 319 |
| 318 void SkPathStroker::postJoinTo(const SkPoint& currPt, const SkVector& normal, | 320 void SkPathStroker::postJoinTo(const SkPoint& currPt, const SkVector& normal, |
| 319 const SkVector& unitNormal) { | 321 const SkVector& unitNormal) { |
| 320 fPrevPt = currPt; | 322 fPrevPt = currPt; |
| 321 fPrevUnitNormal = unitNormal; | 323 fPrevUnitNormal = unitNormal; |
| 322 fPrevNormal = normal; | 324 fPrevNormal = normal; |
| 323 fSegmentCount += 1; | 325 fSegmentCount += 1; |
| 324 } | 326 } |
| 325 | 327 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 fOuter.lineTo(currPt.fX + normal.fX, currPt.fY + normal.fY); | 413 fOuter.lineTo(currPt.fX + normal.fX, currPt.fY + normal.fY); |
| 412 fInner.lineTo(currPt.fX - normal.fX, currPt.fY - normal.fY); | 414 fInner.lineTo(currPt.fX - normal.fX, currPt.fY - normal.fY); |
| 413 } | 415 } |
| 414 | 416 |
| 415 void SkPathStroker::lineTo(const SkPoint& currPt) { | 417 void SkPathStroker::lineTo(const SkPoint& currPt) { |
| 416 if (SkPath::IsLineDegenerate(fPrevPt, currPt)) { | 418 if (SkPath::IsLineDegenerate(fPrevPt, currPt)) { |
| 417 return; | 419 return; |
| 418 } | 420 } |
| 419 SkVector normal, unitNormal; | 421 SkVector normal, unitNormal; |
| 420 | 422 |
| 421 this->preJoinTo(currPt, &normal, &unitNormal, true); | 423 if (!this->preJoinTo(currPt, &normal, &unitNormal, true)) { |
| 424 return; |
| 425 } |
| 422 this->line_to(currPt, normal); | 426 this->line_to(currPt, normal); |
| 423 this->postJoinTo(currPt, normal, unitNormal); | 427 this->postJoinTo(currPt, normal, unitNormal); |
| 424 } | 428 } |
| 425 | 429 |
| 426 #ifdef SK_LEGACY_STROKE_CURVES | 430 #ifdef SK_LEGACY_STROKE_CURVES |
| 427 void SkPathStroker::quad_to(const SkPoint pts[3], | 431 void SkPathStroker::quad_to(const SkPoint pts[3], |
| 428 const SkVector& normalAB, const SkVector& unitNormalAB, | 432 const SkVector& normalAB, const SkVector& unitNormalAB, |
| 429 SkVector* normalBC, SkVector* unitNormalBC, | 433 SkVector* normalBC, SkVector* unitNormalBC, |
| 430 int subDivide) { | 434 int subDivide) { |
| 431 if (!set_normal_unitnormal(pts[1], pts[2], fRadius, | 435 if (!set_normal_unitnormal(pts[1], pts[2], fRadius, |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 if (kDegenerate_ReductionType == reductionType) { | 793 if (kDegenerate_ReductionType == reductionType) { |
| 790 this->lineTo(reduction); | 794 this->lineTo(reduction); |
| 791 SkStrokerPriv::JoinProc saveJoiner = fJoiner; | 795 SkStrokerPriv::JoinProc saveJoiner = fJoiner; |
| 792 fJoiner = SkStrokerPriv::JoinFactory(SkPaint::kRound_Join); | 796 fJoiner = SkStrokerPriv::JoinFactory(SkPaint::kRound_Join); |
| 793 this->lineTo(pt2); | 797 this->lineTo(pt2); |
| 794 fJoiner = saveJoiner; | 798 fJoiner = saveJoiner; |
| 795 return; | 799 return; |
| 796 } | 800 } |
| 797 SkASSERT(kQuad_ReductionType == reductionType); | 801 SkASSERT(kQuad_ReductionType == reductionType); |
| 798 SkVector normalAB, unitAB, normalBC, unitBC; | 802 SkVector normalAB, unitAB, normalBC, unitBC; |
| 799 this->preJoinTo(pt1, &normalAB, &unitAB, false); | 803 if (!this->preJoinTo(pt1, &normalAB, &unitAB, false)) { |
| 804 this->lineTo(pt2); |
| 805 return; |
| 806 } |
| 800 SkQuadConstruct quadPts; | 807 SkQuadConstruct quadPts; |
| 801 this->init(kOuter_StrokeType, &quadPts, 0, 1); | 808 this->init(kOuter_StrokeType, &quadPts, 0, 1); |
| 802 if (!this->conicStroke(conic, &quadPts)) { | 809 (void) this->conicStroke(conic, &quadPts); |
| 803 return; | |
| 804 } | |
| 805 this->init(kInner_StrokeType, &quadPts, 0, 1); | 810 this->init(kInner_StrokeType, &quadPts, 0, 1); |
| 806 if (!this->conicStroke(conic, &quadPts)) { | 811 (void) this->conicStroke(conic, &quadPts); |
| 807 return; | |
| 808 } | |
| 809 this->setConicEndNormal(conic, normalAB, unitAB, &normalBC, &unitBC); | 812 this->setConicEndNormal(conic, normalAB, unitAB, &normalBC, &unitBC); |
| 810 this->postJoinTo(pt2, normalBC, unitBC); | 813 this->postJoinTo(pt2, normalBC, unitBC); |
| 811 } | 814 } |
| 812 #endif | 815 #endif |
| 813 | 816 |
| 814 void SkPathStroker::quadTo(const SkPoint& pt1, const SkPoint& pt2) { | 817 void SkPathStroker::quadTo(const SkPoint& pt1, const SkPoint& pt2) { |
| 815 #ifndef SK_LEGACY_STROKE_CURVES | 818 #ifndef SK_LEGACY_STROKE_CURVES |
| 816 const SkPoint quad[3] = { fPrevPt, pt1, pt2 }; | 819 const SkPoint quad[3] = { fPrevPt, pt1, pt2 }; |
| 817 SkPoint reduction; | 820 SkPoint reduction; |
| 818 ReductionType reductionType = CheckQuadLinear(quad, &reduction); | 821 ReductionType reductionType = CheckQuadLinear(quad, &reduction); |
| 819 if (kPoint_ReductionType == reductionType) { | 822 if (kPoint_ReductionType == reductionType) { |
| 820 return; | 823 return; |
| 821 } | 824 } |
| 822 if (kLine_ReductionType == reductionType) { | 825 if (kLine_ReductionType == reductionType) { |
| 823 this->lineTo(pt2); | 826 this->lineTo(pt2); |
| 824 return; | 827 return; |
| 825 } | 828 } |
| 826 if (kDegenerate_ReductionType == reductionType) { | 829 if (kDegenerate_ReductionType == reductionType) { |
| 827 this->lineTo(reduction); | 830 this->lineTo(reduction); |
| 828 SkStrokerPriv::JoinProc saveJoiner = fJoiner; | 831 SkStrokerPriv::JoinProc saveJoiner = fJoiner; |
| 829 fJoiner = SkStrokerPriv::JoinFactory(SkPaint::kRound_Join); | 832 fJoiner = SkStrokerPriv::JoinFactory(SkPaint::kRound_Join); |
| 830 this->lineTo(pt2); | 833 this->lineTo(pt2); |
| 831 fJoiner = saveJoiner; | 834 fJoiner = saveJoiner; |
| 832 return; | 835 return; |
| 833 } | 836 } |
| 834 SkASSERT(kQuad_ReductionType == reductionType); | 837 SkASSERT(kQuad_ReductionType == reductionType); |
| 835 SkVector normalAB, unitAB, normalBC, unitBC; | 838 SkVector normalAB, unitAB, normalBC, unitBC; |
| 836 this->preJoinTo(pt1, &normalAB, &unitAB, false); | 839 if (!this->preJoinTo(pt1, &normalAB, &unitAB, false)) { |
| 840 this->lineTo(pt2); |
| 841 return; |
| 842 } |
| 837 SkQuadConstruct quadPts; | 843 SkQuadConstruct quadPts; |
| 838 this->init(kOuter_StrokeType, &quadPts, 0, 1); | 844 this->init(kOuter_StrokeType, &quadPts, 0, 1); |
| 839 if (!this->quadStroke(quad, &quadPts)) { | 845 (void) this->quadStroke(quad, &quadPts); |
| 840 return; | |
| 841 } | |
| 842 this->init(kInner_StrokeType, &quadPts, 0, 1); | 846 this->init(kInner_StrokeType, &quadPts, 0, 1); |
| 843 if (!this->quadStroke(quad, &quadPts)) { | 847 (void) this->quadStroke(quad, &quadPts); |
| 844 return; | |
| 845 } | |
| 846 this->setQuadEndNormal(quad, normalAB, unitAB, &normalBC, &unitBC); | 848 this->setQuadEndNormal(quad, normalAB, unitAB, &normalBC, &unitBC); |
| 847 #else | 849 #else |
| 848 bool degenerateAB = SkPath::IsLineDegenerate(fPrevPt, pt1); | 850 bool degenerateAB = SkPath::IsLineDegenerate(fPrevPt, pt1); |
| 849 bool degenerateBC = SkPath::IsLineDegenerate(pt1, pt2); | 851 bool degenerateBC = SkPath::IsLineDegenerate(pt1, pt2); |
| 850 | 852 |
| 851 if (degenerateAB | degenerateBC) { | 853 if (degenerateAB | degenerateBC) { |
| 852 if (degenerateAB ^ degenerateBC) { | 854 if (degenerateAB ^ degenerateBC) { |
| 853 this->lineTo(pt2); | 855 this->lineTo(pt2); |
| 854 } | 856 } |
| 855 return; | 857 return; |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 } | 1399 } |
| 1398 if (kDegenerate3_ReductionType == reductionType) { | 1400 if (kDegenerate3_ReductionType == reductionType) { |
| 1399 this->lineTo(reduction[2]); | 1401 this->lineTo(reduction[2]); |
| 1400 } | 1402 } |
| 1401 this->lineTo(pt3); | 1403 this->lineTo(pt3); |
| 1402 fJoiner = saveJoiner; | 1404 fJoiner = saveJoiner; |
| 1403 return; | 1405 return; |
| 1404 } | 1406 } |
| 1405 SkASSERT(kQuad_ReductionType == reductionType); | 1407 SkASSERT(kQuad_ReductionType == reductionType); |
| 1406 SkVector normalAB, unitAB, normalCD, unitCD; | 1408 SkVector normalAB, unitAB, normalCD, unitCD; |
| 1407 this->preJoinTo(*tangentPt, &normalAB, &unitAB, false); | 1409 if (!this->preJoinTo(*tangentPt, &normalAB, &unitAB, false)) { |
| 1410 this->lineTo(pt3); |
| 1411 return; |
| 1412 } |
| 1408 SkScalar tValues[2]; | 1413 SkScalar tValues[2]; |
| 1409 int count = SkFindCubicInflections(cubic, tValues); | 1414 int count = SkFindCubicInflections(cubic, tValues); |
| 1410 SkScalar lastT = 0; | 1415 SkScalar lastT = 0; |
| 1411 for (int index = 0; index <= count; ++index) { | 1416 for (int index = 0; index <= count; ++index) { |
| 1412 SkScalar nextT = index < count ? tValues[index] : 1; | 1417 SkScalar nextT = index < count ? tValues[index] : 1; |
| 1413 SkQuadConstruct quadPts; | 1418 SkQuadConstruct quadPts; |
| 1414 this->init(kOuter_StrokeType, &quadPts, lastT, nextT); | 1419 this->init(kOuter_StrokeType, &quadPts, lastT, nextT); |
| 1415 if (!this->cubicStroke(cubic, &quadPts)) { | 1420 (void) this->cubicStroke(cubic, &quadPts); |
| 1416 break; | |
| 1417 } | |
| 1418 this->init(kInner_StrokeType, &quadPts, lastT, nextT); | 1421 this->init(kInner_StrokeType, &quadPts, lastT, nextT); |
| 1419 if (!this->cubicStroke(cubic, &quadPts)) { | 1422 (void) this->cubicStroke(cubic, &quadPts); |
| 1420 break; | |
| 1421 } | |
| 1422 lastT = nextT; | 1423 lastT = nextT; |
| 1423 } | 1424 } |
| 1424 // emit the join even if one stroke succeeded but the last one failed | 1425 // emit the join even if one stroke succeeded but the last one failed |
| 1425 // this avoids reversing an inner stroke with a partial path followed by ano
ther moveto | 1426 // this avoids reversing an inner stroke with a partial path followed by ano
ther moveto |
| 1426 this->setCubicEndNormal(cubic, normalAB, unitAB, &normalCD, &unitCD); | 1427 this->setCubicEndNormal(cubic, normalAB, unitAB, &normalCD, &unitCD); |
| 1427 #else | 1428 #else |
| 1428 bool degenerateAB = SkPath::IsLineDegenerate(fPrevPt, pt1); | 1429 bool degenerateAB = SkPath::IsLineDegenerate(fPrevPt, pt1); |
| 1429 bool degenerateBC = SkPath::IsLineDegenerate(pt1, pt2); | 1430 bool degenerateBC = SkPath::IsLineDegenerate(pt1, pt2); |
| 1430 bool degenerateCD = SkPath::IsLineDegenerate(pt2, pt3); | 1431 bool degenerateCD = SkPath::IsLineDegenerate(pt2, pt3); |
| 1431 | 1432 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 default: | 1740 default: |
| 1740 break; | 1741 break; |
| 1741 } | 1742 } |
| 1742 | 1743 |
| 1743 if (fWidth < SkMinScalar(rw, rh) && !fDoFill) { | 1744 if (fWidth < SkMinScalar(rw, rh) && !fDoFill) { |
| 1744 r = rect; | 1745 r = rect; |
| 1745 r.inset(radius, radius); | 1746 r.inset(radius, radius); |
| 1746 dst->addRect(r, reverse_direction(dir)); | 1747 dst->addRect(r, reverse_direction(dir)); |
| 1747 } | 1748 } |
| 1748 } | 1749 } |
| OLD | NEW |