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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 SkScalar radius = SkScalarHalf(rec.getWidth()); | 45 SkScalar radius = SkScalarHalf(rec.getWidth()); |
46 if (0 == radius) { | 46 if (0 == radius) { |
47 radius = SK_Scalar1; // hairlines | 47 radius = SK_Scalar1; // hairlines |
48 } | 48 } |
49 if (SkPaint::kMiter_Join == rec.getJoin()) { | 49 if (SkPaint::kMiter_Join == rec.getJoin()) { |
50 radius = SkScalarMul(radius, rec.getMiter()); | 50 radius = SkScalarMul(radius, rec.getMiter()); |
51 } | 51 } |
52 rect->outset(radius, radius); | 52 rect->outset(radius, radius); |
53 } | 53 } |
54 | 54 |
55 // Attempt to trim the line to minimally cover the cull rect (currently | 55 // Attempt to trim the line to minimally cover the cull rect (currently |
56 // only works for horizontal and vertical lines). | 56 // only works for horizontal and vertical lines). |
57 // Return true if processing should continue; false otherwise. | 57 // Return true if processing should continue; false otherwise. |
58 static bool cull_line(SkPoint* pts, const SkStrokeRec& rec, | 58 static bool cull_line(SkPoint* pts, const SkStrokeRec& rec, |
59 const SkMatrix& ctm, const SkRect* cullRect, | 59 const SkMatrix& ctm, const SkRect* cullRect, |
60 const SkScalar intervalLength) { | 60 const SkScalar intervalLength) { |
61 if (NULL == cullRect) { | 61 if (NULL == cullRect) { |
62 SkASSERT(false); // Shouldn't ever occur in practice | 62 SkASSERT(false); // Shouldn't ever occur in practice |
63 return false; | 63 return false; |
64 } | 64 } |
65 | 65 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 return NULL; | 370 return NULL; |
371 } | 371 } |
372 | 372 |
373 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | 373 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING |
374 SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) | 374 SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) |
375 : INHERITED(buffer) | 375 : INHERITED(buffer) |
376 , fPhase(0) | 376 , fPhase(0) |
377 , fInitialDashLength(0) | 377 , fInitialDashLength(0) |
378 , fInitialDashIndex(0) | 378 , fInitialDashIndex(0) |
379 , fIntervalLength(0) { | 379 , fIntervalLength(0) { |
380 bool useOldPic = buffer.isVersionLT(SkReadBuffer::kDashWritesPhaseIntervals_
Version); | 380 fPhase = buffer.readScalar(); |
381 if (useOldPic) { | |
382 fInitialDashIndex = buffer.readInt(); | |
383 fInitialDashLength = buffer.readScalar(); | |
384 fIntervalLength = buffer.readScalar(); | |
385 buffer.readBool(); // Dummy for old ScalarToFit field | |
386 } else { | |
387 fPhase = buffer.readScalar(); | |
388 } | |
389 | |
390 fCount = buffer.getArrayCount(); | 381 fCount = buffer.getArrayCount(); |
391 size_t allocSize = sizeof(SkScalar) * fCount; | 382 size_t allocSize = sizeof(SkScalar) * fCount; |
392 if (buffer.validateAvailable(allocSize)) { | 383 if (buffer.validateAvailable(allocSize)) { |
393 fIntervals = (SkScalar*)sk_malloc_throw(allocSize); | 384 fIntervals = (SkScalar*)sk_malloc_throw(allocSize); |
394 buffer.readScalarArray(fIntervals, fCount); | 385 buffer.readScalarArray(fIntervals, fCount); |
395 } else { | 386 } else { |
396 fIntervals = NULL; | 387 fIntervals = NULL; |
397 } | 388 } |
398 | 389 |
399 if (useOldPic) { | 390 // set the internal data members, fPhase should have been between 0 and inte
rvalLength |
400 fPhase = 0; | 391 // when written to buffer so no need to adjust it |
401 if (fInitialDashLength != -1) { // Signal for bad dash interval | 392 SkDashPath::CalcDashParameters(fPhase, fIntervals, fCount, |
402 for (int i = 0; i < fInitialDashIndex; ++i) { | 393 &fInitialDashLength, &fInitialDashIndex, &fIn
tervalLength); |
403 fPhase += fIntervals[i]; | |
404 } | |
405 fPhase += fIntervals[fInitialDashIndex] - fInitialDashLength; | |
406 } | |
407 } else { | |
408 // set the internal data members, fPhase should have been between 0 and
intervalLength | |
409 // when written to buffer so no need to adjust it | |
410 SkDashPath::CalcDashParameters(fPhase, fIntervals, fCount, | |
411 &fInitialDashLength, &fInitialDashIndex, &fIntervalLength); | |
412 } | |
413 } | 394 } |
414 #endif | 395 #endif |
415 | 396 |
OLD | NEW |