Commit 8a492e21 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Make |NGFragmentItems::DirtyLinesFromNeedsLayout| static

This patch changes |NGFragmentItems::DirtyLinesFromNeedsLayout|
to static, matching other |DirtyLines*| in crrev.com/c/2505262.

Also removes two calls to |FragmentItems|, which we need to
eliminate to support block fragmentation, in DCHECK and test.

This patch has no behavior changes.

Bug: 1061423
Change-Id: I13c8ad366935f0d7e2c37230030da8d649259b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505707Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822592}
parent 17833a53
......@@ -62,7 +62,7 @@ class NGFragmentItemTest : public NGLayoutTest,
LayoutBlockFlow* block_flow = GetLayoutBlockFlowByElementId(id);
const NGPhysicalBoxFragment* fragment = block_flow->GetPhysicalFragment(0);
const NGFragmentItems* items = fragment->Items();
items->DirtyLinesFromNeedsLayout(block_flow);
NGFragmentItems::DirtyLinesFromNeedsLayout(*block_flow);
const NGFragmentItem* end_reusable_item =
items->EndOfReusableItems(*fragment);
......
......@@ -333,19 +333,25 @@ void NGFragmentItems::DirtyFirstItem(const LayoutBlockFlow& container) {
}
}
// static
void NGFragmentItems::DirtyLinesFromNeedsLayout(
const LayoutBlockFlow* container) const {
DCHECK_EQ(this, container->FragmentItems());
const LayoutBlockFlow& container) {
DCHECK(std::any_of(container.PhysicalFragments().begin(),
container.PhysicalFragments().end(),
[](const NGPhysicalBoxFragment& fragment) {
return fragment.HasItems();
}));
// Mark dirty for the first top-level child that has |NeedsLayout|.
//
// TODO(kojii): We could mark first descendant to increase reuse
// opportunities. Doing this complicates the logic, especially when culled
// inline is involved, and common case is to append to large IFC. Choose
// simpler logic and faster to check over more reuse opportunities.
for (LayoutObject* child = container->FirstChild(); child;
for (LayoutObject* child = container.FirstChild(); child;
child = child->NextSibling()) {
if (child->NeedsLayout()) {
DirtyLinesFromChangedChild(*child, *container);
DirtyLinesFromChangedChild(*child, container);
return;
}
}
......
......@@ -82,7 +82,7 @@ class CORE_EXPORT NGFragmentItems {
const LayoutBlockFlow& container);
// Mark items dirty from |LayoutObject::NeedsLayout| flags.
void DirtyLinesFromNeedsLayout(const LayoutBlockFlow* block_flow) const;
static void DirtyLinesFromNeedsLayout(const LayoutBlockFlow& block_flow);
// The byte size of this instance.
constexpr static wtf_size_t ByteSizeFor(wtf_size_t count) {
......
......@@ -141,16 +141,23 @@ class NGInlineNodeTest : public NGLayoutTest {
return end_offsets;
}
void TestAnyItemsAreDirty(LayoutBlockFlow* block_flow, bool expected) {
const NGFragmentItems* items = block_flow->FragmentItems();
items->DirtyLinesFromNeedsLayout(block_flow);
void TestAnyItemsAreDirty(const LayoutBlockFlow& block_flow, bool expected) {
NGFragmentItems::DirtyLinesFromNeedsLayout(block_flow);
for (const NGPhysicalBoxFragment& fragment :
block_flow.PhysicalFragments()) {
if (const NGFragmentItems* items = fragment.Items()) {
// Check |NGFragmentItem::IsDirty| directly without using
// |EndOfReusableItems|. This is different from the line cache logic, but
// some items may not be reusable even if |!IsDirty()|.
const bool is_any_items_dirty =
std::any_of(items->Items().begin(), items->Items().end(),
[](const NGFragmentItem& item) { return item.IsDirty(); });
EXPECT_EQ(is_any_items_dirty, expected);
// |EndOfReusableItems|. This is different from the line cache logic,
// but some items may not be reusable even if |!IsDirty()|.
for (const NGFragmentItem& item : items->Items()) {
if (item.IsDirty()) {
EXPECT_TRUE(expected);
return;
}
}
}
}
EXPECT_FALSE(expected);
}
scoped_refptr<const ComputedStyle> style_;
......@@ -686,7 +693,7 @@ TEST_P(StyleChangeTest, NeedsCollectInlinesOnStyle) {
if (data.is_line_dirty &&
RuntimeEnabledFeatures::LayoutNGFragmentItemEnabled()) {
TestAnyItemsAreDirty(To<LayoutBlockFlow>(container->GetLayoutObject()),
TestAnyItemsAreDirty(*To<LayoutBlockFlow>(container->GetLayoutObject()),
*data.is_line_dirty);
}
......
......@@ -992,7 +992,9 @@ bool NGBlockLayoutAlgorithm::TryReuseFragmentsFromCache(
DCHECK(previous_items);
// Find reusable lines. Fail if no items are reusable.
previous_items->DirtyLinesFromNeedsLayout(inline_node.GetLayoutBlockFlow());
// TODO(kojii): |DirtyLinesFromNeedsLayout| is needed only once for a
// |LayoutBlockFlow|, not for every fragment.
NGFragmentItems::DirtyLinesFromNeedsLayout(*inline_node.GetLayoutBlockFlow());
const NGFragmentItem* end_item =
previous_items->EndOfReusableItems(previous_fragment);
DCHECK(end_item);
......
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