diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-06 15:59:03 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-06 15:59:03 +0000 |
commit | 094147d52227a0b230d7a894a69bcfeebe58b2ab (patch) | |
tree | 8506b8a696bffba155f7d506abf8b191db79fe70 /gm/xfermodeimagefilter.cpp | |
parent | 80bd0c995d9ec6a70330d6dc3f2f8dd387701d1d (diff) |
Implement srcRect and dstRect functionality in SkBitmapSource. This is required for the "preserveAspectRatio" options of SVG's feImage. Covered by new GM "bitmapsource".
This also includes some changes to the xfermodeimagefilter and tileimagefilter GMs to properly handle the CTM. This worked before only because SkBitmapSource was ignoring the CTM. Now that it respects it, we need to give the correct transform. This also means the GMs now work while zoomed.
R=reed@google.com
Author: senorblanco@chromium.org
Review URL: https://codereview.chromium.org/106933002
git-svn-id: http://skia.googlecode.com/svn/trunk@12528 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/xfermodeimagefilter.cpp')
-rw-r--r-- | gm/xfermodeimagefilter.cpp | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/gm/xfermodeimagefilter.cpp b/gm/xfermodeimagefilter.cpp index 01bfe0ad61..9d73b8314a 100644 --- a/gm/xfermodeimagefilter.cpp +++ b/gm/xfermodeimagefilter.cpp @@ -72,9 +72,19 @@ protected: void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint, SkScalar x, SkScalar y) { canvas->save(); - canvas->clipRect(SkRect::MakeXYWH(x, y, + canvas->translate(x, y); + canvas->clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()))); - canvas->drawBitmap(bitmap, x, y, &paint); + canvas->drawBitmap(bitmap, 0, 0, &paint); + canvas->restore(); + } + + void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkPaint& paint, + SkScalar x, SkScalar y) { + canvas->save(); + canvas->translate(x, y); + canvas->clipRect(rect); + canvas->drawPaint(paint); canvas->restore(); } @@ -156,6 +166,8 @@ protected: x = 0; y += fBitmap.height() + MARGIN; } + SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4), + SkIntToScalar(fBitmap.height() + 4)); // Test offsets on SrcMode (uses fixed-function blend) SkAutoTUnref<SkImageFilter> foreground(SkNEW_ARGS(SkBitmapSource, (fBitmap))); SkAutoTUnref<SkImageFilter> offsetForeground(SkNEW_ARGS(SkOffsetImageFilter, @@ -166,13 +178,7 @@ protected: filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground))); paint.setImageFilter(filter); - canvas->save(); - canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), - SkIntToScalar(y), - SkIntToScalar(fBitmap.width() + 4), - SkIntToScalar(fBitmap.height() + 4))); - canvas->drawPaint(paint); - canvas->restore(); + drawClippedPaint(canvas, clipRect, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; @@ -182,13 +188,7 @@ protected: mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode)); filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground))); paint.setImageFilter(filter); - canvas->save(); - canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), - SkIntToScalar(y), - SkIntToScalar(fBitmap.width() + 4), - SkIntToScalar(fBitmap.height() + 4))); - canvas->drawPaint(paint); - canvas->restore(); + drawClippedPaint(canvas, clipRect, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; @@ -203,8 +203,8 @@ protected: { 10, 10, 10, 10}, {-10, -10, -6, -6}}; for (size_t i = 0; i < nbSamples; ++i) { - SkIRect cropRect = SkIRect::MakeXYWH(x + offsets[i][0], - y + offsets[i][1], + SkIRect cropRect = SkIRect::MakeXYWH(offsets[i][0], + offsets[i][1], fBitmap.width() + offsets[i][2], fBitmap.height() + offsets[i][3]); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); @@ -212,13 +212,7 @@ protected: filter.reset(SkNEW_ARGS(SkXfermodeImageFilter, (mode, offsetBackground, offsetForeground, &rect))); paint.setImageFilter(filter); - canvas->save(); - canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), - SkIntToScalar(y), - SkIntToScalar(fBitmap.width() + 4), - SkIntToScalar(fBitmap.height() + 4))); - canvas->drawPaint(paint); - canvas->restore(); + drawClippedPaint(canvas, clipRect, paint, x, y); x += fBitmap.width() + MARGIN; if (x + fBitmap.width() > WIDTH) { x = 0; |