mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:47:35 +00:00
LibWeb: Optimize scroll offset and clip state recalculation
In this commit we have optimized the handling of scroll offsets and clip rectangles to improve performance. Previously, the process involved multiple full traversals of the paintable tree before each repaint, which was highly inefficient, especially on pages with a large number of paintables. The steps were: 1. Traverse the paintable tree to identify all boxes with scrollable or clipped overflow. 2. Gather the accumulated scroll offset or clip rectangle for each box. 3. Perform another traversal to apply the corresponding scroll offset and clip rectangle to each paintable. To address this, we've adopted a new strategy that separates the assignment of the scroll/clip frame from the refresh of accumulated scroll offsets and clip rectangles, thus reducing the workload: 1. Post-relayout: Identify all boxes with overflow and link each paintable to the state of its containing scroll/clip frame. 2. Pre-repaint: Update the clip rectangle and scroll offset only in the previously identified boxes. This adjustment ensures that the costly tree traversals are only necessary after a relayout, substantially decreasing the amount of work required before each repaint.
This commit is contained in:
parent
fc40d35012
commit
76d1536307
8 changed files with 189 additions and 104 deletions
|
@ -14,6 +14,16 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
struct ScrollFrame : public RefCounted<ScrollFrame> {
|
||||
i32 id { -1 };
|
||||
CSSPixelPoint offset;
|
||||
};
|
||||
|
||||
struct ClipFrame : public RefCounted<ClipFrame> {
|
||||
CSSPixelRect rect;
|
||||
Optional<BorderRadiiData> corner_clip_radii;
|
||||
};
|
||||
|
||||
class PaintableBox : public Paintable {
|
||||
JS_CELL(PaintableBox, Paintable);
|
||||
|
||||
|
@ -193,14 +203,13 @@ public:
|
|||
|
||||
Optional<CSSPixelRect> get_clip_rect() const;
|
||||
|
||||
void set_clip_rect(Optional<CSSPixelRect> rect) { m_clip_rect = rect; }
|
||||
void set_scroll_frame_id(int id) { m_scroll_frame_id = id; }
|
||||
void set_enclosing_scroll_frame_offset(CSSPixelPoint offset) { m_enclosing_scroll_frame_offset = offset; }
|
||||
void set_corner_clip_radii(BorderRadiiData const& corner_radii) { m_corner_clip_radii = corner_radii; }
|
||||
void set_enclosing_scroll_frame(RefPtr<ScrollFrame> scroll_frame) { m_enclosing_scroll_frame = scroll_frame; }
|
||||
void set_enclosing_clip_frame(RefPtr<ClipFrame> clip_frame) { m_enclosing_clip_frame = clip_frame; }
|
||||
|
||||
Optional<int> scroll_frame_id() const { return m_scroll_frame_id; }
|
||||
Optional<CSSPixelPoint> enclosing_scroll_frame_offset() const { return m_enclosing_scroll_frame_offset; }
|
||||
Optional<CSSPixelRect> clip_rect() const { return m_clip_rect; }
|
||||
Optional<int> scroll_frame_id() const;
|
||||
Optional<CSSPixelPoint> enclosing_scroll_frame_offset() const;
|
||||
Optional<CSSPixelRect> clip_rect() const;
|
||||
Optional<BorderRadiiData> corner_clip_radii() const;
|
||||
|
||||
protected:
|
||||
explicit PaintableBox(Layout::Box const&);
|
||||
|
@ -227,10 +236,8 @@ private:
|
|||
mutable bool m_clipping_overflow { false };
|
||||
mutable Optional<u32> m_corner_clipper_id;
|
||||
|
||||
Optional<CSSPixelRect> m_clip_rect;
|
||||
Optional<int> m_scroll_frame_id;
|
||||
Optional<CSSPixelPoint> m_enclosing_scroll_frame_offset;
|
||||
Optional<BorderRadiiData> m_corner_clip_radii;
|
||||
RefPtr<ScrollFrame const> m_enclosing_scroll_frame;
|
||||
RefPtr<ClipFrame const> m_enclosing_clip_frame;
|
||||
|
||||
Optional<BordersDataWithElementKind> m_override_borders_data;
|
||||
Optional<TableCellCoordinates> m_table_cell_coordinates;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue