backends/drm: Change the base class of DrmLeaseOutput
At the moment, the DrmLeaseOutput class inherits from the KWaylandServer::DrmLeaseConnectionV1Interface class. While this works, it's not a future-proof design. For example, kwin could also lease its "desktop" outputs in order to let another wayland compositor run alongside it. Also, it's a good practice to prefer composition over inheritance.
This commit is contained in:
parent
a521525c4d
commit
b62dd29210
5 changed files with 30 additions and 18 deletions
|
@ -616,10 +616,13 @@ void DrmGpu::handleLeaseRequest(KWaylandServer::DrmLeaseV1Interface *leaseReques
|
|||
{
|
||||
QVector<uint32_t> objects;
|
||||
QVector<DrmLeaseOutput *> outputs;
|
||||
const auto conns = leaseRequest->connectors();
|
||||
for (const auto &connector : conns) {
|
||||
auto output = qobject_cast<DrmLeaseOutput *>(connector);
|
||||
if (m_leaseOutputs.contains(output) && !output->lease()) {
|
||||
|
||||
const auto connectors = leaseRequest->connectors();
|
||||
for (KWaylandServer::DrmLeaseConnectorV1Interface *connector : connectors) {
|
||||
if (DrmLeaseOutput *output = findLeaseOutput(connector->id())) {
|
||||
if (output->lease()) {
|
||||
continue; // already leased
|
||||
}
|
||||
if (!output->addLeaseObjects(objects)) {
|
||||
leaseRequest->deny();
|
||||
return;
|
||||
|
@ -627,6 +630,7 @@ void DrmGpu::handleLeaseRequest(KWaylandServer::DrmLeaseV1Interface *leaseReques
|
|||
outputs << output;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t lesseeId;
|
||||
int fd = drmModeCreateLease(m_fd, objects.constData(), objects.count(), 0, &lesseeId);
|
||||
if (fd < 0) {
|
||||
|
@ -650,10 +654,9 @@ void DrmGpu::handleLeaseRequest(KWaylandServer::DrmLeaseV1Interface *leaseReques
|
|||
|
||||
void DrmGpu::handleLeaseRevoked(KWaylandServer::DrmLeaseV1Interface *lease)
|
||||
{
|
||||
const auto conns = lease->connectors();
|
||||
for (const auto &connector : conns) {
|
||||
auto output = qobject_cast<DrmLeaseOutput *>(connector);
|
||||
if (m_leaseOutputs.contains(output)) {
|
||||
const auto connectors = lease->connectors();
|
||||
for (KWaylandServer::DrmLeaseConnectorV1Interface *connector : connectors) {
|
||||
if (DrmLeaseOutput *output = findLeaseOutput(connector->id())) {
|
||||
output->leaseEnded();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,16 @@ namespace KWin
|
|||
{
|
||||
|
||||
DrmLeaseOutput::DrmLeaseOutput(DrmPipeline *pipeline, KWaylandServer::DrmLeaseDeviceV1Interface *leaseDevice)
|
||||
: KWaylandServer::DrmLeaseConnectorV1Interface(
|
||||
leaseDevice,
|
||||
pipeline->connector()->id(),
|
||||
pipeline->connector()->modelName(),
|
||||
QStringLiteral("%1 %2").arg(pipeline->connector()->edid()->manufacturerString(), pipeline->connector()->modelName()))
|
||||
, m_pipeline(pipeline)
|
||||
: m_pipeline(pipeline)
|
||||
{
|
||||
qCDebug(KWIN_DRM) << "offering connector" << m_pipeline->connector()->id() << "for lease";
|
||||
const DrmConnector *connector = pipeline->connector();
|
||||
qCDebug(KWIN_DRM) << "offering connector" << connector->id() << "for lease";
|
||||
|
||||
m_offer = std::make_unique<KWaylandServer::DrmLeaseConnectorV1Interface>(
|
||||
leaseDevice,
|
||||
connector->id(),
|
||||
connector->modelName(),
|
||||
QStringLiteral("%1 %2").arg(connector->edid()->manufacturerString(), connector->modelName()));
|
||||
}
|
||||
|
||||
DrmLeaseOutput::~DrmLeaseOutput()
|
||||
|
|
|
@ -24,12 +24,11 @@ class DrmPipeline;
|
|||
* that is not used directly by the compositor but is instead leased out to
|
||||
* applications (usually VR compositors) that drive the output themselves
|
||||
*/
|
||||
class DrmLeaseOutput : public KWaylandServer::DrmLeaseConnectorV1Interface
|
||||
class DrmLeaseOutput
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DrmLeaseOutput(DrmPipeline *pipeline, KWaylandServer::DrmLeaseDeviceV1Interface *leaseDevice);
|
||||
~DrmLeaseOutput() override;
|
||||
~DrmLeaseOutput();
|
||||
|
||||
bool addLeaseObjects(QVector<uint32_t> &objectList);
|
||||
void leased(KWaylandServer::DrmLeaseV1Interface *lease);
|
||||
|
@ -40,6 +39,7 @@ public:
|
|||
|
||||
private:
|
||||
DrmPipeline *m_pipeline;
|
||||
std::unique_ptr<KWaylandServer::DrmLeaseConnectorV1Interface> m_offer;
|
||||
KWaylandServer::DrmLeaseV1Interface *m_lease = nullptr;
|
||||
};
|
||||
|
||||
|
|
|
@ -182,6 +182,11 @@ DrmLeaseConnectorV1Interface::~DrmLeaseConnectorV1Interface()
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t DrmLeaseConnectorV1Interface::id() const
|
||||
{
|
||||
return d->connectorId;
|
||||
}
|
||||
|
||||
DrmLeaseConnectorV1Interface *DrmLeaseConnectorV1Interface::get(wl_resource *resource)
|
||||
{
|
||||
if (auto connectorPrivate = resource_cast<DrmLeaseConnectorV1InterfacePrivate *>(resource)) {
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
explicit DrmLeaseConnectorV1Interface(DrmLeaseDeviceV1Interface *leaseDevice, uint32_t id, const QString &name, const QString &description);
|
||||
~DrmLeaseConnectorV1Interface() override;
|
||||
|
||||
uint32_t id() const;
|
||||
|
||||
static DrmLeaseConnectorV1Interface *get(wl_resource *resource);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue