From f70be829c6fd957132a45624c5d7e824c379b069 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Fri, 31 Mar 2023 01:22:48 +0200 Subject: [PATCH] backends/drm: don't access nullptr output configs --- src/backends/drm/drm_backend.cpp | 10 +++++++--- src/backends/drm/drm_output.cpp | 7 ++----- src/backends/drm/drm_output.h | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/backends/drm/drm_backend.cpp b/src/backends/drm/drm_backend.cpp index c52844185f..b88edf7096 100644 --- a/src/backends/drm/drm_backend.cpp +++ b/src/backends/drm/drm_backend.cpp @@ -474,7 +474,7 @@ bool DrmBackend::applyOutputChanges(const OutputConfiguration &config) continue; } if (const auto changeset = config.constChangeSet(output)) { - output->queueChanges(config); + output->queueChanges(changeset); if (changeset->enabled) { toBeEnabled << output; } else { @@ -495,10 +495,14 @@ bool DrmBackend::applyOutputChanges(const OutputConfiguration &config) // first, apply changes to drm outputs. // This may remove the placeholder output and thus change m_outputs! for (const auto &output : std::as_const(toBeEnabled)) { - output->applyQueuedChanges(config); + if (const auto changeset = config.constChangeSet(output)) { + output->applyQueuedChanges(changeset); + } } for (const auto &output : std::as_const(toBeDisabled)) { - output->applyQueuedChanges(config); + if (const auto changeset = config.constChangeSet(output)) { + output->applyQueuedChanges(changeset); + } } // only then apply changes to the virtual outputs for (const auto &gpu : std::as_const(m_gpus)) { diff --git a/src/backends/drm/drm_output.cpp b/src/backends/drm/drm_output.cpp index fa7d41ed48..c9c5328c2f 100644 --- a/src/backends/drm/drm_output.cpp +++ b/src/backends/drm/drm_output.cpp @@ -398,12 +398,11 @@ DrmPipeline *DrmOutput::pipeline() const return m_pipeline; } -bool DrmOutput::queueChanges(const OutputConfiguration &config) +bool DrmOutput::queueChanges(const std::shared_ptr &props) { static bool valid; static int envOnlySoftwareRotations = qEnvironmentVariableIntValue("KWIN_DRM_SW_ROTATIONS_ONLY", &valid) == 1 || !valid; - const auto props = config.constChangeSet(this); const auto mode = props->mode.value_or(currentMode()).lock(); if (!mode) { return false; @@ -419,7 +418,7 @@ bool DrmOutput::queueChanges(const OutputConfiguration &config) return true; } -void DrmOutput::applyQueuedChanges(const OutputConfiguration &config) +void DrmOutput::applyQueuedChanges(const std::shared_ptr &props) { if (!m_connector->isConnected()) { return; @@ -427,8 +426,6 @@ void DrmOutput::applyQueuedChanges(const OutputConfiguration &config) Q_EMIT aboutToChange(); m_pipeline->applyPendingChanges(); - auto props = config.constChangeSet(this); - State next = m_state; next.enabled = props->enabled && m_pipeline->crtc(); next.position = props->pos.value_or(m_state.position); diff --git a/src/backends/drm/drm_output.h b/src/backends/drm/drm_output.h index 57eb0f2480..07606c556d 100644 --- a/src/backends/drm/drm_output.h +++ b/src/backends/drm/drm_output.h @@ -29,6 +29,7 @@ class DrmGpu; class DrmPipeline; class DumbSwapchain; class DrmLease; +class OutputChangeSet; class KWIN_EXPORT DrmOutput : public DrmAbstractOutput { @@ -44,8 +45,8 @@ public: DrmOutputLayer *primaryLayer() const override; DrmOutputLayer *cursorLayer() const override; - bool queueChanges(const OutputConfiguration &config); - void applyQueuedChanges(const OutputConfiguration &config); + bool queueChanges(const std::shared_ptr &properties); + void applyQueuedChanges(const std::shared_ptr &properties); void revertQueuedChanges(); void updateModes(); void updateDpmsMode(DpmsMode dpmsMode);