| 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 "SkPathPriv.h" | 10 #include "SkPathPriv.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #else | 44 #else |
| 45 #define STROKER_RESULT(resultType, depth, quadPts, format, ...) \ | 45 #define STROKER_RESULT(resultType, depth, quadPts, format, ...) \ |
| 46 resultType | 46 resultType |
| 47 #define STROKER_DEBUG_PARAMS(...) | 47 #define STROKER_DEBUG_PARAMS(...) |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 50 static inline bool degenerate_vector(const SkVector& v) { | 50 static inline bool degenerate_vector(const SkVector& v) { |
| 51 return !SkPoint::CanNormalize(v.fX, v.fY); | 51 return !SkPoint::CanNormalize(v.fX, v.fY); |
| 52 } | 52 } |
| 53 | 53 |
| 54 static bool set_normal_unitnormal(const SkPoint& before, const SkPoint& after, | 54 static bool set_normal_unitnormal(const SkPoint& before, const SkPoint& after, S
kScalar scale, |
| 55 SkScalar radius, | 55 SkScalar radius, |
| 56 SkVector* normal, SkVector* unitNormal) { | 56 SkVector* normal, SkVector* unitNormal) { |
| 57 if (!unitNormal->setNormalize(after.fX - before.fX, after.fY - before.fY)) { | 57 if (!unitNormal->setNormalize((after.fX - before.fX) * scale, |
| 58 (after.fY - before.fY) * scale)) { |
| 58 return false; | 59 return false; |
| 59 } | 60 } |
| 60 unitNormal->rotateCCW(); | 61 unitNormal->rotateCCW(); |
| 61 unitNormal->scale(radius, normal); | 62 unitNormal->scale(radius, normal); |
| 62 return true; | 63 return true; |
| 63 } | 64 } |
| 64 | 65 |
| 65 static bool set_normal_unitnormal(const SkVector& vec, | 66 static bool set_normal_unitnormal(const SkVector& vec, |
| 66 SkScalar radius, | 67 SkScalar radius, |
| 67 SkVector* normal, SkVector* unitNormal) { | 68 SkVector* normal, SkVector* unitNormal) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 238 |
| 238 /////////////////////////////////////////////////////////////////////////////// | 239 /////////////////////////////////////////////////////////////////////////////// |
| 239 | 240 |
| 240 bool SkPathStroker::preJoinTo(const SkPoint& currPt, SkVector* normal, | 241 bool SkPathStroker::preJoinTo(const SkPoint& currPt, SkVector* normal, |
| 241 SkVector* unitNormal, bool currIsLine) { | 242 SkVector* unitNormal, bool currIsLine) { |
| 242 SkASSERT(fSegmentCount >= 0); | 243 SkASSERT(fSegmentCount >= 0); |
| 243 | 244 |
| 244 SkScalar prevX = fPrevPt.fX; | 245 SkScalar prevX = fPrevPt.fX; |
| 245 SkScalar prevY = fPrevPt.fY; | 246 SkScalar prevY = fPrevPt.fY; |
| 246 | 247 |
| 247 if (!set_normal_unitnormal(fPrevPt, currPt, fRadius, normal, unitNormal)) { | 248 if (!set_normal_unitnormal(fPrevPt, currPt, fResScale, fRadius, normal, unit
Normal)) { |
| 248 if (SkStrokerPriv::CapFactory(SkPaint::kButt_Cap) == fCapper) { | 249 if (SkStrokerPriv::CapFactory(SkPaint::kButt_Cap) == fCapper) { |
| 249 return false; | 250 return false; |
| 250 } | 251 } |
| 251 /* Square caps and round caps draw even if the segment length is zero. | 252 /* Square caps and round caps draw even if the segment length is zero. |
| 252 Since the zero length segment has no direction, set the orientation | 253 Since the zero length segment has no direction, set the orientation |
| 253 to upright as the default orientation */ | 254 to upright as the default orientation */ |
| 254 normal->set(fRadius, 0); | 255 normal->set(fRadius, 0); |
| 255 unitNormal->set(1, 0); | 256 unitNormal->set(1, 0); |
| 256 } | 257 } |
| 257 | 258 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 fFirstPt = fPrevPt = pt; | 361 fFirstPt = fPrevPt = pt; |
| 361 } | 362 } |
| 362 | 363 |
| 363 void SkPathStroker::line_to(const SkPoint& currPt, const SkVector& normal) { | 364 void SkPathStroker::line_to(const SkPoint& currPt, const SkVector& normal) { |
| 364 fOuter.lineTo(currPt.fX + normal.fX, currPt.fY + normal.fY); | 365 fOuter.lineTo(currPt.fX + normal.fX, currPt.fY + normal.fY); |
| 365 fInner.lineTo(currPt.fX - normal.fX, currPt.fY - normal.fY); | 366 fInner.lineTo(currPt.fX - normal.fX, currPt.fY - normal.fY); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void SkPathStroker::lineTo(const SkPoint& currPt) { | 369 void SkPathStroker::lineTo(const SkPoint& currPt) { |
| 369 if (SkStrokerPriv::CapFactory(SkPaint::kButt_Cap) == fCapper | 370 if (SkStrokerPriv::CapFactory(SkPaint::kButt_Cap) == fCapper |
| 370 && SkPath::IsLineDegenerate(fPrevPt, currPt, false)) { | 371 && fPrevPt.equalsWithinTolerance(currPt, SK_ScalarNearlyZero * fInvR
esScale)) { |
| 371 return; | 372 return; |
| 372 } | 373 } |
| 373 SkVector normal, unitNormal; | 374 SkVector normal, unitNormal; |
| 374 | 375 |
| 375 if (!this->preJoinTo(currPt, &normal, &unitNormal, true)) { | 376 if (!this->preJoinTo(currPt, &normal, &unitNormal, true)) { |
| 376 return; | 377 return; |
| 377 } | 378 } |
| 378 this->line_to(currPt, normal); | 379 this->line_to(currPt, normal); |
| 379 this->postJoinTo(currPt, normal, unitNormal); | 380 this->postJoinTo(currPt, normal, unitNormal); |
| 380 } | 381 } |
| 381 | 382 |
| 382 void SkPathStroker::setQuadEndNormal(const SkPoint quad[3], const SkVector& norm
alAB, | 383 void SkPathStroker::setQuadEndNormal(const SkPoint quad[3], const SkVector& norm
alAB, |
| 383 const SkVector& unitNormalAB, SkVector* normalBC, SkVector* unitNormalBC
) { | 384 const SkVector& unitNormalAB, SkVector* normalBC, SkVector* unitNormalBC
) { |
| 384 if (!set_normal_unitnormal(quad[1], quad[2], fRadius, normalBC, unitNormalBC
)) { | 385 if (!set_normal_unitnormal(quad[1], quad[2], fResScale, fRadius, normalBC, u
nitNormalBC)) { |
| 385 *normalBC = normalAB; | 386 *normalBC = normalAB; |
| 386 *unitNormalBC = unitNormalAB; | 387 *unitNormalBC = unitNormalAB; |
| 387 } | 388 } |
| 388 } | 389 } |
| 389 | 390 |
| 390 void SkPathStroker::setConicEndNormal(const SkConic& conic, const SkVector& norm
alAB, | 391 void SkPathStroker::setConicEndNormal(const SkConic& conic, const SkVector& norm
alAB, |
| 391 const SkVector& unitNormalAB, SkVector* normalBC, SkVector* unitNormalBC
) { | 392 const SkVector& unitNormalAB, SkVector* normalBC, SkVector* unitNormalBC
) { |
| 392 setQuadEndNormal(conic.fPts, normalAB, unitNormalAB, normalBC, unitNormalBC)
; | 393 setQuadEndNormal(conic.fPts, normalAB, unitNormalAB, normalBC, unitNormalBC)
; |
| 393 } | 394 } |
| 394 | 395 |
| (...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 default: | 1482 default: |
| 1482 break; | 1483 break; |
| 1483 } | 1484 } |
| 1484 | 1485 |
| 1485 if (fWidth < SkMinScalar(rw, rh) && !fDoFill) { | 1486 if (fWidth < SkMinScalar(rw, rh) && !fDoFill) { |
| 1486 r = rect; | 1487 r = rect; |
| 1487 r.inset(radius, radius); | 1488 r.inset(radius, radius); |
| 1488 dst->addRect(r, reverse_direction(dir)); | 1489 dst->addRect(r, reverse_direction(dir)); |
| 1489 } | 1490 } |
| 1490 } | 1491 } |
| OLD | NEW |