mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-15 08:45:59 +01:00
drm-lease: fix crashes and implementation (#8116)
This commit is contained in:
parent
e7fd0f5aec
commit
ce62521883
2 changed files with 22 additions and 9 deletions
|
@ -44,10 +44,6 @@ CDRMLeaseResource::CDRMLeaseResource(SP<CWpDrmLeaseV1> resource_, SP<CDRMLeaseRe
|
|||
return;
|
||||
}
|
||||
|
||||
LOGM(LOG, "Granting lease, sending fd {}", aqlease->leaseFD);
|
||||
|
||||
resource->sendLeaseFd(aqlease->leaseFD);
|
||||
|
||||
lease = aqlease;
|
||||
|
||||
for (auto const& m : requested) {
|
||||
|
@ -61,8 +57,13 @@ CDRMLeaseResource::CDRMLeaseResource(SP<CWpDrmLeaseV1> resource_, SP<CDRMLeaseRe
|
|||
}
|
||||
|
||||
resource->sendFinished();
|
||||
LOGM(LOG, "Revoking lease for fd {}", lease->leaseFD);
|
||||
});
|
||||
|
||||
LOGM(LOG, "Granting lease, sending fd {}", lease->leaseFD);
|
||||
|
||||
resource->sendLeaseFd(lease->leaseFD);
|
||||
|
||||
close(lease->leaseFD);
|
||||
}
|
||||
|
||||
|
@ -70,6 +71,12 @@ bool CDRMLeaseResource::good() {
|
|||
return resource->resource();
|
||||
}
|
||||
|
||||
CDRMLeaseResource::~CDRMLeaseResource() {
|
||||
// destroy in this order to ensure listener gets called
|
||||
lease.reset();
|
||||
listeners.destroyLease.reset();
|
||||
}
|
||||
|
||||
CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP<CWpDrmLeaseRequestV1> resource_) : resource(resource_) {
|
||||
if (!good())
|
||||
return;
|
||||
|
@ -100,7 +107,7 @@ CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP<CWpDrmLeaseRequestV1> reso
|
|||
return;
|
||||
}
|
||||
|
||||
auto RESOURCE = makeShared<CDRMLeaseResource>(makeShared<CWpDrmLeaseV1>(resource->client(), resource->version(), -1), self.lock());
|
||||
auto RESOURCE = makeShared<CDRMLeaseResource>(makeShared<CWpDrmLeaseV1>(resource->client(), resource->version(), id), self.lock());
|
||||
if (!RESOURCE) {
|
||||
resource->noMemory();
|
||||
return;
|
||||
|
@ -185,6 +192,7 @@ CDRMLeaseDeviceResource::CDRMLeaseDeviceResource(SP<CWpDrmLeaseDeviceV1> resourc
|
|||
close(fd);
|
||||
|
||||
for (auto const& m : PROTO::lease->primaryDevice->offeredOutputs) {
|
||||
if (m)
|
||||
sendConnector(m.lock());
|
||||
}
|
||||
|
||||
|
@ -196,10 +204,10 @@ bool CDRMLeaseDeviceResource::good() {
|
|||
}
|
||||
|
||||
void CDRMLeaseDeviceResource::sendConnector(SP<CMonitor> monitor) {
|
||||
if (std::find_if(connectorsSent.begin(), connectorsSent.end(), [monitor](const auto& e) { return e->monitor == monitor; }) != connectorsSent.end())
|
||||
if (std::find_if(connectorsSent.begin(), connectorsSent.end(), [monitor](const auto& e) { return e && !e->dead && e->monitor == monitor; }) != connectorsSent.end())
|
||||
return;
|
||||
|
||||
auto RESOURCE = makeShared<CDRMLeaseConnectorResource>(makeShared<CWpDrmLeaseConnectorV1>(resource->client(), resource->version(), -1), monitor);
|
||||
auto RESOURCE = makeShared<CDRMLeaseConnectorResource>(makeShared<CWpDrmLeaseConnectorV1>(resource->client(), resource->version(), 0), monitor);
|
||||
if (!RESOURCE) {
|
||||
resource->noMemory();
|
||||
return;
|
||||
|
@ -267,6 +275,9 @@ void CDRMLeaseProtocol::destroyResource(CDRMLeaseDeviceResource* resource) {
|
|||
}
|
||||
|
||||
void CDRMLeaseProtocol::destroyResource(CDRMLeaseConnectorResource* resource) {
|
||||
for (const auto& m : m_vManagers) {
|
||||
std::erase_if(m->connectorsSent, [resource](const auto& e) { return e.expired() || e->dead || e.get() == resource; });
|
||||
}
|
||||
std::erase_if(m_vConnectors, [resource](const auto& e) { return e.get() == resource; });
|
||||
}
|
||||
|
||||
|
@ -279,6 +290,7 @@ void CDRMLeaseProtocol::destroyResource(CDRMLeaseResource* resource) {
|
|||
}
|
||||
|
||||
void CDRMLeaseProtocol::offer(SP<CMonitor> monitor) {
|
||||
std::erase_if(primaryDevice->offeredOutputs, [](const auto& e) { return e.expired(); });
|
||||
if (std::find(primaryDevice->offeredOutputs.begin(), primaryDevice->offeredOutputs.end(), monitor) != primaryDevice->offeredOutputs.end())
|
||||
return;
|
||||
|
||||
|
|
|
@ -22,12 +22,13 @@ class CDRMLeaseRequestResource;
|
|||
class CDRMLeaseResource {
|
||||
public:
|
||||
CDRMLeaseResource(SP<CWpDrmLeaseV1> resource_, SP<CDRMLeaseRequestResource> request);
|
||||
~CDRMLeaseResource();
|
||||
|
||||
bool good();
|
||||
|
||||
WP<CDRMLeaseDeviceResource> parent;
|
||||
std::vector<WP<CDRMLeaseConnectorResource>> requested;
|
||||
WP<Aquamarine::CDRMLease> lease;
|
||||
SP<Aquamarine::CDRMLease> lease;
|
||||
|
||||
int leaseFD = -1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue