Truly independent web browser
UI/Qt: Map the page's window again when Wayland leaves it unexposed
Andreas Klinga3a5ce0320a2
diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.hindex 8c1d70c660a..4dc72fa66e5 100644--- a/UI/Qt/WebContentView.h+++ b/UI/Qt/WebContentView.h@@ -387,10 +387,16 @@ private:bool vulkan_window_has_native_focus() const;void set_vulkan_window_container_visible(bool);void fall_back_to_bitmap_rendering();+ void vulkan_window_exposure_changed();+ void remap_unexposed_vulkan_window();VulkanWindow* m_vulkan_window { nullptr };QWidget* m_vulkan_window_container { nullptr };Optional<bool> m_vulkan_window_supports_alpha_blending;+ bool m_remapped_unexposed_vulkan_window { false };+ 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 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 07ba6a852af..56d154ed4c5 100644--- a/UI/Qt/WebContentViewLinux.cpp+++ b/UI/Qt/WebContentViewLinux.cpp@@ -968,6 +968,33 @@ struct WebContentView::VulkanWindowRenderer final : public QVulkanWindowRendererVulkanRenderer m_renderer;};+namespace {++class ExposeWatcher final : public QObject {+public:+ AK_ALLOC_WITH_KMALLOC;++ ExposeWatcher(QObject* parent, Function<void()> on_exposed)+ : QObject(parent)+ , m_on_exposed(move(on_exposed))+ {+ }++private:+ virtual bool eventFilter(QObject* watched, QEvent* event) override+ {+ if (event->type() == QEvent::Expose && static_cast<QWindow*>(watched)->isExposed()) {+ watched->removeEventFilter(this);+ m_on_exposed();+ }+ return false;+ }++ Function<void()> m_on_exposed;+};++}+struct WebContentView::VulkanWindow final : public QVulkanWindow {AK_ALLOC_WITH_KMALLOC;@@ -992,7 +1019,10 @@ struct WebContentView::VulkanWindow final : public QVulkanWindow {{if (m_view && m_view->handle_vulkan_window_event(event))return true;- return QVulkanWindow::event(event);+ auto handled = QVulkanWindow::event(event);+ if (m_view && event->type() == QEvent::Expose)+ m_view->vulkan_window_exposure_changed();+ return handled;}WebContentView* m_view { nullptr };@@ -1029,6 +1059,10 @@ void WebContentView::create_vulkan_window()m_vulkan_window_container->hide();install_native_window_container_event_forwarding(*this, *m_vulkan_window, *m_vulkan_window_container);++ m_unexposed_vulkan_window_timer.setSingleShot(true);+ m_unexposed_vulkan_window_timer.setInterval(500);+ QObject::connect(&m_unexposed_vulkan_window_timer, &QTimer::timeout, this, [this] { remap_unexposed_vulkan_window(); });}bool WebContentView::vulkan_window_has_native_focus() const@@ -1042,6 +1076,44 @@ void WebContentView::set_vulkan_window_container_visible(bool visible)set_native_window_container_visible(*this, *m_vulkan_window_container, visible);}+void WebContentView::vulkan_window_exposure_changed()+{+ if (!m_vulkan_window)+ return;+ if (m_vulkan_window->isExposed()) {+ m_remapped_unexposed_vulkan_window = false;+ m_unexposed_vulkan_window_timer.stop();+ return;+ }+ if (!m_remapped_unexposed_vulkan_window)+ m_unexposed_vulkan_window_timer.start();+}++void WebContentView::remap_unexposed_vulkan_window()+{+ // NB: Qt stops presenting a window on Wayland when the compositor is late with a frame callback, and only presents+ // again once one arrives. But a window that does not present is never sent one, which can leave the page+ // frozen after a resize. Mapping the window again gets it going, once the window it is in is shown again.+ if (!m_vulkan_window || m_vulkan_window->isExposed() || !m_vulkan_window_container || !m_vulkan_window_container->isVisible())+ return;+ if (m_remapped_unexposed_vulkan_window)+ return;+ auto* top_level_window = window()->windowHandle();+ if (!top_level_window)+ return;+ if (!top_level_window->isExposed()) {+ // NB: A minimized window can stay unexposed for a long time, so wait for it rather than poll.+ if (!m_top_level_expose_watcher)+ m_top_level_expose_watcher = new ExposeWatcher(this, [this] { vulkan_window_exposure_changed(); });+ top_level_window->installEventFilter(m_top_level_expose_watcher);+ return;+ }+ m_remapped_unexposed_vulkan_window = true;+ set_vulkan_window_container_visible(false);+ set_vulkan_window_container_visible(true);+ m_vulkan_window->requestUpdate();+}+void WebContentView::fall_back_to_bitmap_rendering(){// This may be invoked from within QVulkanWindow's startNextFrame(), i.e. while a frame is in flight. Hiding the