In image filters, apply the CTM and offset to the crop rect. This is necessary to compensate for both clipping applied by the compositor (communicated via the CTM) and for cropping applied in upstream image filters (communicated via the offset). This requires a few ugly conversions, since the crop rect is an SkIRect, and the ctm is an SkMatrix.

I also had to offset the matrix passed to filter evaluation by drawSprite() and internalDrawBitmap() by the primitive position. This is the same offset that is applied when drawing the primitive, to compensate for the internal saveLayer().

Also apply the total matrix to the filter params in asNewEffect(), so that (for example) lighting params are offset by both the compositor clipping and upstream crop rects.

R=reed@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk/include@10961 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkImageFilter.h b/core/SkImageFilter.h
index 01b3e0b..7b9dd32 100644
--- a/core/SkImageFilter.h
+++ b/core/SkImageFilter.h
@@ -77,16 +77,18 @@
      *  caller to unref it.
      *
      *  The effect can assume its vertexCoords space maps 1-to-1 with texels
-     *  in the texture.  "offset" is the delta between the source and
-     *  destination rect's origins, when cropped processing is being performed.
+     *  in the texture.  "matrix" is a transformation to apply to filter
+     *  parameters before they are used in the effect. Note that this function
+     *  will be called with (NULL, NULL, SkMatrix::I()) to query for support,
+     *  so returning "true" indicates support for all possible matrices.
      */
-    virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkIPoint& offset) const;
+    virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix) const;
 
     /**
      *  Returns true if the filter can be processed on the GPU.  This is most
      *  often used for multi-pass effects, where intermediate results must be
      *  rendered to textures.  For single-pass effects, use asNewEffect().
-     *  The default implementation returns asNewEffect(NULL, NULL).
+     *  The default implementation returns asNewEffect(NULL, NULL, SkMatrix::I()).
      */
     virtual bool canFilterImageGPU() const;
 
@@ -159,9 +161,10 @@
     // Default impl copies src into dst and returns true
     virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*);
 
-    // Sets rect to the intersection of rect and the crop rect. If there
-    // is no overlap, returns false and leaves rect unchanged.
-    bool applyCropRect(SkIRect* rect) const;
+    // Applies "matrix" to the crop rect, and sets "rect" to the intersection of
+    // "rect" and the transformed crop rect. If there is no overlap, returns
+    // false and leaves "rect" unchanged.
+    bool applyCropRect(SkIRect* rect, const SkMatrix& matrix) const;
 
 private:
     typedef SkFlattenable INHERITED;
diff --git a/effects/SkMagnifierImageFilter.h b/effects/SkMagnifierImageFilter.h
index b5cbd74..31b446f 100644
--- a/effects/SkMagnifierImageFilter.h
+++ b/effects/SkMagnifierImageFilter.h
@@ -17,7 +17,7 @@
     SkMagnifierImageFilter(SkRect srcRect, SkScalar inset);
 
 #if SK_SUPPORT_GPU
-    virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, const SkIPoint& offset) const SK_OVERRIDE;
+    virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, const SkMatrix& matrix) const SK_OVERRIDE;
 #endif
 
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMagnifierImageFilter)
diff --git a/effects/SkMatrixConvolutionImageFilter.h b/effects/SkMatrixConvolutionImageFilter.h
index 71c8938..b2602fe 100644
--- a/effects/SkMatrixConvolutionImageFilter.h
+++ b/effects/SkMatrixConvolutionImageFilter.h
@@ -62,7 +62,7 @@
                                SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
 
 #if SK_SUPPORT_GPU
-    virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkIPoint& offset) const SK_OVERRIDE;
+    virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& matrix) const SK_OVERRIDE;
 #endif
 
 private: