Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, | 58 bool SkMergeImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, |
| 59 const Context& ctx, | 59 const Context& ctx, |
| 60 SkBitmap* result, SkIPoint* offset) const { | 60 SkBitmap* result, SkIPoint* offset) const { |
| 61 if (countInputs() < 1) { | 61 if (countInputs() < 1) { |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 | 64 |
| 65 SkIRect bounds; | 65 SkIRect bounds; |
| 66 if (!this->applyCropRect(ctx, src, SkIPoint::Make(0, 0), &bounds)) { | 66 |
|
robertphillips
2015/11/24 20:58:16
this->countInputs() ?
// Basically move the CL's
Stephen White
2015/11/24 21:15:53
Done (here and elsewhere).
| |
| 67 int inputCount = countInputs(); | |
| 68 SkAutoTDeleteArray<SkBitmap> inputs(new SkBitmap[inputCount]); | |
| 69 SkAutoTDeleteArray<SkIPoint> offsets(new SkIPoint[inputCount]); | |
| 70 bool didProduceResult = false; | |
| 71 for (int i = 0; i < inputCount; ++i) { | |
| 72 inputs[i] = src; | |
| 73 offsets[i].setZero(); | |
| 74 if (!this->filterInput(i, proxy, src, ctx, &inputs[i], &offsets[i])) { | |
| 75 inputs[i].reset(); | |
| 76 continue; | |
| 77 } | |
| 78 SkIRect srcBounds; | |
| 79 inputs[i].getBounds(&srcBounds); | |
| 80 srcBounds.offset(offsets[i]); | |
| 81 if (!didProduceResult) { | |
| 82 bounds = srcBounds; | |
| 83 didProduceResult = true; | |
| 84 } else { | |
| 85 bounds.join(srcBounds); | |
| 86 } | |
| 87 } | |
| 88 if (!didProduceResult) { | |
| 89 return false; | |
| 90 } | |
| 91 if (!this->getCropRect().applyTo(bounds, ctx, &bounds)) { | |
| 67 return false; | 92 return false; |
| 68 } | 93 } |
| 69 | 94 |
| 70 const int x0 = bounds.left(); | 95 const int x0 = bounds.left(); |
| 71 const int y0 = bounds.top(); | 96 const int y0 = bounds.top(); |
| 72 | 97 |
| 73 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he ight())); | 98 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he ight())); |
| 74 if (nullptr == dst) { | 99 if (nullptr == dst) { |
| 75 return false; | 100 return false; |
| 76 } | 101 } |
| 77 SkCanvas canvas(dst); | 102 SkCanvas canvas(dst); |
| 78 SkPaint paint; | 103 SkPaint paint; |
| 79 | 104 |
| 80 bool didProduceResult = false; | |
| 81 int inputCount = countInputs(); | |
| 82 for (int i = 0; i < inputCount; ++i) { | 105 for (int i = 0; i < inputCount; ++i) { |
|
robertphillips
2015/11/24 20:58:16
if (!inputs[i]) {
continue;
}
?
Stephen White
2015/11/24 21:15:53
canvas.drawBitmap() does this as its first line; I
| |
| 83 SkBitmap tmp; | |
| 84 SkBitmap input = src; | |
| 85 SkIPoint pos = SkIPoint::Make(0, 0); | |
| 86 if (!this->filterInput(i, proxy, src, ctx, &input, &pos)) { | |
| 87 continue; | |
| 88 } | |
| 89 if (fModes) { | 106 if (fModes) { |
| 90 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]); | 107 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]); |
| 91 } else { | 108 } else { |
|
robertphillips
2015/11/24 20:58:16
Do we actually need this else clause ?
Stephen White
2015/11/24 21:15:53
Good point. Fixed.
| |
| 92 paint.setXfermode(nullptr); | 109 paint.setXfermode(nullptr); |
| 93 } | 110 } |
|
robertphillips
2015/11/24 20:58:16
\n somewhere ?
Stephen White
2015/11/24 21:15:53
Done.
| |
| 94 canvas.drawBitmap(input, SkIntToScalar(pos.x() - x0), SkIntToScalar(pos. y() - y0), &paint); | 111 canvas.drawBitmap(inputs[i], SkIntToScalar(offsets[i].x() - x0), SkIntTo Scalar(offsets[i].y() - y0), &paint); |
| 95 didProduceResult = true; | |
| 96 } | 112 } |
| 97 | 113 |
| 98 if (!didProduceResult) | |
| 99 return false; | |
| 100 | |
| 101 offset->fX = bounds.left(); | 114 offset->fX = bounds.left(); |
| 102 offset->fY = bounds.top(); | 115 offset->fY = bounds.top(); |
| 103 *result = dst->accessBitmap(false); | 116 *result = dst->accessBitmap(false); |
| 104 return true; | 117 return true; |
| 105 } | 118 } |
| 106 | 119 |
| 107 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) { | 120 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) { |
| 108 Common common; | 121 Common common; |
| 109 if (!common.unflatten(buffer, -1)) { | 122 if (!common.unflatten(buffer, -1)) { |
| 110 return nullptr; | 123 return nullptr; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 for (int i = 0; i < this->countInputs(); ++i) { | 158 for (int i = 0; i < this->countInputs(); ++i) { |
| 146 SkImageFilter* filter = this->getInput(i); | 159 SkImageFilter* filter = this->getInput(i); |
| 147 str->appendf("%d: (", i); | 160 str->appendf("%d: (", i); |
| 148 filter->toString(str); | 161 filter->toString(str); |
| 149 str->appendf(")"); | 162 str->appendf(")"); |
| 150 } | 163 } |
| 151 | 164 |
| 152 str->append(")"); | 165 str->append(")"); |
| 153 } | 166 } |
| 154 #endif | 167 #endif |
| OLD | NEW |