From 907cf72bb0e580f51948ca271663a578abf83d4b Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Fri, 25 Feb 2022 18:04:01 +0100 Subject: [PATCH] backends/drm: only update modes if actually necessary This prevents some unneeded modesets --- src/backends/drm/drm_gpu.cpp | 4 +--- src/backends/drm/drm_object_connector.cpp | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/backends/drm/drm_gpu.cpp b/src/backends/drm/drm_gpu.cpp index ea5a414912..145252ac1a 100644 --- a/src/backends/drm/drm_gpu.cpp +++ b/src/backends/drm/drm_gpu.cpp @@ -263,9 +263,7 @@ bool DrmGpu::updateOutputs() conn->updateProperties(); } if (conn->isConnected()) { - if (auto output = findOutput(conn->id())) { - output->updateModes(); - } else if (!findLeaseOutput(conn->id())) { + if (conn->isNonDesktop() ? !findLeaseOutput(conn->id()) : !findOutput(conn->id())) { qCDebug(KWIN_DRM, "New %soutput on GPU %s: %s", conn->isNonDesktop() ? "non-desktop " : "", qPrintable(m_devNode), qPrintable(conn->modelName())); m_pipelines << conn->pipeline(); if (conn->isNonDesktop()) { diff --git a/src/backends/drm/drm_object_connector.cpp b/src/backends/drm/drm_object_connector.cpp index d7359c4f14..4840724bc6 100644 --- a/src/backends/drm/drm_object_connector.cpp +++ b/src/backends/drm/drm_object_connector.cpp @@ -13,6 +13,7 @@ #include "logging.h" #include "drm_pipeline.h" #include "drm_object_crtc.h" +#include "drm_output.h" #include // frameworks @@ -286,11 +287,19 @@ bool DrmConnector::needsModeset() const void DrmConnector::updateModes() { - m_modes.clear(); - - // reload modes - for (int i = 0; i < m_conn->count_modes; i++) { - m_modes.append(QSharedPointer::create(this, m_conn->modes[i])); + bool equal = m_conn->count_modes == m_modes.count(); + for (int i = 0; equal && i < m_conn->count_modes; i++) { + equal &= checkIfEqual(m_modes[i]->nativeMode(), &m_conn->modes[i]); + } + if (!equal) { + // reload modes + m_modes.clear(); + for (int i = 0; i < m_conn->count_modes; i++) { + m_modes.append(QSharedPointer::create(this, m_conn->modes[i])); + } + if (const auto output = dynamic_cast(m_pipeline->displayDevice())) { + output->updateModes(); + } } }