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/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 50cca07..b24a91e 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -927,7 +927,8 @@
                                                  SkIPoint* offset) {
     SkImageFilter* input = getInput(0);
     SkBitmap src = source;
-    if (input && !input->filterImage(proxy, source, ctm, &src, offset)) {
+    SkIPoint srcOffset = SkIPoint::Make(0, 0);
+    if (input && !input->filterImage(proxy, source, ctm, &src, &srcOffset)) {
         return false;
     }
 
@@ -941,6 +942,7 @@
 
     SkIRect bounds;
     src.getBounds(&bounds);
+    bounds.offset(srcOffset);
     if (!this->applyCropRect(&bounds, ctm)) {
         return false;
     }
@@ -958,6 +960,9 @@
     SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm));
 
     DiffuseLightingType lightingType(fKD);
+    offset->fX = bounds.left();
+    offset->fY = bounds.top();
+    bounds.offset(-srcOffset);
     switch (transformedLight->type()) {
         case SkLight::kDistant_LightType:
             lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
@@ -970,8 +975,6 @@
             break;
     }
 
-    offset->fX += bounds.left();
-    offset->fY += bounds.top();
     return true;
 }
 
@@ -1018,7 +1021,8 @@
                                                   SkIPoint* offset) {
     SkImageFilter* input = getInput(0);
     SkBitmap src = source;
-    if (input && !input->filterImage(proxy, source, ctm, &src, offset)) {
+    SkIPoint srcOffset = SkIPoint::Make(0, 0);
+    if (input && !input->filterImage(proxy, source, ctm, &src, &srcOffset)) {
         return false;
     }
 
@@ -1032,6 +1036,7 @@
 
     SkIRect bounds;
     src.getBounds(&bounds);
+    bounds.offset(srcOffset);
     if (!this->applyCropRect(&bounds, ctm)) {
         return false;
     }
@@ -1047,6 +1052,9 @@
     }
 
     SpecularLightingType lightingType(fKS, fShininess);
+    offset->fX = bounds.left();
+    offset->fY = bounds.top();
+    bounds.offset(-srcOffset);
     SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm));
     switch (transformedLight->type()) {
         case SkLight::kDistant_LightType:
@@ -1059,8 +1067,6 @@
             lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transformedLight, src, dst, surfaceScale(), bounds);
             break;
     }
-    offset->fX += bounds.left();
-    offset->fY += bounds.top();
     return true;
 }