LibWeb: Remove ViewportPaintable::refresh_clip_frames()

After d0da377767 clip frame state is no
longer depends on scroll state, so it could be calculated only once for
each layout invalidation.
This commit is contained in:
Aliaksandr Kalenik 2024-08-14 23:17:10 +02:00 committed by Andreas Kling
commit dc0d5da086
Notes: github-actions[bot] 2024-08-15 11:45:45 +00:00
8 changed files with 23 additions and 50 deletions

View file

@ -1157,6 +1157,9 @@ void Document::update_layout()
set_needs_to_resolve_paint_only_properties();
paintable()->assign_scroll_frames();
// assign_clip_frames() needs border-radius be resolved
update_paint_and_hit_testing_properties_if_needed();
paintable()->assign_clip_frames();
if (navigable->is_traversable()) {
@ -5196,12 +5199,6 @@ void Document::process_top_layer_removals()
}
}
void Document::set_needs_to_refresh_clip_state(bool b)
{
if (auto* paintable = this->paintable())
paintable->set_needs_to_refresh_clip_state(b);
}
void Document::set_needs_to_refresh_scroll_state(bool b)
{
if (auto* paintable = this->paintable())

View file

@ -482,7 +482,6 @@ public:
bool needs_full_style_update() const { return m_needs_full_style_update; }
void set_needs_full_style_update(bool b) { m_needs_full_style_update = b; }
void set_needs_to_refresh_clip_state(bool b);
void set_needs_to_refresh_scroll_state(bool b);
bool has_active_favicon() const { return m_active_favicon; }

View file

@ -2014,7 +2014,6 @@ void Navigable::perform_scroll_of_viewport(CSSPixelPoint new_position)
if (auto document = active_document()) {
document->set_needs_to_refresh_scroll_state(true);
document->set_needs_to_refresh_clip_state(true);
document->inform_all_viewport_clients_about_the_current_viewport_rect();
}
}
@ -2121,7 +2120,6 @@ RefPtr<Painting::DisplayList> Navigable::record_display_list(PaintConfig config)
auto& viewport_paintable = *document->paintable();
viewport_paintable.refresh_scroll_state();
viewport_paintable.refresh_clip_state();
viewport_paintable.paint_all_phases(context);

View file

@ -19,11 +19,6 @@ void ClipFrame::add_clip_rect(CSSPixelRect rect, BorderRadiiData radii, RefPtr<S
m_clip_rects.append({ rect, radii, move(enclosing_scroll_frame) });
}
void ClipFrame::clear_rects()
{
m_clip_rects.clear_with_capacity();
}
CSSPixelRect ClipFrame::clip_rect_for_hit_testing() const
{
VERIFY(!m_clip_rects.is_empty());

View file

@ -21,7 +21,6 @@ struct ClipRectWithScrollFrame {
struct ClipFrame : public RefCounted<ClipFrame> {
Vector<ClipRectWithScrollFrame> const& clip_rects() const { return m_clip_rects; }
void add_clip_rect(CSSPixelRect rect, BorderRadiiData radii, RefPtr<ScrollFrame const> enclosing_scroll_frame);
void clear_rects();
CSSPixelRect clip_rect_for_hit_testing() const;

View file

@ -81,7 +81,6 @@ void PaintableBox::set_scroll_offset(CSSPixelPoint offset)
if (!scrollable_overflow_rect.has_value())
return;
document().set_needs_to_refresh_clip_state(true);
document().set_needs_to_refresh_scroll_state(true);
auto padding_rect = absolute_padding_box_rect();
@ -820,7 +819,6 @@ TraversalDecision PaintableBox::hit_test(CSSPixelPoint position, HitTestType typ
viewport_paintable.build_stacking_context_tree_if_needed();
viewport_paintable.document().update_paint_and_hit_testing_properties_if_needed();
viewport_paintable.refresh_scroll_state();
viewport_paintable.refresh_clip_state();
return stacking_context()->hit_test(position, type, callback);
}

View file

@ -135,6 +135,26 @@ void ViewportPaintable::assign_clip_frames()
}
return TraversalDecision::Continue;
});
for (auto& it : clip_state) {
auto const& paintable_box = *it.key;
auto& clip_frame = *it.value;
for (auto const* block = &paintable_box.layout_box(); !block->is_viewport(); block = block->containing_block()) {
auto const& block_paintable_box = *block->paintable_box();
auto block_overflow_x = block_paintable_box.computed_values().overflow_x();
auto block_overflow_y = block_paintable_box.computed_values().overflow_y();
if (block_overflow_x != CSS::Overflow::Visible && block_overflow_y != CSS::Overflow::Visible) {
auto rect = block_paintable_box.absolute_padding_box_rect();
clip_frame.add_clip_rect(rect, block_paintable_box.normalized_border_radii_data(ShrinkRadiiForBorders::Yes), block_paintable_box.enclosing_scroll_frame());
}
if (auto css_clip_property_rect = block->paintable_box()->get_clip_rect(); css_clip_property_rect.has_value()) {
clip_frame.add_clip_rect(css_clip_property_rect.value(), {}, block_paintable_box.enclosing_scroll_frame());
}
if (block->has_css_transform()) {
break;
}
}
}
}
void ViewportPaintable::refresh_scroll_state()
@ -157,36 +177,6 @@ void ViewportPaintable::refresh_scroll_state()
}
}
void ViewportPaintable::refresh_clip_state()
{
if (!m_needs_to_refresh_clip_state)
return;
m_needs_to_refresh_clip_state = false;
for (auto& it : clip_state) {
auto const& paintable_box = *it.key;
auto& clip_frame = *it.value;
clip_frame.clear_rects();
for (auto const* block = &paintable_box.layout_box(); !block->is_viewport(); block = block->containing_block()) {
auto const& block_paintable_box = *block->paintable_box();
auto block_overflow_x = block_paintable_box.computed_values().overflow_x();
auto block_overflow_y = block_paintable_box.computed_values().overflow_y();
if (block_overflow_x != CSS::Overflow::Visible && block_overflow_y != CSS::Overflow::Visible) {
auto rect = block_paintable_box.absolute_padding_box_rect();
clip_frame.add_clip_rect(rect, block_paintable_box.normalized_border_radii_data(ShrinkRadiiForBorders::Yes), block_paintable_box.enclosing_scroll_frame());
}
if (auto css_clip_property_rect = block->paintable_box()->get_clip_rect(); css_clip_property_rect.has_value()) {
clip_frame.add_clip_rect(css_clip_property_rect.value(), {}, block_paintable_box.enclosing_scroll_frame());
}
if (block->has_css_transform()) {
break;
}
}
}
}
void ViewportPaintable::resolve_paint_only_properties()
{
// Resolves layout-dependent properties not handled during layout and stores them in the paint tree.

View file

@ -27,7 +27,6 @@ public:
HashMap<JS::GCPtr<PaintableBox const>, RefPtr<ClipFrame>> clip_state;
void assign_clip_frames();
void refresh_clip_state();
void resolve_paint_only_properties();
@ -36,7 +35,6 @@ public:
bool handle_mousewheel(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned, int wheel_delta_x, int wheel_delta_y) override;
void set_needs_to_refresh_clip_state(bool value) { m_needs_to_refresh_clip_state = value; }
void set_needs_to_refresh_scroll_state(bool value) { m_needs_to_refresh_scroll_state = value; }
private:
@ -46,7 +44,6 @@ private:
virtual void visit_edges(Visitor&) override;
bool m_needs_to_refresh_clip_state { true };
bool m_needs_to_refresh_scroll_state { true };
};