Skip to content

Commit

Permalink
drm: minor improvements to crtc rechecks
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jul 18, 2024
1 parent c97e83e commit 9d7c69c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,17 +533,23 @@ void Aquamarine::CDRMBackend::recheckCRTCs() {
continue;

bool assigned = false;

// try to use a connected connector
for (auto& c : recheck) {
if (!(c->possibleCrtcs & (1 << i)))
continue;

if (c->status != DRM_MODE_CONNECTED)
continue;

// deactivate old output
if (c->output && c->output->state && c->output->state->state().enabled) {
c->output->state->setEnabled(false);
c->output->commit();
}

backend->log(AQ_LOG_DEBUG, std::format("drm: slot {} crtc {} assigned to {} (old {})", i, crtcs.at(i)->id, c->szName, c->crtc ? (int)c->crtc->id : -1));
backend->log(AQ_LOG_DEBUG,
std::format("drm: connected slot {} crtc {} assigned to {}{}", i, crtcs.at(i)->id, c->szName, c->crtc ? std::format(" (old {})", c->crtc->id) : ""));
c->crtc = crtcs.at(i);
assigned = true;
changed.emplace_back(c);
Expand All @@ -555,6 +561,13 @@ void Aquamarine::CDRMBackend::recheckCRTCs() {
backend->log(AQ_LOG_DEBUG, std::format("drm: slot {} crtc {} unassigned", i, crtcs.at(i)->id));
}

for (auto& c : connectors) {
if (c->status == DRM_MODE_CONNECTED)
continue;

backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} is not connected{}", c->szName, c->crtc ? std::format(", removing old crtc {}", c->crtc->id) : ""));
}

// if any connectors get a crtc and are connected, we need to rescan to assign them outputs.
bool rescan = false;
for (auto& c : changed) {
Expand Down Expand Up @@ -597,6 +610,7 @@ bool Aquamarine::CDRMBackend::registerGPU(SP<CSessionDevice> gpu_, SP<CDRMBacken
if (E.type == CSessionDevice::AQ_SESSION_EVENT_CHANGE_HOTPLUG) {
backend->log(AQ_LOG_DEBUG, std::format("drm: Got a hotplug event for {}", gpuName));
scanConnectors();
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));
scanLeases();
Expand Down Expand Up @@ -652,17 +666,19 @@ void Aquamarine::CDRMBackend::scanConnectors() {
conn = *it;
}

conn->status = drmConn->connection;

if (!conn->crtc) {
backend->log(AQ_LOG_DEBUG, std::format("drm: Ignoring connector {} because it has no CRTC", connectorID));
continue;
}

backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} connection state: {}", connectorID, (int)drmConn->connection));

if (conn->status == DRM_MODE_DISCONNECTED && drmConn->connection == DRM_MODE_CONNECTED) {
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 && drmConn->connection == DRM_MODE_DISCONNECTED) {
} else if (conn->status != DRM_MODE_CONNECTED && conn->output) {
backend->log(AQ_LOG_DEBUG, std::format("drm: Connector {} disconnected", conn->szName));
conn->disconnect();
}
Expand Down

0 comments on commit 9d7c69c

Please sign in to comment.