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