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

Unified Diff: src/effects/SkPictureImageFilter.cpp

Issue 1779743002: Switch SkPictureImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update for sk_sp 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/SkPictureImageFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkPictureImageFilter.cpp
diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp
index 14c14bb1762f4785e04819d91a10ca1053dd2c0a..c18b873ac4cbdda6217134f88e38dd693ea8aab4 100644
--- a/src/effects/SkPictureImageFilter.cpp
+++ b/src/effects/SkPictureImageFilter.cpp
@@ -6,10 +6,11 @@
*/
#include "SkPictureImageFilter.h"
-#include "SkDevice.h"
+
#include "SkCanvas.h"
#include "SkReadBuffer.h"
-#include "SkSurfaceProps.h"
+#include "SkSpecialImage.h"
+#include "SkSpecialSurface.h"
#include "SkWriteBuffer.h"
#include "SkValidationUtils.h"
@@ -84,55 +85,58 @@ void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
}
}
-bool SkPictureImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap&,
- const Context& ctx,
- SkBitmap* result, SkIPoint* offset) const {
+SkSpecialImage* SkPictureImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx,
+ SkIPoint* offset) const {
if (!fPicture) {
offset->fX = offset->fY = 0;
- return true;
+ return nullptr;
}
SkRect floatBounds;
ctx.ctm().mapRect(&floatBounds, fCropRect);
SkIRect bounds = floatBounds.roundOut();
if (!bounds.intersect(ctx.clipBounds())) {
- return false;
+ return nullptr;
}
if (bounds.isEmpty()) {
offset->fX = offset->fY = 0;
- return true;
+ return nullptr;
Stephen White 2016/03/22 19:58:49 I think this will change the behaviour from contin
robertphillips 2016/03/25 16:53:18 I have updated the two above calls sites to duplic
}
- 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);
+ sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
+ if (!surf) {
+ return nullptr;
}
+ SkCanvas* canvas = surf->getCanvas();
+ SkASSERT(canvas);
+
+ canvas->clear(0x0);
+
if (kDeviceSpace_PictureResolution == fPictureResolution ||
0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
- this->drawPictureAtDeviceResolution(device.get(), bounds, ctx);
+ this->drawPictureAtDeviceResolution(canvas, bounds, ctx);
} else {
- this->drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
+ this->drawPictureAtLocalResolution(source, canvas, bounds, ctx);
}
- *result = device.get()->accessBitmap(false);
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
- return true;
+ return surf->makeImageSnapshot().release();
}
-void SkPictureImageFilter::drawPictureAtDeviceResolution(SkBaseDevice* device,
+void SkPictureImageFilter::drawPictureAtDeviceResolution(SkCanvas* canvas,
const SkIRect& deviceBounds,
const Context& ctx) const {
- SkCanvas canvas(device);
-
- canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
- canvas.concat(ctx.ctm());
- canvas.drawPicture(fPicture);
+ canvas->translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
+ canvas->concat(ctx.ctm());
+ canvas->drawPicture(fPicture);
}
-void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevice* device,
+void SkPictureImageFilter::drawPictureAtLocalResolution(SkSpecialImage* source,
+ SkCanvas* canvas,
const SkIRect& deviceBounds,
const Context& ctx) const {
SkMatrix inverseCtm;
@@ -146,20 +150,39 @@ void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevi
return;
}
SkIRect localIBounds = localBounds.roundOut();
- SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.width(), localIBounds.height()));
- SkCanvas localCanvas(localDevice);
- localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(localIBounds.fTop));
- localCanvas.drawPicture(fPicture);
+ sk_sp<SkSpecialImage> localImg;
+ {
+ const SkImageInfo info = SkImageInfo::MakeN32(localIBounds.width(), localIBounds.height(),
+ kPremul_SkAlphaType);
+
+ sk_sp<SkSpecialSurface> localSurface(source->makeSurface(info));
+ if (!localSurface) {
+ return;
+ }
- SkCanvas canvas(device);
+ SkCanvas* localCanvas = localSurface->getCanvas();
+ SkASSERT(localCanvas);
- canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
- canvas.concat(ctx.ctm());
- SkPaint paint;
- paint.setFilterQuality(fFilterQuality);
- canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(localIBounds.fLeft),
- SkIntToScalar(localIBounds.fTop), &paint);
+ localCanvas->translate(-SkIntToScalar(localIBounds.fLeft),
+ -SkIntToScalar(localIBounds.fTop));
+ localCanvas->drawPicture(fPicture);
+
+ localImg = localSurface->makeImageSnapshot();
+ SkASSERT(localImg);
+ }
+
+ {
+ canvas->translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
+ canvas->concat(ctx.ctm());
+ SkPaint paint;
+ paint.setFilterQuality(fFilterQuality);
+
+ localImg->draw(canvas,
+ SkIntToScalar(localIBounds.fLeft),
+ SkIntToScalar(localIBounds.fTop),
+ &paint);
+ }
}
#ifndef SK_IGNORE_TO_STRING
« no previous file with comments | « include/effects/SkPictureImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698