1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

LibWeb: Apply scroll boxes offsets after painting commands recording

With this change, instead of applying scroll offsets during the
recording of the painting command list, we do the following:
1. Collect all boxes with scrollable overflow into a PaintContext,
   each with an id and the total amount of scrolling offset accumulated
   from ancestor scrollable boxes.
2. During the recording phase assign a corresponding scroll_frame_id to
   each command that paints content within a scrollable box.
3. Before executing the recorded commands, translate each command that
   has a scroll_frame_id by the accumulated scroll offset.

This approach has following advantages:
- Implementing nested scrollables becomes much simpler, as the
  recording phase only requires the correct assignment of the nearest
  scrollable's scroll_frame_id, while the accumulated offset from
  ancestors is applied subsequently.
- The recording of painting commands is not tied to a specific offset
  within scrollable boxes, which means in the future, it will be
  possible to update the scrolling offset and repaint without the need
  to re-record painting commands.
This commit is contained in:
Aliaksandr Kalenik 2023-12-29 06:10:32 +01:00 committed by Andreas Kling
parent d3025668a4
commit ac6b3c989d
12 changed files with 307 additions and 24 deletions

View file

@ -188,8 +188,16 @@ void PageClient::paint(Web::DevicePixelRect const& content_rect, Gfx::Bitmap& ta
context.set_should_paint_overlay(paint_options.paint_overlay == Web::PaintOptions::PaintOverlay::Yes);
context.set_device_viewport_rect(content_rect);
context.set_has_focus(m_has_focus);
document->paintable()->collect_scroll_frames(context);
document->paintable()->paint_all_phases(context);
Vector<Gfx::IntPoint> scroll_offsets_by_frame_id;
scroll_offsets_by_frame_id.resize(context.scroll_frames().size());
for (auto [_, scrollable_frame] : context.scroll_frames())
scroll_offsets_by_frame_id[scrollable_frame.id] = context.rounded_device_point(scrollable_frame.offset).to_type<int>();
recording_painter.apply_scroll_offsets(scroll_offsets_by_frame_id);
if (s_use_gpu_painter) {
#ifdef HAS_ACCELERATED_GRAPHICS
Web::Painting::PaintingCommandExecutorGPU painting_command_executor(*m_accelerated_graphics_context, target);