From d308262d4a43e37df8cc196990a1d3dcc0c771d2 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Thu, 16 Sep 2021 14:03:10 +0200 Subject: [PATCH] platforms/drm: simplify active handling a bit --- src/plugins/platforms/drm/drm_object.cpp | 4 ++- src/plugins/platforms/drm/drm_object.h | 3 +- .../platforms/drm/drm_object_connector.cpp | 9 ++---- src/plugins/platforms/drm/drm_pipeline.cpp | 29 ++++++++----------- src/plugins/platforms/drm/drm_pipeline.h | 1 - 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/plugins/platforms/drm/drm_object.cpp b/src/plugins/platforms/drm/drm_object.cpp index f380873109..2002352ca5 100644 --- a/src/plugins/platforms/drm/drm_object.cpp +++ b/src/plugins/platforms/drm/drm_object.cpp @@ -175,7 +175,9 @@ bool DrmObject::updateProperties() } } for (int i = 0; i < m_propertyDefinitions.count(); i++) { - if (m_gpu->atomicModeSetting() && m_propertyDefinitions[i].requirement == Requirement::Required && !m_props[i]) { + bool required = m_gpu->atomicModeSetting() ? m_propertyDefinitions[i].requirement == Requirement::Required + : m_propertyDefinitions[i].requirement == Requirement::RequiredForLegacy; + if (!m_props[i] && required) { qCWarning(KWIN_DRM, "Required property %s for object %d not found!", qPrintable(m_propertyDefinitions[i].name), m_id); return false; } diff --git a/src/plugins/platforms/drm/drm_object.h b/src/plugins/platforms/drm/drm_object.h index 6c53df2bda..f8eb95ac00 100644 --- a/src/plugins/platforms/drm/drm_object.h +++ b/src/plugins/platforms/drm/drm_object.h @@ -183,7 +183,8 @@ public: protected: enum class Requirement { Required, - Optional + RequiredForLegacy, + Optional, }; struct PropertyDefinition { diff --git a/src/plugins/platforms/drm/drm_object_connector.cpp b/src/plugins/platforms/drm/drm_object_connector.cpp index 61c966989e..ed84987828 100644 --- a/src/plugins/platforms/drm/drm_object_connector.cpp +++ b/src/plugins/platforms/drm/drm_object_connector.cpp @@ -25,7 +25,7 @@ DrmConnector::DrmConnector(DrmGpu *gpu, uint32_t connectorId) : DrmObject(gpu, connectorId, { PropertyDefinition(QByteArrayLiteral("CRTC_ID"), Requirement::Required), PropertyDefinition(QByteArrayLiteral("non-desktop"), Requirement::Optional), - PropertyDefinition(QByteArrayLiteral("DPMS"), Requirement::Optional), + PropertyDefinition(QByteArrayLiteral("DPMS"), Requirement::RequiredForLegacy), PropertyDefinition(QByteArrayLiteral("EDID"), Requirement::Optional), PropertyDefinition(QByteArrayLiteral("overscan"), Requirement::Optional), PropertyDefinition(QByteArrayLiteral("vrr_capable"), Requirement::Optional), @@ -83,11 +83,8 @@ bool DrmConnector::init() if (!initProps()) { return false; } - - if (auto dpmsProp = getProp(PropertyIndex::Dpms)) { - dpmsProp->setLegacy(); - } else { - qCDebug(KWIN_DRM) << "Could not find DPMS property!"; + if (const auto &dpms = getProp(PropertyIndex::Dpms)) { + dpms->setLegacy(); } auto underscan = m_props[static_cast(PropertyIndex::Underscan)]; diff --git a/src/plugins/platforms/drm/drm_pipeline.cpp b/src/plugins/platforms/drm/drm_pipeline.cpp index 7314e423e5..9fdd95d080 100644 --- a/src/plugins/platforms/drm/drm_pipeline.cpp +++ b/src/plugins/platforms/drm/drm_pipeline.cpp @@ -184,7 +184,7 @@ bool DrmPipeline::commitPipelines(const QVector &pipelines, Commit bool DrmPipeline::populateAtomicValues(drmModeAtomicReq *req, uint32_t &flags) { bool usesEglStreams = m_gpu->useEglStreams() && m_gpu->eglBackend() != nullptr && m_gpu == m_gpu->platform()->primaryGpu(); - if (!usesEglStreams && m_active) { + if (!usesEglStreams && isActive()) { flags |= DRM_MODE_PAGE_FLIP_EVENT; } bool needsModeset = std::any_of(m_allObjects.constBegin(), m_allObjects.constEnd(), [](auto obj){return obj->needsModeset();}); @@ -197,7 +197,7 @@ bool DrmPipeline::populateAtomicValues(drmModeAtomicReq *req, uint32_t &flags) auto modeSize = m_connector->currentMode().size; m_primaryPlane->set(QPoint(0, 0), m_primaryBuffer ? m_primaryBuffer->size() : modeSize, QPoint(0, 0), modeSize); - m_primaryPlane->setBuffer(m_active ? m_primaryBuffer.get() : nullptr); + m_primaryPlane->setBuffer(isActive() ? m_primaryBuffer.get() : nullptr); for (const auto &obj : qAsConst(m_allObjects)) { if (!obj->atomicPopulate(req)) { return false; @@ -272,7 +272,7 @@ bool DrmPipeline::checkTestBuffer() if (m_primaryBuffer && m_primaryBuffer->size() == sourceSize()) { return true; } - if (!m_active) { + if (!isActive()) { return true; } QSharedPointer buffer; @@ -337,15 +337,13 @@ bool DrmPipeline::moveCursor(QPoint pos) bool DrmPipeline::setActive(bool active) { // disable the cursor before the primary plane to circumvent a crash in amdgpu - if (m_active && !active) { + if (isActive() && !active) { if (drmModeSetCursor(m_gpu->fd(), m_crtc->id(), 0, 0, 0) != 0) { qCWarning(KWIN_DRM) << "Could not set cursor:" << strerror(errno); } } bool success = false; auto mode = m_connector->currentMode().mode; - bool oldActive = m_active; - m_active = active; if (m_gpu->atomicModeSetting()) { m_connector->setPending(DrmConnector::PropertyIndex::CrtcId, active ? m_crtc->id() : 0); m_crtc->setPending(DrmCrtc::PropertyIndex::Active, active); @@ -362,18 +360,12 @@ bool DrmPipeline::setActive(bool active) success = atomicCommit(); } } else { - auto dpmsProp = m_connector->getProp(DrmConnector::PropertyIndex::Dpms); - if (!dpmsProp) { - qCWarning(KWIN_DRM) << "Setting active failed: dpms property missing!"; - } else { - success = dpmsProp->setPropertyLegacy(active ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF); - } + m_connector->getProp(DrmConnector::PropertyIndex::Dpms)->setPropertyLegacy(active ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF); } if (!success) { - m_active = oldActive; qCWarning(KWIN_DRM) << "Setting active to" << active << "failed" << strerror(errno); } - if (m_active) { + if (isActive()) { // enable cursor (again) setCursor(m_cursor.buffer, m_cursor.hotspot); } @@ -461,8 +453,7 @@ bool DrmPipeline::setOverscan(uint32_t overscan) bool DrmPipeline::setRgbRange(AbstractWaylandOutput::RgbRange rgbRange) { - const auto &prop = m_connector->getProp(DrmConnector::PropertyIndex::Broadcast_RGB); - if (prop) { + if (const auto &prop = m_connector->getProp(DrmConnector::PropertyIndex::Broadcast_RGB)) { prop->setEnum(rgbRange); return test(); } else { @@ -486,7 +477,11 @@ DrmPlane::Transformations DrmPipeline::transformation() const bool DrmPipeline::isActive() const { - return m_active; + if (m_gpu->atomicModeSetting()) { + return m_crtc->getProp(DrmCrtc::PropertyIndex::Active)->pending() != 0; + } else { + return m_connector->getProp(DrmConnector::PropertyIndex::Dpms)->current() == DRM_MODE_DPMS_ON; + } } bool DrmPipeline::isCursorVisible() const diff --git a/src/plugins/platforms/drm/drm_pipeline.h b/src/plugins/platforms/drm/drm_pipeline.h index 5938693d8f..a3d43afc25 100644 --- a/src/plugins/platforms/drm/drm_pipeline.h +++ b/src/plugins/platforms/drm/drm_pipeline.h @@ -103,7 +103,6 @@ private: QSharedPointer m_primaryBuffer; QSharedPointer m_oldTestBuffer; - bool m_active = true; bool m_legacyNeedsModeset = true; struct { QPoint pos;