Commit 56f3f825 authored by Koji Ishii's avatar Koji Ishii Committed by Chromium LUCI CQ

Remove NGPaintFragment from NGInlineNode

Bug: 1154531
Change-Id: Idab8197f8c8156a6efcbc1920c94a1a4b70b2692
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2589497
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837003}
parent 40ebc94a
......@@ -12,6 +12,7 @@
#include "third_party/blink/renderer/core/editing/forward.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_fragment_items.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_text_offset.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/platform/text/text_direction.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/string_view.h"
......
......@@ -32,7 +32,6 @@
#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_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/platform/fonts/shaping/harfbuzz_shaper.h"
#include "third_party/blink/renderer/platform/fonts/shaping/run_segmenter.h"
......@@ -1396,56 +1395,6 @@ void NGInlineNode::AssociateItemsWithInlines(NGInlineNodeData* data) const {
}
}
void NGInlineNode::ClearAssociatedFragments(
const NGPhysicalFragment& fragment,
const NGBlockBreakToken* block_break_token) {
auto* block_flow = To<LayoutBlockFlow>(fragment.GetMutableLayoutObject());
if (!block_flow->ChildrenInline())
return;
DCHECK(AreNGBlockFlowChildrenInline(block_flow));
NGInlineNode node = NGInlineNode(block_flow);
DCHECK(node.IsPrepareLayoutFinished());
const Vector<NGInlineItem>& items = node.MaybeDirtyData().items;
unsigned start_index;
if (!block_break_token) {
start_index = 0;
} else {
// TODO(kojii): Not fully supported, need more logic when the block is
// fragmented, because one inline LayoutObject may span across
// fragmentainers.
// TODO(kojii): Not sure if using |block_break_token->InputNode()| is
// correct for multicol. Should verify and somehow get NGInlineNode from it.
// Also change |InlineBreakTokenFor| to receive NGInlineNode instead of
// NGLayoutInputNode once this is done.
const NGInlineBreakToken* inline_break_token =
block_break_token->InlineBreakTokenFor(block_break_token->InputNode());
// TODO(kojii): This needs to investigate in what case this happens. It's
// probably wrong to create NGPaintFragment when there's no inline break
// token.
if (!inline_break_token)
return;
start_index = inline_break_token->ItemIndex();
}
LayoutObject* last_object = nullptr;
for (unsigned i = start_index; i < items.size(); i++) {
const NGInlineItem& item = items[i];
if (item.Type() == NGInlineItem::kFloating ||
item.Type() == NGInlineItem::kOutOfFlowPositioned) {
// These items are not associated and that no need to clear.
DCHECK(!item.GetLayoutObject()->FirstInlineFragment());
continue;
}
LayoutObject* object = item.GetLayoutObject();
if (!object || object == last_object)
continue;
object->SetFirstInlineFragment(nullptr);
last_object = object;
}
}
scoped_refptr<const NGLayoutResult> NGInlineNode::Layout(
const NGConstraintSpace& constraint_space,
const NGBreakToken* break_token,
......@@ -1455,27 +1404,7 @@ scoped_refptr<const NGLayoutResult> NGInlineNode::Layout(
const auto* inline_break_token = To<NGInlineBreakToken>(break_token);
NGInlineLayoutAlgorithm algorithm(*this, constraint_space, inline_break_token,
context);
auto layout_result = algorithm.Layout();
#if defined(OS_ANDROID)
if (!RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
// Cached position data is crucial for line breaking performance and is
// preserved across layouts to speed up subsequent layout passes due to
// reflow, page zoom, window resize, etc. On Android though reflows are less
// common, page zoom isn't used (instead uses pinch-zoom), and the window
// typically can't be resized (apart from rotation). To reduce memory usage
// discard the cached position data after layout.
// TODO(crbug.com/1042604): FragmentItem should save memory enough to re-
// enable the position cache.
NGInlineNodeData* data = MutableData();
for (auto& item : data->items) {
if (item.shape_result_)
item.shape_result_->DiscardPositionData();
}
}
#endif // defined(OS_ANDROID)
return layout_result;
return algorithm.Layout();
}
namespace {
......
......@@ -9,13 +9,11 @@
#include "third_party/blink/renderer/core/layout/layout_block_flow.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_inline_node_data.h"
#include "third_party/blink/renderer/core/layout/ng/ng_layout_input_node.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class NGBlockBreakToken;
class NGConstraintSpace;
class NGInlineChildLayoutContext;
class NGInlineNodeLegacy;
......@@ -53,8 +51,6 @@ class CORE_EXPORT NGInlineNode : public NGLayoutInputNode {
LayoutBlockFlow* block_flow = GetLayoutBlockFlow();
block_flow->ResetNGInlineNodeData();
DCHECK(!IsPrepareLayoutFinished());
// There shouldn't be paint fragment if NGInlineNodeData does not exist.
block_flow->SetPaintFragment(nullptr, nullptr);
}
const NGInlineItemsData& ItemsData(bool is_first_line) const {
......@@ -75,12 +71,6 @@ class CORE_EXPORT NGInlineNode : public NGLayoutInputNode {
// needed.
static String TextContentForStickyImagesQuirk(const NGInlineItemsData&);
// Clear associated fragments for LayoutObjects.
// They are associated when NGPaintFragment is constructed, but when clearing,
// NGInlineItem provides easier and faster logic.
static void ClearAssociatedFragments(const NGPhysicalFragment& fragment,
const NGBlockBreakToken* break_token);
// Returns true if we don't need to collect inline items after replacing
// |layout_text| after deleting replacing subtext from |offset| to |length|
// |new_text| is new text of |layout_text|.
......
......@@ -691,14 +691,12 @@ TEST_P(StyleChangeTest, NeedsCollectInlinesOnStyle) {
EXPECT_FALSE(previous->GetLayoutObject()->NeedsCollectInlines());
EXPECT_FALSE(next->GetLayoutObject()->NeedsCollectInlines());
if (data.is_line_dirty &&
RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
if (data.is_line_dirty) {
TestAnyItemsAreDirty(*To<LayoutBlockFlow>(container->GetLayoutObject()),
*data.is_line_dirty);
}
if (data.invalidate_ink_overflow &&
RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
if (data.invalidate_ink_overflow) {
const LayoutObject* parent_layout_object = parent->GetLayoutObject();
for (const LayoutObject* child = parent_layout_object->SlowFirstChild();
child; child = child->NextInPreOrder(parent_layout_object)) {
......@@ -886,12 +884,7 @@ TEST_F(NGInlineNodeTest, CollectInlinesShouldNotClearFirstInlineFragment) {
// Running |CollectInlines| should not clear |FirstInlineFragment|.
LayoutObject* first_child = container->firstChild()->GetLayoutObject();
if (RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
// TODO(yosin): We should use |FirstInlineItemFragmentIndex()| once we
// implement it.
} else {
EXPECT_NE(first_child->FirstInlineFragment(), nullptr);
}
EXPECT_TRUE(first_child->HasInlineFragments());
}
TEST_F(NGInlineNodeTest, SegmentBidiChangeSetsNeedsLayout) {
......@@ -1136,8 +1129,6 @@ TEST_F(NGInlineNodeTest, ClearFirstInlineFragmentOnSplitFlow) {
NGInlineCursor before_split;
before_split.MoveTo(*text->GetLayoutObject());
EXPECT_TRUE(before_split);
scoped_refptr<const NGPaintFragment> text_fragment_before_split =
before_split.Current().PaintFragment();
// Append <div> to <span>. causing SplitFlow().
Element* outer_span = GetElementById("outer_span");
......@@ -1160,10 +1151,6 @@ TEST_F(NGInlineNodeTest, ClearFirstInlineFragmentOnSplitFlow) {
NGInlineCursor after_layout;
after_layout.MoveTo(*text->GetLayoutObject());
EXPECT_TRUE(after_layout);
if (!RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
EXPECT_NE(text_fragment_before_split.get(),
after_layout.Current().PaintFragment());
}
// Check it is the one owned by the new root inline formatting context.
LayoutBlock* anonymous_block =
......@@ -1175,10 +1162,6 @@ TEST_F(NGInlineNodeTest, ClearFirstInlineFragmentOnSplitFlow) {
EXPECT_TRUE(anonymous_block_cursor);
EXPECT_EQ(anonymous_block_cursor.Current().GetLayoutObject(),
text->GetLayoutObject());
if (!RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
EXPECT_EQ(anonymous_block_cursor.Current().PaintFragment(),
after_layout.Current().PaintFragment());
}
}
TEST_F(NGInlineNodeTest, AddChildToSVGRoot) {
......
......@@ -268,36 +268,6 @@ scoped_refptr<NGPaintFragment> NGPaintFragment::CreateOrReuse(
return new_instance;
}
scoped_refptr<NGPaintFragment> NGPaintFragment::Create(
scoped_refptr<const NGPhysicalFragment> fragment,
const NGBlockBreakToken* block_break_token,
scoped_refptr<NGPaintFragment> previous_instance) {
DCHECK(fragment);
bool has_previous_instance = previous_instance.get();
CreateContext context(std::move(previous_instance), fragment->IsContainer());
scoped_refptr<NGPaintFragment> paint_fragment =
CreateOrReuse(std::move(fragment), PhysicalOffset(), &context);
if (context.populate_children) {
if (has_previous_instance) {
NGInlineNode::ClearAssociatedFragments(paint_fragment->PhysicalFragment(),
block_break_token);
}
HashMap<const LayoutObject*, NGPaintFragment*> last_fragment_map;
context.last_fragment_map = &last_fragment_map;
paint_fragment->PopulateDescendants(&context);
}
context.DestroyPreviousInstances();
if (context.painting_layer_needs_repaint) {
ObjectPaintInvalidator(*paint_fragment->GetLayoutObject())
.SlowSetPaintingLayerNeedsRepaint();
}
return paint_fragment;
}
scoped_refptr<NGPaintFragment>* NGPaintFragment::Find(
scoped_refptr<NGPaintFragment>* fragment,
const NGBlockBreakToken* break_token) {
......
......@@ -46,11 +46,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
NGPaintFragment*);
~NGPaintFragment() override;
static scoped_refptr<NGPaintFragment> Create(
scoped_refptr<const NGPhysicalFragment>,
const NGBlockBreakToken* break_token,
scoped_refptr<NGPaintFragment> previous_instance = nullptr);
const NGPhysicalFragment& PhysicalFragment() const {
CHECK(IsAlive());
return *physical_fragment_;
......
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