Commit ed289cec authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[layoutng] Return PhysicalFragment as a raw pointer

This avoids refcounting overhead where it's not needed.

R=eae@chromium.org, mstensho@chromium.org

Change-Id: Ic9303d8325ee9369b1df3f5a16a5c357da9d87bf
Reviewed-on: https://chromium-review.googlesource.com/c/1306395Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603722}
parent c06b133a
...@@ -52,22 +52,19 @@ TEST_F(NGInlineLayoutAlgorithmTest, BreakToken) { ...@@ -52,22 +52,19 @@ TEST_F(NGInlineLayoutAlgorithmTest, BreakToken) {
NGInlineChildLayoutContext context; NGInlineChildLayoutContext context;
scoped_refptr<NGLayoutResult> layout_result = scoped_refptr<NGLayoutResult> layout_result =
inline_node.Layout(constraint_space, nullptr, &context); inline_node.Layout(constraint_space, nullptr, &context);
auto* line1 = auto* line1 = ToNGPhysicalLineBoxFragment(layout_result->PhysicalFragment());
ToNGPhysicalLineBoxFragment(layout_result->PhysicalFragment().get());
EXPECT_FALSE(line1->BreakToken()->IsFinished()); EXPECT_FALSE(line1->BreakToken()->IsFinished());
// Perform 2nd layout with the break token from the 1st line. // Perform 2nd layout with the break token from the 1st line.
scoped_refptr<NGLayoutResult> layout_result2 = scoped_refptr<NGLayoutResult> layout_result2 =
inline_node.Layout(constraint_space, line1->BreakToken(), &context); inline_node.Layout(constraint_space, line1->BreakToken(), &context);
auto* line2 = auto* line2 = ToNGPhysicalLineBoxFragment(layout_result2->PhysicalFragment());
ToNGPhysicalLineBoxFragment(layout_result2->PhysicalFragment().get());
EXPECT_FALSE(line2->BreakToken()->IsFinished()); EXPECT_FALSE(line2->BreakToken()->IsFinished());
// Perform 3rd layout with the break token from the 2nd line. // Perform 3rd layout with the break token from the 2nd line.
scoped_refptr<NGLayoutResult> layout_result3 = scoped_refptr<NGLayoutResult> layout_result3 =
inline_node.Layout(constraint_space, line2->BreakToken(), &context); inline_node.Layout(constraint_space, line2->BreakToken(), &context);
auto* line3 = auto* line3 = ToNGPhysicalLineBoxFragment(layout_result3->PhysicalFragment());
ToNGPhysicalLineBoxFragment(layout_result3->PhysicalFragment().get());
EXPECT_TRUE(line3->BreakToken()->IsFinished()); EXPECT_TRUE(line3->BreakToken()->IsFinished());
} }
...@@ -188,8 +185,7 @@ TEST_F(NGInlineLayoutAlgorithmTest, ContainerBorderPadding) { ...@@ -188,8 +185,7 @@ TEST_F(NGInlineLayoutAlgorithmTest, ContainerBorderPadding) {
NGConstraintSpace::CreateFromLayoutObject(*block_flow); NGConstraintSpace::CreateFromLayoutObject(*block_flow);
scoped_refptr<NGLayoutResult> layout_result = block_node.Layout(space); scoped_refptr<NGLayoutResult> layout_result = block_node.Layout(space);
auto* block_box = auto* block_box = ToNGPhysicalBoxFragment(layout_result->PhysicalFragment());
ToNGPhysicalBoxFragment(layout_result->PhysicalFragment().get());
EXPECT_TRUE(layout_result->BfcBlockOffset().has_value()); EXPECT_TRUE(layout_result->BfcBlockOffset().has_value());
EXPECT_EQ(0, layout_result->BfcBlockOffset().value()); EXPECT_EQ(0, layout_result->BfcBlockOffset().value());
EXPECT_EQ(0, layout_result->BfcLineOffset()); EXPECT_EQ(0, layout_result->BfcLineOffset());
...@@ -223,8 +219,7 @@ TEST_F(NGInlineLayoutAlgorithmTest, MAYBE_VerticalAlignBottomReplaced) { ...@@ -223,8 +219,7 @@ TEST_F(NGInlineLayoutAlgorithmTest, MAYBE_VerticalAlignBottomReplaced) {
scoped_refptr<NGLayoutResult> layout_result = scoped_refptr<NGLayoutResult> layout_result =
inline_node.Layout(space, nullptr, &context); inline_node.Layout(space, nullptr, &context);
auto* line = auto* line = ToNGPhysicalLineBoxFragment(layout_result->PhysicalFragment());
ToNGPhysicalLineBoxFragment(layout_result->PhysicalFragment().get());
EXPECT_EQ(LayoutUnit(96), line->Size().height); EXPECT_EQ(LayoutUnit(96), line->Size().height);
NGPhysicalOffset img_offset = line->Children()[0].Offset(); NGPhysicalOffset img_offset = line->Children()[0].Offset();
EXPECT_EQ(LayoutUnit(0), img_offset.top); EXPECT_EQ(LayoutUnit(0), img_offset.top);
......
...@@ -115,7 +115,7 @@ class NGInlineNodeTest : public NGLayoutTest { ...@@ -115,7 +115,7 @@ class NGInlineNodeTest : public NGLayoutTest {
.Layout(); .Layout();
const NGPhysicalLineBoxFragment* line = const NGPhysicalLineBoxFragment* line =
ToNGPhysicalLineBoxFragment(result->PhysicalFragment().get()); ToNGPhysicalLineBoxFragment(result->PhysicalFragment());
for (const auto& child : line->Children()) { for (const auto& child : line->Children()) {
fragments_out->push_back(ToNGPhysicalTextFragment(child.get())); fragments_out->push_back(ToNGPhysicalTextFragment(child.get()));
} }
......
...@@ -121,8 +121,7 @@ class CORE_EXPORT NGLineBoxFragmentBuilder final ...@@ -121,8 +121,7 @@ class CORE_EXPORT NGLineBoxFragmentBuilder final
bool HasBidiLevel() const { return bidi_level != 0xff; } bool HasBidiLevel() const { return bidi_level != 0xff; }
bool IsPlaceholder() const { return !HasFragment() && !HasBidiLevel(); } bool IsPlaceholder() const { return !HasFragment() && !HasBidiLevel(); }
const NGPhysicalFragment* PhysicalFragment() const { const NGPhysicalFragment* PhysicalFragment() const {
return layout_result ? layout_result->PhysicalFragment().get() return layout_result ? layout_result->PhysicalFragment() : fragment.get();
: fragment.get();
} }
}; };
......
...@@ -70,7 +70,7 @@ void LayoutNGBlockFlow::UpdateBlockLayout(bool relayout_children) { ...@@ -70,7 +70,7 @@ void LayoutNGBlockFlow::UpdateBlockLayout(bool relayout_children) {
descendant.node.UseOldOutOfFlowPositioning(); descendant.node.UseOldOutOfFlowPositioning();
const NGPhysicalBoxFragment* fragment = const NGPhysicalBoxFragment* fragment =
ToNGPhysicalBoxFragment(result->PhysicalFragment().get()); ToNGPhysicalBoxFragment(result->PhysicalFragment());
// This object has already been positioned in legacy layout by our containing // This object has already been positioned in legacy layout by our containing
// block. Copy the position and place the fragment. // block. Copy the position and place the fragment.
...@@ -241,8 +241,8 @@ void LayoutNGBlockFlow::UpdateOutOfFlowBlockLayout() { ...@@ -241,8 +241,8 @@ void LayoutNGBlockFlow::UpdateOutOfFlowBlockLayout() {
result->OutOfFlowPositionedDescendants()) result->OutOfFlowPositionedDescendants())
descendant.node.UseOldOutOfFlowPositioning(); descendant.node.UseOldOutOfFlowPositioning();
scoped_refptr<const NGPhysicalBoxFragment> fragment = const NGPhysicalBoxFragment* fragment =
ToNGPhysicalBoxFragment(result->PhysicalFragment().get()); ToNGPhysicalBoxFragment(result->PhysicalFragment());
DCHECK_GT(fragment->Children().size(), 0u); DCHECK_GT(fragment->Children().size(), 0u);
// Copy sizes of all child fragments to Legacy. // Copy sizes of all child fragments to Legacy.
// There could be multiple fragments, when this node has descendants whose // There could be multiple fragments, when this node has descendants whose
......
...@@ -33,7 +33,7 @@ void LayoutNGFlexibleBox::UpdateBlockLayout(bool relayout_children) { ...@@ -33,7 +33,7 @@ void LayoutNGFlexibleBox::UpdateBlockLayout(bool relayout_children) {
descendant.node.UseOldOutOfFlowPositioning(); descendant.node.UseOldOutOfFlowPositioning();
const NGPhysicalBoxFragment* fragment = const NGPhysicalBoxFragment* fragment =
ToNGPhysicalBoxFragment(result->PhysicalFragment().get()); ToNGPhysicalBoxFragment(result->PhysicalFragment());
// Pasted from layout_ng_block_flow. TODO(dgrogan): Factor a utility method. // Pasted from layout_ng_block_flow. TODO(dgrogan): Factor a utility method.
const LayoutBlock* containing_block = ContainingBlock(); const LayoutBlock* containing_block = ContainingBlock();
......
...@@ -62,7 +62,7 @@ void LayoutNGMixin<Base>::ResetNGInlineNodeData() { ...@@ -62,7 +62,7 @@ void LayoutNGMixin<Base>::ResetNGInlineNodeData() {
template <typename Base> template <typename Base>
const NGPhysicalBoxFragment* LayoutNGMixin<Base>::CurrentFragment() const { const NGPhysicalBoxFragment* LayoutNGMixin<Base>::CurrentFragment() const {
if (cached_result_) if (cached_result_)
return ToNGPhysicalBoxFragment(cached_result_->PhysicalFragment().get()); return ToNGPhysicalBoxFragment(cached_result_->PhysicalFragment());
return nullptr; return nullptr;
} }
......
...@@ -33,7 +33,7 @@ void LayoutNGTableCell::UpdateBlockLayout(bool relayout_children) { ...@@ -33,7 +33,7 @@ void LayoutNGTableCell::UpdateBlockLayout(bool relayout_children) {
descendant.node.UseOldOutOfFlowPositioning(); descendant.node.UseOldOutOfFlowPositioning();
const NGPhysicalBoxFragment* fragment = const NGPhysicalBoxFragment* fragment =
ToNGPhysicalBoxFragment(result->PhysicalFragment().get()); ToNGPhysicalBoxFragment(result->PhysicalFragment());
const LayoutBox* section = LocationContainer(); const LayoutBox* section = LocationContainer();
NGPhysicalOffset physical_offset; NGPhysicalOffset physical_offset;
......
...@@ -37,9 +37,8 @@ NGBaseLayoutAlgorithmTest::RunBlockLayoutAlgorithmForElement(Element* element) { ...@@ -37,9 +37,8 @@ NGBaseLayoutAlgorithmTest::RunBlockLayoutAlgorithmForElement(Element* element) {
scoped_refptr<NGLayoutResult> result = scoped_refptr<NGLayoutResult> result =
NGBlockLayoutAlgorithm(node, space).Layout(); NGBlockLayoutAlgorithm(node, space).Layout();
return std::make_pair( return std::make_pair(ToNGPhysicalBoxFragment(result->PhysicalFragment()),
ToNGPhysicalBoxFragment(result->PhysicalFragment().get()), std::move(space));
std::move(space));
} }
scoped_refptr<const NGPhysicalBoxFragment> scoped_refptr<const NGPhysicalBoxFragment>
......
...@@ -39,7 +39,7 @@ class NGBlockLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest { ...@@ -39,7 +39,7 @@ class NGBlockLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {
scoped_refptr<NGLayoutResult> result = scoped_refptr<NGLayoutResult> result =
NGBlockLayoutAlgorithm(node, space).Layout(); NGBlockLayoutAlgorithm(node, space).Layout();
return ToNGPhysicalBoxFragment(result->PhysicalFragment().get()); return ToNGPhysicalBoxFragment(result->PhysicalFragment());
} }
MinMaxSize RunComputeMinAndMax(NGBlockNode node) { MinMaxSize RunComputeMinAndMax(NGBlockNode node) {
......
...@@ -116,8 +116,8 @@ scoped_refptr<NGLayoutResult> NGColumnLayoutAlgorithm::Layout() { ...@@ -116,8 +116,8 @@ scoped_refptr<NGLayoutResult> NGColumnLayoutAlgorithm::Layout() {
break_token.get()); break_token.get());
child_algorithm.SetBoxType(NGPhysicalFragment::kColumnBox); child_algorithm.SetBoxType(NGPhysicalFragment::kColumnBox);
scoped_refptr<NGLayoutResult> result = child_algorithm.Layout(); scoped_refptr<NGLayoutResult> result = child_algorithm.Layout();
scoped_refptr<const NGPhysicalBoxFragment> column( const NGPhysicalBoxFragment* column =
ToNGPhysicalBoxFragment(result->PhysicalFragment().get())); ToNGPhysicalBoxFragment(result->PhysicalFragment());
NGLogicalOffset logical_offset(column_inline_offset, column_block_offset); NGLogicalOffset logical_offset(column_inline_offset, column_block_offset);
container_builder_.AddChild(*result, logical_offset); container_builder_.AddChild(*result, logical_offset);
......
...@@ -33,7 +33,7 @@ class NGColumnLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest { ...@@ -33,7 +33,7 @@ class NGColumnLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {
scoped_refptr<NGLayoutResult> result = scoped_refptr<NGLayoutResult> result =
NGBlockLayoutAlgorithm(node, space).Layout(); NGBlockLayoutAlgorithm(node, space).Layout();
return ToNGPhysicalBoxFragment(result->PhysicalFragment().get()); return ToNGPhysicalBoxFragment(result->PhysicalFragment());
} }
scoped_refptr<const NGPhysicalBoxFragment> RunBlockLayoutAlgorithm( scoped_refptr<const NGPhysicalBoxFragment> RunBlockLayoutAlgorithm(
......
...@@ -35,7 +35,7 @@ class NGFieldsetLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest { ...@@ -35,7 +35,7 @@ class NGFieldsetLayoutAlgorithmTest : public NGBaseLayoutAlgorithmTest {
scoped_refptr<NGLayoutResult> result = scoped_refptr<NGLayoutResult> result =
NGBlockLayoutAlgorithm(node, space).Layout(); NGBlockLayoutAlgorithm(node, space).Layout();
return ToNGPhysicalBoxFragment(result->PhysicalFragment().get()); return ToNGPhysicalBoxFragment(result->PhysicalFragment());
} }
scoped_refptr<const NGPhysicalBoxFragment> RunBlockLayoutAlgorithm( scoped_refptr<const NGPhysicalBoxFragment> RunBlockLayoutAlgorithm(
......
...@@ -214,7 +214,7 @@ LayoutUnit ComputeMarginBoxInlineSizeForUnpositionedFloat( ...@@ -214,7 +214,7 @@ LayoutUnit ComputeMarginBoxInlineSizeForUnpositionedFloat(
unpositioned_float); unpositioned_float);
DCHECK(unpositioned_float->layout_result); DCHECK(unpositioned_float->layout_result);
const auto& fragment = unpositioned_float->layout_result->PhysicalFragment(); const auto* fragment = unpositioned_float->layout_result->PhysicalFragment();
DCHECK(fragment); DCHECK(fragment);
DCHECK(!fragment->BreakToken() || fragment->BreakToken()->IsFinished()); DCHECK(!fragment->BreakToken() || fragment->BreakToken()->IsFinished());
......
...@@ -43,7 +43,7 @@ class CORE_EXPORT NGLayoutResult : public RefCounted<NGLayoutResult> { ...@@ -43,7 +43,7 @@ class CORE_EXPORT NGLayoutResult : public RefCounted<NGLayoutResult> {
NGLayoutResult(const NGLayoutResult&); NGLayoutResult(const NGLayoutResult&);
~NGLayoutResult(); ~NGLayoutResult();
scoped_refptr<const NGPhysicalFragment> PhysicalFragment() const { const NGPhysicalFragment* PhysicalFragment() const {
return root_fragment_.get(); return root_fragment_.get();
} }
NGPhysicalOffset Offset() const { return root_fragment_.Offset(); } NGPhysicalOffset Offset() const { return root_fragment_.Offset(); }
......
...@@ -362,7 +362,7 @@ scoped_refptr<NGLayoutResult> NGOutOfFlowLayoutPart::LayoutDescendant( ...@@ -362,7 +362,7 @@ scoped_refptr<NGLayoutResult> NGOutOfFlowLayoutPart::LayoutDescendant(
layout_result = GenerateFragment(descendant.node, container_info, layout_result = GenerateFragment(descendant.node, container_info,
block_estimate, node_position); block_estimate, node_position);
DCHECK(layout_result->PhysicalFragment().get()); DCHECK(layout_result->PhysicalFragment());
NGFragment fragment(descendant_writing_mode, NGFragment fragment(descendant_writing_mode,
*layout_result->PhysicalFragment()); *layout_result->PhysicalFragment());
......
...@@ -52,8 +52,8 @@ scoped_refptr<NGLayoutResult> NGPageLayoutAlgorithm::Layout() { ...@@ -52,8 +52,8 @@ scoped_refptr<NGLayoutResult> NGPageLayoutAlgorithm::Layout() {
NGBlockLayoutAlgorithm child_algorithm(Node(), child_space, NGBlockLayoutAlgorithm child_algorithm(Node(), child_space,
break_token.get()); break_token.get());
scoped_refptr<NGLayoutResult> result = child_algorithm.Layout(); scoped_refptr<NGLayoutResult> result = child_algorithm.Layout();
scoped_refptr<const NGPhysicalBoxFragment> page( const NGPhysicalBoxFragment* page =
ToNGPhysicalBoxFragment(result->PhysicalFragment().get())); ToNGPhysicalBoxFragment(result->PhysicalFragment());
container_builder_.AddChild(*result, page_offset); container_builder_.AddChild(*result, page_offset);
......
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