OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkDashPathEffect.h" | 10 #include "SkDashPathEffect.h" |
11 #include "SkFlattenableBuffers.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" |
12 #include "SkPathMeasure.h" | 13 #include "SkPathMeasure.h" |
13 | 14 |
14 static inline int is_even(int x) { | 15 static inline int is_even(int x) { |
15 return (~x) << 31; | 16 return (~x) << 31; |
16 } | 17 } |
17 | 18 |
18 static SkScalar FindFirstInterval(const SkScalar intervals[], SkScalar phase, | 19 static SkScalar FindFirstInterval(const SkScalar intervals[], SkScalar phase, |
19 int32_t* index, int count) { | 20 int32_t* index, int count) { |
20 for (int i = 0; i < count; ++i) { | 21 for (int i = 0; i < count; ++i) { |
21 if (phase > intervals[i]) { | 22 if (phase > intervals[i]) { |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 SkASSERT(curPt == results->fNumPoints); | 526 SkASSERT(curPt == results->fNumPoints); |
526 } | 527 } |
527 | 528 |
528 return true; | 529 return true; |
529 } | 530 } |
530 | 531 |
531 SkFlattenable::Factory SkDashPathEffect::getFactory() const { | 532 SkFlattenable::Factory SkDashPathEffect::getFactory() const { |
532 return fInitialDashLength < 0 ? NULL : CreateProc; | 533 return fInitialDashLength < 0 ? NULL : CreateProc; |
533 } | 534 } |
534 | 535 |
535 void SkDashPathEffect::flatten(SkFlattenableWriteBuffer& buffer) const { | 536 void SkDashPathEffect::flatten(SkWriteBuffer& buffer) const { |
536 SkASSERT(fInitialDashLength >= 0); | 537 SkASSERT(fInitialDashLength >= 0); |
537 | 538 |
538 this->INHERITED::flatten(buffer); | 539 this->INHERITED::flatten(buffer); |
539 buffer.writeInt(fInitialDashIndex); | 540 buffer.writeInt(fInitialDashIndex); |
540 buffer.writeScalar(fInitialDashLength); | 541 buffer.writeScalar(fInitialDashLength); |
541 buffer.writeScalar(fIntervalLength); | 542 buffer.writeScalar(fIntervalLength); |
542 buffer.writeBool(fScaleToFit); | 543 buffer.writeBool(fScaleToFit); |
543 buffer.writeScalarArray(fIntervals, fCount); | 544 buffer.writeScalarArray(fIntervals, fCount); |
544 } | 545 } |
545 | 546 |
546 SkFlattenable* SkDashPathEffect::CreateProc(SkFlattenableReadBuffer& buffer) { | 547 SkFlattenable* SkDashPathEffect::CreateProc(SkReadBuffer& buffer) { |
547 return SkNEW_ARGS(SkDashPathEffect, (buffer)); | 548 return SkNEW_ARGS(SkDashPathEffect, (buffer)); |
548 } | 549 } |
549 | 550 |
550 SkDashPathEffect::SkDashPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(
buffer) { | 551 SkDashPathEffect::SkDashPathEffect(SkReadBuffer& buffer) : INHERITED(buffer) { |
551 fInitialDashIndex = buffer.readInt(); | 552 fInitialDashIndex = buffer.readInt(); |
552 fInitialDashLength = buffer.readScalar(); | 553 fInitialDashLength = buffer.readScalar(); |
553 fIntervalLength = buffer.readScalar(); | 554 fIntervalLength = buffer.readScalar(); |
554 fScaleToFit = buffer.readBool(); | 555 fScaleToFit = buffer.readBool(); |
555 | 556 |
556 fCount = buffer.getArrayCount(); | 557 fCount = buffer.getArrayCount(); |
557 size_t allocSize = sizeof(SkScalar) * fCount; | 558 size_t allocSize = sizeof(SkScalar) * fCount; |
558 if (buffer.validateAvailable(allocSize)) { | 559 if (buffer.validateAvailable(allocSize)) { |
559 fIntervals = (SkScalar*)sk_malloc_throw(allocSize); | 560 fIntervals = (SkScalar*)sk_malloc_throw(allocSize); |
560 buffer.readScalarArray(fIntervals, fCount); | 561 buffer.readScalarArray(fIntervals, fCount); |
561 } else { | 562 } else { |
562 fIntervals = NULL; | 563 fIntervals = NULL; |
563 } | 564 } |
564 } | 565 } |
OLD | NEW |