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

Unified Diff: src/effects/SkTestImageFilters.cpp

Issue 1859533002: Revert of Switch SkDownSampleImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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/SkTestImageFilters.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkTestImageFilters.cpp
diff --git a/src/effects/SkTestImageFilters.cpp b/src/effects/SkTestImageFilters.cpp
index f1ac33bcd7cedf6b6abf555958e2cc635aa6b16c..e9ec7c19ceb6cd80f1445835daf95c1fed08f7c8 100755
--- a/src/effects/SkTestImageFilters.cpp
+++ b/src/effects/SkTestImageFilters.cpp
@@ -7,22 +7,36 @@
#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<SkBaseDevice> aur(device);
+//
+class OwnDeviceCanvas : public SkCanvas {
+public:
+ OwnDeviceCanvas(SkBaseDevice* device) : SkCanvas(device) {
+ SkSafeUnref(device);
+ }
+};
///////////////////////////////////////////////////////////////////////////////
-sk_sp<SkSpecialImage> SkDownSampleImageFilter::onFilterImage(SkSpecialImage* source,
- const Context& ctx,
- SkIPoint* offset) const {
- if (fScale > SK_Scalar1 || fScale <= 0) {
- return nullptr;
+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;
}
- int dstW = SkScalarRoundToInt(source->width() * fScale);
- int dstH = SkScalarRoundToInt(source->height() * fScale);
+ int dstW = SkScalarRoundToInt(src.width() * scale);
+ int dstH = SkScalarRoundToInt(src.height() * scale);
if (dstW < 1) {
dstW = 1;
}
@@ -30,50 +44,35 @@
dstH = 1;
}
- sk_sp<SkSpecialImage> tmp;
+ SkBitmap tmp;
// downsample
{
- const SkImageInfo info = SkImageInfo::MakeN32Premul(dstW, dstH);
+ SkBaseDevice* dev = proxy->createDevice(dstW, dstH);
+ if (nullptr == dev) {
+ return false;
+ }
+ OwnDeviceCanvas canvas(dev);
+ SkPaint paint;
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
- if (!surf) {
- return nullptr;
- }
-
- SkCanvas* canvas = surf->getCanvas();
- SkASSERT(canvas);
-
- SkPaint paint;
- paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
paint.setFilterQuality(kLow_SkFilterQuality);
-
- canvas->scale(fScale, fScale);
- source->draw(canvas, 0, 0, &paint);
-
- tmp = surf->makeImageSnapshot();
+ canvas.scale(scale, scale);
+ canvas.drawBitmap(src, 0, 0, &paint);
+ tmp = dev->accessBitmap(false);
}
// upscale
{
- const SkImageInfo info = SkImageInfo::MakeN32Premul(source->width(), source->height());
+ SkBaseDevice* dev = proxy->createDevice(src.width(), src.height());
+ if (nullptr == dev) {
+ return false;
+ }
+ OwnDeviceCanvas canvas(dev);
- sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
- if (!surf) {
- return nullptr;
- }
-
- SkCanvas* canvas = surf->getCanvas();
- SkASSERT(canvas);
-
- SkPaint paint;
- paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
-
- canvas->scale(SkScalarInvert(fScale), SkScalarInvert(fScale));
- tmp->draw(canvas, 0, 0, &paint);
-
- return surf->makeImageSnapshot();
+ canvas.drawBitmapRect(tmp, SkRect::MakeIWH(src.width(), src.height()), nullptr);
+ *result = dev->accessBitmap(false);
}
+ return true;
}
sk_sp<SkFlattenable> SkDownSampleImageFilter::CreateProc(SkReadBuffer& buffer) {
« no previous file with comments | « include/effects/SkTestImageFilters.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698