Implement support for a Context parameter in image filters

Some upcoming work (support for expanding crop rects) requires
the clip bounds to be available during filter traversal. This change
replaces the SkMatrix parameter in the onFilterImage() traversals
with a Context parameter. It contains the CTM, as well as the clip
bounds.

BUG=skia:
R=reed@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13803 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h
index 25c35ce..afbefc1 100644
--- a/include/core/SkBitmapDevice.h
+++ b/include/core/SkBitmapDevice.h
@@ -248,7 +248,7 @@
      *  If the device does not recognize or support this filter,
      *  it just returns false and leaves result and offset unchanged.
      */
-    virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
+    virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&,
                              SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
 
 private:
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 39304fa..2d9b0fc 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -15,6 +15,7 @@
 #include "SkCanvas.h"
 #include "SkColor.h"
 #include "SkDeviceProperties.h"
+#include "SkImageFilter.h"
 
 // getDeviceCapabilities() is not called by skia, but this flag keeps it around
 // for clients that have "override" annotations on their subclass. These overrides
@@ -375,7 +376,8 @@
      *  If the device does not recognize or support this filter,
      *  it just returns false and leaves result and offset unchanged.
      */
-    virtual bool filterImage(const SkImageFilter*, const SkBitmap&, const SkMatrix&,
+    virtual bool filterImage(const SkImageFilter*, const SkBitmap&,
+                             const SkImageFilter::Context& ctx,
                              SkBitmap* result, SkIPoint* offset) = 0;
 
     // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 91b98f4..4f33f54 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -9,12 +9,12 @@
 #define SkImageFilter_DEFINED
 
 #include "SkFlattenable.h"
+#include "SkMatrix.h"
 #include "SkRect.h"
 
 class SkBitmap;
 class SkColorFilter;
 class SkBaseDevice;
-class SkMatrix;
 struct SkIPoint;
 class SkShader;
 class GrEffectRef;
@@ -49,6 +49,18 @@
         uint32_t fFlags;
     };
 
+    class Context {
+    public:
+        Context(const SkMatrix& ctm, const SkIRect& clipBounds) :
+            fCTM(ctm), fClipBounds(clipBounds) {
+        }
+        const SkMatrix& ctm() const { return fCTM; }
+        const SkIRect& clipBounds() const { return fClipBounds; }
+    private:
+        SkMatrix fCTM;
+        SkIRect  fClipBounds;
+    };
+
     class Proxy {
     public:
         virtual ~Proxy() {};
@@ -59,7 +71,7 @@
         // returns true if the proxy handled the filter itself. if this returns
         // false then the filter's code will be called.
         virtual bool filterImage(const SkImageFilter*, const SkBitmap& src,
-                                 const SkMatrix& ctm,
+                                 const Context&,
                                  SkBitmap* result, SkIPoint* offset) = 0;
     };
 
@@ -76,7 +88,7 @@
      *  If the result image cannot be created, return false, in which case both
      *  the result and offset parameters will be ignored by the caller.
      */
-    bool filterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
+    bool filterImage(Proxy*, const SkBitmap& src, const Context&,
                      SkBitmap* result, SkIPoint* offset) const;
 
     /**
@@ -104,7 +116,7 @@
      *  relative to the src when it is drawn. The default implementation does
      *  single-pass processing using asNewEffect().
      */
-    virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
+    virtual bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&,
                                 SkBitmap* result, SkIPoint* offset) const;
 
     /**
@@ -156,7 +168,7 @@
      * Recursively evaluate this filter on the GPU. If the filter has no GPU
      * implementation, it will be processed in software and uploaded to the GPU.
      */
-    bool getInputResultGPU(SkImageFilter::Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+    bool getInputResultGPU(SkImageFilter::Proxy* proxy, const SkBitmap& src, const Context&,
                            SkBitmap* result, SkIPoint* offset) const;
 #endif
 
@@ -200,7 +212,7 @@
      *  case both the result and offset parameters will be ignored by the
      *  caller.
      */
-    virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+    virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
                                SkBitmap* result, SkIPoint* offset) const;
     // Given the bounds of the destination rect to be filled in device
     // coordinates (first parameter), and the CTM, compute (conservatively)