Commit 96d484e2 authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[LayoutNG] Fix NGExclusionSpace perf for html5 spec.

This patch does three things:
1) Moves cloning the exclusion space in
   NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild to later, as
   currently it get queried immediately after cloning, causing the
   exclusion space to regenerate its data.
2) Adds a bypasses for the cases where we are going to clear all floats
   and we can just return the maximum available area.
3) For the case where an element isn't clearing anything, just return
   LayoutUnit::Min().

Bug: 873799
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Ie04b80a774348303b248d725cf402751f7a651a1
Reviewed-on: https://chromium-review.googlesource.com/1181125Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584719}
parent 7e18e1f4
...@@ -165,11 +165,13 @@ NGLayoutOpportunity CreateLayoutOpportunity( ...@@ -165,11 +165,13 @@ NGLayoutOpportunity CreateLayoutOpportunity(
NGExclusionSpace::NGExclusionSpace() NGExclusionSpace::NGExclusionSpace()
: exclusions_(RefVector<scoped_refptr<const NGExclusion>>::Create()), : exclusions_(RefVector<scoped_refptr<const NGExclusion>>::Create()),
num_exclusions_(0), num_exclusions_(0),
both_clear_offset_(LayoutUnit::Min()),
derived_geometry_(nullptr) {} derived_geometry_(nullptr) {}
NGExclusionSpace::NGExclusionSpace(const NGExclusionSpace& other) NGExclusionSpace::NGExclusionSpace(const NGExclusionSpace& other)
: exclusions_(other.exclusions_), : exclusions_(other.exclusions_),
num_exclusions_(other.num_exclusions_), num_exclusions_(other.num_exclusions_),
both_clear_offset_(other.both_clear_offset_),
derived_geometry_(std::move(other.derived_geometry_)) { derived_geometry_(std::move(other.derived_geometry_)) {
// This copy-constructor does fun things. It moves the derived_geometry_ to // This copy-constructor does fun things. It moves the derived_geometry_ to
// the newly created exclusion space where it'll more-likely be used. // the newly created exclusion space where it'll more-likely be used.
...@@ -203,6 +205,9 @@ void NGExclusionSpace::Add(scoped_refptr<const NGExclusion> exclusion) { ...@@ -203,6 +205,9 @@ void NGExclusionSpace::Add(scoped_refptr<const NGExclusion> exclusion) {
if (derived_geometry_) if (derived_geometry_)
derived_geometry_->Add(exclusion); derived_geometry_->Add(exclusion);
both_clear_offset_ =
std::max(both_clear_offset_, exclusion->rect.BlockEndOffset());
exclusions_->push_back(std::move(exclusion)); exclusions_->push_back(std::move(exclusion));
num_exclusions_++; num_exclusions_++;
} }
......
...@@ -38,6 +38,15 @@ class CORE_EXPORT NGExclusionSpace { ...@@ -38,6 +38,15 @@ class CORE_EXPORT NGExclusionSpace {
const NGBfcOffset& offset, const NGBfcOffset& offset,
const LayoutUnit available_inline_size, const LayoutUnit available_inline_size,
const NGLogicalSize& minimum_size) const { const NGLogicalSize& minimum_size) const {
// If the area clears all floats, we can just return the layout opportunity
// which matches the available space.
if (offset.block_offset >= both_clear_offset_) {
NGBfcOffset end_offset(
offset.line_offset + available_inline_size.ClampNegativeToZero(),
LayoutUnit::Max());
return NGLayoutOpportunity(NGBfcRect(offset, end_offset), nullptr);
}
return GetDerivedGeometry().FindLayoutOpportunity( return GetDerivedGeometry().FindLayoutOpportunity(
offset, available_inline_size, minimum_size); offset, available_inline_size, minimum_size);
} }
...@@ -45,12 +54,25 @@ class CORE_EXPORT NGExclusionSpace { ...@@ -45,12 +54,25 @@ class CORE_EXPORT NGExclusionSpace {
Vector<NGLayoutOpportunity> AllLayoutOpportunities( Vector<NGLayoutOpportunity> AllLayoutOpportunities(
const NGBfcOffset& offset, const NGBfcOffset& offset,
const LayoutUnit available_inline_size) const { const LayoutUnit available_inline_size) const {
// If the area clears all floats, we can just return a single layout
// opportunity which matches the available space.
if (offset.block_offset >= both_clear_offset_) {
NGBfcOffset end_offset(
offset.line_offset + available_inline_size.ClampNegativeToZero(),
LayoutUnit::Max());
return Vector<NGLayoutOpportunity>(
{NGLayoutOpportunity(NGBfcRect(offset, end_offset), nullptr)});
}
return GetDerivedGeometry().AllLayoutOpportunities(offset, return GetDerivedGeometry().AllLayoutOpportunities(offset,
available_inline_size); available_inline_size);
} }
// Returns the clearance offset based on the provided {@code clear_type}. // Returns the clearance offset based on the provided {@code clear_type}.
LayoutUnit ClearanceOffset(EClear clear_type) const { LayoutUnit ClearanceOffset(EClear clear_type) const {
if (clear_type == EClear::kNone)
return LayoutUnit::Min();
return GetDerivedGeometry().ClearanceOffset(clear_type); return GetDerivedGeometry().ClearanceOffset(clear_type);
} }
...@@ -144,6 +166,7 @@ class CORE_EXPORT NGExclusionSpace { ...@@ -144,6 +166,7 @@ class CORE_EXPORT NGExclusionSpace {
// space has, which may differ to the number of exclusions in the Vector. // space has, which may differ to the number of exclusions in the Vector.
scoped_refptr<RefVector<scoped_refptr<const NGExclusion>>> exclusions_; scoped_refptr<RefVector<scoped_refptr<const NGExclusion>>> exclusions_;
size_t num_exclusions_; size_t num_exclusions_;
LayoutUnit both_clear_offset_;
// The derived geometry struct, is the data-structure which handles all of the // The derived geometry struct, is the data-structure which handles all of the
// queries on the exclusion space. It can always be rebuilt from exclusions_ // queries on the exclusion space. It can always be rebuilt from exclusions_
......
...@@ -1844,12 +1844,6 @@ NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( ...@@ -1844,12 +1844,6 @@ NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild(
.SetBfcOffset(child_data.bfc_offset_estimate) .SetBfcOffset(child_data.bfc_offset_estimate)
.SetMarginStrut(child_data.margin_strut); .SetMarginStrut(child_data.margin_strut);
if (!is_new_fc) {
space_builder.SetExclusionSpace(*exclusion_space_);
space_builder.SetAdjoiningFloatTypes(
container_builder_.AdjoiningFloatTypes());
}
if (!container_builder_.BfcBlockOffset() && if (!container_builder_.BfcBlockOffset() &&
ConstraintSpace().FloatsBfcBlockOffset()) { ConstraintSpace().FloatsBfcBlockOffset()) {
space_builder.SetFloatsBfcBlockOffset( space_builder.SetFloatsBfcBlockOffset(
...@@ -1884,6 +1878,12 @@ NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( ...@@ -1884,6 +1878,12 @@ NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild(
if (child_data.force_clearance) if (child_data.force_clearance)
space_builder.SetShouldForceClearance(true); space_builder.SetShouldForceClearance(true);
if (!is_new_fc) {
space_builder.SetExclusionSpace(*exclusion_space_);
space_builder.SetAdjoiningFloatTypes(
container_builder_.AdjoiningFloatTypes());
}
LayoutUnit space_available; LayoutUnit space_available;
if (ConstraintSpace().HasBlockFragmentation()) { if (ConstraintSpace().HasBlockFragmentation()) {
space_available = ConstraintSpace().FragmentainerSpaceAtBfcStart(); space_available = ConstraintSpace().FragmentainerSpaceAtBfcStart();
......
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