From 969cb5ae3f60bc76e693c9c07d66c5587f27d7e5 Mon Sep 17 00:00:00 2001 From: Ikalco <73481042+ikalco@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:43:22 +0000 Subject: [PATCH] recheck crtcs before connecting on udev event --- include/aquamarine/backend/DRM.hpp | 2 +- patch.txt | 56 ++++++++++++++++++++++++++++++ src/backend/drm/DRM.cpp | 18 +++++----- 3 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 patch.txt diff --git a/include/aquamarine/backend/DRM.hpp b/include/aquamarine/backend/DRM.hpp index 348bbaa..040cad7 100644 --- a/include/aquamarine/backend/DRM.hpp +++ b/include/aquamarine/backend/DRM.hpp @@ -367,7 +367,7 @@ namespace Aquamarine { bool initMgpu(); bool grabFormats(); bool shouldBlit(); - void scanConnectors(); + void scanConnectors(bool allowConnect = true); void scanLeases(); void restoreAfterVT(); void recheckCRTCs(); diff --git a/patch.txt b/patch.txt new file mode 100644 index 0000000..0e82e0b --- /dev/null +++ b/patch.txt @@ -0,0 +1,56 @@ +diff --git a/include/aquamarine/backend/DRM.hpp b/include/aquamarine/backend/DRM.hpp +index 348bbaa..040cad7 100644 +--- a/include/aquamarine/backend/DRM.hpp ++++ b/include/aquamarine/backend/DRM.hpp +@@ -367,7 +367,7 @@ namespace Aquamarine { + bool initMgpu(); + bool grabFormats(); + bool shouldBlit(); +- void scanConnectors(); ++ void scanConnectors(bool allowConnect = true); + void scanLeases(); + void restoreAfterVT(); + void recheckCRTCs(); +diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp +index c2c6125..899bbec 100644 +--- a/src/backend/drm/DRM.cpp ++++ b/src/backend/drm/DRM.cpp +@@ -658,7 +658,7 @@ bool Aquamarine::CDRMBackend::registerGPU(SP gpu_, SP(d); + if (E.type == CSessionDevice::AQ_SESSION_EVENT_CHANGE_HOTPLUG) { + backend->log(AQ_LOG_DEBUG, std::format("drm: Got a hotplug event for {}", gpuName)); +- scanConnectors(); ++ scanConnectors(false); + recheckCRTCs(); + } else if (E.type == CSessionDevice::AQ_SESSION_EVENT_CHANGE_LEASE) { + backend->log(AQ_LOG_DEBUG, std::format("drm: Got a lease event for {}", gpuName)); +@@ -676,7 +676,7 @@ eBackendType Aquamarine::CDRMBackend::type() { + return eBackendType::AQ_BACKEND_DRM; + } + +-void Aquamarine::CDRMBackend::scanConnectors() { ++void Aquamarine::CDRMBackend::scanConnectors(bool allowConnect) { + backend->log(AQ_LOG_DEBUG, std::format("drm: Scanning connectors for {}", gpu->path)); + + auto resources = drmModeGetResources(gpu->fd); +@@ -722,12 +722,14 @@ void Aquamarine::CDRMBackend::scanConnectors() { + + backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} connection state: {}", connectorID, (int)drmConn->connection)); + +- if (conn->status == DRM_MODE_CONNECTED && !conn->output) { +- backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} connected", conn->szName)); +- conn->connect(drmConn); +- } else if (conn->status != DRM_MODE_CONNECTED && conn->output) { +- backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} disconnected", conn->szName)); +- conn->disconnect(); ++ if (allowConnect) { ++ if (conn->status == DRM_MODE_CONNECTED && !conn->output) { ++ backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} connected", conn->szName)); ++ conn->connect(drmConn); ++ } else if (conn->status != DRM_MODE_CONNECTED && conn->output) { ++ backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} disconnected", conn->szName)); ++ conn->disconnect(); ++ } + } + + drmModeFreeConnector(drmConn); diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index c2c6125..899bbec 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -658,7 +658,7 @@ bool Aquamarine::CDRMBackend::registerGPU(SP gpu_, SP(d); if (E.type == CSessionDevice::AQ_SESSION_EVENT_CHANGE_HOTPLUG) { backend->log(AQ_LOG_DEBUG, std::format("drm: Got a hotplug event for {}", gpuName)); - scanConnectors(); + scanConnectors(false); recheckCRTCs(); } else if (E.type == CSessionDevice::AQ_SESSION_EVENT_CHANGE_LEASE) { backend->log(AQ_LOG_DEBUG, std::format("drm: Got a lease event for {}", gpuName)); @@ -676,7 +676,7 @@ eBackendType Aquamarine::CDRMBackend::type() { return eBackendType::AQ_BACKEND_DRM; } -void Aquamarine::CDRMBackend::scanConnectors() { +void Aquamarine::CDRMBackend::scanConnectors(bool allowConnect) { backend->log(AQ_LOG_DEBUG, std::format("drm: Scanning connectors for {}", gpu->path)); auto resources = drmModeGetResources(gpu->fd); @@ -722,12 +722,14 @@ void Aquamarine::CDRMBackend::scanConnectors() { backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} connection state: {}", connectorID, (int)drmConn->connection)); - if (conn->status == DRM_MODE_CONNECTED && !conn->output) { - backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} connected", conn->szName)); - conn->connect(drmConn); - } else if (conn->status != DRM_MODE_CONNECTED && conn->output) { - backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} disconnected", conn->szName)); - conn->disconnect(); + if (allowConnect) { + if (conn->status == DRM_MODE_CONNECTED && !conn->output) { + backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} connected", conn->szName)); + conn->connect(drmConn); + } else if (conn->status != DRM_MODE_CONNECTED && conn->output) { + backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} disconnected", conn->szName)); + conn->disconnect(); + } } drmModeFreeConnector(drmConn);