From 239207c5eee6c042582c8b5769745892d5d994db Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 28 Dec 2022 23:06:55 +0100 Subject: [PATCH] backends/drm: extend connector lifetime to match their outputs As disconnected outputs outlive DrmGpu::updateOutputs, the DrmConnector and DrmPipeline must also be kept valid for that time BUG: 463334 --- src/backends/drm/drm_gpu.cpp | 4 ++-- src/backends/drm/drm_gpu.h | 2 +- src/backends/drm/drm_output.cpp | 11 +++++------ src/backends/drm/drm_output.h | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/backends/drm/drm_gpu.cpp b/src/backends/drm/drm_gpu.cpp index 47723ccacb..79a73fcc33 100644 --- a/src/backends/drm/drm_gpu.cpp +++ b/src/backends/drm/drm_gpu.cpp @@ -253,7 +253,7 @@ bool DrmGpu::updateOutputs() return connector->id() == currentConnector; }); if (it == m_connectors.end()) { - auto conn = std::make_unique(this, currentConnector); + auto conn = std::make_shared(this, currentConnector); if (!conn->init()) { continue; } @@ -278,7 +278,7 @@ bool DrmGpu::updateOutputs() qCDebug(KWIN_DRM, "New %soutput on GPU %s: %s", conn->isNonDesktop() ? "non-desktop " : "", qPrintable(m_devNode), qPrintable(conn->modelName())); const auto pipeline = conn->pipeline(); m_pipelines << pipeline; - auto output = new DrmOutput(pipeline); + auto output = new DrmOutput(*it); m_drmOutputs << output; addedOutputs << output; Q_EMIT outputAdded(output); diff --git a/src/backends/drm/drm_gpu.h b/src/backends/drm/drm_gpu.h index 7850764394..25cbf105a9 100644 --- a/src/backends/drm/drm_gpu.h +++ b/src/backends/drm/drm_gpu.h @@ -139,7 +139,7 @@ private: std::vector> m_planes; std::vector> m_crtcs; - std::vector> m_connectors; + std::vector> m_connectors; QVector m_allObjects; QVector m_pipelines; diff --git a/src/backends/drm/drm_output.cpp b/src/backends/drm/drm_output.cpp index 7ceb84c282..26aa39e71f 100644 --- a/src/backends/drm/drm_output.cpp +++ b/src/backends/drm/drm_output.cpp @@ -38,14 +38,13 @@ namespace KWin { -DrmOutput::DrmOutput(DrmPipeline *pipeline) - : DrmAbstractOutput(pipeline->connector()->gpu()) - , m_pipeline(pipeline) - , m_connector(pipeline->connector()) +DrmOutput::DrmOutput(const std::shared_ptr &conn) + : DrmAbstractOutput(conn->gpu()) + , m_pipeline(conn->pipeline()) + , m_connector(conn) { RenderLoopPrivate::get(m_renderLoop.get())->canDoTearing = gpu()->asyncPageflipSupported(); m_pipeline->setOutput(this); - const auto conn = m_pipeline->connector(); m_renderLoop->setRefreshRate(m_pipeline->mode()->refreshRate()); Capabilities capabilities = Capability::Dpms; @@ -387,7 +386,7 @@ bool DrmOutput::present() DrmConnector *DrmOutput::connector() const { - return m_connector; + return m_connector.get(); } DrmPipeline *DrmOutput::pipeline() const diff --git a/src/backends/drm/drm_output.h b/src/backends/drm/drm_output.h index efadd4d508..90c34b5073 100644 --- a/src/backends/drm/drm_output.h +++ b/src/backends/drm/drm_output.h @@ -35,7 +35,7 @@ class KWIN_EXPORT DrmOutput : public DrmAbstractOutput { Q_OBJECT public: - DrmOutput(DrmPipeline *pipeline); + DrmOutput(const std::shared_ptr &connector); ~DrmOutput() override; DrmConnector *connector() const; @@ -71,7 +71,7 @@ private: void renderCursorQPainter(const RenderTarget &renderTarget); DrmPipeline *m_pipeline; - DrmConnector *m_connector; + const std::shared_ptr m_connector; bool m_setCursorSuccessful = false; bool m_moveCursorSuccessful = false;