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

[layoutng] Optimize CopyFragmentDataToLayoutBox

As well as inlining some NGPhysicalOffset functions.

Change-Id: I005e74367e2817e9c0acd68207ea3a8c3c011d5f
Reviewed-on: https://chromium-review.googlesource.com/c/1316357Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605419}
parent 05ac99d2
...@@ -48,47 +48,6 @@ NGLogicalOffset NGPhysicalOffset::ConvertToLogical( ...@@ -48,47 +48,6 @@ NGLogicalOffset NGPhysicalOffset::ConvertToLogical(
} }
} }
NGPhysicalOffset NGPhysicalOffset::operator+(
const NGPhysicalOffset& other) const {
return NGPhysicalOffset{this->left + other.left, this->top + other.top};
}
NGPhysicalOffset& NGPhysicalOffset::operator+=(const NGPhysicalOffset& other) {
*this = *this + other;
return *this;
}
NGPhysicalOffset NGPhysicalOffset::operator-(
const NGPhysicalOffset& other) const {
return NGPhysicalOffset{this->left - other.left, this->top - other.top};
}
NGPhysicalOffset& NGPhysicalOffset::operator-=(const NGPhysicalOffset& other) {
*this = *this - other;
return *this;
}
bool NGPhysicalOffset::operator==(const NGPhysicalOffset& other) const {
return other.left == left && other.top == top;
}
NGPhysicalOffset::NGPhysicalOffset(const LayoutPoint& point) {
left = point.X();
top = point.Y();
}
NGPhysicalOffset::NGPhysicalOffset(const LayoutSize& size) {
left = size.Width();
top = size.Height();
}
LayoutPoint NGPhysicalOffset::ToLayoutPoint() const {
return {left, top};
}
LayoutSize NGPhysicalOffset::ToLayoutSize() const {
return {left, top};
}
String NGPhysicalOffset::ToString() const { String NGPhysicalOffset::ToString() const {
return String::Format("%d,%d", left.ToInt(), top.ToInt()); return String::Format("%d,%d", left.ToInt(), top.ToInt());
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#define NGPhysicalOffset_h #define NGPhysicalOffset_h
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/geometry/layout_point.h"
#include "third_party/blink/renderer/platform/geometry/layout_size.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h" #include "third_party/blink/renderer/platform/geometry/layout_unit.h"
#include "third_party/blink/renderer/platform/text/text_direction.h" #include "third_party/blink/renderer/platform/text/text_direction.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h" #include "third_party/blink/renderer/platform/text/writing_mode.h"
...@@ -35,23 +37,41 @@ struct CORE_EXPORT NGPhysicalOffset { ...@@ -35,23 +37,41 @@ struct CORE_EXPORT NGPhysicalOffset {
NGPhysicalSize outer_size, NGPhysicalSize outer_size,
NGPhysicalSize inner_size) const; NGPhysicalSize inner_size) const;
NGPhysicalOffset operator+(const NGPhysicalOffset& other) const; NGPhysicalOffset operator+(const NGPhysicalOffset& other) const {
NGPhysicalOffset& operator+=(const NGPhysicalOffset& other); return NGPhysicalOffset{this->left + other.left, this->top + other.top};
}
NGPhysicalOffset operator-(const NGPhysicalOffset& other) const; NGPhysicalOffset& operator+=(const NGPhysicalOffset& other) {
NGPhysicalOffset& operator-=(const NGPhysicalOffset& other); *this = *this + other;
return *this;
bool operator==(const NGPhysicalOffset& other) const; }
NGPhysicalOffset operator-(const NGPhysicalOffset& other) const {
return NGPhysicalOffset{this->left - other.left, this->top - other.top};
}
NGPhysicalOffset& operator-=(const NGPhysicalOffset& other) {
*this = *this - other;
return *this;
}
bool operator==(const NGPhysicalOffset& other) const {
return other.left == left && other.top == top;
}
// Conversions from/to existing code. New code prefers type safety for // Conversions from/to existing code. New code prefers type safety for
// logical/physical distinctions. // logical/physical distinctions.
explicit NGPhysicalOffset(const LayoutPoint& point); explicit NGPhysicalOffset(const LayoutPoint& point) {
explicit NGPhysicalOffset(const LayoutSize& size); left = point.X();
top = point.Y();
}
explicit NGPhysicalOffset(const LayoutSize& size) {
left = size.Width();
top = size.Height();
}
// Conversions from/to existing code. New code prefers type safety for // Conversions from/to existing code. New code prefers type safety for
// logical/physical distinctions. // logical/physical distinctions.
LayoutPoint ToLayoutPoint() const; LayoutPoint ToLayoutPoint() const { return {left, top}; }
LayoutSize ToLayoutSize() const; LayoutSize ToLayoutSize() const { return {left, top}; }
String ToString() const; String ToString() const;
}; };
......
...@@ -103,8 +103,7 @@ void UpdateLegacyMultiColumnFlowThread( ...@@ -103,8 +103,7 @@ void UpdateLegacyMultiColumnFlowThread(
if (!has_processed_first_child) { if (!has_processed_first_child) {
// The offset of the flow thread should be the same as that of the first // The offset of the flow thread should be the same as that of the first
// first column. // first column.
flow_thread->SetX(child.Offset().left); flow_thread->SetLocation(child.Offset().ToLayoutPoint());
flow_thread->SetY(child.Offset().top);
flow_thread->SetLogicalWidth(child_fragment.InlineSize()); flow_thread->SetLogicalWidth(child_fragment.InlineSize());
column_block_size = child_fragment.BlockSize(); column_block_size = child_fragment.BlockSize();
has_processed_first_child = true; has_processed_first_child = true;
...@@ -510,7 +509,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox( ...@@ -510,7 +509,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
const NGConstraintSpace& constraint_space, const NGConstraintSpace& constraint_space,
const NGLayoutResult& layout_result) { const NGLayoutResult& layout_result) {
DCHECK(layout_result.PhysicalFragment()); DCHECK(layout_result.PhysicalFragment());
if (constraint_space.IsIntermediateLayout()) if (UNLIKELY(constraint_space.IsIntermediateLayout()))
return; return;
const NGPhysicalBoxFragment& physical_fragment = const NGPhysicalBoxFragment& physical_fragment =
...@@ -527,7 +526,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox( ...@@ -527,7 +526,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
// legacy layout doesn't support non-uniform fragmentainer widths. // legacy layout doesn't support non-uniform fragmentainer widths.
LayoutUnit logical_height; LayoutUnit logical_height;
LayoutUnit intrinsic_content_logical_height; LayoutUnit intrinsic_content_logical_height;
if (IsFirstFragment(constraint_space, physical_fragment)) { if (LIKELY(IsFirstFragment(constraint_space, physical_fragment))) {
box_->SetLogicalWidth(fragment_logical_size.inline_size); box_->SetLogicalWidth(fragment_logical_size.inline_size);
} else { } else {
DCHECK_EQ(box_->LogicalWidth(), fragment_logical_size.inline_size) DCHECK_EQ(box_->LogicalWidth(), fragment_logical_size.inline_size)
...@@ -547,7 +546,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox( ...@@ -547,7 +546,7 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
NGBoxStrut padding = fragment.Padding(); NGBoxStrut padding = fragment.Padding();
NGBoxStrut border_scrollbar_padding = borders + scrollbars + padding; NGBoxStrut border_scrollbar_padding = borders + scrollbars + padding;
if (IsLastFragment(physical_fragment)) if (LIKELY(IsLastFragment(physical_fragment)))
intrinsic_content_logical_height -= border_scrollbar_padding.BlockSum(); intrinsic_content_logical_height -= border_scrollbar_padding.BlockSum();
box_->SetLogicalHeight(logical_height); box_->SetLogicalHeight(logical_height);
box_->SetIntrinsicContentLogicalHeight(intrinsic_content_logical_height); box_->SetIntrinsicContentLogicalHeight(intrinsic_content_logical_height);
...@@ -557,11 +556,11 @@ void NGBlockNode::CopyFragmentDataToLayoutBox( ...@@ -557,11 +556,11 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
box_->SetMargin(ComputePhysicalMargins(constraint_space, Style())); box_->SetMargin(ComputePhysicalMargins(constraint_space, Style()));
LayoutMultiColumnFlowThread* flow_thread = GetFlowThread(*box_); LayoutMultiColumnFlowThread* flow_thread = GetFlowThread(*box_);
if (flow_thread) { if (UNLIKELY(flow_thread)) {
PlaceChildrenInFlowThread(constraint_space, physical_fragment); PlaceChildrenInFlowThread(constraint_space, physical_fragment);
} else { } else {
NGPhysicalOffset offset_from_start; NGPhysicalOffset offset_from_start;
if (constraint_space.HasBlockFragmentation()) { if (UNLIKELY(constraint_space.HasBlockFragmentation())) {
// Need to include any block space that this container has used in // Need to include any block space that this container has used in
// previous fragmentainers. The offset of children will be relative to // previous fragmentainers. The offset of children will be relative to
// the container, in flow thread coordinates, i.e. the model where // the container, in flow thread coordinates, i.e. the model where
...@@ -576,16 +575,17 @@ void NGBlockNode::CopyFragmentDataToLayoutBox( ...@@ -576,16 +575,17 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
offset_from_start); offset_from_start);
} }
if (box_->IsLayoutBlock() && IsLastFragment(physical_fragment)) { LayoutBlock* block = ToLayoutBlockOrNull(box_);
LayoutBlock* block = ToLayoutBlock(box_); if (LIKELY(block && IsLastFragment(physical_fragment))) {
LayoutUnit intrinsic_block_size = layout_result.IntrinsicBlockSize(); LayoutUnit intrinsic_block_size = layout_result.IntrinsicBlockSize();
if (constraint_space.HasBlockFragmentation()) { if (UNLIKELY(constraint_space.HasBlockFragmentation())) {
intrinsic_block_size += intrinsic_block_size +=
PreviouslyUsedBlockSpace(constraint_space, physical_fragment); PreviouslyUsedBlockSpace(constraint_space, physical_fragment);
} }
block->LayoutPositionedObjects(/* relayout_children */ false); if (UNLIKELY(block->HasPositionedObjects()))
block->LayoutPositionedObjects(/* relayout_children */ false);
if (flow_thread) { if (UNLIKELY(flow_thread)) {
UpdateLegacyMultiColumnFlowThread(*this, flow_thread, constraint_space, UpdateLegacyMultiColumnFlowThread(*this, flow_thread, constraint_space,
physical_fragment); physical_fragment);
} }
...@@ -600,10 +600,9 @@ void NGBlockNode::CopyFragmentDataToLayoutBox( ...@@ -600,10 +600,9 @@ void NGBlockNode::CopyFragmentDataToLayoutBox(
box_->ClearNeedsLayout(); box_->ClearNeedsLayout();
// Overflow computation depends on this being set. // Overflow computation depends on this being set.
if (box_->IsLayoutBlockFlow()) { LayoutBlockFlow* block_flow = ToLayoutBlockFlowOrNull(box_);
LayoutBlockFlow* block_flow = ToLayoutBlockFlow(box_); if (LIKELY(block_flow))
block_flow->UpdateIsSelfCollapsing(); block_flow->UpdateIsSelfCollapsing();
}
} }
void NGBlockNode::PlaceChildrenInLayoutBox( void NGBlockNode::PlaceChildrenInLayoutBox(
...@@ -701,8 +700,8 @@ void NGBlockNode::CopyChildFragmentPosition( ...@@ -701,8 +700,8 @@ void NGBlockNode::CopyChildFragmentPosition(
horizontal_offset = containing_block->Size().Width() - horizontal_offset - horizontal_offset = containing_block->Size().Width() - horizontal_offset -
fragment.Size().width; fragment.Size().width;
} }
layout_box->SetX(horizontal_offset); layout_box->SetLocation(LayoutPoint(
layout_box->SetY(fragment_offset.top + additional_offset.top); horizontal_offset, fragment_offset.top + additional_offset.top));
// Floats need an associated FloatingObject for painting. // Floats need an associated FloatingObject for painting.
if (IsFloatFragment(fragment) && containing_block->IsLayoutBlockFlow()) { if (IsFloatFragment(fragment) && containing_block->IsLayoutBlockFlow()) {
......
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