Fix bounds computation of all 0-input filters.
authorsenorblanco <senorblanco@chromium.org>
Wed, 29 Oct 2014 19:36:32 +0000 (12:36 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 29 Oct 2014 19:36:32 +0000 (12:36 -0700)
The SkRectShaderImageFilter had the same bug as previously fixed for
SkBitmapSource and SkPictureImageFilter. Rather than copy-and-paste
the implementation, this change makes all filters with 0 inputs return
their source bounds, instead of returning false.

BUG=427251

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

expectations/gm/ignored-tests.txt
include/effects/SkBitmapSource.h
include/effects/SkPictureImageFilter.h
src/core/SkImageFilter.cpp
src/effects/SkBitmapSource.cpp
src/effects/SkPictureImageFilter.cpp
tests/ImageFilterTest.cpp

index 1499acc..63d6a84 100644 (file)
 # robertphillips - skia:2995
 blurrects
 
+# senorblanco https://codereview.chromium.org/681643003/
+# minor pixel diffs from bounds change
+testimagefilters
+
 # sugoi https://codereview.chromium.org/646213004/
 # New shadow only option in SkDropShadowImageFilter
 dropshadowimagefilter
index 9004a46..27c7ae2 100644 (file)
@@ -34,7 +34,6 @@ protected:
 
     virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
                                SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
-    virtual bool onFilterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) const SK_OVERRIDE;
 
 private:
     SkBitmap fBitmap;
index fbd04f0..ed5c63c 100644 (file)
@@ -46,8 +46,6 @@ protected:
     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
     virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
                                SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
-    virtual bool onFilterBounds(const SkIRect& src, const SkMatrix&,
-                                SkIRect* dst) const SK_OVERRIDE;
 
 private:
     const SkPicture* fPicture;
index bba5ec0..8f49a06 100644 (file)
@@ -342,7 +342,8 @@ bool SkImageFilter::applyCropRect(const Context& ctx, Proxy* proxy, const SkBitm
 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
                                    SkIRect* dst) const {
     if (fInputCount < 1) {
-        return false;
+        *dst = src;
+        return true;
     }
 
     SkIRect bounds;
index aee4a36..0d9315b 100644 (file)
@@ -97,9 +97,3 @@ bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context&
 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const {
     *dst = fDstRect;
 }
-
-bool SkBitmapSource::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
-                                    SkIRect* dst) const {
-    *dst = src;
-    return true;
-}
index bed19ef..30fbac1 100644 (file)
@@ -110,10 +110,3 @@ bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co
     offset->fY = bounds.fTop;
     return true;
 }
-
-bool SkPictureImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
-                                          SkIRect* dst) const {
-    *dst = src;
-    return true;
-}
-
index 778230b..e032a81 100644 (file)
 #include "SkMergeImageFilter.h"
 #include "SkMorphologyImageFilter.h"
 #include "SkOffsetImageFilter.h"
+#include "SkPerlinNoiseShader.h"
 #include "SkPicture.h"
 #include "SkPictureImageFilter.h"
 #include "SkPictureRecorder.h"
 #include "SkReadBuffer.h"
 #include "SkRect.h"
+#include "SkRectShaderImageFilter.h"
 #include "SkTileImageFilter.h"
 #include "SkXfermodeImageFilter.h"
 #include "Test.h"
@@ -399,6 +401,9 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
     recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), greenPaint);
     SkAutoTUnref<SkPicture> picture(recorder.endRecording());
     SkAutoTUnref<SkImageFilter> pictureFilter(SkPictureImageFilter::Create(picture.get()));
+    SkAutoTUnref<SkShader> shader(SkPerlinNoiseShader::CreateTurbulence(SK_Scalar1, SK_Scalar1, 1, 0));
+
+    SkAutoTUnref<SkImageFilter> rectShaderFilter(SkRectShaderImageFilter::Create(shader.get()));
 
     struct {
         const char*    fName;
@@ -430,6 +435,7 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
         { "matrix", SkMatrixImageFilter::Create(matrix, SkPaint::kLow_FilterLevel) },
         { "blur and offset", SkOffsetImageFilter::Create(five, five, blur.get()) },
         { "picture and blur", SkBlurImageFilter::Create(five, five, pictureFilter.get()) },
+        { "rect shader and blur", SkBlurImageFilter::Create(five, five, rectShaderFilter.get()) },
     };
 
     SkBitmap untiledResult, tiledResult;