Commit dd59f478 authored by flackr's avatar flackr Committed by Commit bot

Only paint the background onto the scrolling contents layer if we have a scrolling contents layer.

BUG=647169,645949
TEST=CompositedLayerMappingTest.BackgroundPaintedIntoGraphicsLayerIfNotCompositedScrolling
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2346883003
Cr-Commit-Position: refs/heads/master@{#419064}
parent d29bb8a2
...@@ -137,11 +137,6 @@ bool LayoutBoxModelObject::hasLocalEquivalentBackground() const ...@@ -137,11 +137,6 @@ bool LayoutBoxModelObject::hasLocalEquivalentBackground() const
if (!style()->hasAutoClip()) if (!style()->hasAutoClip())
return false; return false;
// TODO(flackr): We should be able to paint locally attached borders with a border-radius
// but these currently do not paint correctly. https://crbug.com/645949
if (style()->hasBorderRadius())
return false;
// TODO(flackr): Remove this when box shadows are still painted correctly when painting // TODO(flackr): Remove this when box shadows are still painted correctly when painting
// into the composited scrolling contents layer. https://crbug.com/646464 // into the composited scrolling contents layer. https://crbug.com/646464
if (style()->boxShadow()) if (style()->boxShadow())
......
...@@ -300,7 +300,12 @@ void CompositedLayerMapping::updateIsRootForIsolatedGroup() ...@@ -300,7 +300,12 @@ void CompositedLayerMapping::updateIsRootForIsolatedGroup()
void CompositedLayerMapping::updateBackgroundPaintsOntoScrollingContentsLayer() void CompositedLayerMapping::updateBackgroundPaintsOntoScrollingContentsLayer()
{ {
bool shouldPaintOntoScrollingContentsLayer = m_owningLayer.shouldPaintBackgroundOntoScrollingContentsLayer(); // We can only paint the background onto the scrolling contents layer if
// it would be visually correct and we are using composited scrolling meaning we
// have a scrolling contents layer to paint it into.
bool shouldPaintOntoScrollingContentsLayer =
m_owningLayer.canPaintBackgroundOntoScrollingContentsLayer()
&& m_owningLayer.getScrollableArea()->usesCompositedScrolling();
if (shouldPaintOntoScrollingContentsLayer != backgroundPaintsOntoScrollingContentsLayer()) { if (shouldPaintOntoScrollingContentsLayer != backgroundPaintsOntoScrollingContentsLayer()) {
m_backgroundPaintsOntoScrollingContentsLayer = shouldPaintOntoScrollingContentsLayer; m_backgroundPaintsOntoScrollingContentsLayer = shouldPaintOntoScrollingContentsLayer;
// If the background is no longer painted onto the scrolling contents // If the background is no longer painted onto the scrolling contents
......
...@@ -647,6 +647,25 @@ TEST_F(CompositedLayerMappingTest, ScrollingContentsAndForegroundLayerPaintingPh ...@@ -647,6 +647,25 @@ TEST_F(CompositedLayerMappingTest, ScrollingContentsAndForegroundLayerPaintingPh
EXPECT_FALSE(mapping->foregroundLayer()); EXPECT_FALSE(mapping->foregroundLayer());
} }
TEST_F(CompositedLayerMappingTest, BackgroundPaintedIntoGraphicsLayerIfNotCompositedScrolling)
{
document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true);
setBodyInnerHTML(
"<div id='container' style='overflow: scroll; width: 300px; height: 300px; border-radius: 5px; background: white; will-change: transform;'>"
" <div style='background-color: blue; width: 2000px; height: 2000px;'></div>"
"</div>");
PaintLayer* layer = toLayoutBlock(getLayoutObjectByElementId("container"))->layer();
EXPECT_TRUE(layer->canPaintBackgroundOntoScrollingContentsLayer());
// We currently don't use composited scrolling when the container has a border-radius
// so even though we can paint the background onto the scrolling contents layer we
// don't have a scrolling contents layer to paint into in this case.
CompositedLayerMapping* mapping = layer->compositedLayerMapping();
EXPECT_FALSE(mapping->hasScrollingLayer());
EXPECT_FALSE(mapping->backgroundPaintsOntoScrollingContentsLayer());
}
// Make sure that clipping layers are removed or their masking bit turned off // Make sure that clipping layers are removed or their masking bit turned off
// when they're an ancestor of the root scroller element. // when they're an ancestor of the root scroller element.
TEST_F(CompositedLayerMappingTest, RootScrollerAncestorsNotClipped) TEST_F(CompositedLayerMappingTest, RootScrollerAncestorsNotClipped)
......
...@@ -2358,7 +2358,7 @@ GraphicsLayer* PaintLayer::graphicsLayerBackingForScrolling() const ...@@ -2358,7 +2358,7 @@ GraphicsLayer* PaintLayer::graphicsLayerBackingForScrolling() const
} }
} }
bool PaintLayer::shouldPaintBackgroundOntoScrollingContentsLayer() const bool PaintLayer::canPaintBackgroundOntoScrollingContentsLayer() const
{ {
return !isRootLayer() return !isRootLayer()
&& scrollsOverflow() && scrollsOverflow()
......
...@@ -438,7 +438,7 @@ public: ...@@ -438,7 +438,7 @@ public:
// (i.e. the background can scroll with the content). When the background is also // (i.e. the background can scroll with the content). When the background is also
// opaque this allows us to composite the scroller even on low DPI as we can // opaque this allows us to composite the scroller even on low DPI as we can
// draw with subpixel anti-aliasing. // draw with subpixel anti-aliasing.
bool shouldPaintBackgroundOntoScrollingContentsLayer() const; bool canPaintBackgroundOntoScrollingContentsLayer() const;
// NOTE: If you are using hasCompositedLayerMapping to determine the state of compositing for this layer, // NOTE: If you are using hasCompositedLayerMapping to determine the state of compositing for this layer,
// (and not just to do bookkeeping related to the mapping like, say, allocating or deallocating a mapping), // (and not just to do bookkeeping related to the mapping like, say, allocating or deallocating a mapping),
// then you may have incorrect logic. Use compositingState() instead. // then you may have incorrect logic. Use compositingState() instead.
......
...@@ -1497,7 +1497,7 @@ static bool layerNeedsCompositedScrolling(PaintLayerScrollableArea::LCDTextMode ...@@ -1497,7 +1497,7 @@ static bool layerNeedsCompositedScrolling(PaintLayerScrollableArea::LCDTextMode
// use integer scroll offsets locally when !layer->compositor()->preferCompositingToLCDTextEnabled(), // use integer scroll offsets locally when !layer->compositor()->preferCompositingToLCDTextEnabled(),
// we do not check offsets accumulated from the root (including translates). crbug.com/644833 // we do not check offsets accumulated from the root (including translates). crbug.com/644833
bool backgroundSupportsLCDText = RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled() bool backgroundSupportsLCDText = RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled()
&& layer->shouldPaintBackgroundOntoScrollingContentsLayer() && layer->canPaintBackgroundOntoScrollingContentsLayer()
&& layer->backgroundIsKnownToBeOpaqueInRect(toLayoutBox(layer->layoutObject())->paddingBoxRect()); && layer->backgroundIsKnownToBeOpaqueInRect(toLayoutBox(layer->layoutObject())->paddingBoxRect());
if (mode == PaintLayerScrollableArea::ConsiderLCDText if (mode == PaintLayerScrollableArea::ConsiderLCDText
&& !layer->compositor()->preferCompositingToLCDTextEnabled() && !layer->compositor()->preferCompositingToLCDTextEnabled()
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace blink { namespace blink {
TEST_F(PaintLayerScrollableAreaTest, ShouldPaintBackgroundOntoScrollingContentsLayer) TEST_F(PaintLayerScrollableAreaTest, CanPaintBackgroundOntoScrollingContentsLayer)
{ {
document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true); document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true);
setBodyInnerHTML( setBodyInnerHTML(
...@@ -34,72 +34,67 @@ TEST_F(PaintLayerScrollableAreaTest, ShouldPaintBackgroundOntoScrollingContentsL ...@@ -34,72 +34,67 @@ TEST_F(PaintLayerScrollableAreaTest, ShouldPaintBackgroundOntoScrollingContentsL
"<div id='scroller13' class='scroller' style='background: white border-box;'><div class='spacer'></div></div>" "<div id='scroller13' class='scroller' style='background: white border-box;'><div class='spacer'></div></div>"
"<div id='scroller14' class='scroller' style='background: white; border: 1px solid black; outline: 1px solid blue; outline-offset: -1px;'><div class='spacer'></div></div>" "<div id='scroller14' class='scroller' style='background: white; border: 1px solid black; outline: 1px solid blue; outline-offset: -1px;'><div class='spacer'></div></div>"
"<div id='scroller15' class='scroller' style='background: white; border: 1px solid black; outline: 1px solid blue; outline-offset: -2px;'><div class='spacer'></div></div>" "<div id='scroller15' class='scroller' style='background: white; border: 1px solid black; outline: 1px solid blue; outline-offset: -2px;'><div class='spacer'></div></div>"
"<div id='scroller16' class='scroller' style='background: white; border 1px solid black; border-radius: 2px;'><div class='spacer'></div></div>" "<div id='scroller16' class='scroller' style='background: white; clip: rect(0px,10px,10px,0px);'><div class='spacer'></div></div>"
"<div id='scroller17' class='scroller' style='background: white; clip: rect(0px,10px,10px,0px);'><div class='spacer'></div></div>"
); );
// #scroller1 cannot paint background into scrolling contents layer because it has a negative z-index child. // #scroller1 cannot paint background into scrolling contents layer because it has a negative z-index child.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller1")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller1"));
// #scroller2 cannot paint background into scrolling contents layer because it has a content-box clip without local attachment. // #scroller2 cannot paint background into scrolling contents layer because it has a content-box clip without local attachment.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller2")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller2"));
// #scroller3 can paint background into scrolling contents layer. // #scroller3 can paint background into scrolling contents layer.
EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller3")); EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller3"));
// #scroller4 cannot paint background into scrolling contents layer because the background image is not locally attached. // #scroller4 cannot paint background into scrolling contents layer because the background image is not locally attached.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller4")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller4"));
// #scroller5 can paint background into scrolling contents layer because both the image and color are locally attached. // #scroller5 can paint background into scrolling contents layer because both the image and color are locally attached.
EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller5")); EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller5"));
// #scroller6 can paint background into scrolling contents layer because the image is locally attached and even though // #scroller6 can paint background into scrolling contents layer because the image is locally attached and even though
// the color is not, it is filled to the padding box so it will be drawn the same as a locally attached background. // the color is not, it is filled to the padding box so it will be drawn the same as a locally attached background.
EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller6")); EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller6"));
// #scroller7 cannot paint background into scrolling contents layer because the color is filled to the content // #scroller7 cannot paint background into scrolling contents layer because the color is filled to the content
// box and we have padding so it is not equivalent to a locally attached background. // box and we have padding so it is not equivalent to a locally attached background.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller7")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller7"));
// #scroller8 can paint background into scrolling contents layer because its border-box is equivalent to its // #scroller8 can paint background into scrolling contents layer because its border-box is equivalent to its
// padding box since it has no border. // padding box since it has no border.
EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller8")); EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller8"));
// #scroller9 can paint background into scrolling contents layer because its border is opaque so it completely // #scroller9 can paint background into scrolling contents layer because its border is opaque so it completely
// covers the background outside of the padding-box. // covers the background outside of the padding-box.
EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller9")); EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller9"));
// #scroller10 cannot paint background into scrolling contents layer because its border is partially transparent // #scroller10 cannot paint background into scrolling contents layer because its border is partially transparent
// so the background must be drawn to the border-box edges. // so the background must be drawn to the border-box edges.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller10")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller10"));
// #scroller11 can paint background into scrolling contents layer because its content-box is equivalent to its // #scroller11 can paint background into scrolling contents layer because its content-box is equivalent to its
// padding box since it has no padding. // padding box since it has no padding.
EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller11")); EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller11"));
// #scroller12 cannot paint background into scrolling contents layer because it has padding so its content-box // #scroller12 cannot paint background into scrolling contents layer because it has padding so its content-box
// is not equivalent to its padding-box. // is not equivalent to its padding-box.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller12")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller12"));
// #scroller13 cannot paint background into scrolling contents layer because it has a custom // #scroller13 cannot paint background into scrolling contents layer because it has a custom
// scrollbar which the background may need to draw under. // scrollbar which the background may need to draw under.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller13")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller13"));
// #scroller14 can paint background into scrolling contents layer because the outline is drawn outside the // #scroller14 can paint background into scrolling contents layer because the outline is drawn outside the
// padding box. // padding box.
EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller14")); EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller14"));
// #scroller15 cannot paint background into scrolling contents layer because the outline is drawn inside // #scroller15 cannot paint background into scrolling contents layer because the outline is drawn inside
// the padding box. // the padding box.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller15")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller15"));
// #scroller16 cannot paint background into scrolling contents layer because it has a // #scroller16 cannot paint background into scrolling contents layer because the scroller has a clip which
// border radius.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller16"));
// #scroller17 cannot paint background into scrolling contents layer because the scroller has a clip which
// would not be respected by the scrolling contents layer. // would not be respected by the scrolling contents layer.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller17")); EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller16"));
} }
TEST_F(PaintLayerScrollableAreaTest, OpaqueLayersPromoted) TEST_F(PaintLayerScrollableAreaTest, OpaqueLayersPromoted)
......
...@@ -17,10 +17,10 @@ public: ...@@ -17,10 +17,10 @@ public:
: RenderingTest(SingleChildFrameLoaderClient::create()) : RenderingTest(SingleChildFrameLoaderClient::create())
{ } { }
bool shouldPaintBackgroundOntoScrollingContentsLayer(const char* elementId) bool canPaintBackgroundOntoScrollingContentsLayer(const char* elementId)
{ {
PaintLayer* paintLayer = toLayoutBlock(getLayoutObjectByElementId(elementId))->layer(); PaintLayer* paintLayer = toLayoutBlock(getLayoutObjectByElementId(elementId))->layer();
return paintLayer->shouldPaintBackgroundOntoScrollingContentsLayer(); return paintLayer->canPaintBackgroundOntoScrollingContentsLayer();
} }
private: private:
......
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