Index: src/effects/SkOffsetImageFilter.cpp |
diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp |
index ddc8be8f95ae6aa258d6f1f358e2d25033eec394..d5df654320e6be8878dc385bd3bc7d3c8f3254bb 100644 |
--- a/src/effects/SkOffsetImageFilter.cpp |
+++ b/src/effects/SkOffsetImageFilter.cpp |
@@ -13,53 +13,72 @@ |
#include "SkWriteBuffer.h" |
#include "SkMatrix.h" |
#include "SkPaint.h" |
+#include "SkSpecialImage.h" |
+#include "SkSpecialSurface.h" |
-bool SkOffsetImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source, |
- const Context& ctx, |
- SkBitmap* result, |
- SkIPoint* offset) const { |
- SkBitmap src = source; |
+SkSpecialImage* SkOffsetImageFilter::onFilterImage(SkSpecialImage* srcIn, |
+ 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> src(this->filterInput(0, srcIn, ctx, &srcOffset)); |
+ if (!src) { |
+ 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 src.release(); |
} else { |
- if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) { |
- return false; |
- } |
- |
SkIRect bounds; |
- SkIRect srcBounds = src.bounds(); |
+ SkIRect srcBounds = SkIRect::MakeWH(srcIn->width(), srcIn->height()); |
srcBounds.offset(srcOffset); |
if (!this->applyCropRect(ctx, srcBounds, &bounds)) { |
return false; |
} |
- 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(src->newSurface(info)); |
+ if (!surf) { |
+ return nullptr; |
} |
- SkCanvas canvas(device); |
+ |
+ SkCanvas* canvas = surf->getCanvas(); |
+ |
+ 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)); |
+ |
+ src->draw(canvas, vec.x(), vec.y(), &paint); |
+ |
offset->fX = bounds.fLeft; |
offset->fY = bounds.fTop; |
+ return surf->newImageSnapshot(); |
} |
- return true; |
+} |
+ |
+bool SkOffsetImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source, |
+ const Context& ctx, |
+ SkBitmap* result, |
+ SkIPoint* offset) const { |
+ SkAutoTUnref<SkSpecialImage> specialSrc(SkSpecialImage::internal_fromBM(proxy, source)); |
+ if (!specialSrc) { |
+ return false; |
+ } |
+ |
+ SkAutoTUnref<SkSpecialImage> tmp(this->onFilterImage(specialSrc, ctx, offset)); |
+ if (!tmp) { |
+ return false; |
+ } |
+ |
+ return tmp->internal_getBM(result); |
} |
void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { |