Bug 463064 - Use covered region to minimise foreignObject painting r+sr=roc
authorRobert Longson <longsonr@gmail.com>
Sat, 06 Dec 2008 15:22:01 +0000
changeset 22428 ec95b93b3ae8310b551a3649419910f40113f66e
parent 22427 d503a9f90157a476b106560e2864f2fefc1a5e89
child 22429 fc579917e321374433e182aae2d45a33af4673dc
push idunknown
push userunknown
push dateunknown
bugs463064
milestone1.9.2a1pre
Bug 463064 - Use covered region to minimise foreignObject painting r+sr=roc
layout/reftests/svg/foreignObject-02-ref.svg
layout/reftests/svg/foreignObject-02.svg
layout/reftests/svg/reftest.list
layout/svg/base/src/nsSVGForeignObjectFrame.cpp
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/foreignObject-02-ref.svg
@@ -0,0 +1,20 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/licenses/publicdomain/
+-->
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
+     xmlns:html="http://www.w3.org/1999/xhtml"
+     xmlns:xlink="http://www.w3.org/1999/xlink">
+  <title>Testing that foreignobject works in filters</title>
+  <foreignObject id="fo1" x="150" y="50" width="50" height="50">
+    <html:div style="width:100%; height:100%; background:lime;">
+    </html:div>
+  </foreignObject>
+  <foreignObject id="fo2" x="150" y="150" width="50" height="50" filter="url(#f1)">
+    <html:div style="width:100%; height:100%; background:lime;">
+    </html:div>
+  </foreignObject>
+  <filter id="f1" x="0" y="0" width="100%" height="100%">
+    <feOffset/>
+  </filter>
+</svg>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/foreignObject-02.svg
@@ -0,0 +1,31 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/licenses/publicdomain/
+-->
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
+     xmlns:html="http://www.w3.org/1999/xhtml"
+     xmlns:xlink="http://www.w3.org/1999/xlink" onload="m();">
+  <title>Testing that foreignobject works in filters</title>
+  <foreignObject id="fo1" x="50" y="50" width="50" height="50">
+    <html:div style="width:100%; height:100%; background:lime;">
+    </html:div>
+  </foreignObject>
+  <foreignObject id="fo2" x="50" y="150" width="50" height="50" filter="url(#f1)">
+    <html:div style="width:100%; height:100%; background:lime;">
+    </html:div>
+  </foreignObject>
+  <filter id="f1" x="0" y="0" width="100%" height="100%">
+    <feOffset/>
+  </filter>
+  <script>
+		function m() {
+		var svgns = "http://www.w3.org/2000/svg";
+
+		var fo1 = document.getElementById("fo1");
+		fo1.setAttribute("x", "150");
+
+		var fo2 = document.getElementById("fo2");
+		fo2.setAttribute("x", "150");
+		}
+  </script>
+</svg>
--- a/layout/reftests/svg/reftest.list
+++ b/layout/reftests/svg/reftest.list
@@ -49,16 +49,17 @@ include moz-only/reftest.list
 == fallback-color-02b.svg fallback-color-02-ref.svg
 == fallback-color-03.svg pass.svg
 == filter-basic-01.svg pass.svg
 == filter-basic-02.svg pass.svg
 == filter-basic-03.svg pass.svg
 == filter-foreignObject-01.svg pass.svg
 == filter-translated-01.svg filter-translated-01-ref.svg
 == foreignObject-01.svg pass.svg
+== foreignObject-02.svg foreignObject-02-ref.svg
 == foreignObject-ancestor-style-change-01.svg foreignObject-ancestor-style-change-01-ref.svg
 == foreignObject-change-transform-01.svg pass.svg
 == foreignObject-display-01.svg pass.svg
 == foreignObject-move-repaint-01.svg pass.svg
 == foreignObject-overflow-01.svg pass.svg
 == getElementById-a-element-01.svg pass.svg
 fails == inline-in-xul-basic-01.xul pass.svg
 == image-scaling-01.svg pass.svg
--- a/layout/svg/base/src/nsSVGForeignObjectFrame.cpp
+++ b/layout/svg/base/src/nsSVGForeignObjectFrame.cpp
@@ -260,16 +260,28 @@ nsSVGForeignObjectFrame::PaintSVG(nsSVGR
 
   nsIRenderingContext *ctx = aContext->GetRenderingContext(this);
 
   if (!ctx || matrix.IsSingular()) {
     NS_WARNING("Can't render foreignObject element!");
     return NS_ERROR_FAILURE;
   }
 
+  /* Check if we need to draw anything. */
+  if (aDirtyRect) {
+    gfxRect extent = matrix.TransformBounds(
+                       gfxRect(kid->GetRect().x, kid->GetRect().y, 
+                               kid->GetRect().width, kid->GetRect().height));
+    extent.RoundOut();
+    nsIntRect rect;
+    if (NS_SUCCEEDED(nsSVGUtils::GfxRectToIntRect(extent, &rect)) &&
+        !aDirtyRect->Intersects(rect))
+      return NS_OK;
+  }
+
   gfxContext *gfx = aContext->GetGfxContext();
 
   gfx->Save();
 
   if (GetStyleDisplay()->IsScrollableOverflow()) {
     float x, y, width, height;
     static_cast<nsSVGElement*>(mContent)->
       GetAnimatedLengthValues(&x, &y, &width, &height, nsnull);