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