| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 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 "SkDashPathEffect.h" | 8 #include "SkDashPathEffect.h" |
| 9 | 9 |
| 10 #include "SkDashPathPriv.h" | 10 #include "SkDashPathPriv.h" |
| 11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
| 13 #include "SkStrokeRec.h" | 13 #include "SkStrokeRec.h" |
| 14 | 14 |
| 15 SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count, SkScal
ar phase) | 15 SkDashPathEffect::SkDashPathEffect(const SkScalar intervals[], int count, SkScal
ar phase) |
| 16 : fPhase(0) | 16 : fPhase(0) |
| 17 , fInitialDashLength(0) | 17 , fInitialDashLength(-1) |
| 18 , fInitialDashIndex(0) | 18 , fInitialDashIndex(0) |
| 19 , fIntervalLength(0) { | 19 , fIntervalLength(0) { |
| 20 SkASSERT(intervals); | 20 SkASSERT(intervals); |
| 21 SkASSERT(count > 1 && SkAlign2(count) == count); | 21 SkASSERT(count > 1 && SkAlign2(count) == count); |
| 22 | 22 |
| 23 fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * count); | 23 fIntervals = (SkScalar*)sk_malloc_throw(sizeof(SkScalar) * count); |
| 24 fCount = count; | 24 fCount = count; |
| 25 for (int i = 0; i < count; i++) { | 25 for (int i = 0; i < count; i++) { |
| 26 SkASSERT(intervals[i] >= 0); | |
| 27 fIntervals[i] = intervals[i]; | 26 fIntervals[i] = intervals[i]; |
| 28 } | 27 } |
| 29 | 28 |
| 30 // set the internal data members | 29 // set the internal data members |
| 31 SkDashPath::CalcDashParameters(phase, fIntervals, fCount, | 30 SkDashPath::CalcDashParameters(phase, fIntervals, fCount, |
| 32 &fInitialDashLength, &fInitialDashIndex, &fIntervalLength, &fPhase); | 31 &fInitialDashLength, &fInitialDashIndex, &fIntervalLength, &fPhase); |
| 33 } | 32 } |
| 34 | 33 |
| 35 SkDashPathEffect::~SkDashPathEffect() { | 34 SkDashPathEffect::~SkDashPathEffect() { |
| 36 sk_free(fIntervals); | 35 sk_free(fIntervals); |
| 37 } | 36 } |
| 38 | 37 |
| 39 bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src, | 38 bool SkDashPathEffect::filterPath(SkPath* dst, const SkPath& src, |
| 40 SkStrokeRec* rec, const SkRect* cullRect) const { | 39 SkStrokeRec* rec, const SkRect* cullRect) const { |
| 41 return SkDashPath::FilterDashPath(dst, src, rec, cullRect, fIntervals, fCoun
t, | 40 return SkDashPath::InternalFilter(dst, src, rec, cullRect, fIntervals, fCoun
t, |
| 42 fInitialDashLength, fInitialDashIndex, fIn
tervalLength); | 41 fInitialDashLength, fInitialDashIndex, fIn
tervalLength); |
| 43 } | 42 } |
| 44 | 43 |
| 45 static void outset_for_stroke(SkRect* rect, const SkStrokeRec& rec) { | 44 static void outset_for_stroke(SkRect* rect, const SkStrokeRec& rec) { |
| 46 SkScalar radius = SkScalarHalf(rec.getWidth()); | 45 SkScalar radius = SkScalarHalf(rec.getWidth()); |
| 47 if (0 == radius) { | 46 if (0 == radius) { |
| 48 radius = SK_Scalar1; // hairlines | 47 radius = SK_Scalar1; // hairlines |
| 49 } | 48 } |
| 50 if (SkPaint::kMiter_Join == rec.getJoin()) { | 49 if (SkPaint::kMiter_Join == rec.getJoin()) { |
| 51 radius = SkScalarMul(radius, rec.getMiter()); | 50 radius = SkScalarMul(radius, rec.getMiter()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // Currently asPoints is more restrictive then it needs to be. In the future | 154 // Currently asPoints is more restrictive then it needs to be. In the future |
| 156 // we need to: | 155 // we need to: |
| 157 // allow kRound_Cap capping (could allow rotations in the matrix with this) | 156 // allow kRound_Cap capping (could allow rotations in the matrix with this) |
| 158 // allow paths to be returned | 157 // allow paths to be returned |
| 159 bool SkDashPathEffect::asPoints(PointData* results, | 158 bool SkDashPathEffect::asPoints(PointData* results, |
| 160 const SkPath& src, | 159 const SkPath& src, |
| 161 const SkStrokeRec& rec, | 160 const SkStrokeRec& rec, |
| 162 const SkMatrix& matrix, | 161 const SkMatrix& matrix, |
| 163 const SkRect* cullRect) const { | 162 const SkRect* cullRect) const { |
| 164 // width < 0 -> fill && width == 0 -> hairline so requiring width > 0 rules
both out | 163 // width < 0 -> fill && width == 0 -> hairline so requiring width > 0 rules
both out |
| 165 if (fInitialDashLength < 0 || 0 >= rec.getWidth()) { | 164 if (0 >= rec.getWidth()) { |
| 166 return false; | 165 return false; |
| 167 } | 166 } |
| 168 | 167 |
| 169 // TODO: this next test could be eased up. We could allow any number of | 168 // TODO: this next test could be eased up. We could allow any number of |
| 170 // intervals as long as all the ons match and all the offs match. | 169 // intervals as long as all the ons match and all the offs match. |
| 171 // Additionally, they do not necessarily need to be integers. | 170 // Additionally, they do not necessarily need to be integers. |
| 172 // We cannot allow arbitrary intervals since we want the returned points | 171 // We cannot allow arbitrary intervals since we want the returned points |
| 173 // to be uniformly sized. | 172 // to be uniformly sized. |
| 174 if (fCount != 2 || | 173 if (fCount != 2 || |
| 175 !SkScalarNearlyEqual(fIntervals[0], fIntervals[1]) || | 174 !SkScalarNearlyEqual(fIntervals[0], fIntervals[1]) || |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 str->appendf(", "); | 380 str->appendf(", "); |
| 382 } | 381 } |
| 383 } | 382 } |
| 384 str->appendf("))"); | 383 str->appendf("))"); |
| 385 } | 384 } |
| 386 #endif | 385 #endif |
| 387 | 386 |
| 388 ////////////////////////////////////////////////////////////////////////////////
////////////////// | 387 ////////////////////////////////////////////////////////////////////////////////
////////////////// |
| 389 | 388 |
| 390 SkPathEffect* SkDashPathEffect::Create(const SkScalar intervals[], int count, Sk
Scalar phase) { | 389 SkPathEffect* SkDashPathEffect::Create(const SkScalar intervals[], int count, Sk
Scalar phase) { |
| 391 if ((count < 2) || !SkIsAlign2(count)) { | 390 if (!SkDashPath::ValidDashPath(phase, intervals, count)) { |
| 392 return nullptr; | 391 return nullptr; |
| 393 } | 392 } |
| 394 for (int i = 0; i < count; i++) { | |
| 395 if (intervals[i] < 0) { | |
| 396 return nullptr; | |
| 397 } | |
| 398 } | |
| 399 return new SkDashPathEffect(intervals, count, phase); | 393 return new SkDashPathEffect(intervals, count, phase); |
| 400 } | 394 } |
| OLD | NEW |