From 424abe62424a1618f7fbb79f12ac4f771c17f9c6 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Mon, 22 Jan 2024 15:33:59 +0100 Subject: [PATCH] client: Fix deletion of new queued shm buffers during reconnect When reconnecting the cleanup of existing buffers is delayed in order to preserve contents and copy them to buffers belonging to the new connection. Due to the order of events it could happen that a new buffer was deleted along with the old ones but still being referenced by a window. During reconnect all QScreens are removed and new ones added for the wl_outputs on the new connection during the initial roundtrips. When the first new QScreen is added all QWindows move form the placeholder screen to it. This can cause for example QWidgets to repaint. At this point the windows are not reinited yet, and the buffer is queued inside the window. Only afterwards the reconnected signal was emitted which would cause deletion of all existing buffers including the newly queued ones. To fix this the signal is moved after the first roundtrip where all globals are announced and new buffers can be created but no new screens have been announced yet. The signal is renamed to be more fit for its new location. Pick-to: 6.7 Pick-to: 6.6 Change-Id: I06be14d235ac342a4b420176aadad3ccf18178fe Reviewed-by: David Edmundson --- src/plugins/platforms/wayland/qwaylanddisplay.cpp | 4 ++-- src/plugins/platforms/wayland/qwaylanddisplay_p.h | 2 +- src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index 43f9443fbec..1040c3b7ab7 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -391,6 +391,8 @@ bool QWaylandDisplay::initialize() forceRoundTrip(); + emit connected(); + if (!mWaitingScreens.isEmpty()) { // Give wl_output.done and zxdg_output_v1.done events a chance to arrive forceRoundTrip(); @@ -481,8 +483,6 @@ void QWaylandDisplay::reconnect() wl_event_queue_destroy(m_frameEventQueue); initEventThread(); - emit reconnected(); - auto needsRecreate = [](QPlatformWindow *window) { return window && !static_cast(window)->wlSurface(); }; diff --git a/src/plugins/platforms/wayland/qwaylanddisplay_p.h b/src/plugins/platforms/wayland/qwaylanddisplay_p.h index 477a5dbf267..e647f41c035 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay_p.h +++ b/src/plugins/platforms/wayland/qwaylanddisplay_p.h @@ -259,7 +259,7 @@ public Q_SLOTS: void flushRequests(); Q_SIGNALS: - void reconnected(); + void connected(); void globalAdded(const RegistryGlobal &global); void globalRemoved(const RegistryGlobal &global); diff --git a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp index fc5e7822104..723b264d518 100644 --- a/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp +++ b/src/plugins/platforms/wayland/qwaylandshmbackingstore.cpp @@ -137,7 +137,7 @@ QWaylandShmBackingStore::QWaylandShmBackingStore(QWindow *window, QWaylandDispla : QPlatformBackingStore(window) , mDisplay(display) { - QObject::connect(mDisplay, &QWaylandDisplay::reconnected, window, [this]() { + QObject::connect(mDisplay, &QWaylandDisplay::connected, window, [this]() { auto copy = mBuffers; // clear available buffers so we create new ones // actual deletion is deferred till after resize call so we can copy