Commit b144a2a5 authored by chrishtr's avatar chrishtr Committed by Commit bot

Convert recursion to iteration in clearClipRectsIncludingDescendants

BUG=674795
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2617903002
Cr-Commit-Position: refs/heads/master@{#442063}
parent 1cec8405
...@@ -177,28 +177,32 @@ ClipRects& PaintLayerClipper::getClipRects( ...@@ -177,28 +177,32 @@ ClipRects& PaintLayerClipper::getClipRects(
return storeClipRectsInCache(context, parentClipRects, *clipRects); return storeClipRectsInCache(context, parentClipRects, *clipRects);
} }
void PaintLayerClipper::clearClipRectsIncludingDescendants() { void PaintLayerClipper::clearCache(ClipRectsCacheSlot cacheSlot) {
if (cacheSlot == NumberOfClipRectsCacheSlots)
m_layer.clearClipRectsCache();
else if (ClipRectsCache* cache = m_layer.clipRectsCache())
cache->clear(cacheSlot);
if (m_geometryMapper) if (m_geometryMapper)
m_geometryMapper.reset(new GeometryMapper); m_geometryMapper.reset(new GeometryMapper);
m_layer.clearClipRectsCache(); }
for (PaintLayer* layer = m_layer.firstChild(); layer; void PaintLayerClipper::clearClipRectsIncludingDescendants() {
layer = layer->nextSibling()) { clearClipRectsIncludingDescendants(NumberOfClipRectsCacheSlots);
layer->clipper().clearClipRectsIncludingDescendants();
}
} }
void PaintLayerClipper::clearClipRectsIncludingDescendants( void PaintLayerClipper::clearClipRectsIncludingDescendants(
ClipRectsCacheSlot cacheSlot) { ClipRectsCacheSlot cacheSlot) {
if (m_geometryMapper) std::stack<const PaintLayer*> layers;
m_geometryMapper.reset(new GeometryMapper); layers.push(&m_layer);
if (ClipRectsCache* cache = m_layer.clipRectsCache()) while (!layers.empty()) {
cache->clear(cacheSlot); const PaintLayer* currentLayer = layers.top();
layers.pop();
for (PaintLayer* layer = m_layer.firstChild(); layer; currentLayer->clipper().clearCache(cacheSlot);
layer = layer->nextSibling()) { for (const PaintLayer* layer = currentLayer->firstChild(); layer;
layer->clipper().clearClipRectsIncludingDescendants(cacheSlot); layer = layer->nextSibling())
layers.push(layer);
} }
} }
......
...@@ -200,6 +200,7 @@ class CORE_EXPORT PaintLayerClipper { ...@@ -200,6 +200,7 @@ class CORE_EXPORT PaintLayerClipper {
const LayoutSize& subpixelAccumulation) const; const LayoutSize& subpixelAccumulation) const;
private: private:
void clearCache(ClipRectsCacheSlot);
ClipRects& getClipRects(const ClipRectsContext&) const; ClipRects& getClipRects(const ClipRectsContext&) const;
void calculateClipRects(const ClipRectsContext&, ClipRects&) const; void calculateClipRects(const ClipRectsContext&, ClipRects&) const;
......
...@@ -144,4 +144,92 @@ TEST_F(PaintLayerClipperTest, LocalClipRectFixedUnderTransform) { ...@@ -144,4 +144,92 @@ TEST_F(PaintLayerClipperTest, LocalClipRectFixedUnderTransform) {
fixed->clipper().localClipRect(transformed)); fixed->clipper().localClipRect(transformed));
} }
TEST_F(PaintLayerClipperTest, ClearClipRectsRecursive) {
setBodyInnerHTML(
"<style>"
"div { "
" width: 5px; height: 5px; background: blue;"
" position: relative;"
"}"
"</style>"
"<div id='parent'>"
" <div id='child'>"
" <div id='grandchild'></div>"
" </div>"
"</div>");
PaintLayer* parent =
toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer();
PaintLayer* child =
toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer();
EXPECT_TRUE(parent->clipRectsCache());
EXPECT_TRUE(child->clipRectsCache());
parent->clipper().clearClipRectsIncludingDescendants();
EXPECT_FALSE(parent->clipRectsCache());
EXPECT_FALSE(child->clipRectsCache());
}
TEST_F(PaintLayerClipperTest, ClearClipRectsRecursiveChild) {
setBodyInnerHTML(
"<style>"
"div { "
" width: 5px; height: 5px; background: blue;"
" position: relative;"
"}"
"</style>"
"<div id='parent'>"
" <div id='child'>"
" <div id='grandchild'></div>"
" </div>"
"</div>");
PaintLayer* parent =
toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer();
PaintLayer* child =
toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer();
EXPECT_TRUE(parent->clipRectsCache());
EXPECT_TRUE(child->clipRectsCache());
child->clipper().clearClipRectsIncludingDescendants();
EXPECT_TRUE(parent->clipRectsCache());
EXPECT_FALSE(child->clipRectsCache());
}
TEST_F(PaintLayerClipperTest, ClearClipRectsRecursiveOneType) {
setBodyInnerHTML(
"<style>"
"div { "
" width: 5px; height: 5px; background: blue;"
" position: relative;"
"}"
"</style>"
"<div id='parent'>"
" <div id='child'>"
" <div id='grandchild'></div>"
" </div>"
"</div>");
PaintLayer* parent =
toLayoutBoxModelObject(getLayoutObjectByElementId("parent"))->layer();
PaintLayer* child =
toLayoutBoxModelObject(getLayoutObjectByElementId("child"))->layer();
EXPECT_TRUE(parent->clipRectsCache());
EXPECT_TRUE(child->clipRectsCache());
EXPECT_TRUE(parent->clipRectsCache()->get(AbsoluteClipRects).root);
EXPECT_TRUE(child->clipRectsCache()->get(AbsoluteClipRects).root);
parent->clipper().clearClipRectsIncludingDescendants(AbsoluteClipRects);
EXPECT_TRUE(parent->clipRectsCache());
EXPECT_TRUE(child->clipRectsCache());
EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root);
EXPECT_FALSE(parent->clipRectsCache()->get(AbsoluteClipRects).root);
}
} // namespace blink } // namespace blink
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