Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Unified Diff: src/effects/SkMergeImageFilter.cpp

Issue 1763223002: Switch SkMergeImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@if-follow-on
Patch Set: Address code review comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/effects/SkMergeImageFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkMergeImageFilter.cpp
diff --git a/src/effects/SkMergeImageFilter.cpp b/src/effects/SkMergeImageFilter.cpp
index 79e5329ef1455e0c5d57cd0512db5de956ff6a71..e6761e9960b88c39dfd83233269b0905311080a7 100755
--- a/src/effects/SkMergeImageFilter.cpp
+++ b/src/effects/SkMergeImageFilter.cpp
@@ -6,9 +6,11 @@
*/
#include "SkMergeImageFilter.h"
+
#include "SkCanvas.h"
-#include "SkDevice.h"
#include "SkReadBuffer.h"
+#include "SkSpecialImage.h"
+#include "SkSpecialSurface.h"
#include "SkWriteBuffer.h"
#include "SkValidationUtils.h"
@@ -55,72 +57,76 @@ SkMergeImageFilter::~SkMergeImageFilter() {
}
}
-bool SkMergeImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src,
- const Context& ctx,
- SkBitmap* result, SkIPoint* offset) const {
+SkSpecialImage* SkMergeImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx,
+ SkIPoint* offset) const {
int inputCount = this->countInputs();
if (inputCount < 1) {
- return false;
+ return nullptr;
}
SkIRect bounds;
+ bounds.setEmpty();
- SkAutoTDeleteArray<SkBitmap> inputs(new SkBitmap[inputCount]);
+ SkAutoTDeleteArray<SkAutoTUnref<SkSpecialImage>> inputs(
+ new SkAutoTUnref<SkSpecialImage>[inputCount]);
Stephen White 2016/03/08 16:04:03 Nit: spacing is slightly weird here.
SkAutoTDeleteArray<SkIPoint> offsets(new SkIPoint[inputCount]);
- bool didProduceResult = false;
// Filter all of the inputs.
for (int i = 0; i < inputCount; ++i) {
- inputs[i] = src;
offsets[i].setZero();
- if (!this->filterInputDeprecated(i, proxy, src, ctx, &inputs[i], &offsets[i])) {
- inputs[i].reset();
+ inputs[i].reset(this->filterInput(i, source, ctx, &offsets[i]));
+ if (!inputs[i]) {
continue;
}
- SkIRect srcBounds;
- inputs[i].getBounds(&srcBounds);
- srcBounds.offset(offsets[i]);
- if (!didProduceResult) {
- bounds = srcBounds;
- didProduceResult = true;
- } else {
- bounds.join(srcBounds);
- }
+ const SkIRect inputBounds = SkIRect::MakeXYWH(offsets[i].fX, offsets[i].fY,
+ inputs[i]->width(), inputs[i]->height());
+ bounds.join(inputBounds);
}
- if (!didProduceResult) {
- return false;
+ if (bounds.isEmpty()) {
+ return nullptr;
}
// Apply the crop rect to the union of the inputs' bounds.
this->getCropRect().applyTo(bounds, ctx.ctm(), &bounds);
if (!bounds.intersect(ctx.clipBounds())) {
- return false;
+ return nullptr;
}
const int x0 = bounds.left();
const int y0 = bounds.top();
- // Allocate the destination buffer.
- SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.height()));
- if (nullptr == dst) {
- return false;
+ SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
+ kPremul_SkAlphaType);
+
+ SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
+ if (!surf) {
+ return nullptr;
}
- SkCanvas canvas(dst);
+
+ SkCanvas* canvas = surf->getCanvas();
+ SkASSERT(canvas);
+
+ canvas->clear(0x0);
// Composite all of the filter inputs.
for (int i = 0; i < inputCount; ++i) {
+ if (!inputs[i]) {
+ continue;
+ }
+
SkPaint paint;
if (fModes) {
paint.setXfermodeMode((SkXfermode::Mode)fModes[i]);
}
- canvas.drawBitmap(inputs[i], SkIntToScalar(offsets[i].x() - x0),
- SkIntToScalar(offsets[i].y() - y0), &paint);
+
+ inputs[i]->draw(canvas,
+ SkIntToScalar(offsets[i].x() - x0), SkIntToScalar(offsets[i].y() - y0),
+ &paint);
}
offset->fX = bounds.left();
offset->fY = bounds.top();
- *result = dst->accessBitmap(false);
- return true;
+ return surf->newImageSnapshot();
}
SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) {
« no previous file with comments | « include/effects/SkMergeImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698