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

Unified Diff: src/effects/SkOffsetImageFilter.cpp

Issue 1695823002: Get OffsetImageFilter really working with SkSpecialImages (Closed) Base URL: https://skia.googlesource.com/skia.git@use-special
Patch Set: Fix bug Created 4 years, 10 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 | « src/core/SkImageFilter.cpp ('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..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 {
« no previous file with comments | « src/core/SkImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698