OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 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 "SkColorFilterImageFilter.h" | 8 #include "SkColorFilterImageFilter.h" |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkColorFilter.h" | 11 #include "SkColorFilter.h" |
12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
13 #include "SkSpecialImage.h" | 13 #include "SkSpecialImage.h" |
14 #include "SkSpecialSurface.h" | 14 #include "SkSpecialSurface.h" |
15 #include "SkWriteBuffer.h" | 15 #include "SkWriteBuffer.h" |
16 | 16 |
17 SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter
* input, | 17 sk_sp<SkImageFilter> SkColorFilterImageFilter::Make(sk_sp<SkColorFilter> cf, |
18 const CropRect* cropRect) { | 18 sk_sp<SkImageFilter> input, |
| 19 const CropRect* cropRect) { |
19 if (!cf) { | 20 if (!cf) { |
20 return nullptr; | 21 return nullptr; |
21 } | 22 } |
22 | 23 |
23 SkColorFilter* inputCF; | 24 SkColorFilter* inputCF; |
24 if (input && input->isColorFilterNode(&inputCF)) { | 25 if (input && input->isColorFilterNode(&inputCF)) { |
25 // This is an optimization, as it collapses the hierarchy by just combin
ing the two | 26 // This is an optimization, as it collapses the hierarchy by just combin
ing the two |
26 // colorfilters into a single one, which the new imagefilter will wrap. | 27 // colorfilters into a single one, which the new imagefilter will wrap. |
27 sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf
), | 28 sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(cf,// can't
move bc of fallthru |
28 sk_sp<SkColo
rFilter>(inputCF))); | 29 sk_sp<SkColo
rFilter>(inputCF))); |
29 if (newCF) { | 30 if (newCF) { |
30 return new SkColorFilterImageFilter(newCF.get(), input->getInput(0),
cropRect); | 31 return sk_sp<SkImageFilter>(new SkColorFilterImageFilter(std::move(n
ewCF), |
| 32 sk_ref_sp(i
nput->getInput(0)), |
| 33 cropRect)); |
31 } | 34 } |
32 } | 35 } |
33 | 36 |
34 return new SkColorFilterImageFilter(cf, input, cropRect); | 37 return sk_sp<SkImageFilter>(new SkColorFilterImageFilter(std::move(cf), |
| 38 std::move(input), |
| 39 cropRect)); |
35 } | 40 } |
36 | 41 |
37 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, | 42 SkColorFilterImageFilter::SkColorFilterImageFilter(sk_sp<SkColorFilter> cf, |
38 SkImageFilter* input, | 43 sk_sp<SkImageFilter> input, |
39 const CropRect* cropRect) | 44 const CropRect* cropRect) |
40 : INHERITED(1, &input, cropRect) | 45 : INHERITED(&input, 1, cropRect) |
41 , fColorFilter(SkRef(cf)) { | 46 , fColorFilter(std::move(cf)) { |
42 } | 47 } |
43 | 48 |
44 sk_sp<SkFlattenable> SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer)
{ | 49 sk_sp<SkFlattenable> SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer)
{ |
45 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 50 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
46 sk_sp<SkColorFilter> cf(buffer.readColorFilter()); | 51 sk_sp<SkColorFilter> cf(buffer.readColorFilter()); |
47 return sk_sp<SkFlattenable>(Create(cf.get(), common.getInput(0).get(), &comm
on.cropRect())); | 52 return Make(std::move(cf), common.getInput(0), &common.cropRect()); |
48 } | 53 } |
49 | 54 |
50 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { | 55 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { |
51 this->INHERITED::flatten(buffer); | 56 this->INHERITED::flatten(buffer); |
52 buffer.writeFlattenable(fColorFilter.get()); | 57 buffer.writeFlattenable(fColorFilter.get()); |
53 } | 58 } |
54 | 59 |
55 sk_sp<SkSpecialImage> SkColorFilterImageFilter::onFilterImage(SkSpecialImage* so
urce, | 60 sk_sp<SkSpecialImage> SkColorFilterImageFilter::onFilterImage(SkSpecialImage* so
urce, |
56 const Context& ctx
, | 61 const Context& ctx
, |
57 SkIPoint* offset)
const { | 62 SkIPoint* offset)
const { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if (this->getInput(0)) { | 139 if (this->getInput(0)) { |
135 this->getInput(0)->toString(str); | 140 this->getInput(0)->toString(str); |
136 } | 141 } |
137 | 142 |
138 str->appendf(") color filter: "); | 143 str->appendf(") color filter: "); |
139 fColorFilter->toString(str); | 144 fColorFilter->toString(str); |
140 | 145 |
141 str->append(")"); | 146 str->append(")"); |
142 } | 147 } |
143 #endif | 148 #endif |
OLD | NEW |