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 "SkMergeImageFilter.h" | 8 #include "SkMergeImageFilter.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkDevice.h" | 10 #include "SkDevice.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 this->initModes(modes); | 48 this->initModes(modes); |
49 } | 49 } |
50 | 50 |
51 SkMergeImageFilter::~SkMergeImageFilter() { | 51 SkMergeImageFilter::~SkMergeImageFilter() { |
52 | 52 |
53 if (fModes != SkTCast<uint8_t*>(fStorage)) { | 53 if (fModes != SkTCast<uint8_t*>(fStorage)) { |
54 sk_free(fModes); | 54 sk_free(fModes); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, | 58 bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkImage* src, |
59 const Context& ctx, | 59 const Context& ctx, |
60 SkBitmap* result, SkIPoint* offset) const
{ | 60 SkAutoTUnref<const SkImage>& result, |
| 61 SkIPoint* offset) const { |
61 if (countInputs() < 1) { | 62 if (countInputs() < 1) { |
62 return false; | 63 return false; |
63 } | 64 } |
64 | 65 |
65 SkIRect bounds; | 66 SkIRect bounds; |
66 if (!this->applyCropRect(ctx, src, SkIPoint::Make(0, 0), &bounds)) { | 67 if (!this->applyCropRect(ctx, src, SkIPoint::Make(0, 0), &bounds)) { |
67 return false; | 68 return false; |
68 } | 69 } |
69 | 70 |
70 const int x0 = bounds.left(); | 71 const int x0 = bounds.left(); |
71 const int y0 = bounds.top(); | 72 const int y0 = bounds.top(); |
72 | 73 |
73 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he
ight())); | 74 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he
ight())); |
74 if (NULL == dst) { | 75 if (NULL == dst) { |
75 return false; | 76 return false; |
76 } | 77 } |
77 SkCanvas canvas(dst); | 78 SkCanvas canvas(dst); |
78 SkPaint paint; | 79 SkPaint paint; |
79 | 80 |
80 int inputCount = countInputs(); | 81 int inputCount = countInputs(); |
81 for (int i = 0; i < inputCount; ++i) { | 82 for (int i = 0; i < inputCount; ++i) { |
82 SkBitmap tmp; | 83 SkAutoTUnref<const SkImage> filteredImage(SkRef(src)); |
83 const SkBitmap* srcPtr; | |
84 SkIPoint pos = SkIPoint::Make(0, 0); | 84 SkIPoint pos = SkIPoint::Make(0, 0); |
85 SkImageFilter* filter = getInput(i); | 85 SkImageFilter* filter = getInput(i); |
86 if (filter) { | 86 if (filter && !filter->filterImage(proxy, src, ctx, filteredImage, &pos)
) { |
87 if (!filter->filterImage(proxy, src, ctx, &tmp, &pos)) { | 87 return false; |
88 return false; | |
89 } | |
90 srcPtr = &tmp; | |
91 } else { | |
92 srcPtr = &src; | |
93 } | 88 } |
94 | 89 |
95 if (fModes) { | 90 if (fModes) { |
96 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]); | 91 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]); |
97 } else { | 92 } else { |
98 paint.setXfermode(NULL); | 93 paint.setXfermode(NULL); |
99 } | 94 } |
100 canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint); | 95 canvas.drawImageAsSprite(*filteredImage, pos.x() - x0, pos.y() - y0, &pa
int); |
101 } | 96 } |
102 | 97 SkImage* image = dst->newImageSnapshot(); |
| 98 if (NULL == image) { |
| 99 return false; |
| 100 } |
| 101 result.reset(image); |
103 offset->fX = bounds.left(); | 102 offset->fX = bounds.left(); |
104 offset->fY = bounds.top(); | 103 offset->fY = bounds.top(); |
105 *result = dst->accessBitmap(false); | |
106 return true; | 104 return true; |
107 } | 105 } |
108 | 106 |
109 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) { | 107 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) { |
110 Common common; | 108 Common common; |
111 if (!common.unflatten(buffer, -1)) { | 109 if (!common.unflatten(buffer, -1)) { |
112 return NULL; | 110 return NULL; |
113 } | 111 } |
114 | 112 |
115 const int count = common.inputCount(); | 113 const int count = common.inputCount(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 for (int i = 0; i < this->countInputs(); ++i) { | 145 for (int i = 0; i < this->countInputs(); ++i) { |
148 SkImageFilter* filter = this->getInput(i); | 146 SkImageFilter* filter = this->getInput(i); |
149 str->appendf("%d: (", i); | 147 str->appendf("%d: (", i); |
150 filter->toString(str); | 148 filter->toString(str); |
151 str->appendf(")"); | 149 str->appendf(")"); |
152 } | 150 } |
153 | 151 |
154 str->append(")"); | 152 str->append(")"); |
155 } | 153 } |
156 #endif | 154 #endif |
OLD | NEW |