From daa9da4937b6dfc9e1047239b4afd41b1c5474d5 Mon Sep 17 00:00:00 2001 From: robertphillips Date: Fri, 1 Apr 2016 07:13:23 -0700 Subject: Switch SkDownSampleImageFilter over to new onFilterImage interface This will slightly change the testimagefilters GM images TBR=reed@google.com BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1851583002 Review URL: https://codereview.chromium.org/1851583002 --- src/effects/SkTestImageFilters.cpp | 75 ++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/effects/SkTestImageFilters.cpp b/src/effects/SkTestImageFilters.cpp index a77f5190ff..e0afc47df3 100755 --- a/src/effects/SkTestImageFilters.cpp +++ b/src/effects/SkTestImageFilters.cpp @@ -7,36 +7,22 @@ #include "SkTestImageFilters.h" #include "SkCanvas.h" -#include "SkDevice.h" #include "SkReadBuffer.h" +#include "SkSpecialImage.h" +#include "SkSpecialSurface.h" #include "SkWriteBuffer.h" -// Simple helper canvas that "takes ownership" of the provided device, so that -// when this canvas goes out of scope, so will its device. Could be replaced -// with the following: -// -// SkCanvas canvas(device); -// SkAutoTUnref aur(device); -// -class OwnDeviceCanvas : public SkCanvas { -public: - OwnDeviceCanvas(SkBaseDevice* device) : SkCanvas(device) { - SkSafeUnref(device); - } -}; - /////////////////////////////////////////////////////////////////////////////// -bool SkDownSampleImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src, - const Context&, - SkBitmap* result, SkIPoint*) const { - SkScalar scale = fScale; - if (scale > SK_Scalar1 || scale <= 0) { - return false; +sk_sp SkDownSampleImageFilter::onFilterImage(SkSpecialImage* source, + const Context& ctx, + SkIPoint* offset) const { + if (fScale > SK_Scalar1 || fScale <= 0) { + return nullptr; } - int dstW = SkScalarRoundToInt(src.width() * scale); - int dstH = SkScalarRoundToInt(src.height() * scale); + int dstW = SkScalarRoundToInt(source->width() * fScale); + int dstH = SkScalarRoundToInt(source->height() * fScale); if (dstW < 1) { dstW = 1; } @@ -44,35 +30,46 @@ bool SkDownSampleImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitm dstH = 1; } - SkBitmap tmp; + sk_sp tmp; // downsample { - SkBaseDevice* dev = proxy->createDevice(dstW, dstH); - if (nullptr == dev) { - return false; + const SkImageInfo info = SkImageInfo::MakeN32Premul(dstW, dstH); + + sk_sp surf(source->makeSurface(info)); + if (!surf) { + return nullptr; } - OwnDeviceCanvas canvas(dev); - SkPaint paint; + SkCanvas* canvas = surf->getCanvas(); + SkASSERT(canvas); + + SkPaint paint; paint.setFilterQuality(kLow_SkFilterQuality); - canvas.scale(scale, scale); - canvas.drawBitmap(src, 0, 0, &paint); - tmp = dev->accessBitmap(false); + + canvas->scale(fScale, fScale); + source->draw(canvas, 0, 0, &paint); + + tmp = surf->makeImageSnapshot(); } // upscale { - SkBaseDevice* dev = proxy->createDevice(src.width(), src.height()); - if (nullptr == dev) { - return false; + const SkImageInfo info = SkImageInfo::MakeN32Premul(source->width(), source->height()); + + sk_sp surf(source->makeSurface(info)); + if (!surf) { + return nullptr; } - OwnDeviceCanvas canvas(dev); - canvas.drawBitmapRect(tmp, SkRect::MakeIWH(src.width(), src.height()), nullptr); - *result = dev->accessBitmap(false); + SkCanvas* canvas = surf->getCanvas(); + SkASSERT(canvas); + + canvas->scale(SkScalarInvert(fScale), SkScalarInvert(fScale)); + tmp->draw(canvas, 0, 0, nullptr); + + return surf->makeImageSnapshot(); } - return true; } SkFlattenable* SkDownSampleImageFilter::CreateProc(SkReadBuffer& buffer) { -- cgit v1.2.3