Skip to content

Commit

Permalink
drm: avoid crashes on connecting a null crtc
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Aug 16, 2024
1 parent e947af7 commit 4f66428
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
1 change: 1 addition & 0 deletions include/aquamarine/backend/DRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ namespace Aquamarine {
void applyCommit(const SDRMConnectorCommitData& data);
void rollbackCommit(const SDRMConnectorCommitData& data);
void onPresent();
void recheckCRTCProps();

Hyprutils::Memory::CSharedPointer<CDRMOutput> output;
Hyprutils::Memory::CWeakPointer<CDRMBackend> backend;
Expand Down
45 changes: 26 additions & 19 deletions src/backend/drm/DRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,8 @@ void Aquamarine::CDRMBackend::scanConnectors() {

conn->status = drmConn->connection;

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

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

Expand Down Expand Up @@ -1157,6 +1155,23 @@ void Aquamarine::SDRMConnector::parseEDID(std::vector<uint8_t> data) {
di_info_destroy(info);
}

void Aquamarine::SDRMConnector::recheckCRTCProps() {
if (!crtc || !output)
return;

uint64_t prop = 0;
canDoVrr = props.vrr_capable && crtc->props.vrr_enabled && getDRMProp(backend->gpu->fd, id, props.vrr_capable, &prop) && prop;
output->vrrCapable = canDoVrr;

backend->backend->log(AQ_LOG_DEBUG,
std::format("drm: connector {} crtc is {} of vrr: props.vrr_capable -> {}, crtc->props.vrr_enabled -> {}", szName, (canDoVrr ? "capable" : "incapable"),
props.vrr_capable, crtc->props.vrr_enabled));

output->supportsExplicit = backend->drmProps.supportsTimelines && crtc->props.out_fence_ptr && crtc->primary->props.in_fence_fd;

backend->backend->log(AQ_LOG_DEBUG, std::format("drm: Explicit sync {}", output->supportsExplicit ? "supported" : "unsupported"));
}

void Aquamarine::SDRMConnector::connect(drmModeConnector* connector) {
if (output) {
backend->backend->log(AQ_LOG_DEBUG, std::format("drm: Not connecting connector {} because it's already connected", szName));
Expand Down Expand Up @@ -1228,13 +1243,6 @@ void Aquamarine::SDRMConnector::connect(drmModeConnector* connector) {
output->nonDesktop = prop;
}

canDoVrr = props.vrr_capable && crtc->props.vrr_enabled && getDRMProp(backend->gpu->fd, id, props.vrr_capable, &prop) && prop;
output->vrrCapable = canDoVrr;

backend->backend->log(AQ_LOG_DEBUG,
std::format("drm: crtc is {} of vrr: props.vrr_capable -> {}, crtc->props.vrr_enabled -> {}", (canDoVrr ? "capable" : "incapable"), props.vrr_capable,
crtc->props.vrr_enabled));

maxBpcBounds.fill(0);

if (props.max_bpc && !introspectDRMPropRange(backend->gpu->fd, props.max_bpc, maxBpcBounds.data(), &maxBpcBounds[1]))
Expand All @@ -1251,19 +1259,18 @@ void Aquamarine::SDRMConnector::connect(drmModeConnector* connector) {

// TODO: subconnectors

output->make = make;
output->model = model;
output->serial = serial;
output->description = std::format("{} {} {} ({})", make, model, serial, szName);
output->needsFrame = true;
output->supportsExplicit = backend->drmProps.supportsTimelines && crtc->props.out_fence_ptr && crtc->primary->props.in_fence_fd;

backend->backend->log(AQ_LOG_DEBUG, std::format("drm: Explicit sync {}", output->supportsExplicit ? "supported" : "unsupported"));
output->make = make;
output->model = model;
output->serial = serial;
output->description = std::format("{} {} {} ({})", make, model, serial, szName);
output->needsFrame = true;

backend->backend->log(AQ_LOG_DEBUG, std::format("drm: Description {}", output->description));

status = DRM_MODE_CONNECTED;

recheckCRTCProps();

if (!backend->backend->ready)
return;

Expand Down

0 comments on commit 4f66428

Please sign in to comment.