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 SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, | 18 SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, |
19 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) { | 19 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) { |
20 if (NULL == cf) { | 20 if (NULL == cf) { |
21 return NULL; | 21 return NULL; |
22 } | 22 } |
23 | 23 |
24 SkColorFilter* inputCF; | 24 SkColorFilter* inputColorFilter; |
25 if (input && input->asColorFilter(&inputCF)) { | 25 if (input && input->asColorFilter(&inputColorFilter)) { |
26 // This is an optimization, as it collapses the hierarchy by just combin
ing the two | 26 SkAutoUnref autoUnref(inputColorFilter); |
27 // colorfilters into a single one, which the new imagefilter will wrap. | 27 SkAutoTUnref<SkColorFilter> newCF(cf->newComposed(inputColorFilter)); |
28 SkAutoUnref autoUnref(inputCF); | |
29 SkAutoTUnref<SkColorFilter> newCF(SkColorFilter::CreateComposeFilter(cf,
inputCF)); | |
30 if (newCF) { | 28 if (newCF) { |
31 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(
0), cropRect, 0)); | 29 return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(
0), cropRect, 0)); |
32 } | 30 } |
33 } | 31 } |
34 | 32 |
35 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect, uniqueID))
; | 33 return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect, uniqueID))
; |
36 } | 34 } |
37 | 35 |
38 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, | 36 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, |
39 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) | 37 SkImageFilter* input, const CropRect* cropRect, uint32_t uniqueID) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 paint.setColorFilter(fColorFilter); | 79 paint.setColorFilter(fColorFilter); |
82 canvas.drawSprite(src, srcOffset.fX - bounds.fLeft, srcOffset.fY - bounds.fT
op, &paint); | 80 canvas.drawSprite(src, srcOffset.fX - bounds.fLeft, srcOffset.fY - bounds.fT
op, &paint); |
83 | 81 |
84 *result = device.get()->accessBitmap(false); | 82 *result = device.get()->accessBitmap(false); |
85 offset->fX = bounds.fLeft; | 83 offset->fX = bounds.fLeft; |
86 offset->fY = bounds.fTop; | 84 offset->fY = bounds.fTop; |
87 return true; | 85 return true; |
88 } | 86 } |
89 | 87 |
90 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { | 88 bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { |
91 if (!this->cropRectIsSet()) { | 89 if (!cropRectIsSet()) { |
92 SkASSERT(1 == this->countInputs()); | |
93 // Since our factory has already performed the collapse optimization, we
can assert that | |
94 // if we have an input, it is *not* also a colorfilter. | |
95 SkASSERT(!this->getInput(0) || !this->getInput(0)->asColorFilter(NULL)); | |
96 if (filter) { | 90 if (filter) { |
97 *filter = SkRef(fColorFilter); | 91 *filter = fColorFilter; |
| 92 fColorFilter->ref(); |
98 } | 93 } |
99 return true; | 94 return true; |
100 } | 95 } |
101 return false; | 96 return false; |
102 } | 97 } |
103 | 98 |
104 #ifndef SK_IGNORE_TO_STRING | 99 #ifndef SK_IGNORE_TO_STRING |
105 void SkColorFilterImageFilter::toString(SkString* str) const { | 100 void SkColorFilterImageFilter::toString(SkString* str) const { |
106 str->appendf("SkColorFilterImageFilter: ("); | 101 str->appendf("SkColorFilterImageFilter: ("); |
107 | 102 |
108 str->appendf("input: ("); | 103 str->appendf("input: ("); |
109 | 104 |
110 if (this->getInput(0)) { | 105 if (this->getInput(0)) { |
111 this->getInput(0)->toString(str); | 106 this->getInput(0)->toString(str); |
112 } | 107 } |
113 | 108 |
114 str->appendf(") color filter: "); | 109 str->appendf(") color filter: "); |
115 fColorFilter->toString(str); | 110 fColorFilter->toString(str); |
116 | 111 |
117 str->append(")"); | 112 str->append(")"); |
118 } | 113 } |
119 #endif | 114 #endif |
OLD | NEW |