Skip to content

Truly independent web browser

UI/Qt: Paint only the part of the view the page's window leaves bare

Andreas Kling8c617c91b778
diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp
index e8055c42b5f..7f9759d7783 100644
--- a/UI/Qt/WebContentView.cpp
+++ b/UI/Qt/WebContentView.cpp
@@ -1216,7 +1216,14 @@ void WebContentView::paintEvent(QPaintEvent*)
}
auto background_color = page_background_color();
- painter.fillRect(QRect(0, 0, m_viewport_size.width(), m_viewport_size.height()), QColor(background_color.red(), background_color.green(), background_color.blue()));
+ QRegion background { QRect(0, 0, m_viewport_size.width(), m_viewport_size.height()) };
+# ifdef LADYBIRD_QT_USE_VULKAN_WINDOW
+ // NB: Filling the part of the widget under the page's window would only touch memory that nobody sees. During a
+ // resize, that is most of a window-sized buffer at every step.
+ background -= rect_covered_by_page_window();
+# endif
+ for (auto const& rect : background)
+ painter.fillRect(rect, QColor(background_color.red(), background_color.green(), background_color.blue()));
}
#endif
diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.h
index 4dc72fa66e5..3953a806a40 100644
--- a/UI/Qt/WebContentView.h
+++ b/UI/Qt/WebContentView.h
@@ -388,6 +388,7 @@ private:
void set_vulkan_window_container_visible(bool);
void fall_back_to_bitmap_rendering();
void vulkan_window_exposure_changed();
+ QRect rect_covered_by_page_window() const;
void remap_unexposed_vulkan_window();
VulkanWindow* m_vulkan_window { nullptr };
@@ -397,6 +398,8 @@ private:
QTimer m_unexposed_vulkan_window_timer;
// Waits for the browser window to be exposed again, before the page's window is mapped again.
QObject* m_top_level_expose_watcher { nullptr };
+ // The size of the page's last frame on screen, in device pixels.
+ QSize m_presented_page_window_size;
// The pixels of the frame on screen, read back from GPU memory once for each frame that Qt paints itself.
struct FrameReadFromGpu {
diff --git a/UI/Qt/WebContentViewLinux.cpp b/UI/Qt/WebContentViewLinux.cpp
index 056bc315719..7e6b6e44002 100644
--- a/UI/Qt/WebContentViewLinux.cpp
+++ b/UI/Qt/WebContentViewLinux.cpp
@@ -959,8 +959,11 @@ struct WebContentView::VulkanWindowRenderer final : public QVulkanWindowRenderer
vkCmdEndRenderPass(command_buffer);
m_window.frameReady();
- if (!rendered)
+ if (!rendered) {
m_view.fall_back_to_bitmap_rendering();
+ return;
+ }
+ m_view.m_presented_page_window_size = target_size;
}
WebContentView& m_view;
@@ -1080,10 +1083,22 @@ bool WebContentView::vulkan_window_has_native_focus() const
void WebContentView::set_vulkan_window_container_visible(bool visible)
{
+ if (!visible)
+ m_presented_page_window_size = {};
if (m_vulkan_window_container)
set_native_window_container_visible(*this, *m_vulkan_window_container, visible);
}
+QRect WebContentView::rect_covered_by_page_window() const
+{
+ // NB: Hover-expanded chrome punches strips out of the page's window, and the page shows through them.
+ if (!m_vulkan_window_container || !m_vulkan_window_container->isVisible())
+ return {};
+ if (m_vertical_tab_overlay_left != 0 || m_vertical_tab_overlay_right != 0 || m_bookmarks_bar_overlay_height != 0)
+ return {};
+ return { QPoint { 0, 0 }, m_presented_page_window_size };
+}
+
void WebContentView::vulkan_window_exposure_changed()
{
if (!m_vulkan_window)