1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:08:12 +00:00

LibWebView+WebContent: Drive repainting from WebContent process

With this change, chrome no longer has to ask the WebContent process
to paint the next frame into a specified bitmap. Instead, it allocates
bitmaps and sends them to WebContent, which then lets chrome know when
the painting is done.

This work is a preparation to move the execution of painting commands
into a separate thread. Now, it is much easier to start working on the
next frame while the current one is still rendering. This is because
WebContent does not have to inform chrome that the current frame is
ready before it can request the next frame.

Additionally, as a side bonus, we can now eliminate the
did_invalidate_content_rect and did_change_selection IPC calls. These
were used solely for the purpose of informing chrome that it needed to
request a repaint.
This commit is contained in:
Aliaksandr Kalenik 2023-12-21 22:58:54 +01:00 committed by Andreas Kling
parent ac63d1e59d
commit 02936f6944
17 changed files with 68 additions and 152 deletions

View file

@ -50,36 +50,16 @@ WebContentClient const& ViewImplementation::client() const
void ViewImplementation::server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize size)
{
if (m_client_state.back_bitmap.id != bitmap_id)
return;
m_client_state.has_usable_bitmap = true;
m_client_state.back_bitmap.pending_paints--;
m_client_state.back_bitmap.last_painted_size = size.to_type<Web::DevicePixels>();
swap(m_client_state.back_bitmap, m_client_state.front_bitmap);
// We don't need the backup bitmap anymore, so drop it.
m_backup_bitmap = nullptr;
if (on_ready_to_paint)
on_ready_to_paint();
if (m_client_state.got_repaint_requests_while_painting) {
m_client_state.got_repaint_requests_while_painting = false;
request_repaint();
if (m_client_state.back_bitmap.id == bitmap_id) {
m_client_state.has_usable_bitmap = true;
m_client_state.back_bitmap.last_painted_size = size.to_type<Web::DevicePixels>();
swap(m_client_state.back_bitmap, m_client_state.front_bitmap);
m_backup_bitmap = nullptr;
if (on_ready_to_paint)
on_ready_to_paint();
}
}
void ViewImplementation::server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect)
{
request_repaint();
}
void ViewImplementation::server_did_change_selection(Badge<WebContentClient>)
{
request_repaint();
}
void ViewImplementation::load(AK::URL const& url)
{
m_url = url;
@ -322,16 +302,14 @@ void ViewImplementation::resize_backing_stores_if_needed(WindowResizeInProgress
m_client_state.back_bitmap = {};
}
auto old_front_bitmap_id = m_client_state.front_bitmap.id;
auto old_back_bitmap_id = m_client_state.back_bitmap.id;
auto reallocate_backing_store_if_needed = [&](SharedBitmap& backing_store) {
if (!backing_store.bitmap || !backing_store.bitmap->size().contains(minimum_needed_size.to_type<int>())) {
if (auto new_bitmap_or_error = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRA8888, minimum_needed_size.to_type<int>()); !new_bitmap_or_error.is_error()) {
if (backing_store.bitmap)
client().async_remove_backing_store(backing_store.id);
backing_store.pending_paints = 0;
backing_store.bitmap = new_bitmap_or_error.release_value();
backing_store.id = m_client_state.next_bitmap_id++;
client().async_add_backing_store(backing_store.id, backing_store.bitmap->to_shareable_bitmap());
}
backing_store.last_painted_size = viewport_rect.size();
}
@ -340,22 +318,11 @@ void ViewImplementation::resize_backing_stores_if_needed(WindowResizeInProgress
reallocate_backing_store_if_needed(m_client_state.front_bitmap);
reallocate_backing_store_if_needed(m_client_state.back_bitmap);
request_repaint();
}
auto& front_bitmap = m_client_state.front_bitmap;
auto& back_bitmap = m_client_state.back_bitmap;
void ViewImplementation::request_repaint()
{
// If this widget was instantiated but not yet added to a window,
// it won't have a back bitmap yet, so we can just skip repaint requests.
if (!m_client_state.back_bitmap.bitmap)
return;
// Don't request a repaint until pending paint requests have finished.
if (m_client_state.back_bitmap.pending_paints) {
m_client_state.got_repaint_requests_while_painting = true;
return;
}
m_client_state.back_bitmap.pending_paints++;
client().async_paint(viewport_rect(), m_client_state.back_bitmap.id);
if (front_bitmap.id != old_front_bitmap_id || back_bitmap.id != old_back_bitmap_id)
client().async_add_backing_store(front_bitmap.id, front_bitmap.bitmap->to_shareable_bitmap(), back_bitmap.id, back_bitmap.bitmap->to_shareable_bitmap());
}
void ViewImplementation::handle_web_content_process_crash()