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

Unified Diff: src/effects/SkPictureImageFilter.cpp

Issue 920513003: Make filters use SkImage instead of SkBitmap Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
Index: src/effects/SkPictureImageFilter.cpp
diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp
index 391af1116927aca5903923a65b28aa780e52f5ed..e181db5b8dc91c0b6cca2412ca3eeb3035fa7c5c 100644
--- a/src/effects/SkPictureImageFilter.cpp
+++ b/src/effects/SkPictureImageFilter.cpp
@@ -6,7 +6,7 @@
*/
#include "SkPictureImageFilter.h"
-#include "SkDevice.h"
+#include "SkSurface.h"
#include "SkCanvas.h"
#include "SkReadBuffer.h"
#include "SkSurfaceProps.h"
@@ -90,8 +90,8 @@ void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
}
}
-bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Context& ctx,
- SkBitmap* result, SkIPoint* offset) const {
+bool SkPictureImageFilter::onFilterImage(Proxy* proxy, SkImage&, const Context& ctx,
+ SkAutoTUnref<SkImage>& result, SkIPoint* offset) const {
if (!fPicture) {
offset->fX = offset->fY = 0;
return true;
@@ -109,39 +109,44 @@ bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co
return true;
}
- SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
- if (NULL == device.get()) {
+ SkAutoTUnref<SkSurface> surface(proxy->createSurface(bounds.width(), bounds.height()));
+ if (NULL == surface.get()) {
return false;
}
if (kDeviceSpace_PictureResolution == fPictureResolution ||
0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
- drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx);
+ drawPictureAtSurfaceResolution(proxy, surface.get(), bounds, ctx);
} else {
- drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
+ drawPictureAtLocalResolution(proxy, surface.get(), bounds, ctx);
}
- *result = device.get()->accessBitmap(false);
+ SkImage* snapshot = surface->newImageSnapshot(SkSurface::kYes_Budgeted);
+ if (NULL == snapshot) {
+ return false;
+ }
+ result.reset(snapshot);
+
offset->fX = bounds.fLeft;
offset->fY = bounds.fTop;
return true;
}
-void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDevice* device,
- const SkIRect& deviceBounds,
+void SkPictureImageFilter::drawPictureAtSurfaceResolution(Proxy* proxy, SkSurface* surface,
+ const SkIRect& surfaceBounds,
const Context& ctx) const {
// Pass explicit surface props, as the simplified canvas constructor discards device properties.
// FIXME: switch back to the public constructor (and unfriend) after
// https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
- SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
+ SkCanvas* canvas = surface->getCanvas(); //TODO:(surface, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
- canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
- canvas.concat(ctx.ctm());
- canvas.drawPicture(fPicture);
+ canvas->translate(-SkIntToScalar(surfaceBounds.fLeft), -SkIntToScalar(surfaceBounds.fTop));
+ canvas->concat(ctx.ctm());
+ canvas->drawPicture(fPicture);
}
-void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevice* device,
- const SkIRect& deviceBounds,
+void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkSurface* surface,
+ const SkIRect& surfaceBounds,
const Context& ctx) const {
SkMatrix inverseCtm;
if (!ctx.ctm().invert(&inverseCtm))
@@ -151,25 +156,30 @@ void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevi
if (!localBounds.intersect(fCropRect))
return;
SkIRect localIBounds = localBounds.roundOut();
- SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.width(), localIBounds.height()));
+ SkAutoTUnref<SkSurface> localSurface(proxy->createSurface(localIBounds.width(), localIBounds.height()));
+
// Pass explicit surface props, as the simplified canvas constructor discards device properties.
// FIXME: switch back to the public constructor (and unfriend) after
// https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
- SkCanvas localCanvas(localDevice, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
- localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(localIBounds.fTop));
- localCanvas.drawPicture(fPicture);
+ SkCanvas* localCanvas = localSurface->getCanvas(); // TODO :PROPS!
+ localCanvas->translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(localIBounds.fTop));
+ localCanvas->drawPicture(fPicture);
+
+ SkAutoTUnref<SkImage> image(localSurface->newImageSnapshot(SkSurface::kYes_Budgeted));
+ if (NULL == image) {
+ return;
+ }
// Pass explicit surface props, as the simplified canvas constructor discards device properties.
// FIXME: switch back to the public constructor (and unfriend) after
// https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
- SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
-
- canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
- canvas.concat(ctx.ctm());
+ SkCanvas* canvas = surface->getCanvas(); // TODO: (device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
+ canvas->translate(-SkIntToScalar(surfaceBounds.fLeft), -SkIntToScalar(surfaceBounds.fTop));
+ canvas->concat(ctx.ctm());
SkPaint paint;
paint.setFilterLevel(fFilterLevel);
- canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(localIBounds.fLeft),
+ canvas->drawImage(image, SkIntToScalar(localIBounds.fLeft),
SkIntToScalar(localIBounds.fTop), &paint);
//canvas.drawPicture(fPicture);
}

Powered by Google App Engine
This is Rietveld 408576698