Commit a0a11e8d authored by fmalita@chromium.org's avatar fmalita@chromium.org

[SVG] Skip layout viewport change calculation when not needed.

SVGRenderSupport::layoutChildren() determines whether the size of the
nearest viewport has changed upfront, and then uses this information to
force a re-layout of relative-length children.

But the relative-length flag is always propagated up the ancestor chain
(see SVGElement::updateRelativeLengthsInformation), so we can
immediately tell whether there are any relative-length descendants. If
there aren't, we can skip the viewport change crawl and related logic.

R=pdr@chromium.org,schenney@chromium.org,fs@opera.com,ed@opera.com

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

git-svn-id: svn://svn.chromium.org/blink/trunk@180071 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 7df0f1da
<svg id="svg" width="400" height="400" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<mask id="mask">
<rect width="25%" height="25%" fill="white"/>
</mask>
<clipPath id="clip">
<rect x="27%" width="25%" height="25%"/>
</clipPath>
<pattern id="pattern" patternUnits="userSpaceOnUse" x="0" y="0" width="800" height="800">
<rect x="54%" width="25%" height="25%" fill="green"/>
</pattern>
</defs>
<rect width="25%" height="25%" fill="red"/>
<rect width="800" height="800" fill="green" mask="url(#mask)"/>
<rect x="27%" width="25%" height="25%" fill="red"/>
<rect width="800" height="800" fill="green" clip-path="url(#clip)"/>
<rect x="54%" width="25%" height="25%" fill="red"/>
<rect width="800" height="800" fill="url(#pattern)"/>
</svg>
<svg id="svg" width="200" height="200" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<mask id="mask">
<rect width="25%" height="25%" fill="white"/>
</mask>
<clipPath id="clip">
<rect x="27%" width="25%" height="25%"/>
</clipPath>
<pattern id="pattern" patternUnits="userSpaceOnUse" x="0" y="0" width="800" height="800">
<rect x="54%" width="25%" height="25%" fill="green"/>
</pattern>
</defs>
<rect width="25%" height="25%" fill="red"/>
<rect width="800" height="800" fill="green" mask="url(#mask)"/>
<rect x="27%" width="25%" height="25%" fill="red"/>
<rect width="800" height="800" fill="green" clip-path="url(#clip)"/>
<rect x="54%" width="25%" height="25%" fill="red"/>
<rect width="800" height="800" fill="url(#pattern)"/>
<script>
var delay=250;
if (window.testRunner) {
delay=0;
testRunner.waitUntilDone();
}
setTimeout(function() {
document.getElementById('svg').setAttribute('width', '400');
document.getElementById('svg').setAttribute('height', '400');
if (window.testRunner)
testRunner.notifyDone();
}, delay);
</script>
</svg>
...@@ -157,16 +157,6 @@ const RenderSVGRoot* SVGRenderSupport::findTreeRootObject(const RenderObject* st ...@@ -157,16 +157,6 @@ const RenderSVGRoot* SVGRenderSupport::findTreeRootObject(const RenderObject* st
return toRenderSVGRoot(start); return toRenderSVGRoot(start);
} }
inline void SVGRenderSupport::invalidateResourcesOfChildren(RenderObject* start)
{
ASSERT(!start->needsLayout());
if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(start))
resources->removeClientFromCache(start, false);
for (RenderObject* child = start->slowFirstChild(); child; child = child->nextSibling())
invalidateResourcesOfChildren(child);
}
inline bool SVGRenderSupport::layoutSizeOfNearestViewportChanged(const RenderObject* start) inline bool SVGRenderSupport::layoutSizeOfNearestViewportChanged(const RenderObject* start)
{ {
while (start && !start->isSVGRoot() && !start->isSVGViewportContainer()) while (start && !start->isSVGRoot() && !start->isSVGViewportContainer())
...@@ -195,24 +185,27 @@ bool SVGRenderSupport::transformToRootChanged(RenderObject* ancestor) ...@@ -195,24 +185,27 @@ bool SVGRenderSupport::transformToRootChanged(RenderObject* ancestor)
void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout) void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout)
{ {
bool layoutSizeChanged = layoutSizeOfNearestViewportChanged(start); // When hasRelativeLengths() is false, no descendants have relative lengths
// (hence no one is interested in viewport size changes).
bool layoutSizeChanged = toSVGElement(start->node())->hasRelativeLengths()
&& layoutSizeOfNearestViewportChanged(start);
bool transformChanged = transformToRootChanged(start); bool transformChanged = transformToRootChanged(start);
HashSet<RenderObject*> notlayoutedObjects;
for (RenderObject* child = start->slowFirstChild(); child; child = child->nextSibling()) { for (RenderObject* child = start->slowFirstChild(); child; child = child->nextSibling()) {
bool needsLayout = selfNeedsLayout; bool forceLayout = selfNeedsLayout;
if (transformChanged) { if (transformChanged) {
// If the transform changed we need to update the text metrics (note: this also happens for layoutSizeChanged=true). // If the transform changed we need to update the text metrics (note: this also happens for layoutSizeChanged=true).
if (child->isSVGText()) if (child->isSVGText())
toRenderSVGText(child)->setNeedsTextMetricsUpdate(); toRenderSVGText(child)->setNeedsTextMetricsUpdate();
needsLayout = true; forceLayout = true;
} }
if (layoutSizeChanged) { if (layoutSizeChanged) {
// When selfNeedsLayout is false and the layout size changed, we have to check whether this child uses relative lengths // When selfNeedsLayout is false and the layout size changed, we have to check whether this child uses relative lengths
if (SVGElement* element = child->node()->isSVGElement() ? toSVGElement(child->node()) : 0) { if (SVGElement* element = child->node()->isSVGElement() ? toSVGElement(child->node()) : 0) {
if (element->hasRelativeLengths()) { if (element->hasRelativeLengths()) {
// FIXME: this should be done on invalidation, not during layout.
// When the layout size changed and when using relative values tell the RenderSVGShape to update its shape object // When the layout size changed and when using relative values tell the RenderSVGShape to update its shape object
if (child->isSVGShape()) { if (child->isSVGShape()) {
toRenderSVGShape(child)->setNeedsShapeUpdate(); toRenderSVGShape(child)->setNeedsShapeUpdate();
...@@ -221,7 +214,7 @@ void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout) ...@@ -221,7 +214,7 @@ void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout)
toRenderSVGText(child)->setNeedsPositioningValuesUpdate(); toRenderSVGText(child)->setNeedsPositioningValuesUpdate();
} }
needsLayout = true; forceLayout = true;
} }
} }
} }
...@@ -231,27 +224,13 @@ void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout) ...@@ -231,27 +224,13 @@ void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout)
// Since they only care about viewport size changes (to resolve their relative lengths), we trigger // Since they only care about viewport size changes (to resolve their relative lengths), we trigger
// their invalidation directly from SVGSVGElement::svgAttributeChange() or at a higher // their invalidation directly from SVGSVGElement::svgAttributeChange() or at a higher
// SubtreeLayoutScope (in RenderView::layout()). // SubtreeLayoutScope (in RenderView::layout()).
if (needsLayout && !child->isSVGResourceContainer()) if (forceLayout && !child->isSVGResourceContainer())
layoutScope.setNeedsLayout(child); layoutScope.setNeedsLayout(child);
// Lay out any referenced resources before the child.
layoutResourcesIfNeeded(child); layoutResourcesIfNeeded(child);
child->layoutIfNeeded();
if (child->needsLayout()) {
child->layout();
} else if (layoutSizeChanged) {
notlayoutedObjects.add(child);
}
} }
if (!layoutSizeChanged) {
ASSERT(notlayoutedObjects.isEmpty());
return;
}
// If the layout size changed, invalidate all resources of all children that didn't go through the layout() code path.
HashSet<RenderObject*>::iterator end = notlayoutedObjects.end();
for (HashSet<RenderObject*>::iterator it = notlayoutedObjects.begin(); it != end; ++it)
invalidateResourcesOfChildren(*it);
} }
void SVGRenderSupport::layoutResourcesIfNeeded(const RenderObject* object) void SVGRenderSupport::layoutResourcesIfNeeded(const RenderObject* object)
......
...@@ -92,7 +92,6 @@ public: ...@@ -92,7 +92,6 @@ public:
private: private:
static void updateObjectBoundingBox(FloatRect& objectBoundingBox, bool& objectBoundingBoxValid, RenderObject* other, FloatRect otherBoundingBox); static void updateObjectBoundingBox(FloatRect& objectBoundingBox, bool& objectBoundingBoxValid, RenderObject* other, FloatRect otherBoundingBox);
static void invalidateResourcesOfChildren(RenderObject* start);
static bool layoutSizeOfNearestViewportChanged(const RenderObject* start); static bool layoutSizeOfNearestViewportChanged(const RenderObject* start);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment