Commit 1c8b6637 authored by Ian Kilpatrick's avatar Ian Kilpatrick Committed by Commit Bot

[LayoutNG] Introduce NGConstraintSpace::RareData.

This moves fields relating to:
 - Floats clearance
 - Fragmentation
 - Margin struts
 - Weird percentages

... to a rare data member. This decreases partition alloc usage on
system_health.memory_desktop by approximately 6-7%, at the cost of
0-6% on most benchmarks.

Change-Id: Ifaeaf5d874efcd13ce9eff785d8093d24637de86
Bug: 635619
Reviewed-on: https://chromium-review.googlesource.com/c/1323803
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Reviewed-by: default avatarChristian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609030}
parent 20ef032a
...@@ -424,6 +424,7 @@ blink_core_sources("layout") { ...@@ -424,6 +424,7 @@ blink_core_sources("layout") {
"ng/ng_column_layout_algorithm.h", "ng/ng_column_layout_algorithm.h",
"ng/ng_constraint_space.cc", "ng/ng_constraint_space.cc",
"ng/ng_constraint_space.h", "ng/ng_constraint_space.h",
"ng/ng_constraint_space_builder.cc",
"ng/ng_constraint_space_builder.h", "ng/ng_constraint_space_builder.h",
"ng/ng_container_fragment_builder.cc", "ng/ng_container_fragment_builder.cc",
"ng/ng_container_fragment_builder.h", "ng/ng_container_fragment_builder.h",
......
...@@ -32,6 +32,9 @@ struct CORE_EXPORT NGLogicalSize { ...@@ -32,6 +32,9 @@ struct CORE_EXPORT NGLogicalSize {
return std::tie(other.inline_size, other.block_size) == return std::tie(other.inline_size, other.block_size) ==
std::tie(inline_size, block_size); std::tie(inline_size, block_size);
} }
bool operator!=(const NGLogicalSize& other) const {
return !(*this == other);
}
bool IsEmpty() const { bool IsEmpty() const {
return inline_size == LayoutUnit() || block_size == LayoutUnit(); return inline_size == LayoutUnit() || block_size == LayoutUnit();
......
...@@ -36,6 +36,7 @@ bool NGMarginStrut::operator==(const NGMarginStrut& other) const { ...@@ -36,6 +36,7 @@ bool NGMarginStrut::operator==(const NGMarginStrut& other) const {
return positive_margin == other.positive_margin && return positive_margin == other.positive_margin &&
negative_margin == other.negative_margin && negative_margin == other.negative_margin &&
quirky_positive_margin == other.quirky_positive_margin && quirky_positive_margin == other.quirky_positive_margin &&
discard_margins == other.discard_margins &&
is_quirky_container_start == other.is_quirky_container_start; is_quirky_container_start == other.is_quirky_container_start;
} }
......
...@@ -158,8 +158,11 @@ void ComputeAbsoluteHorizontal(const NGConstraintSpace& space, ...@@ -158,8 +158,11 @@ void ComputeAbsoluteHorizontal(const NGConstraintSpace& space,
const WritingMode container_writing_mode, const WritingMode container_writing_mode,
const TextDirection container_direction, const TextDirection container_direction,
NGAbsolutePhysicalPosition* position) { NGAbsolutePhysicalPosition* position) {
NGPhysicalSize percentage_physical = ToNGPhysicalSize( LayoutUnit percentage_width =
space.PercentageResolutionSize(), space.GetWritingMode()); LIKELY(space.GetWritingMode() == WritingMode::kHorizontalTb)
? space.PercentageResolutionInlineSize()
: space.PercentageResolutionBlockSize();
base::Optional<LayoutUnit> margin_left; base::Optional<LayoutUnit> margin_left;
if (!style.MarginLeft().IsAuto()) if (!style.MarginLeft().IsAuto())
margin_left = ResolveMarginPaddingLength(space, style.MarginLeft()); margin_left = ResolveMarginPaddingLength(space, style.MarginLeft());
...@@ -168,10 +171,10 @@ void ComputeAbsoluteHorizontal(const NGConstraintSpace& space, ...@@ -168,10 +171,10 @@ void ComputeAbsoluteHorizontal(const NGConstraintSpace& space,
margin_right = ResolveMarginPaddingLength(space, style.MarginRight()); margin_right = ResolveMarginPaddingLength(space, style.MarginRight());
base::Optional<LayoutUnit> left; base::Optional<LayoutUnit> left;
if (!style.Left().IsAuto()) if (!style.Left().IsAuto())
left = ValueForLength(style.Left(), percentage_physical.width); left = ValueForLength(style.Left(), percentage_width);
base::Optional<LayoutUnit> right; base::Optional<LayoutUnit> right;
if (!style.Right().IsAuto()) if (!style.Right().IsAuto())
right = ValueForLength(style.Right(), percentage_physical.width); right = ValueForLength(style.Right(), percentage_width);
base::Optional<LayoutUnit> width = incoming_width; base::Optional<LayoutUnit> width = incoming_width;
NGPhysicalSize container_size = NGPhysicalSize container_size =
ToNGPhysicalSize(space.AvailableSize(), space.GetWritingMode()); ToNGPhysicalSize(space.AvailableSize(), space.GetWritingMode());
...@@ -320,8 +323,10 @@ void ComputeAbsoluteVertical(const NGConstraintSpace& space, ...@@ -320,8 +323,10 @@ void ComputeAbsoluteVertical(const NGConstraintSpace& space,
const WritingMode container_writing_mode, const WritingMode container_writing_mode,
const TextDirection container_direction, const TextDirection container_direction,
NGAbsolutePhysicalPosition* position) { NGAbsolutePhysicalPosition* position) {
NGPhysicalSize percentage_physical = ToNGPhysicalSize( LayoutUnit percentage_height =
space.PercentageResolutionSize(), space.GetWritingMode()); LIKELY(space.GetWritingMode() == WritingMode::kHorizontalTb)
? space.PercentageResolutionBlockSize()
: space.PercentageResolutionInlineSize();
base::Optional<LayoutUnit> margin_top; base::Optional<LayoutUnit> margin_top;
if (!style.MarginTop().IsAuto()) if (!style.MarginTop().IsAuto())
...@@ -331,10 +336,10 @@ void ComputeAbsoluteVertical(const NGConstraintSpace& space, ...@@ -331,10 +336,10 @@ void ComputeAbsoluteVertical(const NGConstraintSpace& space,
margin_bottom = ResolveMarginPaddingLength(space, style.MarginBottom()); margin_bottom = ResolveMarginPaddingLength(space, style.MarginBottom());
base::Optional<LayoutUnit> top; base::Optional<LayoutUnit> top;
if (!style.Top().IsAuto()) if (!style.Top().IsAuto())
top = ValueForLength(style.Top(), percentage_physical.height); top = ValueForLength(style.Top(), percentage_height);
base::Optional<LayoutUnit> bottom; base::Optional<LayoutUnit> bottom;
if (!style.Bottom().IsAuto()) if (!style.Bottom().IsAuto())
bottom = ValueForLength(style.Bottom(), percentage_physical.height); bottom = ValueForLength(style.Bottom(), percentage_height);
LayoutUnit border_padding = VerticalBorderPadding(space, style); LayoutUnit border_padding = VerticalBorderPadding(space, style);
base::Optional<LayoutUnit> height = incoming_height; base::Optional<LayoutUnit> height = incoming_height;
......
...@@ -2091,12 +2091,12 @@ NGConstraintSpace NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( ...@@ -2091,12 +2091,12 @@ NGConstraintSpace NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild(
// to bother to check whether we're actually at the start). // to bother to check whether we're actually at the start).
space_builder.SetSeparateLeadingFragmentainerMargins( space_builder.SetSeparateLeadingFragmentainerMargins(
ConstraintSpace().HasSeparateLeadingFragmentainerMargins()); ConstraintSpace().HasSeparateLeadingFragmentainerMargins());
space_builder.SetFragmentainerBlockSize(
ConstraintSpace().FragmentainerBlockSize());
space_builder.SetFragmentainerSpaceAtBfcStart(space_available);
space_builder.SetFragmentationType(
ConstraintSpace().BlockFragmentationType());
} }
space_builder.SetFragmentainerBlockSize(
ConstraintSpace().FragmentainerBlockSize());
space_builder.SetFragmentainerSpaceAtBfcStart(space_available);
space_builder.SetFragmentationType(
ConstraintSpace().BlockFragmentationType());
return space_builder.ToConstraintSpace(); return space_builder.ToConstraintSpace();
} }
......
...@@ -148,9 +148,9 @@ LayoutUnit CalculateAvailableInlineSizeForLegacy( ...@@ -148,9 +148,9 @@ LayoutUnit CalculateAvailableInlineSizeForLegacy(
const NGConstraintSpace& space) { const NGConstraintSpace& space) {
if (box.StyleRef().LogicalWidth().IsPercent()) { if (box.StyleRef().LogicalWidth().IsPercent()) {
if (box.ShouldComputeSizeAsReplaced()) if (box.ShouldComputeSizeAsReplaced())
return space.ReplacedPercentageResolutionSize().inline_size; return space.ReplacedPercentageResolutionInlineSize();
return space.PercentageResolutionSize().inline_size; return space.PercentageResolutionInlineSize();
} }
return space.AvailableSize().inline_size; return space.AvailableSize().inline_size;
...@@ -161,9 +161,9 @@ LayoutUnit CalculateAvailableBlockSizeForLegacy( ...@@ -161,9 +161,9 @@ LayoutUnit CalculateAvailableBlockSizeForLegacy(
const NGConstraintSpace& space) { const NGConstraintSpace& space) {
if (box.StyleRef().LogicalHeight().IsPercent()) { if (box.StyleRef().LogicalHeight().IsPercent()) {
if (box.ShouldComputeSizeAsReplaced()) if (box.ShouldComputeSizeAsReplaced())
return space.ReplacedPercentageResolutionSize().block_size; return space.ReplacedPercentageResolutionBlockSize();
return space.PercentageResolutionSize().block_size; return space.PercentageResolutionBlockSize();
} }
return space.AvailableSize().block_size; return space.AvailableSize().block_size;
...@@ -193,8 +193,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::Layout( ...@@ -193,8 +193,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::Layout(
// TODO(layoutng): Figure out why these two call can't be inside the // TODO(layoutng): Figure out why these two call can't be inside the
// !constraint_space.IsIntermediateLayout() block below. // !constraint_space.IsIntermediateLayout() block below.
UpdateShapeOutsideInfoIfNeeded( UpdateShapeOutsideInfoIfNeeded(
*layout_result, *layout_result, constraint_space.PercentageResolutionInlineSize());
constraint_space.PercentageResolutionSize().inline_size);
// We may need paint invalidation even if we can reuse layout, as our // We may need paint invalidation even if we can reuse layout, as our
// paint offset/visual rect may have changed due to relative // paint offset/visual rect may have changed due to relative
// positioning changes. Otherwise we fail fast/css/ // positioning changes. Otherwise we fail fast/css/
...@@ -278,7 +277,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::Layout( ...@@ -278,7 +277,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::Layout(
// TODO(ikilpatrick): This should be fixed by moving the shape-outside data // TODO(ikilpatrick): This should be fixed by moving the shape-outside data
// to the NGLayoutResult, removing this "side" data-structure. // to the NGLayoutResult, removing this "side" data-structure.
UpdateShapeOutsideInfoIfNeeded( UpdateShapeOutsideInfoIfNeeded(
*layout_result, constraint_space.PercentageResolutionSize().inline_size); *layout_result, constraint_space.PercentageResolutionInlineSize());
return layout_result; return layout_result;
} }
...@@ -893,7 +892,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::RunOldLayout( ...@@ -893,7 +892,7 @@ scoped_refptr<NGLayoutResult> NGBlockNode::RunOldLayout(
scoped_refptr<NGLayoutResult> layout_result = builder.ToBoxFragment(); scoped_refptr<NGLayoutResult> layout_result = builder.ToBoxFragment();
UpdateShapeOutsideInfoIfNeeded( UpdateShapeOutsideInfoIfNeeded(
*layout_result, constraint_space.PercentageResolutionSize().inline_size); *layout_result, constraint_space.PercentageResolutionInlineSize());
return layout_result; return layout_result;
} }
......
...@@ -18,14 +18,14 @@ namespace blink { ...@@ -18,14 +18,14 @@ namespace blink {
namespace { namespace {
struct SameSizeAsNGConstraintSpace { struct SameSizeAsNGConstraintSpace {
NGLogicalSize logical_sizes[3]; NGLogicalSize available_size;
NGPhysicalSize physical_sizes[1]; NGPhysicalSize initial_containing_block_size;
NGMarginStrut margin_strut; union {
NGBfcOffset bfc_offset; NGBfcOffset bfc_offset;
void* rare_data;
};
NGExclusionSpace exclusion_space; NGExclusionSpace exclusion_space;
base::Optional<LayoutUnit> optional_layout_unit; unsigned bitfields[1];
LayoutUnit layout_units[3];
unsigned flags[1];
}; };
static_assert(sizeof(NGConstraintSpace) == sizeof(SameSizeAsNGConstraintSpace), static_assert(sizeof(NGConstraintSpace) == sizeof(SameSizeAsNGConstraintSpace),
...@@ -33,16 +33,6 @@ static_assert(sizeof(NGConstraintSpace) == sizeof(SameSizeAsNGConstraintSpace), ...@@ -33,16 +33,6 @@ static_assert(sizeof(NGConstraintSpace) == sizeof(SameSizeAsNGConstraintSpace),
} // namespace } // namespace
NGConstraintSpace::NGConstraintSpace(WritingMode out_writing_mode,
NGPhysicalSize icb_size)
: initial_containing_block_size_(icb_size),
block_direction_fragmentation_type_(static_cast<unsigned>(kFragmentNone)),
table_cell_child_layout_phase_(static_cast<unsigned>(kNotTableCellChild)),
adjoining_floats_(static_cast<unsigned>(kFloatTypeNone)),
writing_mode_(static_cast<unsigned>(out_writing_mode)),
direction_(static_cast<unsigned>(TextDirection::kLtr)),
flags_(kFixedSizeBlockIsDefinite) {}
NGConstraintSpace NGConstraintSpace::CreateFromLayoutObject( NGConstraintSpace NGConstraintSpace::CreateFromLayoutObject(
const LayoutBox& box) { const LayoutBox& box) {
auto writing_mode = box.StyleRef().GetWritingMode(); auto writing_mode = box.StyleRef().GetWritingMode();
...@@ -155,11 +145,20 @@ NGConstraintSpace NGConstraintSpace::CreateFromLayoutObject( ...@@ -155,11 +145,20 @@ NGConstraintSpace NGConstraintSpace::CreateFromLayoutObject(
} }
bool NGConstraintSpace::operator==(const NGConstraintSpace& other) const { bool NGConstraintSpace::operator==(const NGConstraintSpace& other) const {
return AreSizesEqual(other) && if (!AreSizesEqual(other))
bfc_offset_.block_offset == other.bfc_offset_.block_offset && return false;
initial_containing_block_size_ ==
other.initial_containing_block_size_ && if (!MaySkipLayout(other))
MaySkipLayout(other); return false;
if (initial_containing_block_size_ != other.initial_containing_block_size_)
return false;
if (!HasRareData() && !other.HasRareData() &&
bfc_offset_.block_offset != other.bfc_offset_.block_offset)
return false;
return true;
} }
String NGConstraintSpace::ToString() const { String NGConstraintSpace::ToString() const {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space_builder.h"
#include "third_party/blink/renderer/core/layout/ng/ng_constraint_space.h"
namespace blink {
namespace {
NGPercentageStorage GetPercentageStorage(LayoutUnit percentage_size,
LayoutUnit available_size) {
if (percentage_size == available_size)
return kSameAsAvailable;
if (percentage_size == NGSizeIndefinite)
return kIndefinite;
if (percentage_size == LayoutUnit())
return kZero;
return kRareDataPercentage;
}
} // namespace
NGConstraintSpaceBuilder& NGConstraintSpaceBuilder::SetPercentageResolutionSize(
NGLogicalSize percentage_resolution_size) {
#if DCHECK_IS_ON()
DCHECK(is_available_size_set_);
#endif
if (LIKELY(is_in_parallel_flow_)) {
space_.bitfields_.percentage_inline_storage =
GetPercentageStorage(percentage_resolution_size.inline_size,
space_.available_size_.inline_size);
if (UNLIKELY(space_.bitfields_.percentage_inline_storage ==
kRareDataPercentage)) {
space_.EnsureRareData()->percentage_resolution_size.inline_size =
percentage_resolution_size.inline_size;
}
space_.bitfields_.percentage_block_storage =
GetPercentageStorage(percentage_resolution_size.block_size,
space_.available_size_.block_size);
if (space_.bitfields_.percentage_block_storage == kRareDataPercentage) {
space_.EnsureRareData()->percentage_resolution_size.block_size =
percentage_resolution_size.block_size;
}
} else {
AdjustInlineSizeIfNeeded(&percentage_resolution_size.block_size);
space_.bitfields_.percentage_inline_storage =
GetPercentageStorage(percentage_resolution_size.block_size,
space_.available_size_.inline_size);
if (space_.bitfields_.percentage_inline_storage == kRareDataPercentage) {
space_.EnsureRareData()->percentage_resolution_size.inline_size =
percentage_resolution_size.block_size;
}
space_.bitfields_.percentage_block_storage =
GetPercentageStorage(percentage_resolution_size.inline_size,
space_.available_size_.block_size);
if (space_.bitfields_.percentage_block_storage == kRareDataPercentage) {
space_.EnsureRareData()->percentage_resolution_size.block_size =
percentage_resolution_size.inline_size;
}
}
return *this;
}
NGConstraintSpaceBuilder&
NGConstraintSpaceBuilder::SetReplacedPercentageResolutionSize(
NGLogicalSize replaced_percentage_resolution_size) {
#if DCHECK_IS_ON()
DCHECK(is_available_size_set_);
#endif
if (LIKELY(is_in_parallel_flow_)) {
space_.bitfields_.replaced_percentage_inline_storage =
GetPercentageStorage(replaced_percentage_resolution_size.inline_size,
space_.available_size_.inline_size);
if (UNLIKELY(space_.bitfields_.replaced_percentage_inline_storage ==
kRareDataPercentage)) {
space_.EnsureRareData()->replaced_percentage_resolution_size.inline_size =
replaced_percentage_resolution_size.inline_size;
}
space_.bitfields_.replaced_percentage_block_storage =
GetPercentageStorage(replaced_percentage_resolution_size.block_size,
space_.available_size_.block_size);
if (space_.bitfields_.replaced_percentage_block_storage ==
kRareDataPercentage) {
space_.EnsureRareData()->replaced_percentage_resolution_size.block_size =
replaced_percentage_resolution_size.block_size;
}
} else {
AdjustInlineSizeIfNeeded(&replaced_percentage_resolution_size.block_size);
space_.bitfields_.replaced_percentage_inline_storage =
GetPercentageStorage(replaced_percentage_resolution_size.block_size,
space_.available_size_.inline_size);
if (space_.bitfields_.replaced_percentage_inline_storage ==
kRareDataPercentage) {
space_.EnsureRareData()->replaced_percentage_resolution_size.inline_size =
replaced_percentage_resolution_size.block_size;
}
space_.bitfields_.replaced_percentage_block_storage =
GetPercentageStorage(replaced_percentage_resolution_size.inline_size,
space_.available_size_.block_size);
if (space_.bitfields_.replaced_percentage_block_storage ==
kRareDataPercentage) {
space_.EnsureRareData()->replaced_percentage_resolution_size.block_size =
replaced_percentage_resolution_size.inline_size;
}
}
return *this;
}
} // namespace blink
...@@ -32,7 +32,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -32,7 +32,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
is_new_fc) { is_new_fc) {
// Propagate the intermediate layout bit to the child constraint space. // Propagate the intermediate layout bit to the child constraint space.
if (parent_space.IsIntermediateLayout()) if (parent_space.IsIntermediateLayout())
space_.flags_ |= NGConstraintSpace::kIntermediateLayout; space_.bitfields_.flags |= NGConstraintSpace::kIntermediateLayout;
} }
// The setters on this builder are in the writing mode of parent_writing_mode. // The setters on this builder are in the writing mode of parent_writing_mode.
...@@ -54,10 +54,10 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -54,10 +54,10 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
force_orthogonal_writing_mode_root_( force_orthogonal_writing_mode_root_(
force_orthogonal_writing_mode_root) { force_orthogonal_writing_mode_root) {
if (is_new_fc_) if (is_new_fc_)
space_.flags_ |= NGConstraintSpace::kNewFormattingContext; space_.bitfields_.flags |= NGConstraintSpace::kNewFormattingContext;
if (!is_in_parallel_flow_ || force_orthogonal_writing_mode_root_) if (!is_in_parallel_flow_ || force_orthogonal_writing_mode_root_)
space_.flags_ |= NGConstraintSpace::kOrthogonalWritingModeRoot; space_.bitfields_.flags |= NGConstraintSpace::kOrthogonalWritingModeRoot;
} }
// If inline size is indefinite, use size of initial containing block. // If inline size is indefinite, use size of initial containing block.
...@@ -68,7 +68,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -68,7 +68,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
if (*inline_size != NGSizeIndefinite) if (*inline_size != NGSizeIndefinite)
return; return;
if (static_cast<WritingMode>(space_.writing_mode_) == if (static_cast<WritingMode>(space_.bitfields_.writing_mode) ==
WritingMode::kHorizontalTb) WritingMode::kHorizontalTb)
*inline_size = space_.initial_containing_block_size_.width; *inline_size = space_.initial_containing_block_size_.width;
else else
...@@ -76,6 +76,9 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -76,6 +76,9 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
} }
NGConstraintSpaceBuilder& SetAvailableSize(NGLogicalSize available_size) { NGConstraintSpaceBuilder& SetAvailableSize(NGLogicalSize available_size) {
#if DCHECK_IS_ON()
is_available_size_set_ = true;
#endif
space_.available_size_ = available_size; space_.available_size_ = available_size;
if (UNLIKELY(!is_in_parallel_flow_)) { if (UNLIKELY(!is_in_parallel_flow_)) {
...@@ -87,43 +90,33 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -87,43 +90,33 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
} }
NGConstraintSpaceBuilder& SetPercentageResolutionSize( NGConstraintSpaceBuilder& SetPercentageResolutionSize(
NGLogicalSize percentage_resolution_size) { NGLogicalSize percentage_resolution_size);
space_.percentage_resolution_size_ = percentage_resolution_size;
if (UNLIKELY(!is_in_parallel_flow_)) {
space_.percentage_resolution_size_.Flip();
AdjustInlineSizeIfNeeded(&space_.percentage_resolution_size_.inline_size);
}
return *this;
}
NGConstraintSpaceBuilder& SetReplacedPercentageResolutionSize( NGConstraintSpaceBuilder& SetReplacedPercentageResolutionSize(
NGLogicalSize replaced_percentage_resolution_size) { NGLogicalSize replaced_percentage_resolution_size);
space_.replaced_percentage_resolution_size_ =
replaced_percentage_resolution_size;
if (UNLIKELY(!is_in_parallel_flow_)) {
space_.replaced_percentage_resolution_size_.Flip();
AdjustInlineSizeIfNeeded(
&space_.replaced_percentage_resolution_size_.inline_size);
}
return *this;
}
NGConstraintSpaceBuilder& SetFragmentainerBlockSize(LayoutUnit size) { NGConstraintSpaceBuilder& SetFragmentainerBlockSize(LayoutUnit size) {
space_.fragmentainer_block_size_ = size; #if DCHECK_IS_ON()
DCHECK(!is_fragmentainer_block_size_set_);
is_fragmentainer_block_size_set_ = true;
#endif
if (size != NGSizeIndefinite)
space_.EnsureRareData()->fragmentainer_block_size = size;
return *this; return *this;
} }
NGConstraintSpaceBuilder& SetFragmentainerSpaceAtBfcStart(LayoutUnit space) { NGConstraintSpaceBuilder& SetFragmentainerSpaceAtBfcStart(LayoutUnit space) {
space_.fragmentainer_space_at_bfc_start_ = space; #if DCHECK_IS_ON()
DCHECK(!is_fragmentainer_space_at_bfc_start_set_);
is_fragmentainer_space_at_bfc_start_set_ = true;
#endif
if (space != NGSizeIndefinite)
space_.EnsureRareData()->fragmentainer_space_at_bfc_start = space;
return *this; return *this;
} }
NGConstraintSpaceBuilder& SetTextDirection(TextDirection direction) { NGConstraintSpaceBuilder& SetTextDirection(TextDirection direction) {
space_.direction_ = static_cast<unsigned>(direction); space_.bitfields_.direction = static_cast<unsigned>(direction);
return *this; return *this;
} }
...@@ -164,7 +157,14 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -164,7 +157,14 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
NGConstraintSpaceBuilder& SetFragmentationType( NGConstraintSpaceBuilder& SetFragmentationType(
NGFragmentationType fragmentation_type) { NGFragmentationType fragmentation_type) {
space_.block_direction_fragmentation_type_ = fragmentation_type; #if DCHECK_IS_ON()
DCHECK(!is_block_direction_fragmentation_type_set_);
is_block_direction_fragmentation_type_set_ = true;
#endif
if (fragmentation_type != NGFragmentationType::kFragmentNone) {
space_.EnsureRareData()->block_direction_fragmentation_type =
fragmentation_type;
}
return *this; return *this;
} }
...@@ -185,35 +185,53 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -185,35 +185,53 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
NGConstraintSpaceBuilder& SetAdjoiningFloatTypes(NGFloatTypes floats) { NGConstraintSpaceBuilder& SetAdjoiningFloatTypes(NGFloatTypes floats) {
if (!is_new_fc_) if (!is_new_fc_)
space_.adjoining_floats_ = static_cast<unsigned>(floats); space_.bitfields_.adjoining_floats = static_cast<unsigned>(floats);
return *this; return *this;
} }
NGConstraintSpaceBuilder& SetMarginStrut(const NGMarginStrut& margin_strut) { NGConstraintSpaceBuilder& SetMarginStrut(const NGMarginStrut& margin_strut) {
if (!is_new_fc_) #if DCHECK_IS_ON()
space_.margin_strut_ = margin_strut; DCHECK(!is_margin_strut_set_);
is_margin_strut_set_ = true;
#endif
if (!is_new_fc_ && margin_strut != NGMarginStrut())
space_.EnsureRareData()->margin_strut = margin_strut;
return *this; return *this;
} }
NGConstraintSpaceBuilder& SetBfcOffset(const NGBfcOffset& bfc_offset) { NGConstraintSpaceBuilder& SetBfcOffset(const NGBfcOffset& bfc_offset) {
if (!is_new_fc_) if (!is_new_fc_) {
space_.bfc_offset_ = bfc_offset; if (space_.HasRareData())
space_.rare_data_->bfc_offset = bfc_offset;
else
space_.bfc_offset_ = bfc_offset;
}
return *this; return *this;
} }
NGConstraintSpaceBuilder& SetFloatsBfcBlockOffset( NGConstraintSpaceBuilder& SetFloatsBfcBlockOffset(
const base::Optional<LayoutUnit>& floats_bfc_block_offset) { const base::Optional<LayoutUnit>& floats_bfc_block_offset) {
if (!is_new_fc_) #if DCHECK_IS_ON()
space_.floats_bfc_block_offset_ = floats_bfc_block_offset; DCHECK(!is_floats_bfc_block_offset_set_);
is_floats_bfc_block_offset_set_ = true;
#endif
if (LIKELY(!is_new_fc_ && floats_bfc_block_offset != base::nullopt)) {
space_.EnsureRareData()->floats_bfc_block_offset =
floats_bfc_block_offset;
}
return *this; return *this;
} }
NGConstraintSpaceBuilder& SetClearanceOffset(LayoutUnit clearance_offset) { NGConstraintSpaceBuilder& SetClearanceOffset(LayoutUnit clearance_offset) {
if (!is_new_fc_) #if DCHECK_IS_ON()
space_.clearance_offset_ = clearance_offset; DCHECK(!is_clearance_offset_set_);
is_clearance_offset_set_ = true;
#endif
if (!is_new_fc_ && clearance_offset != LayoutUnit::Min())
space_.EnsureRareData()->clearance_offset = clearance_offset;
return *this; return *this;
} }
...@@ -225,7 +243,8 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -225,7 +243,8 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
NGConstraintSpaceBuilder& SetTableCellChildLayoutPhase( NGConstraintSpaceBuilder& SetTableCellChildLayoutPhase(
NGTableCellChildLayoutPhase table_cell_child_layout_phase) { NGTableCellChildLayoutPhase table_cell_child_layout_phase) {
space_.table_cell_child_layout_phase_ = table_cell_child_layout_phase; space_.bitfields_.table_cell_child_layout_phase =
table_cell_child_layout_phase;
return *this; return *this;
} }
...@@ -255,7 +274,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -255,7 +274,7 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
to_constraint_space_called_ = true; to_constraint_space_called_ = true;
#endif #endif
DCHECK(!is_new_fc_ || !space_.adjoining_floats_); DCHECK(!is_new_fc_ || !space_.bitfields_.adjoining_floats);
DCHECK_EQ(space_.HasFlag(NGConstraintSpace::kOrthogonalWritingModeRoot), DCHECK_EQ(space_.HasFlag(NGConstraintSpace::kOrthogonalWritingModeRoot),
!is_in_parallel_flow_ || force_orthogonal_writing_mode_root_); !is_in_parallel_flow_ || force_orthogonal_writing_mode_root_);
...@@ -264,14 +283,15 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -264,14 +283,15 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
"simultaneously. Inferred means the constraints are in parent " "simultaneously. Inferred means the constraints are in parent "
"writing mode, forced means they are in child writing mode."; "writing mode, forced means they are in child writing mode.";
space_.baseline_requests_ = baseline_requests_.Serialize(); space_.bitfields_.baseline_requests = baseline_requests_.Serialize();
return std::move(space_); return std::move(space_);
} }
private: private:
void SetFlag(NGConstraintSpace::ConstraintSpaceFlags mask, bool value) { void SetFlag(NGConstraintSpace::ConstraintSpaceFlags mask, bool value) {
space_.flags_ = (space_.flags_ & ~static_cast<unsigned>(mask)) | space_.bitfields_.flags =
(-(int32_t)value & static_cast<unsigned>(mask)); (space_.bitfields_.flags & ~static_cast<unsigned>(mask)) |
(-(int32_t)value & static_cast<unsigned>(mask));
} }
NGConstraintSpace space_; NGConstraintSpace space_;
...@@ -280,6 +300,14 @@ class CORE_EXPORT NGConstraintSpaceBuilder final { ...@@ -280,6 +300,14 @@ class CORE_EXPORT NGConstraintSpaceBuilder final {
bool force_orthogonal_writing_mode_root_; bool force_orthogonal_writing_mode_root_;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
bool is_available_size_set_ = false;
bool is_fragmentainer_block_size_set_ = false;
bool is_fragmentainer_space_at_bfc_start_set_ = false;
bool is_block_direction_fragmentation_type_set_ = false;
bool is_margin_strut_set_ = false;
bool is_floats_bfc_block_offset_set_ = false;
bool is_clearance_offset_set_ = false;
bool to_constraint_space_called_ = false; bool to_constraint_space_called_ = false;
#endif #endif
......
...@@ -35,7 +35,7 @@ TEST(NGConstraintSpaceBuilderTest, AvailableSizeFromHorizontalICB) { ...@@ -35,7 +35,7 @@ TEST(NGConstraintSpaceBuilderTest, AvailableSizeFromHorizontalICB) {
NGConstraintSpace space = vertical_builder.ToConstraintSpace(); NGConstraintSpace space = vertical_builder.ToConstraintSpace();
EXPECT_EQ(space.AvailableSize().inline_size, icb_size.height); EXPECT_EQ(space.AvailableSize().inline_size, icb_size.height);
EXPECT_EQ(space.PercentageResolutionSize().inline_size, icb_size.height); EXPECT_EQ(space.PercentageResolutionInlineSize(), icb_size.height);
}; };
// Asserts that indefinite inline length becomes initial containing // Asserts that indefinite inline length becomes initial containing
...@@ -62,7 +62,7 @@ TEST(NGConstraintSpaceBuilderTest, AvailableSizeFromVerticalICB) { ...@@ -62,7 +62,7 @@ TEST(NGConstraintSpaceBuilderTest, AvailableSizeFromVerticalICB) {
NGConstraintSpace space = vertical_builder.ToConstraintSpace(); NGConstraintSpace space = vertical_builder.ToConstraintSpace();
EXPECT_EQ(space.AvailableSize().inline_size, icb_size.width); EXPECT_EQ(space.AvailableSize().inline_size, icb_size.width);
EXPECT_EQ(space.PercentageResolutionSize().inline_size, icb_size.width); EXPECT_EQ(space.PercentageResolutionInlineSize(), icb_size.width);
}; };
} // namespace } // namespace
......
...@@ -214,9 +214,9 @@ NGFieldsetLayoutAlgorithm::CreateConstraintSpaceForFieldsetContent( ...@@ -214,9 +214,9 @@ NGFieldsetLayoutAlgorithm::CreateConstraintSpaceForFieldsetContent(
NGConstraintSpaceBuilder builder(ConstraintSpace(), NGConstraintSpaceBuilder builder(ConstraintSpace(),
ConstraintSpace().GetWritingMode(), ConstraintSpace().GetWritingMode(),
/* is_new_fc */ true); /* is_new_fc */ true);
builder.SetAvailableSize(padding_box_size);
builder.SetPercentageResolutionSize( builder.SetPercentageResolutionSize(
ConstraintSpace().PercentageResolutionSize()); ConstraintSpace().PercentageResolutionSize());
builder.SetAvailableSize(padding_box_size);
builder.SetIsFixedSizeBlock(padding_box_size.block_size != NGSizeIndefinite); builder.SetIsFixedSizeBlock(padding_box_size.block_size != NGSizeIndefinite);
return builder.ToConstraintSpace(); return builder.ToConstraintSpace();
} }
......
...@@ -85,8 +85,8 @@ NGConstraintSpace CreateConstraintSpaceForFloat( ...@@ -85,8 +85,8 @@ NGConstraintSpace CreateConstraintSpaceForFloat(
builder.SetFragmentationType(NGFragmentationType::kFragmentNone); builder.SetFragmentationType(NGFragmentationType::kFragmentNone);
} }
return builder.SetPercentageResolutionSize(float_percentage_size) return builder.SetAvailableSize(float_available_size)
.SetAvailableSize(float_available_size) .SetPercentageResolutionSize(float_percentage_size)
.SetReplacedPercentageResolutionSize(float_replaced_percentage_size) .SetReplacedPercentageResolutionSize(float_replaced_percentage_size)
.SetIsShrinkToFit(style.LogicalWidth().IsAuto()) .SetIsShrinkToFit(style.LogicalWidth().IsAuto())
.SetTextDirection(style.Direction()) .SetTextDirection(style.Direction())
......
...@@ -65,8 +65,8 @@ inline bool InlineLengthMayChange(Length length, ...@@ -65,8 +65,8 @@ inline bool InlineLengthMayChange(Length length,
return true; return true;
} }
if (is_unspecified || length.IsPercentOrCalc()) { if (is_unspecified || length.IsPercentOrCalc()) {
if (new_space.PercentageResolutionSize().inline_size != if (new_space.PercentageResolutionInlineSize() !=
old_space.PercentageResolutionSize().inline_size) old_space.PercentageResolutionInlineSize())
return true; return true;
} }
return false; return false;
...@@ -84,11 +84,11 @@ inline bool BlockLengthMayChange(Length length, ...@@ -84,11 +84,11 @@ inline bool BlockLengthMayChange(Length length,
// (in addition to percent values). The reason is that percentage resolution // (in addition to percent values). The reason is that percentage resolution
// block sizes may be passed through auto-sized blocks, in some cases, // block sizes may be passed through auto-sized blocks, in some cases,
// e.g. for anonymous blocks, and also in quirks mode. // e.g. for anonymous blocks, and also in quirks mode.
if (new_space.PercentageResolutionSize().block_size != if (new_space.PercentageResolutionBlockSize() !=
old_space.PercentageResolutionSize().block_size) old_space.PercentageResolutionBlockSize())
return true; return true;
if (new_space.ReplacedPercentageResolutionSize().block_size != if (new_space.ReplacedPercentageResolutionBlockSize() !=
old_space.ReplacedPercentageResolutionSize().block_size) old_space.ReplacedPercentageResolutionBlockSize())
return true; return true;
} }
return false; return false;
...@@ -123,8 +123,7 @@ LayoutUnit ResolveInlineLength( ...@@ -123,8 +123,7 @@ LayoutUnit ResolveInlineLength(
LengthResolvePhase phase, LengthResolvePhase phase,
const base::Optional<NGBoxStrut>& opt_border_padding) { const base::Optional<NGBoxStrut>& opt_border_padding) {
DCHECK_GE(constraint_space.AvailableSize().inline_size, LayoutUnit()); DCHECK_GE(constraint_space.AvailableSize().inline_size, LayoutUnit());
DCHECK_GE(constraint_space.PercentageResolutionSize().inline_size, DCHECK_GE(constraint_space.PercentageResolutionInlineSize(), LayoutUnit());
LayoutUnit());
DCHECK_EQ(constraint_space.GetWritingMode(), style.GetWritingMode()); DCHECK_EQ(constraint_space.GetWritingMode(), style.GetWritingMode());
if (constraint_space.IsAnonymous()) if (constraint_space.IsAnonymous())
...@@ -168,7 +167,7 @@ LayoutUnit ResolveInlineLength( ...@@ -168,7 +167,7 @@ LayoutUnit ResolveInlineLength(
case kFixed: case kFixed:
case kCalculated: { case kCalculated: {
LayoutUnit percentage_resolution_size = LayoutUnit percentage_resolution_size =
constraint_space.PercentageResolutionSize().inline_size; constraint_space.PercentageResolutionInlineSize();
LayoutUnit value = ValueForLength(length, percentage_resolution_size); LayoutUnit value = ValueForLength(length, percentage_resolution_size);
if (style.BoxSizing() == EBoxSizing::kContentBox) { if (style.BoxSizing() == EBoxSizing::kContentBox) {
value += border_and_padding.InlineSum(); value += border_and_padding.InlineSum();
...@@ -251,8 +250,7 @@ LayoutUnit ResolveBlockLength( ...@@ -251,8 +250,7 @@ LayoutUnit ResolveBlockLength(
if (length.IsPercentOrCalc()) { if (length.IsPercentOrCalc()) {
size_is_unresolvable = size_is_unresolvable =
phase == LengthResolvePhase::kIntrinsic || phase == LengthResolvePhase::kIntrinsic ||
constraint_space.PercentageResolutionSize().block_size == constraint_space.PercentageResolutionBlockSize() == NGSizeIndefinite;
NGSizeIndefinite;
} else if (length.GetType() == kFillAvailable) { } else if (length.GetType() == kFillAvailable) {
size_is_unresolvable = size_is_unresolvable =
phase == LengthResolvePhase::kIntrinsic || phase == LengthResolvePhase::kIntrinsic ||
...@@ -283,7 +281,7 @@ LayoutUnit ResolveBlockLength( ...@@ -283,7 +281,7 @@ LayoutUnit ResolveBlockLength(
case kFixed: case kFixed:
case kCalculated: { case kCalculated: {
LayoutUnit percentage_resolution_size = LayoutUnit percentage_resolution_size =
constraint_space.PercentageResolutionSize().block_size; constraint_space.PercentageResolutionBlockSize();
LayoutUnit value = ValueForLength(length, percentage_resolution_size); LayoutUnit value = ValueForLength(length, percentage_resolution_size);
// Percentage-sized children of table cells, in the table "layout" phase, // Percentage-sized children of table cells, in the table "layout" phase,
...@@ -699,8 +697,8 @@ bool SizeMayChange(const ComputedStyle& style, ...@@ -699,8 +697,8 @@ bool SizeMayChange(const ComputedStyle& style,
return true; return true;
} }
if (new_space.PercentageResolutionSize().inline_size != if (new_space.PercentageResolutionInlineSize() !=
old_space.PercentageResolutionSize().inline_size) { old_space.PercentageResolutionInlineSize()) {
// Percentage-based padding is resolved against the inline content box size // Percentage-based padding is resolved against the inline content box size
// of the containing block. // of the containing block.
if (style.PaddingTop().IsPercentOrCalc() || if (style.PaddingTop().IsPercentOrCalc() ||
...@@ -1104,7 +1102,7 @@ NGLogicalSize CalculateChildPercentageSize( ...@@ -1104,7 +1102,7 @@ NGLogicalSize CalculateChildPercentageSize(
return AdjustChildPercentageSizeForQuirksAndFlex( return AdjustChildPercentageSizeForQuirksAndFlex(
space, node, child_percentage_size, space, node, child_percentage_size,
space.PercentageResolutionSize().block_size); space.PercentageResolutionBlockSize());
} }
NGLogicalSize CalculateReplacedChildPercentageSize( NGLogicalSize CalculateReplacedChildPercentageSize(
...@@ -1139,7 +1137,7 @@ NGLogicalSize CalculateReplacedChildPercentageSize( ...@@ -1139,7 +1137,7 @@ NGLogicalSize CalculateReplacedChildPercentageSize(
return AdjustChildPercentageSizeForQuirksAndFlex( return AdjustChildPercentageSizeForQuirksAndFlex(
space, node, child_percentage_size, space, node, child_percentage_size,
space.ReplacedPercentageResolutionSize().block_size); space.ReplacedPercentageResolutionBlockSize());
} }
} // namespace blink } // namespace blink
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