Commit 758185a9 authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Avoid constructing a local PaintLayer in calls to Location().

This presumably avoids defeating a RVO optimization in the compiler,
and recovers nearly all of the performance lost in the referenced bug
in local testing on Linux.

Bug: 984965

Change-Id: I99567cc96391d410e71aba2fe4c2d29d5324fd11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1717923
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681146}
parent b09f5ca5
......@@ -520,6 +520,8 @@ void MouseEvent::ComputeRelativePosition() {
PaintLayer* layer = n->GetLayoutObject()->EnclosingLayer();
while (layer) {
PhysicalOffset physical_offset = layer->Location();
if (layer->GetLayoutObject().IsInFlowPositioned())
physical_offset += layer->GetLayoutObject().OffsetForInFlowPosition();
PaintLayer* containing_layer = layer->ContainingLayer();
if (containing_layer) {
physical_offset -=
......
......@@ -1532,6 +1532,8 @@ static inline const PaintLayer* AccumulateOffsetTowardsAncestor(
return nullptr;
location += layer->Location();
if (layer->GetLayoutObject().IsInFlowPositioned())
location += layer->GetLayoutObject().OffsetForInFlowPosition();
location -= PhysicalOffset(containing_layer->ScrolledContentOffset());
return containing_layer;
}
......
......@@ -296,15 +296,13 @@ class CORE_EXPORT PaintLayer : public DisplayItemClient {
}
// The physical offset from this PaintLayer to its ContainingLayer.
// Does not include any scroll offset of the ContainingLayer.
PhysicalOffset Location() const {
// Does not include any scroll offset of the ContainingLayer. Also does not
// include offsets for positioned elements.
const PhysicalOffset& Location() const {
#if DCHECK_IS_ON()
DCHECK(!needs_position_update_);
#endif
PhysicalOffset location = location_;
if (GetLayoutObject().IsInFlowPositioned())
location += GetLayoutObject().OffsetForInFlowPosition();
return location;
return location_;
}
LayoutSize ScrolledContentOffset() const;
......
......@@ -1353,12 +1353,18 @@ TEST_P(PaintLayerTest, FloatLayerAndAbsoluteUnderInlineLayer) {
EXPECT_EQ(container, span->ContainingLayer());
if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
EXPECT_EQ(PhysicalOffset(50, 50), floating->Location());
EXPECT_EQ(PhysicalOffset(0, 0), floating->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
floating->GetLayoutObject().OffsetForInFlowPosition());
} else {
EXPECT_EQ(PhysicalOffset(83, 83), floating->Location());
EXPECT_EQ(PhysicalOffset(33, 33), floating->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
floating->GetLayoutObject().OffsetForInFlowPosition());
}
EXPECT_EQ(PhysicalOffset(50, 50), absolute->Location());
EXPECT_EQ(PhysicalOffset(133, 133), span->Location());
EXPECT_EQ(PhysicalOffset(33, 33), span->Location());
EXPECT_EQ(PhysicalOffset(100, 100),
span->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(PhysicalOffset(20, 20), container->Location());
if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
......@@ -1403,16 +1409,22 @@ TEST_P(PaintLayerTest, FloatLayerUnderInlineLayerScrolled) {
EXPECT_EQ(container, span->Parent());
EXPECT_EQ(container, span->ContainingLayer());
EXPECT_EQ(PhysicalOffset(100, 100), span->Location());
EXPECT_EQ(PhysicalOffset(0, 0), span->Location());
EXPECT_EQ(PhysicalOffset(100, 100),
span->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(LayoutSize(0, 400),
span->ContainingLayer()->ScrolledContentOffset());
if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
EXPECT_EQ(PhysicalOffset(50, 50), floating->Location());
EXPECT_EQ(PhysicalOffset(0, 0), floating->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
floating->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(PhysicalOffset(50, 50), floating->VisualOffsetFromAncestor(span));
EXPECT_EQ(PhysicalOffset(150, -250),
floating->VisualOffsetFromAncestor(container));
} else {
EXPECT_EQ(PhysicalOffset(50, 50), floating->Location());
EXPECT_EQ(PhysicalOffset(0, 0), floating->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
floating->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(LayoutSize(0, 400),
floating->ContainingLayer()->ScrolledContentOffset());
EXPECT_EQ(PhysicalOffset(-50, -50),
......@@ -1440,8 +1452,12 @@ TEST_P(PaintLayerTest, FloatLayerUnderBlockUnderInlineLayer) {
EXPECT_EQ(span, floating->Parent());
EXPECT_EQ(span, floating->ContainingLayer());
EXPECT_EQ(PhysicalOffset(83, 83), floating->Location());
EXPECT_EQ(PhysicalOffset(100, 100), span->Location());
EXPECT_EQ(PhysicalOffset(33, 33), floating->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
floating->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(PhysicalOffset(0, 0), span->Location());
EXPECT_EQ(PhysicalOffset(100, 100),
span->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(PhysicalOffset(83, 83), floating->VisualOffsetFromAncestor(span));
EXPECT_EQ(PhysicalOffset(183, 183),
floating->VisualOffsetFromAncestor(
......@@ -1470,8 +1486,12 @@ TEST_P(PaintLayerTest, FloatLayerUnderFloatUnderInlineLayer) {
EXPECT_EQ(span->Parent(), floating->ContainingLayer());
}
EXPECT_EQ(PhysicalOffset(83, 83), floating->Location());
EXPECT_EQ(PhysicalOffset(100, 100), span->Location());
EXPECT_EQ(PhysicalOffset(33, 33), floating->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
floating->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(PhysicalOffset(0, 0), span->Location());
EXPECT_EQ(PhysicalOffset(100, 100),
span->GetLayoutObject().OffsetForInFlowPosition());
if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
EXPECT_EQ(PhysicalOffset(83, 83), floating->VisualOffsetFromAncestor(span));
EXPECT_EQ(PhysicalOffset(183, 183),
......@@ -1512,9 +1532,13 @@ TEST_P(PaintLayerTest, FloatLayerUnderFloatLayerUnderInlineLayer) {
EXPECT_EQ(span->Parent(), floating_parent->ContainingLayer());
}
EXPECT_EQ(PhysicalOffset(50, 50), floating->Location());
EXPECT_EQ(PhysicalOffset(0, 0), floating->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
floating->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(PhysicalOffset(33, 33), floating_parent->Location());
EXPECT_EQ(PhysicalOffset(100, 100), span->Location());
EXPECT_EQ(PhysicalOffset(0, 0), span->Location());
EXPECT_EQ(PhysicalOffset(100, 100),
span->GetLayoutObject().OffsetForInFlowPosition());
if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
EXPECT_EQ(PhysicalOffset(83, 83), floating->VisualOffsetFromAncestor(span));
EXPECT_EQ(PhysicalOffset(33, 33),
......@@ -1556,8 +1580,12 @@ TEST_P(PaintLayerTest, LayerUnderFloatUnderInlineLayer) {
EXPECT_EQ(span->Parent(), child->ContainingLayer());
}
EXPECT_EQ(PhysicalOffset(83, 83), child->Location());
EXPECT_EQ(PhysicalOffset(100, 100), span->Location());
EXPECT_EQ(PhysicalOffset(33, 33), child->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
child->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(PhysicalOffset(0, 0), span->Location());
EXPECT_EQ(PhysicalOffset(100, 100),
span->GetLayoutObject().OffsetForInFlowPosition());
if (RuntimeEnabledFeatures::LayoutNGEnabled()) {
EXPECT_EQ(PhysicalOffset(83, 83), child->VisualOffsetFromAncestor(span));
EXPECT_EQ(PhysicalOffset(183, 183),
......@@ -1657,10 +1685,15 @@ TEST_P(PaintLayerTest, ColumnSpanLayerUnderExtraLayerScrolled) {
EXPECT_EQ(columns, extra_layer->Parent()->Parent());
EXPECT_EQ(columns, extra_layer->ContainingLayer()->Parent());
EXPECT_EQ(PhysicalOffset(50, 50), spanner->Location());
EXPECT_EQ(PhysicalOffset(0, 0), spanner->Location());
EXPECT_EQ(PhysicalOffset(50, 50),
spanner->GetLayoutObject().OffsetForInFlowPosition());
EXPECT_EQ(LayoutSize(200, 0),
spanner->ContainingLayer()->ScrolledContentOffset());
EXPECT_EQ(PhysicalOffset(100, 100), extra_layer->Location());
EXPECT_EQ(PhysicalOffset(0, 0), extra_layer->Location());
EXPECT_EQ(PhysicalOffset(100, 100),
extra_layer->GetLayoutObject().OffsetForInFlowPosition());
// -60 = 2nd-column-x(40) - scroll-offset-x(200) + x-location(100)
// 20 = y-location(100) - column-height(80)
EXPECT_EQ(PhysicalOffset(-60, 20),
......
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