Commit 3fc2105e authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Optimize visual overflow computation code by devirtualizing some methods.

Before this patch, ComputeVisualOverflow() was virtual, and so was
AddVisualOverflowFromChildren(), which was called by
ComputeVisualOverflow(). This pattern existed to share a bit more
code with LayoutBlock other than the code to collect rects from
children. This CL instead inlines the duplicated code in a few places
and de-virtualizes AddVisualOverflowFromChildren.

Bug: 894244

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: Ic9e36c0271ac6d88ee660e9113e1a2b7db8e0148
Reviewed-on: https://chromium-review.googlesource.com/c/1281234Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600156}
parent 9dd0a84e
...@@ -449,11 +449,11 @@ class CORE_EXPORT LayoutBlock : public LayoutBox { ...@@ -449,11 +449,11 @@ class CORE_EXPORT LayoutBlock : public LayoutBox {
private: private:
void AddVisualOverflowFromBlockChildren(); void AddVisualOverflowFromBlockChildren();
void AddVisualOverflowFromTheme();
void AddLayoutOverflowFromPositionedObjects(); void AddLayoutOverflowFromPositionedObjects();
void AddLayoutOverflowFromBlockChildren(); void AddLayoutOverflowFromBlockChildren();
protected: protected:
void AddVisualOverflowFromTheme();
virtual void ComputeVisualOverflow( virtual void ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect, const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats); bool recompute_floats);
...@@ -461,7 +461,7 @@ class CORE_EXPORT LayoutBlock : public LayoutBox { ...@@ -461,7 +461,7 @@ class CORE_EXPORT LayoutBlock : public LayoutBox {
bool recompute_floats); bool recompute_floats);
virtual void AddLayoutOverflowFromChildren(); virtual void AddLayoutOverflowFromChildren();
virtual void AddVisualOverflowFromChildren(); void AddVisualOverflowFromChildren();
void AddOutlineRects(Vector<LayoutRect>&, void AddOutlineRects(Vector<LayoutRect>&,
const LayoutPoint& additional_offset, const LayoutPoint& additional_offset,
......
...@@ -2566,11 +2566,20 @@ void LayoutBlockFlow::UpdatePaintFragmentFromCachedLayoutResult( ...@@ -2566,11 +2566,20 @@ void LayoutBlockFlow::UpdatePaintFragmentFromCachedLayoutResult(
void LayoutBlockFlow::ComputeVisualOverflow( void LayoutBlockFlow::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect, const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) { bool recompute_floats) {
LayoutBlock::ComputeVisualOverflow(previous_visual_overflow_rect, AddVisualOverflowFromChildren();
recompute_floats);
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (recompute_floats || CreatesNewFormattingContext() || if (recompute_floats || CreatesNewFormattingContext() ||
HasSelfPaintingLayer()) HasSelfPaintingLayer())
AddVisualOverflowFromFloats(); AddVisualOverflowFromFloats();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
} }
void LayoutBlockFlow::ComputeLayoutOverflow(LayoutUnit old_client_after_edge, void LayoutBlockFlow::ComputeLayoutOverflow(LayoutUnit old_client_after_edge,
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/layout/layout_list_marker.h" #include "third_party/blink/renderer/core/layout/layout_list_marker.h"
#include "third_party/blink/renderer/core/paint/list_item_painter.h" #include "third_party/blink/renderer/core/paint/list_item_painter.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/platform/wtf/saturated_arithmetic.h" #include "third_party/blink/renderer/platform/wtf/saturated_arithmetic.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
...@@ -289,6 +290,25 @@ bool LayoutListItem::UpdateMarkerLocation() { ...@@ -289,6 +290,25 @@ bool LayoutListItem::UpdateMarkerLocation() {
return false; return false;
} }
void LayoutListItem::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (recompute_floats || CreatesNewFormattingContext() ||
HasSelfPaintingLayer())
AddVisualOverflowFromFloats();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
void LayoutListItem::AddVisualOverflowFromChildren() { void LayoutListItem::AddVisualOverflowFromChildren() {
LayoutBlockFlow::AddVisualOverflowFromChildren(); LayoutBlockFlow::AddVisualOverflowFromChildren();
UpdateOverflow(Visual); UpdateOverflow(Visual);
......
...@@ -70,7 +70,9 @@ class LayoutListItem final : public LayoutBlockFlow { ...@@ -70,7 +70,9 @@ class LayoutListItem final : public LayoutBlockFlow {
void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override; void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
void AddVisualOverflowFromChildren() override; void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) final;
void AddVisualOverflowFromChildren();
void AddLayoutOverflowFromChildren() override; void AddLayoutOverflowFromChildren() override;
void AlignMarkerInBlockDirection(); void AlignMarkerInBlockDirection();
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/core/layout/layout_multi_column_flow_thread.h" #include "third_party/blink/renderer/core/layout/layout_multi_column_flow_thread.h"
#include "third_party/blink/renderer/core/layout/multi_column_fragmentainer_group.h" #include "third_party/blink/renderer/core/layout/multi_column_fragmentainer_group.h"
#include "third_party/blink/renderer/core/paint/multi_column_set_painter.h" #include "third_party/blink/renderer/core/paint/multi_column_set_painter.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
namespace blink { namespace blink {
...@@ -520,6 +521,25 @@ LayoutRect LayoutMultiColumnSet::FragmentsBoundingBox( ...@@ -520,6 +521,25 @@ LayoutRect LayoutMultiColumnSet::FragmentsBoundingBox(
return result; return result;
} }
void LayoutMultiColumnSet::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (recompute_floats || CreatesNewFormattingContext() ||
HasSelfPaintingLayer())
AddVisualOverflowFromFloats();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
void LayoutMultiColumnSet::AddVisualOverflowFromChildren() { void LayoutMultiColumnSet::AddVisualOverflowFromChildren() {
// It's useless to calculate overflow if we haven't determined the page // It's useless to calculate overflow if we haven't determined the page
// logical height yet. // logical height yet.
......
...@@ -255,7 +255,9 @@ class CORE_EXPORT LayoutMultiColumnSet : public LayoutBlockFlow { ...@@ -255,7 +255,9 @@ class CORE_EXPORT LayoutMultiColumnSet : public LayoutBlockFlow {
void PaintObject(const PaintInfo&, void PaintObject(const PaintInfo&,
const LayoutPoint& paint_offset) const override; const LayoutPoint& paint_offset) const override;
void AddVisualOverflowFromChildren() override; void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) final;
void AddVisualOverflowFromChildren();
void AddLayoutOverflowFromChildren() override; void AddLayoutOverflowFromChildren() override;
MultiColumnFragmentainerGroupList fragmentainer_groups_; MultiColumnFragmentainerGroupList fragmentainer_groups_;
......
...@@ -910,6 +910,21 @@ void LayoutTable::InvalidateCollapsedBordersForAllCellsIfNeeded() { ...@@ -910,6 +910,21 @@ void LayoutTable::InvalidateCollapsedBordersForAllCellsIfNeeded() {
} }
} }
void LayoutTable::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
void LayoutTable::AddVisualOverflowFromChildren() { void LayoutTable::AddVisualOverflowFromChildren() {
// Add overflow from borders. // Add overflow from borders.
// Technically it's odd that we are incorporating the borders into layout // Technically it's odd that we are incorporating the borders into layout
......
...@@ -474,7 +474,9 @@ class CORE_EXPORT LayoutTable final : public LayoutBlock { ...@@ -474,7 +474,9 @@ class CORE_EXPORT LayoutTable final : public LayoutBlock {
OverlayScrollbarClipBehavior = OverlayScrollbarClipBehavior =
kIgnorePlatformOverlayScrollbarSize) const override; kIgnorePlatformOverlayScrollbarSize) const override;
void AddVisualOverflowFromChildren() override; void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) final;
void AddVisualOverflowFromChildren();
void AddLayoutOverflowFromChildren() override; void AddLayoutOverflowFromChildren() override;
void RecalcSections() const; void RecalcSections() const;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "third_party/blink/renderer/core/layout/hit_test_result.h" #include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_analyzer.h" #include "third_party/blink/renderer/core/layout/layout_analyzer.h"
#include "third_party/blink/renderer/core/layout/layout_theme.h" #include "third_party/blink/renderer/core/layout/layout_theme.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/text_control_single_line_painter.h" #include "third_party/blink/renderer/core/paint/text_control_single_line_painter.h"
#include "third_party/blink/renderer/platform/fonts/simple_font_data.h" #include "third_party/blink/renderer/platform/fonts/simple_font_data.h"
...@@ -317,4 +318,23 @@ HTMLInputElement* LayoutTextControlSingleLine::InputElement() const { ...@@ -317,4 +318,23 @@ HTMLInputElement* LayoutTextControlSingleLine::InputElement() const {
return ToHTMLInputElement(GetNode()); return ToHTMLInputElement(GetNode());
} }
void LayoutTextControlSingleLine::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
AddVisualOverflowFromChildren();
AddVisualEffectOverflow();
AddVisualOverflowFromTheme();
if (recompute_floats || CreatesNewFormattingContext() ||
HasSelfPaintingLayer())
AddVisualOverflowFromFloats();
if (VisualOverflowRect() != previous_visual_overflow_rect) {
if (Layer())
Layer()->SetNeedsCompositingInputsUpdate();
GetFrameView()->SetIntersectionObservationState(LocalFrameView::kDesired);
}
}
} // namespace blink } // namespace blink
...@@ -78,10 +78,11 @@ class LayoutTextControlSingleLine : public LayoutTextControl { ...@@ -78,10 +78,11 @@ class LayoutTextControlSingleLine : public LayoutTextControl {
LayoutUnit line_height, LayoutUnit line_height,
LayoutUnit non_content_height) const override; LayoutUnit non_content_height) const override;
void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) override;
// If the INPUT content height is smaller than the font height, the // If the INPUT content height is smaller than the font height, the
// inner-editor element overflows the INPUT box intentionally, however it // inner-editor element overflows the INPUT box intentionally, however it
// shouldn't affect outside of the INPUT box. So we ignore child overflow. // shouldn't affect outside of the INPUT box. So we ignore child overflow.
void AddVisualOverflowFromChildren() final {}
void AddLayoutOverflowFromChildren() final {} void AddLayoutOverflowFromChildren() final {}
bool AllowsOverflowClip() const override { return false; } bool AllowsOverflowClip() const override { return false; }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "third_party/blink/renderer/core/layout/ng/ng_relative_utils.h" #include "third_party/blink/renderer/core/layout/ng/ng_relative_utils.h"
#include "third_party/blink/renderer/core/paint/ng/ng_block_flow_painter.h" #include "third_party/blink/renderer/core/paint/ng/ng_block_flow_painter.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h" #include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
namespace blink { namespace blink {
...@@ -65,6 +66,21 @@ const NGPhysicalBoxFragment* LayoutNGMixin<Base>::CurrentFragment() const { ...@@ -65,6 +66,21 @@ const NGPhysicalBoxFragment* LayoutNGMixin<Base>::CurrentFragment() const {
return nullptr; return nullptr;
} }
template <typename Base>
void LayoutNGMixin<Base>::ComputeVisualOverflow(
const LayoutRect& previous_visual_overflow_rect,
bool recompute_floats) {
Base::ComputeVisualOverflow(previous_visual_overflow_rect, recompute_floats);
AddVisualOverflowFromChildren();
if (Base::VisualOverflowRect() != previous_visual_overflow_rect) {
if (Base::Layer())
Base::Layer()->SetNeedsCompositingInputsUpdate();
Base::GetFrameView()->SetIntersectionObservationState(
LocalFrameView::kDesired);
}
}
template <typename Base> template <typename Base>
void LayoutNGMixin<Base>::AddVisualOverflowFromChildren() { void LayoutNGMixin<Base>::AddVisualOverflowFromChildren() {
// |ComputeOverflow()| calls this, which is called from // |ComputeOverflow()| calls this, which is called from
......
...@@ -83,7 +83,9 @@ class LayoutNGMixin : public Base { ...@@ -83,7 +83,9 @@ class LayoutNGMixin : public Base {
protected: protected:
bool IsOfType(LayoutObject::LayoutObjectType) const override; bool IsOfType(LayoutObject::LayoutObjectType) const override;
void AddVisualOverflowFromChildren() final; void ComputeVisualOverflow(const LayoutRect&, bool recompute_floats) final;
void AddVisualOverflowFromChildren();
void AddLayoutOverflowFromChildren() final; void AddLayoutOverflowFromChildren() final;
private: private:
......
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