diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt index fc0c652089..c6483c9016 100644 --- a/expectations/gm/ignored-tests.txt +++ b/expectations/gm/ignored-tests.txt @@ -41,3 +41,7 @@ inverse_paths # senorblanco will rebaseline. imagefiltersclipped imagefiltersscaled + +# Added as part of https://codereview.chromium.org/186643003/. +# senorblanco will rebaseline. +offsetimagefilter diff --git a/gm/offsetimagefilter.cpp b/gm/offsetimagefilter.cpp index 0425311b0a..52d6de9503 100644 --- a/gm/offsetimagefilter.cpp +++ b/gm/offsetimagefilter.cpp @@ -9,7 +9,7 @@ #include "SkOffsetImageFilter.h" #include "SkBitmapSource.h" -#define WIDTH 400 +#define WIDTH 600 #define HEIGHT 100 #define MARGIN 12 @@ -63,14 +63,26 @@ protected: return make_isize(WIDTH, HEIGHT); } - void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, - SkScalar x, SkScalar y) { + void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, SkScalar scale, const SkIRect& cropRect) { canvas->save(); - canvas->translate(x, y); - canvas->clipRect(SkRect::MakeXYWH(0, 0, - SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); + SkRect clipRect = SkRect::MakeWH( + SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); + canvas->clipRect(clipRect); + canvas->scale(scale, scale); canvas->drawBitmap(bitmap, 0, 0, &paint); canvas->restore(); + SkPaint strokePaint; + strokePaint.setStyle(SkPaint::kStroke_Style); + strokePaint.setColor(SK_ColorRED); + + // Draw a boundary rect around the intersection of the clip rect + // and crop rect. + SkMatrix scaleMatrix; + scaleMatrix.setScale(scale, scale); + SkRect cropRectFloat; + scaleMatrix.mapRect(&cropRectFloat, SkRect::Make(cropRect)); + clipRect.intersect(cropRectFloat); + canvas->drawRect(clipRect, strokePaint); } virtual void onDraw(SkCanvas* canvas) { @@ -82,7 +94,6 @@ protected: canvas->clear(0x00000000); SkPaint paint; - int x = 0, y = 0; for (int i = 0; i < 4; i++) { SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; SkIRect cropRect = SkIRect::MakeXYWH(i * 12, @@ -96,13 +107,16 @@ protected: SkAutoTUnref filter(SkNEW_ARGS( SkOffsetImageFilter, (dx, dy, tileInput, &rect))); paint.setImageFilter(filter); - drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); - x += bitmap->width() + MARGIN; - if (x + bitmap->width() > WIDTH) { - x = 0; - y += bitmap->height() + MARGIN; - } + drawClippedBitmap(canvas, *bitmap, paint, SK_Scalar1, cropRect); + canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0); } + + SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); + SkImageFilter::CropRect rect(SkRect::Make(cropRect)); + SkAutoTUnref filter(SkNEW_ARGS( + SkOffsetImageFilter, (SkIntToScalar(-5), SkIntToScalar(-10), NULL, &rect))); + paint.setImageFilter(filter); + drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(2), cropRect); } private: typedef GM INHERITED; diff --git a/src/effects/SkOffsetImageFilter.cpp b/src/effects/SkOffsetImageFilter.cpp index b36ef8a3ed..6322a5a9b3 100644 --- a/src/effects/SkOffsetImageFilter.cpp +++ b/src/effects/SkOffsetImageFilter.cpp @@ -58,7 +58,9 @@ bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, paint.setXfermodeMode(SkXfermode::kSrc_Mode); canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), SkIntToScalar(srcOffset.fY - bounds.fTop)); - canvas.drawBitmap(src, fOffset.x(), fOffset.y(), &paint); + SkVector vec; + matrix.mapVectors(&vec, &fOffset, 1); + canvas.drawBitmap(src, vec.x(), vec.y(), &paint); *result = device->accessBitmap(false); offset->fX = bounds.fLeft; offset->fY = bounds.fTop;