Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent's crop rect.  This is required by SVG semantics, and is more sane anyway.

To do this, this patch changes the "offset/loc" parameter in filterImage() / onFilterImage() from an inout-param to an out-param only, so that the calling filter can know how much the input filter wants its result offset (and doesn't include the original primitive position). This offset can then be applied to the current filter's crop rect. (I've renamed the parameter "offset" in all cases to make this clear.) This makes the call sites in SkCanvas/SkGpuDevice responsible for applying the resulting offset to the primitive's position, which is actually a fairly small change.

This change also fixes SkTileImageFilter and SkOffsetImageFilter to correctly handle an input offset, which they weren't before. This required modifying the GM's, since they assumed the broken behaviour.

NOTE: this will require rebaselining the imagefiltersgraph test, since it has a new test case.

NOTE: this will "break" the Blink layout tests css3/filters/effect-reference-subregion-chained-hw.html and css3/filters/effect-reference-subregion-hw.html, but it actually makes them give correct results. It should be suppressed on the skia roll, and I'll rebaseline it.

R=reed@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@12895 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/SkTileImageFilter.cpp b/src/effects/SkTileImageFilter.cpp
index 73e5304..08dfec4 100644
--- a/src/effects/SkTileImageFilter.cpp
+++ b/src/effects/SkTileImageFilter.cpp
@@ -19,15 +19,17 @@
                                       SkBitmap* dst, SkIPoint* offset) {
     SkBitmap source = src;
     SkImageFilter* input = getInput(0);
-    SkIPoint localOffset = SkIPoint::Make(0, 0);
-    if (input && !input->filterImage(proxy, src, ctm, &source, &localOffset)) {
+    SkIPoint srcOffset = SkIPoint::Make(0, 0);
+    if (input && !input->filterImage(proxy, src, ctm, &source, &srcOffset)) {
         return false;
     }
 
     SkRect dstRect;
     ctm.mapRect(&dstRect, fDstRect);
-    int w = SkScalarCeilToInt(dstRect.width());
-    int h = SkScalarCeilToInt(dstRect.height());
+    SkIRect dstIRect;
+    dstRect.roundOut(&dstIRect);
+    int w = dstIRect.width();
+    int h = dstIRect.height();
     if (!fSrcRect.width() || !fSrcRect.height() || !w || !h) {
         return false;
     }
@@ -36,10 +38,13 @@
     ctm.mapRect(&srcRect, fSrcRect);
     SkIRect srcIRect;
     srcRect.roundOut(&srcIRect);
+    srcIRect.offset(-srcOffset);
     SkBitmap subset;
     SkIRect bounds;
     source.getBounds(&bounds);
+
     if (!srcIRect.intersect(bounds)) {
+        offset->fX = offset->fY = 0;
         return true;
     } else if (!source.extractSubset(&subset, srcIRect)) {
         return false;
@@ -55,10 +60,16 @@
 
     SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(subset,
                                   SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
+    SkMatrix shaderMatrix;
+    shaderMatrix.setTranslate(SkIntToScalar(srcOffset.fX),
+                              SkIntToScalar(srcOffset.fY));
+    shader->setLocalMatrix(shaderMatrix);
     paint.setShader(shader);
-    dstRect.offset(SkIntToScalar(localOffset.fX), SkIntToScalar(localOffset.fY));
+    canvas.translate(-dstRect.fLeft, -dstRect.fTop);
     canvas.drawRect(dstRect, paint);
     *dst = device->accessBitmap(false);
+    offset->fX = dstIRect.fLeft;
+    offset->fY = dstIRect.fTop;
     return true;
 }