diff options
author | senorblanco <senorblanco@chromium.org> | 2016-01-26 08:41:02 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-26 08:41:03 -0800 |
commit | eae84c2e0e2126374cd488a1c8a3e18169145635 (patch) | |
tree | 768f4953e9c7f31a10bfcbb61e6d98309800c4d0 /gm/imagefiltersgraph.cpp | |
parent | 978d08a4a90d69961bd53811ed3ab222b88e2d30 (diff) |
Image filters: fix srcOffset handling in asFragmentProcessor() path.
Filters such as SkMatrixConvolutionImageFilter which use the
asFragmentProcessor() path were not correctly handling srcOffset.
It is correctly applied to the bounds, but the srcRect and dstRect
were computed from the pre-offset bounds.
The fix is to move them to just above where they're used in drawing.
Note: this change adds a new test case to the imagefiltersgraph GM,
so it will have to be rebaselined post-landing.
BUG=skia:4855
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1637443003
Review URL: https://codereview.chromium.org/1637443003
Diffstat (limited to 'gm/imagefiltersgraph.cpp')
-rw-r--r-- | gm/imagefiltersgraph.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp index 14752dbab5..e783789124 100644 --- a/gm/imagefiltersgraph.cpp +++ b/gm/imagefiltersgraph.cpp @@ -15,6 +15,7 @@ #include "SkColorMatrixFilter.h" #include "SkImage.h" #include "SkImageSource.h" +#include "SkMatrixConvolutionImageFilter.h" #include "SkReadBuffer.h" #include "SkWriteBuffer.h" #include "SkMergeImageFilter.h" @@ -107,7 +108,7 @@ protected: return SkString("imagefiltersgraph"); } - SkISize onISize() override { return SkISize::Make(500, 150); } + SkISize onISize() override { return SkISize::Make(600, 150); } void onOnceBeforeDraw() override { fImage.reset(SkImage::NewFromBitmap( @@ -182,6 +183,40 @@ protected: canvas->translate(SkIntToScalar(100), 0); } { + // Dilate -> matrix convolution. + // This tests that a filter using asFragmentProcessor (matrix + // convolution) correctly handles a non-zero source offset + // (supplied by the dilate). + SkAutoTUnref<SkImageFilter> dilate(SkDilateImageFilter::Create(5, 5)); + + SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcIn_Mode)); + + SkScalar kernel[9] = { + SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), + SkIntToScalar(-1), SkIntToScalar( 7 ), SkIntToScalar(-1), + SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1), + }; + SkISize kernelSize = SkISize::Make(3, 3); + SkScalar gain = 1.0f, bias = SkIntToScalar(0); + SkIPoint kernelOffset = SkIPoint::Make(1, 1); + auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode; + bool convolveAlpha = false; + SkAutoTUnref<SkImageFilter> convolve( + SkMatrixConvolutionImageFilter::Create(kernelSize, + kernel, + gain, + bias, + kernelOffset, + tileMode, + convolveAlpha, + dilate)); + + SkPaint paint; + paint.setImageFilter(convolve); + DrawClippedImage(canvas, fImage, paint); + canvas->translate(SkIntToScalar(100), 0); + } + { // Test that crop offsets are absolute, not relative to the parent's crop rect. SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode)); |