From 20bef824f4b78598fbffa5ada8271e22b658f635 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 12 Sep 2022 13:28:08 +0100 Subject: [PATCH 38/51] Hold surface read lock throughout QWaylandEglWindow::updateSurface QWaylandEGLWindow::updateSurface is called from both the main and render threads. It is called on the render thread when making the surface current, which could be after the window is hidden if there are cleanup jobs to be done. Whilst the getter wlSurface() holds a read lock, it's not enough as we need the instance alive between the two calls and throughout the mesa code. This potentially fixes a crash seen in mesa where we crash creating a surface for an invalid wl_surface object. Change-Id: I497356e752ffaf3549d174f10c4c268234b02cbd Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit 50f1ccc66c68f9f4c0b08400747942109c16b2be) --- src/client/qwaylandwindow_p.h | 6 ++++-- .../client/wayland-egl/qwaylandeglwindow.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h index 2be87bc0..ea3d1995 100644 --- a/src/client/qwaylandwindow_p.h +++ b/src/client/qwaylandwindow_p.h @@ -220,7 +220,11 @@ signals: protected: QWaylandDisplay *mDisplay = nullptr; + + // mSurface can be written by the main thread. Other threads should claim a read lock for access + mutable QReadWriteLock mSurfaceLock; QScopedPointer mSurface; + QWaylandShellSurface *mShellSurface = nullptr; QWaylandSubSurface *mSubSurfaceWindow = nullptr; QVector mChildren; @@ -294,8 +298,6 @@ private: static QWaylandWindow *mMouseGrab; - mutable QReadWriteLock mSurfaceLock; - friend class QWaylandSubSurface; }; diff --git a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp index 13dd747a..872a6237 100644 --- a/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp +++ b/src/hardwareintegration/client/wayland-egl/qwaylandeglwindow.cpp @@ -40,6 +40,7 @@ #include "qwaylandeglwindow.h" #include +#include #include "qwaylandglcontext.h" #include @@ -115,6 +116,7 @@ void QWaylandEglWindow::updateSurface(bool create) } mOffset = QPoint(); } else { + QReadLocker locker(&mSurfaceLock); if (m_waylandEglWindow) { int current_width, current_height; static bool disableResizeCheck = qgetenv("QT_WAYLAND_DISABLE_RESIZECHECK").toInt(); @@ -129,8 +131,8 @@ void QWaylandEglWindow::updateSurface(bool create) m_resize = true; } - } else if (create && wlSurface()) { - m_waylandEglWindow = wl_egl_window_create(wlSurface(), sizeWithMargins.width(), sizeWithMargins.height()); + } else if (create && mSurface) { + m_waylandEglWindow = wl_egl_window_create(mSurface->object(), sizeWithMargins.width(), sizeWithMargins.height()); m_requestedSize = sizeWithMargins; } -- 2.40.1