Fixed double offset in resize filter
The fix is trivial, simply remove the extra offset
I added another case to the resizeimagefilter gm and made it so that it looks exactly like the one next to it, so that failure is easy to detect visually.
BUG=skia:
R=senorblanco@google.com, senorblanco@chromium.org
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/208303002
git-svn-id: http://skia.googlecode.com/svn/trunk@13892 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt
index 33a787a..607f218 100644
--- a/expectations/gm/ignored-tests.txt
+++ b/expectations/gm/ignored-tests.txt
@@ -55,3 +55,7 @@
# This change removes an API that this GM was testing. If/when it lands and sticks,
# I will likely just delete the GM.
canvas-layer-state
+
+# sugoi: https://codereview.chromium.org/208303002/
+# This path fixes a double offset with the resize filter and adds a gm case to test it
+resizeimagefilter
diff --git a/gm/resizeimagefilter.cpp b/gm/resizeimagefilter.cpp
index 8f5c015..02bbaff 100644
--- a/gm/resizeimagefilter.cpp
+++ b/gm/resizeimagefilter.cpp
@@ -6,8 +6,11 @@
*/
#include "gm.h"
+#include "SkBitmapDevice.h"
+#include "SkBitmapSource.h"
#include "SkColor.h"
#include "SkResizeImageFilter.h"
+#include "SkRefCnt.h"
namespace skiagm {
@@ -25,7 +28,8 @@
void draw(SkCanvas* canvas,
const SkRect& rect,
const SkSize& deviceSize,
- SkPaint::FilterLevel filterLevel) {
+ SkPaint::FilterLevel filterLevel,
+ SkImageFilter* input = NULL) {
SkRect dstRect;
canvas->getTotalMatrix().mapRect(&dstRect, rect);
canvas->save();
@@ -37,7 +41,8 @@
SkAutoTUnref<SkImageFilter> imageFilter(
SkResizeImageFilter::Create(SkScalarInvert(deviceScaleX),
SkScalarInvert(deviceScaleY),
- filterLevel));
+ filterLevel,
+ input));
SkPaint filteredPaint;
filteredPaint.setImageFilter(imageFilter.get());
canvas->saveLayer(&rect, &filteredPaint);
@@ -51,7 +56,7 @@
}
virtual SkISize onISize() {
- return make_isize(420, 100);
+ return make_isize(520, 100);
}
virtual void onDraw(SkCanvas* canvas) {
@@ -82,6 +87,28 @@
srcRect,
deviceSize,
SkPaint::kHigh_FilterLevel);
+
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 16);
+ bitmap.eraseARGB(0x00, 0x00, 0x00, 0x00);
+ {
+ SkBitmapDevice bitmapDevice(bitmap);
+ SkCanvas bitmapCanvas(&bitmapDevice);
+ SkPaint paint;
+ paint.setColor(0xFF00FF00);
+ SkRect ovalRect = SkRect::MakeWH(16, 16);
+ ovalRect.inset(SkScalarDiv(2.0f, 3.0f), SkScalarDiv(2.0f, 3.0f));
+ bitmapCanvas.drawOval(ovalRect, paint);
+ }
+ SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20);
+ SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120);
+ SkAutoTUnref<SkBitmapSource> source(SkBitmapSource::Create(bitmap, inRect, outRect));
+ canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
+ draw(canvas,
+ srcRect,
+ deviceSize,
+ SkPaint::kHigh_FilterLevel,
+ source.get());
}
private:
diff --git a/src/effects/SkResizeImageFilter.cpp b/src/effects/SkResizeImageFilter.cpp
index 87c30c6..7a52c22 100644
--- a/src/effects/SkResizeImageFilter.cpp
+++ b/src/effects/SkResizeImageFilter.cpp
@@ -76,7 +76,7 @@
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
paint.setFilterLevel(fFilterLevel);
- canvas.drawBitmap(src, srcRect.left(), srcRect.top(), &paint);
+ canvas.drawBitmap(src, 0, 0, &paint);
*result = device.get()->accessBitmap(false);
offset->fX = dstBounds.fLeft;