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

Unified Diff: src/effects/SkOffsetImageFilter.cpp

Issue 1766743003: Switch SkOffsetImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@if-follow-on
Patch Set: Fix bogus return value 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/SkOffsetImageFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkOffsetImageFilter.cpp
diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp
index ddc8be8f95ae6aa258d6f1f358e2d25033eec394..77cf4423844af2207ff821ff49b95e0c80e93cad 100644
--- a/src/effects/SkOffsetImageFilter.cpp
+++ b/src/effects/SkOffsetImageFilter.cpp
@@ -6,60 +6,63 @@
*/
#include "SkOffsetImageFilter.h"
-#include "SkBitmap.h"
+
#include "SkCanvas.h"
-#include "SkDevice.h"
-#include "SkReadBuffer.h"
-#include "SkWriteBuffer.h"
#include "SkMatrix.h"
#include "SkPaint.h"
+#include "SkReadBuffer.h"
+#include "SkSpecialImage.h"
+#include "SkSpecialSurface.h"
+#include "SkWriteBuffer.h"
-bool SkOffsetImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source,
- const Context& ctx,
- SkBitmap* result,
- SkIPoint* offset) const {
- SkBitmap src = source;
+SkSpecialImage* SkOffsetImageFilter::onFilterImage(SkSpecialImage* source,
+ const Context& ctx,
+ SkIPoint* offset) const {
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (!cropRectIsSet()) {
- if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) {
- return false;
- }
+ SkAutoTUnref<SkSpecialImage> input(this->filterInput(0, source, ctx, &srcOffset));
+ if (!input) {
+ return nullptr;
+ }
- SkVector vec;
- ctx.ctm().mapVectors(&vec, &fOffset, 1);
+ SkVector vec;
+ ctx.ctm().mapVectors(&vec, &fOffset, 1);
+ if (!this->cropRectIsSet()) {
offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX);
offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY);
- *result = src;
+ return input.release();
} else {
- if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) {
- return false;
- }
-
SkIRect bounds;
- SkIRect srcBounds = src.bounds();
+ SkIRect srcBounds = SkIRect::MakeWH(input->width(), input->height());
srcBounds.offset(srcOffset);
if (!this->applyCropRect(ctx, srcBounds, &bounds)) {
- return false;
+ return nullptr;
}
- SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
- if (nullptr == device.get()) {
- return false;
+ SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
+ kPremul_SkAlphaType);
+ SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
+ if (!surf) {
+ return nullptr;
}
- SkCanvas canvas(device);
+
+ SkCanvas* canvas = surf->getCanvas();
+ SkASSERT(canvas);
+
+ // TODO: it seems like this clear shouldn't be necessary (see skbug.com/5075)
+ canvas->clear(0x0);
+
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft),
- SkIntToScalar(srcOffset.fY - bounds.fTop));
- SkVector vec;
- ctx.ctm().mapVectors(&vec, &fOffset, 1);
- canvas.drawBitmap(src, vec.x(), vec.y(), &paint);
- *result = device->accessBitmap(false);
+ canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft),
+ SkIntToScalar(srcOffset.fY - bounds.fTop));
+
+ input->draw(canvas, vec.x(), vec.y(), &paint);
+
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
+ return surf->newImageSnapshot();
}
- return true;
}
void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const {
« no previous file with comments | « include/effects/SkOffsetImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698