Commit 54a034b7 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

platforms/drm: Use dev nums to find gpus

This way we don't need to convert strings to ints every time
udev_device_get_sysnum() is called.
parent fe003909
......@@ -246,7 +246,7 @@ void DrmBackend::handleUdevEvent()
}
}
} else if (device->action() == QStringLiteral("remove")) {
DrmGpu *gpu = findGpu(device->sysNum());
DrmGpu *gpu = findGpu(device->devNum());
if (gpu) {
if (primaryGpu() == gpu) {
qCCritical(KWIN_DRM) << "Primary gpu has been removed! Quitting...";
......@@ -261,7 +261,7 @@ void DrmBackend::handleUdevEvent()
}
}
} else if (device->action() == QStringLiteral("change")) {
DrmGpu *gpu = findGpu(device->sysNum());
DrmGpu *gpu = findGpu(device->devNum());
if (gpu) {
qCDebug(KWIN_DRM) << "Received hot plug event for monitored drm device";
updateOutputs();
......@@ -288,7 +288,7 @@ DrmGpu *DrmBackend::addGpu(std::unique_ptr<UdevDevice> device)
}
drmModeFreeResources(resources);
DrmGpu *gpu = new DrmGpu(this, device->devNode(), fd, device->sysNum());
DrmGpu *gpu = new DrmGpu(this, device->devNode(), fd, device->devNum());
if (!gpu->useEglStreams() || m_gpus.isEmpty()) {
m_gpus.append(gpu);
m_active = true;
......@@ -673,10 +673,10 @@ DrmGpu *DrmBackend::primaryGpu() const
return m_gpus.isEmpty() ? nullptr : m_gpus[0];
}
DrmGpu *DrmBackend::findGpu(int sysNum) const
DrmGpu *DrmBackend::findGpu(dev_t deviceId) const
{
for (DrmGpu *gpu : qAsConst(m_gpus)) {
if (gpu->drmId() == sysNum) {
if (gpu->deviceId() == deviceId) {
return gpu;
}
}
......
......@@ -64,7 +64,7 @@ public:
QString supportInformation() const override;
DrmGpu *primaryGpu() const;
DrmGpu *findGpu(int sysNum) const;
DrmGpu *findGpu(dev_t deviceId) const;
public Q_SLOTS:
void turnOutputsOn();
......
......@@ -36,11 +36,11 @@
namespace KWin
{
DrmGpu::DrmGpu(DrmBackend *backend, QByteArray devNode, int fd, int drmId)
DrmGpu::DrmGpu(DrmBackend *backend, QByteArray devNode, int fd, dev_t deviceId)
: m_backend(backend)
, m_devNode(devNode)
, m_fd(fd)
, m_drmId(drmId)
, m_deviceId(deviceId)
, m_atomicModeSetting(false)
, m_gbmDevice(nullptr)
{
......
......@@ -34,7 +34,7 @@ class DrmGpu : public QObject
{
Q_OBJECT
public:
DrmGpu(DrmBackend *backend, QByteArray devNode, int fd, int drmId);
DrmGpu(DrmBackend *backend, QByteArray devNode, int fd, dev_t deviceId);
~DrmGpu();
// getters
......@@ -46,8 +46,8 @@ public:
return m_fd;
}
int drmId() const {
return m_drmId;
dev_t deviceId() const {
return m_deviceId;
}
bool atomicModeSetting() const {
......@@ -122,7 +122,7 @@ private:
const QByteArray m_devNode;
QSize m_cursorSize;
const int m_fd;
const int m_drmId;
const dev_t m_deviceId;
bool m_atomicModeSetting;
bool m_useEglStreams;
gbm_device* m_gbmDevice;
......
......@@ -213,9 +213,9 @@ const char *UdevDevice::devNode()
return udev_device_get_devnode(m_device);
}
int UdevDevice::sysNum() const
dev_t UdevDevice::devNum() const
{
return QByteArray(udev_device_get_sysnum(m_device)).toInt();
return udev_device_get_devnum(m_device);
}
const char *UdevDevice::property(const char *key)
......
......@@ -29,7 +29,7 @@ public:
~UdevDevice();
const char *devNode();
int sysNum() const;
dev_t devNum() const;
const char *property(const char *key);
bool hasProperty(const char *key, const char *value);
QString action() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment