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
if (!style()->hasAutoClip())
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
// into the composited scrolling contents layer. https://crbug.com/646464
if (style()->boxShadow())
......
......@@ -300,7 +300,12 @@ void CompositedLayerMapping::updateIsRootForIsolatedGroup()
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()) {
m_backgroundPaintsOntoScrollingContentsLayer = shouldPaintOntoScrollingContentsLayer;
// If the background is no longer painted onto the scrolling contents
......
......@@ -647,6 +647,25 @@ TEST_F(CompositedLayerMappingTest, ScrollingContentsAndForegroundLayerPaintingPh
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
// when they're an ancestor of the root scroller element.
TEST_F(CompositedLayerMappingTest, RootScrollerAncestorsNotClipped)
......
......@@ -2358,7 +2358,7 @@ GraphicsLayer* PaintLayer::graphicsLayerBackingForScrolling() const
}
}
bool PaintLayer::shouldPaintBackgroundOntoScrollingContentsLayer() const
bool PaintLayer::canPaintBackgroundOntoScrollingContentsLayer() const
{
return !isRootLayer()
&& scrollsOverflow()
......
......@@ -438,7 +438,7 @@ public:
// (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
// 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,
// (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.
......
......@@ -1497,7 +1497,7 @@ static bool layerNeedsCompositedScrolling(PaintLayerScrollableArea::LCDTextMode
// use integer scroll offsets locally when !layer->compositor()->preferCompositingToLCDTextEnabled(),
// we do not check offsets accumulated from the root (including translates). crbug.com/644833
bool backgroundSupportsLCDText = RuntimeEnabledFeatures::compositeOpaqueScrollersEnabled()
&& layer->shouldPaintBackgroundOntoScrollingContentsLayer()
&& layer->canPaintBackgroundOntoScrollingContentsLayer()
&& layer->backgroundIsKnownToBeOpaqueInRect(toLayoutBox(layer->layoutObject())->paddingBoxRect());
if (mode == PaintLayerScrollableArea::ConsiderLCDText
&& !layer->compositor()->preferCompositingToLCDTextEnabled()
......
......@@ -8,7 +8,7 @@
namespace blink {
TEST_F(PaintLayerScrollableAreaTest, ShouldPaintBackgroundOntoScrollingContentsLayer)
TEST_F(PaintLayerScrollableAreaTest, CanPaintBackgroundOntoScrollingContentsLayer)
{
document().frame()->settings()->setPreferCompositingToLCDTextEnabled(true);
setBodyInnerHTML(
......@@ -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='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='scroller16' class='scroller' style='background: white; border 1px solid black; border-radius: 2px;'><div class='spacer'></div></div>"
"<div id='scroller17' class='scroller' style='background: white; clip: rect(0px,10px,10px,0px);'><div class='spacer'></div></div>"
"<div id='scroller16' 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.
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.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller2"));
EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller2"));
// #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.
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.
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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// 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
// padding box.
EXPECT_TRUE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller14"));
EXPECT_TRUE(canPaintBackgroundOntoScrollingContentsLayer("scroller14"));
// #scroller15 cannot paint background into scrolling contents layer because the outline is drawn inside
// the padding box.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller15"));
EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller15"));
// #scroller16 cannot paint background into scrolling contents layer because it has a
// border radius.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller16"));
// #scroller17 cannot paint background into scrolling contents layer because the scroller has a clip which
// #scroller16 cannot paint background into scrolling contents layer because the scroller has a clip which
// would not be respected by the scrolling contents layer.
EXPECT_FALSE(shouldPaintBackgroundOntoScrollingContentsLayer("scroller17"));
EXPECT_FALSE(canPaintBackgroundOntoScrollingContentsLayer("scroller16"));
}
TEST_F(PaintLayerScrollableAreaTest, OpaqueLayersPromoted)
......
......@@ -17,10 +17,10 @@ public:
: RenderingTest(SingleChildFrameLoaderClient::create())
{ }
bool shouldPaintBackgroundOntoScrollingContentsLayer(const char* elementId)
bool canPaintBackgroundOntoScrollingContentsLayer(const char* elementId)
{
PaintLayer* paintLayer = toLayoutBlock(getLayoutObjectByElementId(elementId))->layer();
return paintLayer->shouldPaintBackgroundOntoScrollingContentsLayer();
return paintLayer->canPaintBackgroundOntoScrollingContentsLayer();
}
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