Commit 115dc0aa authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

[LayoutNG] NGPhysicalFragment size reduction and warning

This patch reduces the size of NGPhysicalFragment by:
* NGPhysicalFragment by pointer, by removing virtual
  functions.
* NGPhysicalTextFragment by a word, by moving flags to
  NGPhysicalFragment.
* NGPhysicalTextFragment::EndEffect() is no longer used
  and that removed.

Also adds size warning to all subclasses.

Currently, NGPhysicalFragment has 13 bits in flags, plus
5 bits for its subclasses, 18 bits total.

Bug: 591099
Change-Id: I189f691c1976da1eb1223ac9c782e02567038310
Reviewed-on: https://chromium-review.googlesource.com/c/1329703
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarIan Kilpatrick <ikilpatrick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607159}
parent 48fbdf22
...@@ -11,6 +11,18 @@ ...@@ -11,6 +11,18 @@
namespace blink { namespace blink {
namespace {
struct SameSizeAsNGPhysicalLineBoxFragment : NGPhysicalContainerFragment {
NGLineHeightMetrics metrics;
};
static_assert(sizeof(NGPhysicalLineBoxFragment) ==
sizeof(SameSizeAsNGPhysicalLineBoxFragment),
"NGPhysicalLineBoxFragment should stay small");
} // namespace
scoped_refptr<const NGPhysicalLineBoxFragment> scoped_refptr<const NGPhysicalLineBoxFragment>
NGPhysicalLineBoxFragment::Create(NGLineBoxFragmentBuilder* builder) { NGPhysicalLineBoxFragment::Create(NGLineBoxFragmentBuilder* builder) {
// We store the children list inline in the fragment as a flexible // We store the children list inline in the fragment as a flexible
......
...@@ -18,6 +18,16 @@ namespace blink { ...@@ -18,6 +18,16 @@ namespace blink {
namespace { namespace {
struct SameSizeAsNGPhysicalTextFragment : NGPhysicalFragment {
void* pointers[2];
NGPhysicalOffsetRect rect;
unsigned offsets[2];
};
static_assert(sizeof(NGPhysicalTextFragment) ==
sizeof(SameSizeAsNGPhysicalTextFragment),
"NGPhysicalTextFragment should stay small");
inline bool IsPhysicalTextFragmentAnonymousText( inline bool IsPhysicalTextFragmentAnonymousText(
const LayoutObject* layout_object) { const LayoutObject* layout_object) {
if (!layout_object) if (!layout_object)
...@@ -55,7 +65,6 @@ NGPhysicalTextFragment::NGPhysicalTextFragment( ...@@ -55,7 +65,6 @@ NGPhysicalTextFragment::NGPhysicalTextFragment(
unsigned end_offset, unsigned end_offset,
NGPhysicalSize size, NGPhysicalSize size,
NGLineOrientation line_orientation, NGLineOrientation line_orientation,
NGTextEndEffect end_effect,
scoped_refptr<const ShapeResultView> shape_result) scoped_refptr<const ShapeResultView> shape_result)
: NGPhysicalFragment(layout_object, : NGPhysicalFragment(layout_object,
style, style,
...@@ -66,11 +75,11 @@ NGPhysicalTextFragment::NGPhysicalTextFragment( ...@@ -66,11 +75,11 @@ NGPhysicalTextFragment::NGPhysicalTextFragment(
text_(text), text_(text),
start_offset_(start_offset), start_offset_(start_offset),
end_offset_(end_offset), end_offset_(end_offset),
shape_result_(shape_result), shape_result_(shape_result) {
line_orientation_(static_cast<unsigned>(line_orientation)),
end_effect_(static_cast<unsigned>(end_effect)),
is_anonymous_text_(IsPhysicalTextFragmentAnonymousText(layout_object)) {
DCHECK(shape_result_ || IsFlowControl()) << ToString(); DCHECK(shape_result_ || IsFlowControl()) << ToString();
line_orientation_ = static_cast<unsigned>(line_orientation);
is_anonymous_text_ = IsPhysicalTextFragmentAnonymousText(layout_object);
self_ink_overflow_ = ComputeSelfInkOverflow(); self_ink_overflow_ = ComputeSelfInkOverflow();
} }
...@@ -79,13 +88,13 @@ NGPhysicalTextFragment::NGPhysicalTextFragment(NGTextFragmentBuilder* builder) ...@@ -79,13 +88,13 @@ NGPhysicalTextFragment::NGPhysicalTextFragment(NGTextFragmentBuilder* builder)
text_(builder->text_), text_(builder->text_),
start_offset_(builder->start_offset_), start_offset_(builder->start_offset_),
end_offset_(builder->end_offset_), end_offset_(builder->end_offset_),
shape_result_(std::move(builder->shape_result_)), shape_result_(std::move(builder->shape_result_)) {
line_orientation_(
static_cast<unsigned>(ToLineOrientation(builder->GetWritingMode()))),
end_effect_(static_cast<unsigned>(builder->end_effect_)),
is_anonymous_text_(
IsPhysicalTextFragmentAnonymousText(builder->layout_object_)) {
DCHECK(shape_result_ || IsFlowControl()) << ToString(); DCHECK(shape_result_ || IsFlowControl()) << ToString();
line_orientation_ =
static_cast<unsigned>(ToLineOrientation(builder->GetWritingMode()));
is_anonymous_text_ =
IsPhysicalTextFragmentAnonymousText(builder->layout_object_);
self_ink_overflow_ = ComputeSelfInkOverflow(); self_ink_overflow_ = ComputeSelfInkOverflow();
} }
...@@ -247,8 +256,7 @@ scoped_refptr<const NGPhysicalFragment> NGPhysicalTextFragment::TrimText( ...@@ -247,8 +256,7 @@ scoped_refptr<const NGPhysicalFragment> NGPhysicalTextFragment::TrimText(
TextType(), text_, new_start_offset, new_end_offset, TextType(), text_, new_start_offset, new_end_offset,
IsHorizontal() ? NGPhysicalSize{new_inline_size, size_.height} IsHorizontal() ? NGPhysicalSize{new_inline_size, size_.height}
: NGPhysicalSize{size_.width, new_inline_size}, : NGPhysicalSize{size_.width, new_inline_size},
LineOrientation(), EndEffect(), LineOrientation(), ShapeResultView::Create(new_shape_result.get())));
ShapeResultView::Create(new_shape_result.get())));
} }
unsigned NGPhysicalTextFragment::TextOffsetForPoint( unsigned NGPhysicalTextFragment::TextOffsetForPoint(
...@@ -299,7 +307,7 @@ UBiDiLevel NGPhysicalTextFragment::BidiLevel() const { ...@@ -299,7 +307,7 @@ UBiDiLevel NGPhysicalTextFragment::BidiLevel() const {
TextDirection NGPhysicalTextFragment::ResolvedDirection() const { TextDirection NGPhysicalTextFragment::ResolvedDirection() const {
if (TextShapeResult()) if (TextShapeResult())
return TextShapeResult()->Direction(); return TextShapeResult()->Direction();
return NGPhysicalFragment::ResolvedDirection(); return DirectionFromLevel(BidiLevel());
} }
} // namespace blink } // namespace blink
...@@ -104,10 +104,6 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment { ...@@ -104,10 +104,6 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment {
// properties, in local coordinates. // properties, in local coordinates.
NGPhysicalOffsetRect SelfInkOverflow() const { return self_ink_overflow_; } NGPhysicalOffsetRect SelfInkOverflow() const { return self_ink_overflow_; }
NGTextEndEffect EndEffect() const {
return static_cast<NGTextEndEffect>(end_effect_);
}
// Create a new fragment that has part of the text of this fragment. // Create a new fragment that has part of the text of this fragment.
// All other properties are the same as this fragment. // All other properties are the same as this fragment.
scoped_refptr<const NGPhysicalFragment> TrimText(unsigned start_offset, scoped_refptr<const NGPhysicalFragment> TrimText(unsigned start_offset,
...@@ -127,8 +123,8 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment { ...@@ -127,8 +123,8 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment {
// Returns the text offset in the fragment placed closest to the given point. // Returns the text offset in the fragment placed closest to the given point.
unsigned TextOffsetForPoint(const NGPhysicalOffset&) const; unsigned TextOffsetForPoint(const NGPhysicalOffset&) const;
UBiDiLevel BidiLevel() const override; UBiDiLevel BidiLevel() const;
TextDirection ResolvedDirection() const override; TextDirection ResolvedDirection() const;
// Compute line-relative coordinates for given offsets, this is not // Compute line-relative coordinates for given offsets, this is not
// flow-relative: // flow-relative:
...@@ -148,7 +144,6 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment { ...@@ -148,7 +144,6 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment {
unsigned end_offset, unsigned end_offset,
NGPhysicalSize size, NGPhysicalSize size,
NGLineOrientation line_orientation, NGLineOrientation line_orientation,
NGTextEndEffect end_effect,
scoped_refptr<const ShapeResultView> shape_result); scoped_refptr<const ShapeResultView> shape_result);
LayoutUnit InlinePositionForOffset(unsigned offset, LayoutUnit InlinePositionForOffset(unsigned offset,
...@@ -168,10 +163,6 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment { ...@@ -168,10 +163,6 @@ class CORE_EXPORT NGPhysicalTextFragment final : public NGPhysicalFragment {
const unsigned end_offset_; const unsigned end_offset_;
NGPhysicalOffsetRect self_ink_overflow_; NGPhysicalOffsetRect self_ink_overflow_;
const scoped_refptr<const ShapeResultView> shape_result_; const scoped_refptr<const ShapeResultView> shape_result_;
const unsigned line_orientation_ : 2; // NGLineOrientation
const unsigned end_effect_ : 1; // NGTextEndEffect
const unsigned is_anonymous_text_ : 1;
}; };
DEFINE_TYPE_CASTS(NGPhysicalTextFragment, DEFINE_TYPE_CASTS(NGPhysicalTextFragment,
......
...@@ -17,6 +17,19 @@ ...@@ -17,6 +17,19 @@
namespace blink { namespace blink {
namespace {
struct SameSizeAsNGPhysicalBoxFragment : NGPhysicalContainerFragment {
NGBaselineList baselines;
NGPhysicalBoxStrut box_struts[2];
};
static_assert(sizeof(NGPhysicalBoxFragment) ==
sizeof(SameSizeAsNGPhysicalBoxFragment),
"NGPhysicalBoxFragment should stay small");
} // namespace
scoped_refptr<const NGPhysicalBoxFragment> NGPhysicalBoxFragment::Create( scoped_refptr<const NGPhysicalBoxFragment> NGPhysicalBoxFragment::Create(
NGBoxFragmentBuilder* builder, NGBoxFragmentBuilder* builder,
WritingMode block_or_line_writing_mode) { WritingMode block_or_line_writing_mode) {
......
...@@ -82,7 +82,7 @@ class CORE_EXPORT NGPhysicalBoxFragment final ...@@ -82,7 +82,7 @@ class CORE_EXPORT NGPhysicalBoxFragment final
const LayoutPoint& additional_offset, const LayoutPoint& additional_offset,
NGOutlineType include_block_overflows) const; NGOutlineType include_block_overflows) const;
UBiDiLevel BidiLevel() const override; UBiDiLevel BidiLevel() const;
scoped_refptr<const NGPhysicalFragment> CloneWithoutOffset() const; scoped_refptr<const NGPhysicalFragment> CloneWithoutOffset() const;
......
...@@ -14,6 +14,19 @@ ...@@ -14,6 +14,19 @@
namespace blink { namespace blink {
namespace {
struct SameSizeAsNGPhysicalContainerFragment : NGPhysicalFragment {
wtf_size_t size;
void* pointer;
};
static_assert(sizeof(NGPhysicalContainerFragment) ==
sizeof(SameSizeAsNGPhysicalContainerFragment),
"NGPhysicalContainerFragment should stay small");
} // namespace
NGPhysicalContainerFragment::NGPhysicalContainerFragment( NGPhysicalContainerFragment::NGPhysicalContainerFragment(
NGContainerFragmentBuilder* builder, NGContainerFragmentBuilder* builder,
WritingMode block_or_line_writing_mode, WritingMode block_or_line_writing_mode,
......
...@@ -21,6 +21,17 @@ ...@@ -21,6 +21,17 @@
namespace blink { namespace blink {
namespace { namespace {
struct SameSizeAsNGPhysicalFragment
: RefCounted<const NGPhysicalFragment, NGPhysicalFragmentTraits> {
void* pointers[3];
NGPhysicalSize size;
unsigned flags;
};
static_assert(sizeof(NGPhysicalFragment) ==
sizeof(SameSizeAsNGPhysicalFragment),
"NGPhysicalFragment should stay small");
bool AppendFragmentOffsetAndSize( bool AppendFragmentOffsetAndSize(
const NGPhysicalFragment* fragment, const NGPhysicalFragment* fragment,
base::Optional<NGPhysicalOffset> fragment_offset, base::Optional<NGPhysicalOffset> fragment_offset,
...@@ -434,15 +445,33 @@ TouchAction NGPhysicalFragment::EffectiveWhitelistedTouchAction() const { ...@@ -434,15 +445,33 @@ TouchAction NGPhysicalFragment::EffectiveWhitelistedTouchAction() const {
} }
UBiDiLevel NGPhysicalFragment::BidiLevel() const { UBiDiLevel NGPhysicalFragment::BidiLevel() const {
switch (Type()) {
case kFragmentText:
return ToNGPhysicalTextFragment(*this).BidiLevel();
case kFragmentBox:
case kFragmentRenderedLegend:
return ToNGPhysicalBoxFragment(*this).BidiLevel();
case kFragmentLineBox:
break;
}
NOTREACHED(); NOTREACHED();
return 0; return 0;
} }
TextDirection NGPhysicalFragment::ResolvedDirection() const { TextDirection NGPhysicalFragment::ResolvedDirection() const {
DCHECK(IsInline()); switch (Type()) {
DCHECK(IsText() || IsAtomicInline()); case kFragmentText:
// TODO(xiaochengh): Store direction in |base_direction_| flag. return ToNGPhysicalTextFragment(*this).ResolvedDirection();
return DirectionFromLevel(BidiLevel()); case kFragmentBox:
case kFragmentRenderedLegend:
DCHECK(IsInline() && IsAtomicInline());
// TODO(xiaochengh): Store direction in |base_direction_| flag.
return DirectionFromLevel(BidiLevel());
case kFragmentLineBox:
break;
}
NOTREACHED();
return TextDirection::kLtr;
} }
String NGPhysicalFragment::ToString() const { String NGPhysicalFragment::ToString() const {
......
...@@ -199,11 +199,11 @@ class CORE_EXPORT NGPhysicalFragment ...@@ -199,11 +199,11 @@ class CORE_EXPORT NGPhysicalFragment
TouchAction EffectiveWhitelistedTouchAction() const; TouchAction EffectiveWhitelistedTouchAction() const;
// Returns the bidi level of a text or atomic inline fragment. // Returns the bidi level of a text or atomic inline fragment.
virtual UBiDiLevel BidiLevel() const; UBiDiLevel BidiLevel() const;
// Returns the resolved direction of a text or atomic inline fragment. Not to // Returns the resolved direction of a text or atomic inline fragment. Not to
// be confused with the CSS 'direction' property. // be confused with the CSS 'direction' property.
virtual TextDirection ResolvedDirection() const; TextDirection ResolvedDirection() const;
String ToString() const; String ToString() const;
...@@ -256,12 +256,20 @@ class CORE_EXPORT NGPhysicalFragment ...@@ -256,12 +256,20 @@ class CORE_EXPORT NGPhysicalFragment
unsigned is_old_layout_root_ : 1; unsigned is_old_layout_root_ : 1;
unsigned border_edge_ : 4; // NGBorderEdges::Physical unsigned border_edge_ : 4; // NGBorderEdges::Physical
const unsigned style_variant_ : 2; // NGStyleVariant const unsigned style_variant_ : 2; // NGStyleVariant
unsigned base_direction_ : 1; // TextDirection, for NGPhysicalLineBoxFragment
// The following bitfield is only to be used by NGPhysicalLineBoxFragment
// (it's defined here to save memory, since that class has no bitfields).
unsigned base_direction_ : 1; // TextDirection
// The following bitfield is only to be used by NGPhysicalBoxFragment (it's // The following bitfield is only to be used by NGPhysicalBoxFragment (it's
// defined here to save memory, since that class has no bitfields). // defined here to save memory, since that class has no bitfields).
unsigned children_inline_ : 1; unsigned children_inline_ : 1;
// The following bitfield is only to be used by NGPhysicalTextFragment (it's
// defined here to save memory, since that class has no bitfields).
unsigned line_orientation_ : 2; // NGLineOrientation
unsigned is_anonymous_text_ : 1;
private: private:
friend struct NGPhysicalFragmentTraits; friend struct NGPhysicalFragmentTraits;
void Destroy() const; void Destroy() const;
......
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