OLD | NEW |
| 1 |
1 /* | 2 /* |
2 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
3 * | 4 * |
4 * 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 |
5 * found in the LICENSE file. | 6 * found in the LICENSE file. |
6 */ | 7 */ |
7 | 8 |
8 #include "SkPathEffect.h" | 9 #include "SkPathEffect.h" |
9 #include "SkPath.h" | 10 #include "SkPath.h" |
10 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
11 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
12 | 13 |
13 /////////////////////////////////////////////////////////////////////////////// | 14 /////////////////////////////////////////////////////////////////////////////// |
14 | 15 |
15 void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const { | 16 void SkPathEffect::computeFastBounds(SkRect* dst, const SkRect& src) const { |
16 *dst = src; | 17 *dst = src; |
17 } | 18 } |
18 | 19 |
19 bool SkPathEffect::asPoints(PointData* results, const SkPath& src, | 20 bool SkPathEffect::asPoints(PointData* results, const SkPath& src, |
20 const SkStrokeRec&, const SkMatrix&, const SkRect*) const { | 21 const SkStrokeRec&, const SkMatrix&, const SkRect*) const { |
21 return false; | 22 return false; |
22 } | 23 } |
23 | 24 |
24 SkPathEffect::DashType SkPathEffect::asADash(DashInfo* info) const { | 25 SkPathEffect::DashType SkPathEffect::asADash(DashInfo* info) const { |
25 return kNone_DashType; | 26 return kNone_DashType; |
26 } | 27 } |
27 | 28 |
28 /////////////////////////////////////////////////////////////////////////////// | 29 /////////////////////////////////////////////////////////////////////////////// |
29 | 30 |
30 SkPairPathEffect::SkPairPathEffect(sk_sp<SkPathEffect> pe0, sk_sp<SkPathEffect>
pe1) | 31 SkPairPathEffect::SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1) |
31 : fPE0(std::move(pe0)), fPE1(std::move(pe1)) | 32 : fPE0(pe0), fPE1(pe1) { |
32 { | 33 SkASSERT(pe0); |
33 SkASSERT(fPE0.get()); | 34 SkASSERT(pe1); |
34 SkASSERT(fPE1.get()); | 35 fPE0->ref(); |
| 36 fPE1->ref(); |
| 37 } |
| 38 |
| 39 SkPairPathEffect::~SkPairPathEffect() { |
| 40 SkSafeUnref(fPE0); |
| 41 SkSafeUnref(fPE1); |
35 } | 42 } |
36 | 43 |
37 /* | 44 /* |
38 Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data] | 45 Format: [oe0-factory][pe1-factory][pe0-size][pe0-data][pe1-data] |
39 */ | 46 */ |
40 void SkPairPathEffect::flatten(SkWriteBuffer& buffer) const { | 47 void SkPairPathEffect::flatten(SkWriteBuffer& buffer) const { |
41 buffer.writeFlattenable(fPE0.get()); | 48 buffer.writeFlattenable(fPE0); |
42 buffer.writeFlattenable(fPE1.get()); | 49 buffer.writeFlattenable(fPE1); |
43 } | 50 } |
44 | 51 |
45 #ifndef SK_IGNORE_TO_STRING | 52 #ifndef SK_IGNORE_TO_STRING |
46 void SkPairPathEffect::toString(SkString* str) const { | 53 void SkPairPathEffect::toString(SkString* str) const { |
47 str->appendf("first: "); | 54 str->appendf("first: "); |
48 if (fPE0) { | 55 if (fPE0) { |
49 fPE0->toString(str); | 56 fPE0->toString(str); |
50 } | 57 } |
51 str->appendf(" second: "); | 58 str->appendf(" second: "); |
52 if (fPE1) { | 59 if (fPE1) { |
53 fPE1->toString(str); | 60 fPE1->toString(str); |
54 } | 61 } |
55 } | 62 } |
56 #endif | 63 #endif |
57 | 64 |
58 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
59 | 66 |
60 SkFlattenable* SkComposePathEffect::CreateProc(SkReadBuffer& buffer) { | 67 SkFlattenable* SkComposePathEffect::CreateProc(SkReadBuffer& buffer) { |
61 sk_sp<SkPathEffect> pe0(buffer.readPathEffect()); | 68 SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect()); |
62 sk_sp<SkPathEffect> pe1(buffer.readPathEffect()); | 69 SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect()); |
63 return SkComposePathEffect::Make(std::move(pe0), std::move(pe1)).release(); | 70 if (pe0 && pe1) { |
| 71 return SkComposePathEffect::Create(pe0, pe1); |
| 72 } else { |
| 73 return nullptr; |
| 74 } |
64 } | 75 } |
65 | 76 |
66 bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src, | 77 bool SkComposePathEffect::filterPath(SkPath* dst, const SkPath& src, |
67 SkStrokeRec* rec, const SkRect* cullRect) const { | 78 SkStrokeRec* rec, const SkRect* cullRect) const { |
| 79 // we may have failed to unflatten these, so we have to check |
| 80 if (!fPE0 || !fPE1) { |
| 81 return false; |
| 82 } |
| 83 |
68 SkPath tmp; | 84 SkPath tmp; |
69 const SkPath* ptr = &src; | 85 const SkPath* ptr = &src; |
70 | 86 |
71 if (fPE1->filterPath(&tmp, src, rec, cullRect)) { | 87 if (fPE1->filterPath(&tmp, src, rec, cullRect)) { |
72 ptr = &tmp; | 88 ptr = &tmp; |
73 } | 89 } |
74 return fPE0->filterPath(dst, *ptr, rec, cullRect); | 90 return fPE0->filterPath(dst, *ptr, rec, cullRect); |
75 } | 91 } |
76 | 92 |
77 | 93 |
78 #ifndef SK_IGNORE_TO_STRING | 94 #ifndef SK_IGNORE_TO_STRING |
79 void SkComposePathEffect::toString(SkString* str) const { | 95 void SkComposePathEffect::toString(SkString* str) const { |
80 str->appendf("SkComposePathEffect: ("); | 96 str->appendf("SkComposePathEffect: ("); |
81 this->INHERITED::toString(str); | 97 this->INHERITED::toString(str); |
82 str->appendf(")"); | 98 str->appendf(")"); |
83 } | 99 } |
84 #endif | 100 #endif |
85 | 101 |
86 /////////////////////////////////////////////////////////////////////////////// | 102 /////////////////////////////////////////////////////////////////////////////// |
87 | 103 |
88 SkFlattenable* SkSumPathEffect::CreateProc(SkReadBuffer& buffer) { | 104 SkFlattenable* SkSumPathEffect::CreateProc(SkReadBuffer& buffer) { |
89 sk_sp<SkPathEffect> pe0(buffer.readPathEffect()); | 105 SkAutoTUnref<SkPathEffect> pe0(buffer.readPathEffect()); |
90 sk_sp<SkPathEffect> pe1(buffer.readPathEffect()); | 106 SkAutoTUnref<SkPathEffect> pe1(buffer.readPathEffect()); |
91 return SkSumPathEffect::Make(pe0, pe1).release(); | 107 if (pe0 && pe1) { |
| 108 return SkSumPathEffect::Create(pe0, pe1); |
| 109 } else { |
| 110 return nullptr; |
| 111 } |
92 } | 112 } |
93 | 113 |
94 bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src, | 114 bool SkSumPathEffect::filterPath(SkPath* dst, const SkPath& src, |
95 SkStrokeRec* rec, const SkRect* cullRect) const { | 115 SkStrokeRec* rec, const SkRect* cullRect) const { |
96 // use bit-or so that we always call both, even if the first one succeeds | 116 // use bit-or so that we always call both, even if the first one succeeds |
97 return fPE0->filterPath(dst, src, rec, cullRect) | | 117 return fPE0->filterPath(dst, src, rec, cullRect) | |
98 fPE1->filterPath(dst, src, rec, cullRect); | 118 fPE1->filterPath(dst, src, rec, cullRect); |
99 } | 119 } |
100 | 120 |
101 | 121 |
102 #ifndef SK_IGNORE_TO_STRING | 122 #ifndef SK_IGNORE_TO_STRING |
103 void SkSumPathEffect::toString(SkString* str) const { | 123 void SkSumPathEffect::toString(SkString* str) const { |
104 str->appendf("SkSumPathEffect: ("); | 124 str->appendf("SkSumPathEffect: ("); |
105 this->INHERITED::toString(str); | 125 this->INHERITED::toString(str); |
106 str->appendf(")"); | 126 str->appendf(")"); |
107 } | 127 } |
108 #endif | 128 #endif |
OLD | NEW |