platforms/drm: Don't search for gpus on add udev event

If a gpu is added, don't search for it pointlessly in m_gpus.
This commit is contained in:
Vlad Zahorodnii 2021-04-28 21:09:38 +03:00
parent a2ed8cb9da
commit fe0039091c
2 changed files with 26 additions and 17 deletions

View file

@ -236,13 +236,7 @@ void DrmBackend::handleUdevEvent()
if (!session()->isActive()) {
continue;
}
DrmGpu *drmGpu = nullptr;
for (const auto &gpu : qAsConst(m_gpus)) {
if (gpu->drmId() == device->sysNum()) {
drmGpu = gpu;
break;
}
}
if (device->action() == QStringLiteral("add")) {
if (m_gpus.isEmpty() || !primaryGpu()->useEglStreams()) {
if (const auto &gpu = addGpu(std::move(device))) {
@ -251,24 +245,28 @@ void DrmBackend::handleUdevEvent()
emit gpuAdded(gpu);
}
}
} else if (drmGpu) {
if (device->action() == QStringLiteral("change")) {
qCDebug(KWIN_DRM) << "Received hot plug event for monitored drm device";
updateOutputs();
updateCursor();
} else if (device->action() == QStringLiteral("remove")) {
if (primaryGpu() == drmGpu) {
} else if (device->action() == QStringLiteral("remove")) {
DrmGpu *gpu = findGpu(device->sysNum());
if (gpu) {
if (primaryGpu() == gpu) {
qCCritical(KWIN_DRM) << "Primary gpu has been removed! Quitting...";
kwinApp()->quit();
return;
} else {
emit gpuRemoved(drmGpu);
m_gpus.removeOne(drmGpu);
delete drmGpu;
emit gpuRemoved(gpu);
m_gpus.removeOne(gpu);
delete gpu;
updateOutputs();
updateCursor();
}
}
} else if (device->action() == QStringLiteral("change")) {
DrmGpu *gpu = findGpu(device->sysNum());
if (gpu) {
qCDebug(KWIN_DRM) << "Received hot plug event for monitored drm device";
updateOutputs();
updateCursor();
}
}
}
}
@ -675,4 +673,14 @@ DrmGpu *DrmBackend::primaryGpu() const
return m_gpus.isEmpty() ? nullptr : m_gpus[0];
}
DrmGpu *DrmBackend::findGpu(int sysNum) const
{
for (DrmGpu *gpu : qAsConst(m_gpus)) {
if (gpu->drmId() == sysNum) {
return gpu;
}
}
return nullptr;
}
}

View file

@ -64,6 +64,7 @@ public:
QString supportInformation() const override;
DrmGpu *primaryGpu() const;
DrmGpu *findGpu(int sysNum) const;
public Q_SLOTS:
void turnOutputsOn();