Truly independent web browser
UI/Qt: Don't present the page's last frame again only to resize it
Andreas Klingdee505e5c9e7
diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cppindex 7f9759d7783..0ecbcc582c0 100644--- a/UI/Qt/WebContentView.cpp+++ b/UI/Qt/WebContentView.cpp@@ -1128,6 +1128,7 @@ void WebContentView::schedule_repaint(){#if defined(LADYBIRD_QT_USE_VULKAN_WINDOW)m_frame_read_from_gpu = {};+ ++m_page_window_content_serial;schedule_vulkan_window_update();#elif defined(LADYBIRD_QT_USE_IOSURFACE_LAYER)present_current_paintable_as_layer_contents();diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.hindex 3953a806a40..ff1783e3792 100644--- a/UI/Qt/WebContentView.h+++ b/UI/Qt/WebContentView.h@@ -389,6 +389,7 @@ private:void fall_back_to_bitmap_rendering();void vulkan_window_exposure_changed();QRect rect_covered_by_page_window() const;+ bool vulkan_window_update_would_only_resize() const;void remap_unexposed_vulkan_window();VulkanWindow* m_vulkan_window { nullptr };@@ -400,6 +401,9 @@ private: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;+ // Counts the changes to what the page's window shows, so that a present that would only resize it can be skipped.+ u64 m_page_window_content_serial { 0 };+ u64 m_presented_page_window_content_serial { 0 };// 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.cppindex 7e6b6e44002..f2339855a23 100644--- a/UI/Qt/WebContentViewLinux.cpp+++ b/UI/Qt/WebContentViewLinux.cpp@@ -860,6 +860,7 @@ struct WebContentView::VulkanWindowRenderer final : public QVulkanWindowRenderervirtual void startNextFrame() override{m_view.update_vulkan_alpha_blending_support();+ auto content_serial = m_view.m_page_window_content_serial;auto command_buffer = m_window.currentCommandBuffer();auto target_size = m_window.swapChainImageSize();@@ -964,6 +965,7 @@ struct WebContentView::VulkanWindowRenderer final : public QVulkanWindowRendererreturn;}m_view.m_presented_page_window_size = target_size;+ m_view.m_presented_page_window_content_serial = content_serial;}WebContentView& m_view;@@ -1022,6 +1024,11 @@ struct WebContentView::VulkanWindow final : public QVulkanWindow {{if (m_view && m_view->handle_vulkan_window_event(event))return true;+ // NB: Every step of a resize asks to present again, which recreates the swap chain at the new size only to show+ // the same frame in it. Until the page has a frame for the new size, keep the last one on screen. Its+ // surface keeps its size until it presents again, and the view paints the edge it leaves bare.+ if (m_view && event->type() == QEvent::UpdateRequest && m_view->vulkan_window_update_would_only_resize())+ return true;auto handled = QVulkanWindow::event(event);if (m_view && event->type() == QEvent::Expose)m_view->vulkan_window_exposure_changed();@@ -1089,6 +1096,21 @@ void WebContentView::set_vulkan_window_container_visible(bool visible)set_native_window_container_visible(*this, *m_vulkan_window_container, visible);}+bool WebContentView::vulkan_window_update_would_only_resize() const+{+ // NB: Elsewhere, the page's window is opaque wherever it has not presented to, and covers the view's painting.+ if (!m_vulkan_window || m_presented_page_window_size.isEmpty() || QGuiApplication::platformName() != "wayland")+ return false;+ // NB: A frame scaled to fit the view has to be scaled again for its new size.+ if (m_scales_frames_to_fit)+ return false;+ if (m_presented_page_window_content_serial != m_page_window_content_serial)+ return false;+ // NB: The compositor doesn't clip the page's window to the browser window, so a window that shrinks presents again.+ auto size = m_vulkan_window->size() * m_vulkan_window->devicePixelRatio();+ return size != m_presented_page_window_size && size.width() >= m_presented_page_window_size.width() && size.height() >= m_presented_page_window_size.height();+}+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.