Apply the CTM to the offset in the slow SkOffsetImageFilter path.

This was being done in the fast path, but not the slow path.

Since I had to rebaseline the offsetimagefilter GM anyway (to accomodate
the new test case), I added a red border around the intersection
of the (transformed) crop rect and clip rect in each sample, beyond
which no pixels should be drawn.

Chrome bug: https://code.google.com/p/chromium/issues/detail?id=346362

BUG=skia:
R=sugoi@google.com

Review URL: https://codereview.chromium.org/186643003

git-svn-id: http://skia.googlecode.com/svn/trunk@13656 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
senorblanco@chromium.org 2014-03-04 19:05:25 +00:00
parent 707bd60203
commit e09244d463
3 changed files with 34 additions and 14 deletions

View File

@ -41,3 +41,7 @@ inverse_paths
# senorblanco will rebaseline. # senorblanco will rebaseline.
imagefiltersclipped imagefiltersclipped
imagefiltersscaled imagefiltersscaled
# Added as part of https://codereview.chromium.org/186643003/.
# senorblanco will rebaseline.
offsetimagefilter

View File

@ -9,7 +9,7 @@
#include "SkOffsetImageFilter.h" #include "SkOffsetImageFilter.h"
#include "SkBitmapSource.h" #include "SkBitmapSource.h"
#define WIDTH 400 #define WIDTH 600
#define HEIGHT 100 #define HEIGHT 100
#define MARGIN 12 #define MARGIN 12
@ -63,14 +63,26 @@ protected:
return make_isize(WIDTH, HEIGHT); return make_isize(WIDTH, HEIGHT);
} }
void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, SkScalar scale, const SkIRect& cropRect) {
SkScalar x, SkScalar y) {
canvas->save(); canvas->save();
canvas->translate(x, y); SkRect clipRect = SkRect::MakeWH(
canvas->clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()));
SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); canvas->clipRect(clipRect);
canvas->scale(scale, scale);
canvas->drawBitmap(bitmap, 0, 0, &paint); canvas->drawBitmap(bitmap, 0, 0, &paint);
canvas->restore(); 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) { virtual void onDraw(SkCanvas* canvas) {
@ -82,7 +94,6 @@ protected:
canvas->clear(0x00000000); canvas->clear(0x00000000);
SkPaint paint; SkPaint paint;
int x = 0, y = 0;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
SkIRect cropRect = SkIRect::MakeXYWH(i * 12, SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
@ -96,13 +107,16 @@ protected:
SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
SkOffsetImageFilter, (dx, dy, tileInput, &rect))); SkOffsetImageFilter, (dx, dy, tileInput, &rect)));
paint.setImageFilter(filter); paint.setImageFilter(filter);
drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); drawClippedBitmap(canvas, *bitmap, paint, SK_Scalar1, cropRect);
x += bitmap->width() + MARGIN; canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0);
if (x + bitmap->width() > WIDTH) {
x = 0;
y += bitmap->height() + MARGIN;
}
} }
SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS(
SkOffsetImageFilter, (SkIntToScalar(-5), SkIntToScalar(-10), NULL, &rect)));
paint.setImageFilter(filter);
drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(2), cropRect);
} }
private: private:
typedef GM INHERITED; typedef GM INHERITED;

View File

@ -58,7 +58,9 @@ bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
paint.setXfermodeMode(SkXfermode::kSrc_Mode); paint.setXfermodeMode(SkXfermode::kSrc_Mode);
canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft),
SkIntToScalar(srcOffset.fY - bounds.fTop)); 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); *result = device->accessBitmap(false);
offset->fX = bounds.fLeft; offset->fX = bounds.fLeft;
offset->fY = bounds.fTop; offset->fY = bounds.fTop;