Commit 0fe57a48 authored by Koji Ishii's avatar Koji Ishii Committed by Chromium LUCI CQ

Remove uses of FragmentItem runtime flag in NGBlockLayoutAlgorithm

Also change |NGInlineChildLayoutContext| to own
|NGFragmentItemsBuilder| because it is always needed when
|FragmentItem| is enabled. This simplifies allocations and
call sites slightly.

Bug: 1154531
Change-Id: I7458f80978bc9ef7348fb6836f44ca9adf4574f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592568
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837046}
parent c4c6be42
...@@ -11,9 +11,10 @@ namespace blink { ...@@ -11,9 +11,10 @@ namespace blink {
namespace { namespace {
struct SameSizeAsNGInlineChildLayoutContext { struct SameSizeAsNGInlineChildLayoutContext {
NGFragmentItemsBuilder items_builder_;
NGLogicalLineItems line_items_; NGLogicalLineItems line_items_;
base::Optional<NGInlineLayoutStateStack> box_states_; base::Optional<NGInlineLayoutStateStack> box_states_;
void* pointers[2]; void* pointers[1];
unsigned number; unsigned number;
Vector<scoped_refptr<const NGBlockBreakToken>> propagated_float_break_tokens_; Vector<scoped_refptr<const NGBlockBreakToken>> propagated_float_break_tokens_;
}; };
...@@ -26,7 +27,10 @@ static_assert( ...@@ -26,7 +27,10 @@ static_assert(
} // namespace } // namespace
NGInlineChildLayoutContext::NGInlineChildLayoutContext() = default; NGInlineChildLayoutContext::NGInlineChildLayoutContext(
const NGInlineNode& node,
WritingDirectionMode writing_direction)
: items_builder_(node, writing_direction) {}
NGInlineChildLayoutContext::~NGInlineChildLayoutContext() = default; NGInlineChildLayoutContext::~NGInlineChildLayoutContext() = default;
NGInlineLayoutStateStack* NGInlineLayoutStateStack*
......
...@@ -24,16 +24,11 @@ class CORE_EXPORT NGInlineChildLayoutContext { ...@@ -24,16 +24,11 @@ class CORE_EXPORT NGInlineChildLayoutContext {
STACK_ALLOCATED(); STACK_ALLOCATED();
public: public:
NGInlineChildLayoutContext(); NGInlineChildLayoutContext(const NGInlineNode& node,
WritingDirectionMode writing_direction);
~NGInlineChildLayoutContext(); ~NGInlineChildLayoutContext();
NGFragmentItemsBuilder* ItemsBuilder() { return items_builder_; } NGFragmentItemsBuilder* ItemsBuilder() { return &items_builder_; }
void SetItemsBuilder(NGFragmentItemsBuilder* builder) {
DCHECK(!items_builder_ || !builder);
items_builder_ = builder;
if (builder)
builder->AddLogicalLineItemsPool(&logical_line_items_);
}
// Returns an instance of |NGLogicalLineItems|. This is reused when laying out // Returns an instance of |NGLogicalLineItems|. This is reused when laying out
// the next line. // the next line.
...@@ -65,9 +60,7 @@ class CORE_EXPORT NGInlineChildLayoutContext { ...@@ -65,9 +60,7 @@ class CORE_EXPORT NGInlineChildLayoutContext {
void PropagateBreakToken(scoped_refptr<const NGBlockBreakToken>); void PropagateBreakToken(scoped_refptr<const NGBlockBreakToken>);
private: private:
// TODO(kojii): Probably better to own |NGInlineChildLayoutContext|. While we NGFragmentItemsBuilder items_builder_;
// transit, allocating separately is easier.
NGFragmentItemsBuilder* items_builder_ = nullptr;
NGLogicalLineItems logical_line_items_; NGLogicalLineItems logical_line_items_;
......
...@@ -52,14 +52,12 @@ TEST_F(NGInlineLayoutAlgorithmTest, BreakToken) { ...@@ -52,14 +52,12 @@ TEST_F(NGInlineLayoutAlgorithmTest, BreakToken) {
builder.SetAvailableSize(size); builder.SetAvailableSize(size);
NGConstraintSpace constraint_space = builder.ToConstraintSpace(); NGConstraintSpace constraint_space = builder.ToConstraintSpace();
NGInlineChildLayoutContext context;
NGBoxFragmentBuilder container_builder( NGBoxFragmentBuilder container_builder(
block_flow, block_flow->Style(), block_flow, block_flow->Style(),
block_flow->Style()->GetWritingDirection()); block_flow->Style()->GetWritingDirection());
NGFragmentItemsBuilder items_builder(inline_node, NGInlineChildLayoutContext context(inline_node,
container_builder.GetWritingDirection()); container_builder.GetWritingDirection());
container_builder.SetItemsBuilder(&items_builder); container_builder.SetItemsBuilder(context.ItemsBuilder());
context.SetItemsBuilder(&items_builder);
scoped_refptr<const NGLayoutResult> layout_result = scoped_refptr<const NGLayoutResult> layout_result =
inline_node.Layout(constraint_space, nullptr, &context); inline_node.Layout(constraint_space, nullptr, &context);
const auto& line1 = layout_result->PhysicalFragment(); const auto& line1 = layout_result->PhysicalFragment();
......
...@@ -44,11 +44,9 @@ scoped_refptr<const NGLayoutResult> NGMathOperatorLayoutAlgorithm::Layout() { ...@@ -44,11 +44,9 @@ scoped_refptr<const NGLayoutResult> NGMathOperatorLayoutAlgorithm::Layout() {
DCHECK(!child.NextSibling()); DCHECK(!child.NextSibling());
DCHECK(!child.IsOutOfFlowPositioned()); DCHECK(!child.IsOutOfFlowPositioned());
NGInlineChildLayoutContext context; NGInlineChildLayoutContext context(To<NGInlineNode>(child),
NGFragmentItemsBuilder items_builder( container_builder_.GetWritingDirection());
To<NGInlineNode>(child), container_builder_.GetWritingDirection()); container_builder_.SetItemsBuilder(context.ItemsBuilder());
container_builder_.SetItemsBuilder(&items_builder);
context.SetItemsBuilder(&items_builder);
scoped_refptr<const NGLayoutResult> child_layout_result = scoped_refptr<const NGLayoutResult> child_layout_result =
To<NGInlineNode>(child).Layout(ConstraintSpace(), nullptr, &context); To<NGInlineNode>(child).Layout(ConstraintSpace(), nullptr, &context);
container_builder_.AddResult(*child_layout_result, {}); container_builder_.AddResult(*child_layout_result, {});
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "third_party/blink/renderer/core/layout/ng/ng_positioned_float.h" #include "third_party/blink/renderer/core/layout/ng/ng_positioned_float.h"
#include "third_party/blink/renderer/core/layout/ng/ng_space_utils.h" #include "third_party/blink/renderer/core/layout/ng/ng_space_utils.h"
#include "third_party/blink/renderer/core/layout/ng/ng_unpositioned_float.h" #include "third_party/blink/renderer/core/layout/ng/ng_unpositioned_float.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/core/style/computed_style.h"
namespace blink { namespace blink {
...@@ -429,26 +428,13 @@ scoped_refptr<const NGLayoutResult> NGBlockLayoutAlgorithm::Layout() { ...@@ -429,26 +428,13 @@ scoped_refptr<const NGLayoutResult> NGBlockLayoutAlgorithm::Layout() {
NOINLINE scoped_refptr<const NGLayoutResult> NOINLINE scoped_refptr<const NGLayoutResult>
NGBlockLayoutAlgorithm::LayoutWithInlineChildLayoutContext( NGBlockLayoutAlgorithm::LayoutWithInlineChildLayoutContext(
const NGLayoutInputNode& first_child) { const NGLayoutInputNode& first_child) {
NGInlineChildLayoutContext context; NGInlineChildLayoutContext context(To<NGInlineNode>(first_child),
if (!RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) container_builder_.GetWritingDirection());
return Layout(&context); container_builder_.SetItemsBuilder(context.ItemsBuilder());
return LayoutWithItemsBuilder(To<NGInlineNode>(first_child), &context); scoped_refptr<const NGLayoutResult> result = Layout(&context);
} // |NGFragmentItemsBuilder| is owned by |NGInlineChildLayoutContext| which is
// on stack. Make sure it is no longer referred.
NOINLINE scoped_refptr<const NGLayoutResult>
NGBlockLayoutAlgorithm::LayoutWithItemsBuilder(
const NGInlineNode& first_child,
NGInlineChildLayoutContext* context) {
NGFragmentItemsBuilder items_builder(
first_child, container_builder_.GetWritingDirection());
container_builder_.SetItemsBuilder(&items_builder);
context->SetItemsBuilder(&items_builder);
scoped_refptr<const NGLayoutResult> result = Layout(context);
// Ensure stack-allocated |NGFragmentItemsBuilder| is not used anymore.
// TODO(kojii): Revisit when the storage of |NGFragmentItemsBuilder| is
// finalized.
container_builder_.SetItemsBuilder(nullptr); container_builder_.SetItemsBuilder(nullptr);
context->SetItemsBuilder(nullptr);
return result; return result;
} }
...@@ -981,7 +967,6 @@ bool NGBlockLayoutAlgorithm::TryReuseFragmentsFromCache( ...@@ -981,7 +967,6 @@ bool NGBlockLayoutAlgorithm::TryReuseFragmentsFromCache(
NGInlineNode inline_node, NGInlineNode inline_node,
NGPreviousInflowPosition* previous_inflow_position, NGPreviousInflowPosition* previous_inflow_position,
scoped_refptr<const NGInlineBreakToken>* inline_break_token_out) { scoped_refptr<const NGInlineBreakToken>* inline_break_token_out) {
DCHECK(RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled());
DCHECK(previous_result_); DCHECK(previous_result_);
DCHECK(!inline_node.IsEmptyInline()); DCHECK(!inline_node.IsEmptyInline());
DCHECK(container_builder_.BfcBlockOffset()); DCHECK(container_builder_.BfcBlockOffset());
...@@ -1601,8 +1586,7 @@ NGLayoutResult::EStatus NGBlockLayoutAlgorithm::HandleInflow( ...@@ -1601,8 +1586,7 @@ NGLayoutResult::EStatus NGBlockLayoutAlgorithm::HandleInflow(
is_non_empty_inline = !child_inline_node->IsEmptyInline(); is_non_empty_inline = !child_inline_node->IsEmptyInline();
// Add reusable line boxes from |previous_result_| if any. // Add reusable line boxes from |previous_result_| if any.
if (is_non_empty_inline && !child_break_token && previous_result_ && if (is_non_empty_inline && !child_break_token && previous_result_) {
RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
if (!ResolveBfcBlockOffset(previous_inflow_position)) if (!ResolveBfcBlockOffset(previous_inflow_position))
return NGLayoutResult::kBfcBlockOffsetResolved; return NGLayoutResult::kBfcBlockOffsetResolved;
DCHECK(container_builder_.BfcBlockOffset()); DCHECK(container_builder_.BfcBlockOffset());
......
...@@ -68,9 +68,6 @@ class CORE_EXPORT NGBlockLayoutAlgorithm ...@@ -68,9 +68,6 @@ class CORE_EXPORT NGBlockLayoutAlgorithm
private: private:
NOINLINE scoped_refptr<const NGLayoutResult> NOINLINE scoped_refptr<const NGLayoutResult>
LayoutWithInlineChildLayoutContext(const NGLayoutInputNode& first_child); LayoutWithInlineChildLayoutContext(const NGLayoutInputNode& first_child);
NOINLINE scoped_refptr<const NGLayoutResult> LayoutWithItemsBuilder(
const NGInlineNode& first_child,
NGInlineChildLayoutContext* context);
// Lay out again, this time with a predefined good breakpoint that we // Lay out again, this time with a predefined good breakpoint that we
// discovered in the first pass. This happens when we run out of space in a // discovered in the first pass. This happens when we run out of space in a
......
...@@ -227,13 +227,11 @@ scoped_refptr<const NGLayoutResult> NGSimplifiedLayoutAlgorithm::Layout() { ...@@ -227,13 +227,11 @@ scoped_refptr<const NGLayoutResult> NGSimplifiedLayoutAlgorithm::Layout() {
// We add both items and line-box fragments for existing mechanisms to work. // We add both items and line-box fragments for existing mechanisms to work.
// We may revisit this in future. See also |NGBoxFragmentBuilder::AddResult|. // We may revisit this in future. See also |NGBoxFragmentBuilder::AddResult|.
if (RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) { if (const NGFragmentItems* previous_items = previous_fragment.Items()) {
if (const NGFragmentItems* previous_items = previous_fragment.Items()) { auto* items_builder = container_builder_.ItemsBuilder();
auto* items_builder = container_builder_.ItemsBuilder(); DCHECK(items_builder);
DCHECK(items_builder); DCHECK_EQ(items_builder->GetWritingDirection(), writing_direction_);
DCHECK_EQ(items_builder->GetWritingDirection(), writing_direction_); items_builder->AddPreviousItems(previous_fragment, *previous_items);
items_builder->AddPreviousItems(previous_fragment, *previous_items);
}
} }
NGOutOfFlowLayoutPart(Node(), ConstraintSpace(), &container_builder_).Run(); NGOutOfFlowLayoutPart(Node(), ConstraintSpace(), &container_builder_).Run();
......
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