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 "SkDevice.h" |
12 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
13 #include "SkSpecialImage.h" | |
14 #include "SkSpecialSurface.h" | |
15 #include "SkWriteBuffer.h" | 14 #include "SkWriteBuffer.h" |
16 | 15 |
17 sk_sp<SkImageFilter> SkColorFilterImageFilter::Make(sk_sp<SkColorFilter> cf, | 16 sk_sp<SkImageFilter> SkColorFilterImageFilter::Make(sk_sp<SkColorFilter> cf, |
18 sk_sp<SkImageFilter> input, | 17 sk_sp<SkImageFilter> input, |
19 const CropRect* cropRect) { | 18 const CropRect* cropRect) { |
20 if (!cf) { | 19 if (!cf) { |
21 return nullptr; | 20 return nullptr; |
22 } | 21 } |
23 | 22 |
24 SkColorFilter* inputCF; | 23 SkColorFilter* inputCF; |
(...skipping 25 matching lines...) Expand all Loading... |
50 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 49 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
51 sk_sp<SkColorFilter> cf(buffer.readColorFilter()); | 50 sk_sp<SkColorFilter> cf(buffer.readColorFilter()); |
52 return Make(std::move(cf), common.getInput(0), &common.cropRect()); | 51 return Make(std::move(cf), common.getInput(0), &common.cropRect()); |
53 } | 52 } |
54 | 53 |
55 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { | 54 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { |
56 this->INHERITED::flatten(buffer); | 55 this->INHERITED::flatten(buffer); |
57 buffer.writeFlattenable(fColorFilter.get()); | 56 buffer.writeFlattenable(fColorFilter.get()); |
58 } | 57 } |
59 | 58 |
60 sk_sp<SkSpecialImage> SkColorFilterImageFilter::onFilterImage(SkSpecialImage* so
urce, | 59 bool SkColorFilterImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBit
map& source, |
61 const Context& ctx
, | 60 const Context& ctx, |
62 SkIPoint* offset)
const { | 61 SkBitmap* result, |
63 SkIPoint inputOffset = SkIPoint::Make(0, 0); | 62 SkIPoint* offset) const { |
64 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset))
; | 63 SkBitmap src = source; |
| 64 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 65 bool inputResult = this->filterInputDeprecated(0, proxy, source, ctx, &src,
&srcOffset); |
65 | 66 |
66 SkIRect inputBounds; | 67 SkIRect srcBounds; |
| 68 |
67 if (fColorFilter->affectsTransparentBlack()) { | 69 if (fColorFilter->affectsTransparentBlack()) { |
68 // If the color filter affects transparent black, the bounds are the ent
ire clip. | 70 // If the color filter affects transparent black, the bounds are the ent
ire clip. |
69 inputBounds = ctx.clipBounds(); | 71 srcBounds = ctx.clipBounds(); |
70 } else if (!input) { | 72 } else if (!inputResult) { |
71 return nullptr; | 73 return false; |
72 } else { | 74 } else { |
73 inputBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y(), | 75 srcBounds = src.bounds(); |
74 input->width(), input->height()); | 76 srcBounds.offset(srcOffset); |
75 } | 77 } |
76 | 78 |
77 SkIRect bounds; | 79 SkIRect bounds; |
78 if (!this->applyCropRect(ctx, inputBounds, &bounds)) { | 80 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { |
79 return nullptr; | 81 return false; |
80 } | 82 } |
81 | 83 |
82 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), kPr
emul_SkAlphaType); | 84 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
83 sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); | 85 if (nullptr == device.get()) { |
84 if (!surf) { | 86 return false; |
85 return nullptr; | |
86 } | 87 } |
87 | 88 SkCanvas canvas(device.get()); |
88 SkCanvas* canvas = surf->getCanvas(); | |
89 SkASSERT(canvas); | |
90 | 89 |
91 SkPaint paint; | 90 SkPaint paint; |
92 | |
93 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 91 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
94 paint.setColorFilter(fColorFilter); | 92 paint.setColorFilter(fColorFilter); |
95 | 93 |
96 // TODO: it may not be necessary to clear or drawPaint inside the input boun
ds | 94 // TODO: it may not be necessary to clear or drawPaint inside the input boun
ds |
97 // (see skbug.com/5075) | 95 // (see skbug.com/5075) |
98 if (fColorFilter->affectsTransparentBlack()) { | 96 if (fColorFilter->affectsTransparentBlack()) { |
99 // The subsequent input->draw() call may not fill the entire canvas. For
filters which | 97 // The subsequent drawBitmap call may not fill the entire canvas. For fi
lters which |
100 // affect transparent black, ensure that the filter is applied everywher
e. | 98 // affect transparent black, ensure that the filter is applied everywher
e. |
101 canvas->drawPaint(paint); | 99 canvas.drawPaint(paint); |
102 } else { | |
103 canvas->clear(0x0); | |
104 } | 100 } |
105 | 101 |
106 if (input) { | 102 canvas.drawBitmap(src, SkIntToScalar(srcOffset.fX - bounds.fLeft), |
107 input->draw(canvas, | 103 SkIntToScalar(srcOffset.fY - bounds.fTop), &paint); |
108 SkIntToScalar(inputOffset.fX - bounds.fLeft), | 104 *result = device.get()->accessBitmap(false); |
109 SkIntToScalar(inputOffset.fY - bounds.fTop), | |
110 &paint); | |
111 } | |
112 | |
113 offset->fX = bounds.fLeft; | 105 offset->fX = bounds.fLeft; |
114 offset->fY = bounds.fTop; | 106 offset->fY = bounds.fTop; |
115 return surf->makeImageSnapshot(); | 107 return true; |
116 } | 108 } |
117 | 109 |
118 bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const
{ | 110 bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const
{ |
119 SkASSERT(1 == this->countInputs()); | 111 SkASSERT(1 == this->countInputs()); |
120 if (!this->cropRectIsSet()) { | 112 if (!this->cropRectIsSet()) { |
121 if (filter) { | 113 if (filter) { |
122 *filter = SkRef(fColorFilter.get()); | 114 *filter = SkRef(fColorFilter.get()); |
123 } | 115 } |
124 return true; | 116 return true; |
125 } | 117 } |
(...skipping 13 matching lines...) Expand all Loading... |
139 if (this->getInput(0)) { | 131 if (this->getInput(0)) { |
140 this->getInput(0)->toString(str); | 132 this->getInput(0)->toString(str); |
141 } | 133 } |
142 | 134 |
143 str->appendf(") color filter: "); | 135 str->appendf(") color filter: "); |
144 fColorFilter->toString(str); | 136 fColorFilter->toString(str); |
145 | 137 |
146 str->append(")"); | 138 str->append(")"); |
147 } | 139 } |
148 #endif | 140 #endif |
OLD | NEW |