From dbf4a59527169c7b028295a2ec77f9c11a93d38b Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Mon, 30 Aug 2021 14:59:46 +0200 Subject: [PATCH] platforms/drm: prevent having zero outputs at any time Instead of updating all outputs first, create the placeholder output before the last output gets removed. --- src/plugins/platforms/drm/drm_backend.cpp | 15 +++++++++++---- src/plugins/platforms/drm/drm_output.h | 1 - 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/plugins/platforms/drm/drm_backend.cpp b/src/plugins/platforms/drm/drm_backend.cpp index 3a50f5d229..775b5db2c0 100644 --- a/src/plugins/platforms/drm/drm_backend.cpp +++ b/src/plugins/platforms/drm/drm_backend.cpp @@ -334,10 +334,21 @@ void DrmBackend::addOutput(DrmAbstractOutput *o) m_enabledOutputs.append(o); Q_EMIT outputAdded(o); Q_EMIT outputEnabled(o); + if (m_placeHolderOutput) { + qCDebug(KWIN_DRM) << "removing placeholder output"; + primaryGpu()->removeVirtualOutput(m_placeHolderOutput); + m_placeHolderOutput = nullptr; + } } void DrmBackend::removeOutput(DrmAbstractOutput *o) { + if (m_outputs.count() == 1 && !kwinApp()->isTerminating()) { + qCDebug(KWIN_DRM) << "adding placeholder output"; + m_placeHolderOutput = primaryGpu()->createVirtualOutput(); + // placeholder doesn't actually need to render anything + m_placeHolderOutput->renderLoop()->inhibit(); + } if (m_enabledOutputs.removeOne(o)) { Q_EMIT outputDisabled(o); } @@ -366,10 +377,6 @@ void DrmBackend::updateOutputs() m_placeHolderOutput = primaryGpu()->createVirtualOutput(); // placeholder doesn't actually need to render anything m_placeHolderOutput->renderLoop()->inhibit(); - } else if (m_placeHolderOutput && m_outputs.count() > 1) { - qCDebug(KWIN_DRM) << "removing placeholder output"; - primaryGpu()->removeVirtualOutput(m_placeHolderOutput); - m_placeHolderOutput = nullptr; } std::sort(m_outputs.begin(), m_outputs.end(), [] (DrmAbstractOutput *a, DrmAbstractOutput *b) { diff --git a/src/plugins/platforms/drm/drm_output.h b/src/plugins/platforms/drm/drm_output.h index f5cad16367..3f0be804e0 100644 --- a/src/plugins/platforms/drm/drm_output.h +++ b/src/plugins/platforms/drm/drm_output.h @@ -38,7 +38,6 @@ class KWIN_EXPORT DrmOutput : public DrmAbstractOutput { Q_OBJECT public: - ///deletes the output, calling this whilst a page flip is pending will result in an error ~DrmOutput() override; bool initCursor(const QSize &cursorSize) override;