OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 #ifndef _SkTestImageFilters_h | 8 #ifndef _SkTestImageFilters_h |
9 #define _SkTestImageFilters_h | 9 #define _SkTestImageFilters_h |
10 | 10 |
11 #include "SkImageFilter.h" | 11 #include "SkImageFilter.h" |
12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
13 | 13 |
14 // Fun mode that scales down (only) and then scales back up to look pixelated | 14 // Fun mode that scales down (only) and then scales back up to look pixelated |
15 class SK_API SkDownSampleImageFilter : public SkImageFilter { | 15 class SK_API SkDownSampleImageFilter : public SkImageFilter { |
16 public: | 16 public: |
17 static SkImageFilter* Create(SkScalar scale, SkImageFilter* input = NULL) { | 17 static sk_sp<SkImageFilter> Make(SkScalar scale, sk_sp<SkImageFilter> input)
{ |
18 if (!SkScalarIsFinite(scale)) { | 18 if (!SkScalarIsFinite(scale)) { |
19 return NULL; | 19 return nullptr; |
20 } | 20 } |
21 // we don't support scale in this range | 21 // we don't support scale in this range |
22 if (scale > SK_Scalar1 || scale <= 0) { | 22 if (scale > SK_Scalar1 || scale <= 0) { |
23 return NULL; | 23 return nullptr; |
24 } | 24 } |
25 return new SkDownSampleImageFilter(scale, input); | 25 return sk_sp<SkImageFilter>(new SkDownSampleImageFilter(scale, std::move
(input))); |
26 } | 26 } |
27 | 27 |
28 SK_TO_STRING_OVERRIDE() | 28 SK_TO_STRING_OVERRIDE() |
29 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDownSampleImageFilter) | 29 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDownSampleImageFilter) |
30 | 30 |
| 31 #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR |
| 32 static SkImageFilter* Create(SkScalar scale, SkImageFilter* input = nullptr)
{ |
| 33 return Make(scale, sk_ref_sp<SkImageFilter>(input)).release(); |
| 34 } |
| 35 #endif |
| 36 |
31 protected: | 37 protected: |
32 void flatten(SkWriteBuffer&) const override; | 38 void flatten(SkWriteBuffer&) const override; |
33 | 39 |
34 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, | 40 sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&, |
35 SkIPoint* offset) const override; | 41 SkIPoint* offset) const override; |
36 | 42 |
37 private: | 43 private: |
38 SkDownSampleImageFilter(SkScalar scale, SkImageFilter* input) | 44 SkDownSampleImageFilter(SkScalar scale, sk_sp<SkImageFilter> input) |
39 : INHERITED(1, &input), fScale(scale) {} | 45 : INHERITED(&input, 1, nullptr), fScale(scale) {} |
40 | 46 |
41 SkScalar fScale; | 47 SkScalar fScale; |
42 | 48 |
43 typedef SkImageFilter INHERITED; | 49 typedef SkImageFilter INHERITED; |
44 }; | 50 }; |
45 | 51 |
46 #endif | 52 #endif |
OLD | NEW |