Commit 16e6b253 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Introduce NGPaintFragment::RareData

This patch Introduces |NGPaintFragment::RareData()| to reduce memory usage
of |NGPaintFragment|.

Change-Id: I4b74f1b0cddcbb432b84847173f93bb4c897d08d
Reviewed-on: https://chromium-review.googlesource.com/c/1343810Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609893}
parent 90927154
...@@ -39,7 +39,7 @@ struct SameSizeAsNGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -39,7 +39,7 @@ struct SameSizeAsNGPaintFragment : public RefCounted<NGPaintFragment>,
public ImageResourceObserver { public ImageResourceObserver {
void* pointers[6]; void* pointers[6];
NGPhysicalOffset offsets[2]; NGPhysicalOffset offsets[2];
LayoutRect rects[2]; LayoutRect rects[1];
unsigned flags; unsigned flags;
}; };
...@@ -302,6 +302,12 @@ scoped_refptr<NGPaintFragment> NGPaintFragment::Create( ...@@ -302,6 +302,12 @@ scoped_refptr<NGPaintFragment> NGPaintFragment::Create(
return paint_fragment; return paint_fragment;
} }
NGPaintFragment::RareData& NGPaintFragment::EnsureRareData() {
if (!rare_data_)
rare_data_ = std::make_unique<RareData>();
return *rare_data_;
}
void NGPaintFragment::UpdateFromCachedLayoutResult( void NGPaintFragment::UpdateFromCachedLayoutResult(
scoped_refptr<const NGPhysicalFragment> fragment, scoped_refptr<const NGPhysicalFragment> fragment,
NGPhysicalOffset offset) { NGPhysicalOffset offset) {
...@@ -329,16 +335,22 @@ void NGPaintFragment::UpdateFromCachedLayoutResult( ...@@ -329,16 +335,22 @@ void NGPaintFragment::UpdateFromCachedLayoutResult(
NGPaintFragment* NGPaintFragment::Last(const NGBreakToken& break_token) { NGPaintFragment* NGPaintFragment::Last(const NGBreakToken& break_token) {
for (NGPaintFragment* fragment = this; fragment; for (NGPaintFragment* fragment = this; fragment;
fragment = fragment->next_fragmented_.get()) { fragment = fragment->Next()) {
if (fragment->PhysicalFragment().BreakToken() == &break_token) if (fragment->PhysicalFragment().BreakToken() == &break_token)
return fragment; return fragment;
} }
return nullptr; return nullptr;
} }
NGPaintFragment* NGPaintFragment::Next() {
if (!rare_data_)
return nullptr;
return rare_data_->next_fragmented_.get();
}
NGPaintFragment* NGPaintFragment::Last() { NGPaintFragment* NGPaintFragment::Last() {
for (NGPaintFragment* fragment = this;;) { for (NGPaintFragment* fragment = this;;) {
NGPaintFragment* next = fragment->next_fragmented_.get(); NGPaintFragment* next = fragment->Next();
if (!next) if (!next)
return fragment; return fragment;
fragment = next; fragment = next;
...@@ -360,7 +372,8 @@ scoped_refptr<NGPaintFragment>* NGPaintFragment::Find( ...@@ -360,7 +372,8 @@ scoped_refptr<NGPaintFragment>* NGPaintFragment::Find(
if (!*fragment) if (!*fragment)
return fragment; return fragment;
scoped_refptr<NGPaintFragment>* next = &(*fragment)->next_fragmented_; scoped_refptr<NGPaintFragment>* next =
&(*fragment)->EnsureRareData().next_fragmented_;
if ((*fragment)->PhysicalFragment().BreakToken() == break_token) if ((*fragment)->PhysicalFragment().BreakToken() == break_token)
return next; return next;
fragment = next; fragment = next;
...@@ -369,7 +382,9 @@ scoped_refptr<NGPaintFragment>* NGPaintFragment::Find( ...@@ -369,7 +382,9 @@ scoped_refptr<NGPaintFragment>* NGPaintFragment::Find(
} }
void NGPaintFragment::SetNext(scoped_refptr<NGPaintFragment> fragment) { void NGPaintFragment::SetNext(scoped_refptr<NGPaintFragment> fragment) {
next_fragmented_ = std::move(fragment); if (!rare_data_ && !fragment)
return;
EnsureRareData().next_fragmented_ = std::move(fragment);
} }
bool NGPaintFragment::IsDescendantOfNotSelf( bool NGPaintFragment::IsDescendantOfNotSelf(
...@@ -397,6 +412,18 @@ bool NGPaintFragment::ShouldClipOverflow() const { ...@@ -397,6 +412,18 @@ bool NGPaintFragment::ShouldClipOverflow() const {
ToNGPhysicalBoxFragment(*physical_fragment_).ShouldClipOverflow(); ToNGPhysicalBoxFragment(*physical_fragment_).ShouldClipOverflow();
} }
LayoutRect NGPaintFragment::SelectionVisualRect() const {
if (!rare_data_)
return LayoutRect();
return rare_data_->selection_visual_rect_;
}
void NGPaintFragment::SetSelectionVisualRect(const LayoutRect& rect) {
if (!rare_data_ && rect.IsEmpty())
return;
EnsureRareData().selection_visual_rect_ = rect;
}
LayoutRect NGPaintFragment::SelfInkOverflow() const { LayoutRect NGPaintFragment::SelfInkOverflow() const {
return physical_fragment_->InkOverflow().ToLayoutRect(); return physical_fragment_->InkOverflow().ToLayoutRect();
} }
......
...@@ -58,7 +58,7 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -58,7 +58,7 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
NGPhysicalOffset offset); NGPhysicalOffset offset);
// Next/last fragment for when this is fragmented. // Next/last fragment for when this is fragmented.
NGPaintFragment* Next() { return next_fragmented_.get(); } NGPaintFragment* Next();
void SetNext(scoped_refptr<NGPaintFragment>); void SetNext(scoped_refptr<NGPaintFragment>);
NGPaintFragment* Last(); NGPaintFragment* Last();
NGPaintFragment* Last(const NGBreakToken&); NGPaintFragment* Last(const NGBreakToken&);
...@@ -170,10 +170,8 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -170,10 +170,8 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
LayoutRect VisualRect() const override { return visual_rect_; } LayoutRect VisualRect() const override { return visual_rect_; }
void SetVisualRect(const LayoutRect& rect) { visual_rect_ = rect; } void SetVisualRect(const LayoutRect& rect) { visual_rect_ = rect; }
LayoutRect SelectionVisualRect() const { return selection_visual_rect_; } LayoutRect SelectionVisualRect() const;
void SetSelectionVisualRect(const LayoutRect& rect) { void SetSelectionVisualRect(const LayoutRect& rect);
selection_visual_rect_ = rect;
}
// CSS ink overflow https://www.w3.org/TR/css-overflow-3/#ink // CSS ink overflow https://www.w3.org/TR/css-overflow-3/#ink
// Encloses all pixels painted by self + children. // Encloses all pixels painted by self + children.
...@@ -334,8 +332,18 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -334,8 +332,18 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
scoped_refptr<NGPaintFragment> first_child_; scoped_refptr<NGPaintFragment> first_child_;
scoped_refptr<NGPaintFragment> next_sibling_; scoped_refptr<NGPaintFragment> next_sibling_;
// The next fragment for when this is fragmented. struct RareData {
scoped_refptr<NGPaintFragment> next_fragmented_; USING_FAST_MALLOC(RareData);
public:
// The next fragment for when this is fragmented.
scoped_refptr<NGPaintFragment> next_fragmented_;
// Used for invalidating selected fragment.
LayoutRect selection_visual_rect_;
};
RareData& EnsureRareData();
std::unique_ptr<RareData> rare_data_;
NGPaintFragment* next_for_same_layout_object_ = nullptr; NGPaintFragment* next_for_same_layout_object_ = nullptr;
NGPhysicalOffset inline_offset_to_container_box_; NGPhysicalOffset inline_offset_to_container_box_;
...@@ -351,7 +359,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>, ...@@ -351,7 +359,6 @@ class CORE_EXPORT NGPaintFragment : public RefCounted<NGPaintFragment>,
// //
LayoutRect visual_rect_; LayoutRect visual_rect_;
LayoutRect selection_visual_rect_;
}; };
extern template class CORE_EXTERN_TEMPLATE_EXPORT extern template class CORE_EXTERN_TEMPLATE_EXPORT
......
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