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 #ifndef SkPathEffect_DEFINED | 10 #ifndef SkPathEffect_DEFINED |
11 #define SkPathEffect_DEFINED | 11 #define SkPathEffect_DEFINED |
12 | 12 |
13 #include "SkFlattenable.h" | 13 #include "SkFlattenable.h" |
14 #include "SkPath.h" | 14 #include "SkPath.h" |
15 #include "SkPoint.h" | 15 #include "SkPoint.h" |
16 #include "SkRect.h" | 16 #include "SkRect.h" |
17 | 17 |
18 class SkPath; | 18 class SkPath; |
19 class SkStrokeRec; | 19 class SkStrokeRec; |
20 | 20 |
| 21 #ifndef SK_SUPPORT_LEGACY_PATHEFFECT_PTR |
| 22 #define SK_SUPPORT_LEGACY_PATHEFFECT_PTR |
| 23 #endif |
| 24 |
21 /** \class SkPathEffect | 25 /** \class SkPathEffect |
22 | 26 |
23 SkPathEffect is the base class for objects in the SkPaint that affect | 27 SkPathEffect is the base class for objects in the SkPaint that affect |
24 the geometry of a drawing primitive before it is transformed by the | 28 the geometry of a drawing primitive before it is transformed by the |
25 canvas' matrix and drawn. | 29 canvas' matrix and drawn. |
26 | 30 |
27 Dashing is implemented as a subclass of SkPathEffect. | 31 Dashing is implemented as a subclass of SkPathEffect. |
28 */ | 32 */ |
29 class SK_API SkPathEffect : public SkFlattenable { | 33 class SK_API SkPathEffect : public SkFlattenable { |
30 public: | 34 public: |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 typedef SkFlattenable INHERITED; | 151 typedef SkFlattenable INHERITED; |
148 }; | 152 }; |
149 | 153 |
150 /** \class SkPairPathEffect | 154 /** \class SkPairPathEffect |
151 | 155 |
152 Common baseclass for Compose and Sum. This subclass manages two pathEffects, | 156 Common baseclass for Compose and Sum. This subclass manages two pathEffects, |
153 including flattening them. It does nothing in filterPath, and is only useful | 157 including flattening them. It does nothing in filterPath, and is only useful |
154 for managing the lifetimes of its two arguments. | 158 for managing the lifetimes of its two arguments. |
155 */ | 159 */ |
156 class SkPairPathEffect : public SkPathEffect { | 160 class SkPairPathEffect : public SkPathEffect { |
157 public: | |
158 virtual ~SkPairPathEffect(); | |
159 | |
160 protected: | 161 protected: |
161 SkPairPathEffect(SkPathEffect* pe0, SkPathEffect* pe1); | 162 SkPairPathEffect(sk_sp<SkPathEffect> pe0, sk_sp<SkPathEffect> pe1); |
162 | 163 |
163 void flatten(SkWriteBuffer&) const override; | 164 void flatten(SkWriteBuffer&) const override; |
164 | 165 |
165 // these are visible to our subclasses | 166 // these are visible to our subclasses |
166 SkPathEffect* fPE0, *fPE1; | 167 sk_sp<SkPathEffect> fPE0; |
| 168 sk_sp<SkPathEffect> fPE1; |
167 | 169 |
168 SK_TO_STRING_OVERRIDE() | 170 SK_TO_STRING_OVERRIDE() |
169 | 171 |
170 private: | 172 private: |
171 typedef SkPathEffect INHERITED; | 173 typedef SkPathEffect INHERITED; |
172 }; | 174 }; |
173 | 175 |
174 /** \class SkComposePathEffect | 176 /** \class SkComposePathEffect |
175 | 177 |
176 This subclass of SkPathEffect composes its two arguments, to create | 178 This subclass of SkPathEffect composes its two arguments, to create |
177 a compound pathEffect. | 179 a compound pathEffect. |
178 */ | 180 */ |
179 class SkComposePathEffect : public SkPairPathEffect { | 181 class SkComposePathEffect : public SkPairPathEffect { |
180 public: | 182 public: |
181 /** Construct a pathEffect whose effect is to apply first the inner pathEffe
ct | 183 /** Construct a pathEffect whose effect is to apply first the inner pathEffe
ct |
182 and the the outer pathEffect (e.g. outer(inner(path))) | 184 and the the outer pathEffect (e.g. outer(inner(path))) |
183 The reference counts for outer and inner are both incremented in the con
structor, | 185 The reference counts for outer and inner are both incremented in the con
structor, |
184 and decremented in the destructor. | 186 and decremented in the destructor. |
185 */ | 187 */ |
186 static SkPathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) { | 188 static sk_sp<SkPathEffect> Make(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffec
t> inner) { |
187 if (!outer) { | 189 if (!outer) { |
188 return SkSafeRef(inner); | 190 return inner; |
189 } | 191 } |
190 if (!inner) { | 192 if (!inner) { |
191 return SkSafeRef(outer); | 193 return outer; |
192 } | 194 } |
193 return new SkComposePathEffect(outer, inner); | 195 return sk_sp<SkPathEffect>(new SkComposePathEffect(outer, inner)); |
194 } | 196 } |
195 | 197 |
| 198 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR |
| 199 static SkPathEffect* Create(SkPathEffect* outer, SkPathEffect* inner) { |
| 200 return Make(sk_ref_sp(outer), sk_ref_sp(inner)).release(); |
| 201 } |
| 202 #endif |
| 203 |
196 virtual bool filterPath(SkPath* dst, const SkPath& src, | 204 virtual bool filterPath(SkPath* dst, const SkPath& src, |
197 SkStrokeRec*, const SkRect*) const override; | 205 SkStrokeRec*, const SkRect*) const override; |
198 | 206 |
199 SK_TO_STRING_OVERRIDE() | 207 SK_TO_STRING_OVERRIDE() |
200 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect) | 208 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkComposePathEffect) |
201 | 209 |
202 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 210 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
203 bool exposedInAndroidJavaAPI() const override { return true; } | 211 bool exposedInAndroidJavaAPI() const override { return true; } |
204 #endif | 212 #endif |
205 | 213 |
206 protected: | 214 protected: |
207 SkComposePathEffect(SkPathEffect* outer, SkPathEffect* inner) : INHERITED(ou
ter, inner) {} | 215 SkComposePathEffect(sk_sp<SkPathEffect> outer, sk_sp<SkPathEffect> inner) |
| 216 : INHERITED(outer, inner) {} |
208 | 217 |
209 private: | 218 private: |
210 // illegal | 219 // illegal |
211 SkComposePathEffect(const SkComposePathEffect&); | 220 SkComposePathEffect(const SkComposePathEffect&); |
212 SkComposePathEffect& operator=(const SkComposePathEffect&); | 221 SkComposePathEffect& operator=(const SkComposePathEffect&); |
213 | 222 |
214 typedef SkPairPathEffect INHERITED; | 223 typedef SkPairPathEffect INHERITED; |
215 }; | 224 }; |
216 | 225 |
217 /** \class SkSumPathEffect | 226 /** \class SkSumPathEffect |
218 | 227 |
219 This subclass of SkPathEffect applies two pathEffects, one after the other. | 228 This subclass of SkPathEffect applies two pathEffects, one after the other. |
220 Its filterPath() returns true if either of the effects succeeded. | 229 Its filterPath() returns true if either of the effects succeeded. |
221 */ | 230 */ |
222 class SkSumPathEffect : public SkPairPathEffect { | 231 class SkSumPathEffect : public SkPairPathEffect { |
223 public: | 232 public: |
224 /** Construct a pathEffect whose effect is to apply two effects, in sequence
. | 233 /** Construct a pathEffect whose effect is to apply two effects, in sequence
. |
225 (e.g. first(path) + second(path)) | 234 (e.g. first(path) + second(path)) |
226 The reference counts for first and second are both incremented in the co
nstructor, | 235 The reference counts for first and second are both incremented in the co
nstructor, |
227 and decremented in the destructor. | 236 and decremented in the destructor. |
228 */ | 237 */ |
229 static SkPathEffect* Create(SkPathEffect* first, SkPathEffect* second) { | 238 static sk_sp<SkPathEffect> Make(sk_sp<SkPathEffect> first, sk_sp<SkPathEffec
t> second) { |
230 if (!first) { | 239 if (!first) { |
231 return SkSafeRef(second); | 240 return second; |
232 } | 241 } |
233 if (!second) { | 242 if (!second) { |
234 return SkSafeRef(first); | 243 return first; |
235 } | 244 } |
236 return new SkSumPathEffect(first, second); | 245 return sk_sp<SkPathEffect>(new SkSumPathEffect(first, second)); |
237 } | 246 } |
238 | 247 |
| 248 #ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR |
| 249 static SkPathEffect* Create(SkPathEffect* first, SkPathEffect* second) { |
| 250 return Make(sk_ref_sp(first), sk_ref_sp(second)).release(); |
| 251 } |
| 252 #endif |
239 virtual bool filterPath(SkPath* dst, const SkPath& src, | 253 virtual bool filterPath(SkPath* dst, const SkPath& src, |
240 SkStrokeRec*, const SkRect*) const override; | 254 SkStrokeRec*, const SkRect*) const override; |
241 | 255 |
242 SK_TO_STRING_OVERRIDE() | 256 SK_TO_STRING_OVERRIDE() |
243 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect) | 257 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSumPathEffect) |
244 | 258 |
245 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 259 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
246 bool exposedInAndroidJavaAPI() const override { return true; } | 260 bool exposedInAndroidJavaAPI() const override { return true; } |
247 #endif | 261 #endif |
248 | 262 |
249 protected: | 263 protected: |
250 SkSumPathEffect(SkPathEffect* first, SkPathEffect* second) : INHERITED(first
, second) {} | 264 SkSumPathEffect(sk_sp<SkPathEffect> first, sk_sp<SkPathEffect> second) |
| 265 : INHERITED(first, second) {} |
251 | 266 |
252 private: | 267 private: |
253 // illegal | 268 // illegal |
254 SkSumPathEffect(const SkSumPathEffect&); | 269 SkSumPathEffect(const SkSumPathEffect&); |
255 SkSumPathEffect& operator=(const SkSumPathEffect&); | 270 SkSumPathEffect& operator=(const SkSumPathEffect&); |
256 | 271 |
257 typedef SkPairPathEffect INHERITED; | 272 typedef SkPairPathEffect INHERITED; |
258 }; | 273 }; |
259 | 274 |
260 #endif | 275 #endif |
OLD | NEW |