| 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 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkColorMatrixFilter.h" | 11 #include "SkColorMatrixFilter.h" |
| 12 #include "SkDevice.h" | 12 #include "SkDevice.h" |
| 13 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
| 14 #include "SkReadBuffer.h" | 14 #include "SkReadBuffer.h" |
| 15 #include "SkTableColorFilter.h" | 15 #include "SkTableColorFilter.h" |
| 16 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
| 17 | 17 |
| 18 SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter
* input, | 18 SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter
* input, |
| 19 const CropRect* cropRect) { | 19 const CropRect* cropRect) { |
| 20 if (nullptr == cf) { | 20 if (nullptr == cf) { |
| 21 return nullptr; | 21 return nullptr; |
| 22 } | 22 } |
| 23 | 23 |
| 24 SkColorFilter* inputCF; | 24 SkColorFilter* inputCF; |
| 25 if (input && input->isColorFilterNode(&inputCF)) { | 25 if (input && input->isColorFilterNode(&inputCF)) { |
| 26 // 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 |
| 27 // colorfilters into a single one, which the new imagefilter will wrap. | 27 // colorfilters into a single one, which the new imagefilter will wrap. |
| 28 SkAutoUnref autoUnref(inputCF); | 28 sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf
), |
| 29 SkAutoTUnref<SkColorFilter> newCF(SkColorFilter::CreateComposeFilter(cf,
inputCF)); | 29 sk_sp<SkColo
rFilter>(inputCF))); |
| 30 if (newCF) { | 30 if (newCF) { |
| 31 return new SkColorFilterImageFilter(newCF, input->getInput(0), cropR
ect); | 31 return new SkColorFilterImageFilter(newCF.get(), input->getInput(0),
cropRect); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 return new SkColorFilterImageFilter(cf, input, cropRect); | 35 return new SkColorFilterImageFilter(cf, input, cropRect); |
| 36 } | 36 } |
| 37 | 37 |
| 38 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, | 38 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, |
| 39 SkImageFilter* input, const CropRect* cropRect) | 39 SkImageFilter* input, const CropRect* cropRect) |
| 40 : INHERITED(1, &input, cropRect), fColorFilter(SkRef(cf)) { | 40 : INHERITED(1, &input, cropRect), fColorFilter(SkRef(cf)) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) { | 43 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 44 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 44 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 45 SkAutoTUnref<SkColorFilter> cf(buffer.readColorFilter()); | 45 sk_sp<SkColorFilter> cf(buffer.readColorFilter()); |
| 46 return Create(cf, common.getInput(0), &common.cropRect()); | 46 return Create(cf.get(), common.getInput(0), &common.cropRect()); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { | 49 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { |
| 50 this->INHERITED::flatten(buffer); | 50 this->INHERITED::flatten(buffer); |
| 51 buffer.writeFlattenable(fColorFilter); | 51 buffer.writeFlattenable(fColorFilter.get()); |
| 52 } | |
| 53 | |
| 54 SkColorFilterImageFilter::~SkColorFilterImageFilter() { | |
| 55 fColorFilter->unref(); | |
| 56 } | 52 } |
| 57 | 53 |
| 58 bool SkColorFilterImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBit
map& source, | 54 bool SkColorFilterImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBit
map& source, |
| 59 const Context& ctx, | 55 const Context& ctx, |
| 60 SkBitmap* result, | 56 SkBitmap* result, |
| 61 SkIPoint* offset) const { | 57 SkIPoint* offset) const { |
| 62 SkBitmap src = source; | 58 SkBitmap src = source; |
| 63 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 59 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 64 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) { | 60 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) { |
| 65 return false; | 61 return false; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 87 *result = device.get()->accessBitmap(false); | 83 *result = device.get()->accessBitmap(false); |
| 88 offset->fX = bounds.fLeft; | 84 offset->fX = bounds.fLeft; |
| 89 offset->fY = bounds.fTop; | 85 offset->fY = bounds.fTop; |
| 90 return true; | 86 return true; |
| 91 } | 87 } |
| 92 | 88 |
| 93 bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const
{ | 89 bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const
{ |
| 94 SkASSERT(1 == this->countInputs()); | 90 SkASSERT(1 == this->countInputs()); |
| 95 if (!this->cropRectIsSet()) { | 91 if (!this->cropRectIsSet()) { |
| 96 if (filter) { | 92 if (filter) { |
| 97 *filter = SkRef(fColorFilter); | 93 *filter = SkRef(fColorFilter.get()); |
| 98 } | 94 } |
| 99 return true; | 95 return true; |
| 100 } | 96 } |
| 101 return false; | 97 return false; |
| 102 } | 98 } |
| 103 | 99 |
| 104 bool SkColorFilterImageFilter::canComputeFastBounds() const { | 100 bool SkColorFilterImageFilter::canComputeFastBounds() const { |
| 105 if (fColorFilter->affectsTransparentBlack()) { | 101 if (fColorFilter->affectsTransparentBlack()) { |
| 106 return false; | 102 return false; |
| 107 } | 103 } |
| 108 return INHERITED::canComputeFastBounds(); | 104 return INHERITED::canComputeFastBounds(); |
| 109 } | 105 } |
| 110 | 106 |
| 111 #ifndef SK_IGNORE_TO_STRING | 107 #ifndef SK_IGNORE_TO_STRING |
| 112 void SkColorFilterImageFilter::toString(SkString* str) const { | 108 void SkColorFilterImageFilter::toString(SkString* str) const { |
| 113 str->appendf("SkColorFilterImageFilter: ("); | 109 str->appendf("SkColorFilterImageFilter: ("); |
| 114 | 110 |
| 115 str->appendf("input: ("); | 111 str->appendf("input: ("); |
| 116 | 112 |
| 117 if (this->getInput(0)) { | 113 if (this->getInput(0)) { |
| 118 this->getInput(0)->toString(str); | 114 this->getInput(0)->toString(str); |
| 119 } | 115 } |
| 120 | 116 |
| 121 str->appendf(") color filter: "); | 117 str->appendf(") color filter: "); |
| 122 fColorFilter->toString(str); | 118 fColorFilter->toString(str); |
| 123 | 119 |
| 124 str->append(")"); | 120 str->append(")"); |
| 125 } | 121 } |
| 126 #endif | 122 #endif |
| OLD | NEW |