From c2c007b356e62044e8b7dcea71bd2ad559570248 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 17 Sep 2021 14:54:51 +0200 Subject: [PATCH] LibWeb: Don't request WebContent repaint while we have repaints pending This prevents flickering by ensuring that WebContent is only ever painting into the back buffer bitmap. Without this change, it was possible for WebContent to paint into the front buffer bitmap. --- .../Libraries/LibWeb/OutOfProcessWebView.cpp | 17 +++++++++-------- Userland/Libraries/LibWeb/OutOfProcessWebView.h | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index 0ad119df66..4bf06133d5 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -128,18 +128,14 @@ void OutOfProcessWebView::handle_resize() m_backup_bitmap = m_client_state.front_bitmap.bitmap; } - if (m_client_state.front_bitmap.bitmap) { - m_client_state.front_bitmap.bitmap = nullptr; + if (m_client_state.front_bitmap.bitmap) client().async_remove_backing_store(m_client_state.front_bitmap.id); - } - if (m_client_state.back_bitmap.bitmap) { - m_client_state.back_bitmap.bitmap = nullptr; + if (m_client_state.back_bitmap.bitmap) client().async_remove_backing_store(m_client_state.back_bitmap.id); - } - m_client_state.front_bitmap.id = -1; - m_client_state.back_bitmap.id = -1; + m_client_state.front_bitmap = {}; + m_client_state.back_bitmap = {}; m_client_state.has_usable_bitmap = false; if (available_size().is_empty()) @@ -201,6 +197,7 @@ void OutOfProcessWebView::notify_server_did_paint(Badge, i32 b { if (m_client_state.back_bitmap.id == bitmap_id) { m_client_state.has_usable_bitmap = true; + m_client_state.back_bitmap.pending_paints--; 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; @@ -396,6 +393,10 @@ void OutOfProcessWebView::request_repaint() // 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) + return; + m_client_state.back_bitmap.pending_paints++; client().async_paint(m_client_state.back_bitmap.bitmap->rect().translated(horizontal_scrollbar().value(), vertical_scrollbar().value()), m_client_state.back_bitmap.id); } diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h index 49a74c3f9c..9e70436725 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h @@ -112,6 +112,7 @@ private: struct SharedBitmap { i32 id { -1 }; + i32 pending_paints { 0 }; RefPtr bitmap; };