diff --git a/src/plugins/platforms/drm/drm_gpu.cpp b/src/plugins/platforms/drm/drm_gpu.cpp index 3aebf181b6..a5fe5d50ee 100644 --- a/src/plugins/platforms/drm/drm_gpu.cpp +++ b/src/plugins/platforms/drm/drm_gpu.cpp @@ -111,7 +111,7 @@ void DrmGpu::tryAMS() // create the plane objects for (unsigned int i = 0; i < planeResources->count_planes; ++i) { DrmScopedPointer kplane(drmModeGetPlane(m_fd, planeResources->planes[i])); - DrmPlane *p = new DrmPlane(kplane->plane_id, m_fd); + DrmPlane *p = new DrmPlane(this, kplane->plane_id); if (p->init()) { m_planes << p; } else { @@ -142,7 +142,7 @@ bool DrmGpu::updateOutputs() const uint32_t currentConnector = resources->connectors[i]; auto it = std::find_if(m_connectors.constBegin(), m_connectors.constEnd(), [currentConnector] (DrmConnector *c) { return c->id() == currentConnector; }); if (it == m_connectors.constEnd()) { - auto c = new DrmConnector(currentConnector, m_fd); + auto c = new DrmConnector(this, currentConnector); if (!c->init()) { delete c; continue; @@ -165,7 +165,7 @@ bool DrmGpu::updateOutputs() const uint32_t currentCrtc = resources->crtcs[i]; auto it = std::find_if(m_crtcs.constBegin(), m_crtcs.constEnd(), [currentCrtc] (DrmCrtc *c) { return c->id() == currentCrtc; }); if (it == m_crtcs.constEnd()) { - auto c = new DrmCrtc(currentCrtc, m_backend, this, i); + auto c = new DrmCrtc(this, currentCrtc, m_backend, i); if (!c->init()) { delete c; continue; diff --git a/src/plugins/platforms/drm/drm_object.cpp b/src/plugins/platforms/drm/drm_object.cpp index 072967fa1d..ce1837fccc 100644 --- a/src/plugins/platforms/drm/drm_object.cpp +++ b/src/plugins/platforms/drm/drm_object.cpp @@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "drm_object.h" +#include "drm_gpu.h" #include "drm_pointer.h" #include "logging.h" @@ -18,8 +19,8 @@ namespace KWin * Definitions for class DrmObject */ -DrmObject::DrmObject(uint32_t object_id, int fd) - : m_fd(fd) +DrmObject::DrmObject(DrmGpu *gpu, uint32_t object_id) + : m_gpu(gpu) , m_id(object_id) { } @@ -33,14 +34,14 @@ DrmObject::~DrmObject() bool DrmObject::initProps(const QVector &&vector, uint32_t objectType) { - DrmScopedPointer properties(drmModeObjectGetProperties(fd(), m_id, objectType)); + DrmScopedPointer properties(drmModeObjectGetProperties(m_gpu->fd(), m_id, objectType)); if (!properties) { qCWarning(KWIN_DRM) << "Failed to get properties for object" << m_id; return false; } m_props.resize(vector.count()); for (uint32_t i = 0; i < properties->count_props; i++) { - DrmScopedPointer prop(drmModeGetProperty(fd(), properties->props[i])); + DrmScopedPointer prop(drmModeGetProperty(m_gpu->fd(), properties->props[i])); if (!prop) { qCWarning(KWIN_DRM, "Getting property %d of object %d failed!", i, m_id); continue; @@ -50,7 +51,7 @@ bool DrmObject::initProps(const QVector &&vector, uint32_t o if (def.name == prop->name) { drmModePropertyBlobRes *blob = nullptr; if (prop->flags & DRM_MODE_PROP_BLOB) { - blob = drmModeGetPropertyBlob(fd(), properties->prop_values[i]); + blob = drmModeGetPropertyBlob(m_gpu->fd(), properties->prop_values[i]); if (!blob) { break; } @@ -171,5 +172,5 @@ void DrmObject::Property::initEnumMap(drmModePropertyRes *prop) QDebug& operator<<(QDebug& s, const KWin::DrmObject *obj) { - return s.nospace() << "DrmObject(" << obj->id() << ", fd: "<< obj->fd() << ')'; + return s.nospace() << "DrmObject(" << obj->id() << ", gpu: "<< obj->gpu() << ')'; } diff --git a/src/plugins/platforms/drm/drm_object.h b/src/plugins/platforms/drm/drm_object.h index 51611c9b04..fe553713e0 100644 --- a/src/plugins/platforms/drm/drm_object.h +++ b/src/plugins/platforms/drm/drm_object.h @@ -20,6 +20,7 @@ namespace KWin { class DrmBackend; +class DrmGpu; class DrmOutput; class DrmObject @@ -30,7 +31,7 @@ public: * @param object_id provided by the kernel * @param fd of the DRM device */ - DrmObject(uint32_t object_id, int fd); + DrmObject(DrmGpu *gpu, uint32_t object_id); virtual ~DrmObject(); /** @@ -43,8 +44,8 @@ public: return m_id; } - int fd() const { - return m_fd; + DrmGpu *gpu() const { + return m_gpu; } /** @@ -163,6 +164,7 @@ protected: }; private: + DrmGpu *m_gpu; QVector m_propsNames; }; diff --git a/src/plugins/platforms/drm/drm_object_connector.cpp b/src/plugins/platforms/drm/drm_object_connector.cpp index c703e8d890..cfbd43f8b1 100644 --- a/src/plugins/platforms/drm/drm_object_connector.cpp +++ b/src/plugins/platforms/drm/drm_object_connector.cpp @@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "drm_object_connector.h" +#include "drm_gpu.h" #include "drm_pointer.h" #include "logging.h" @@ -17,9 +18,9 @@ namespace KWin { -DrmConnector::DrmConnector(uint32_t connector_id, int fd) - : DrmObject(connector_id, fd) - , m_conn(drmModeGetConnector(fd, connector_id)) +DrmConnector::DrmConnector(DrmGpu *gpu, uint32_t connector_id) + : DrmObject(gpu, connector_id) + , m_conn(drmModeGetConnector(gpu->fd(), connector_id)) { for (int i = 0; i < m_conn->count_encoders; ++i) { m_encoders << m_conn->encoders[i]; @@ -84,7 +85,7 @@ bool DrmConnector::init() bool DrmConnector::isConnected() { - DrmScopedPointer con(drmModeGetConnector(fd(), m_id)); + DrmScopedPointer con(drmModeGetConnector(gpu()->fd(), m_id)); if (!con) { return false; } diff --git a/src/plugins/platforms/drm/drm_object_connector.h b/src/plugins/platforms/drm/drm_object_connector.h index 16440f6a37..41752eb9dc 100644 --- a/src/plugins/platforms/drm/drm_object_connector.h +++ b/src/plugins/platforms/drm/drm_object_connector.h @@ -20,8 +20,7 @@ namespace KWin class DrmConnector : public DrmObject { public: - DrmConnector(uint32_t connector_id, int fd); - + DrmConnector(DrmGpu *gpu, uint32_t connector_id); ~DrmConnector() override; bool init() override; diff --git a/src/plugins/platforms/drm/drm_object_crtc.cpp b/src/plugins/platforms/drm/drm_object_crtc.cpp index c7f6e58fa6..b3d05bd3d2 100644 --- a/src/plugins/platforms/drm/drm_object_crtc.cpp +++ b/src/plugins/platforms/drm/drm_object_crtc.cpp @@ -17,12 +17,11 @@ namespace KWin { -DrmCrtc::DrmCrtc(uint32_t crtc_id, DrmBackend *backend, DrmGpu *gpu, int resIndex) - : DrmObject(crtc_id, gpu->fd()), +DrmCrtc::DrmCrtc(DrmGpu *gpu, uint32_t crtc_id, DrmBackend *backend, int resIndex) + : DrmObject(gpu, crtc_id), m_crtc(drmModeGetCrtc(gpu->fd(), crtc_id)), m_resIndex(resIndex), - m_backend(backend), - m_gpu(gpu) + m_backend(backend) { } @@ -49,12 +48,12 @@ void DrmCrtc::flipBuffer() bool DrmCrtc::blank(DrmOutput *output) { - if (m_gpu->atomicModeSetting()) { + if (gpu()->atomicModeSetting()) { return false; } if (!m_blackBuffer) { - DrmDumbBuffer *blackBuffer = new DrmDumbBuffer(m_gpu, output->pixelSize()); + DrmDumbBuffer *blackBuffer = new DrmDumbBuffer(gpu(), output->pixelSize()); if (!blackBuffer->map()) { delete blackBuffer; return false; @@ -77,7 +76,7 @@ bool DrmCrtc::setGammaRamp(const GammaRamp &gamma) uint16_t *green = const_cast(gamma.green()); uint16_t *blue = const_cast(gamma.blue()); - const bool isError = drmModeCrtcSetGamma(m_gpu->fd(), m_id, + const bool isError = drmModeCrtcSetGamma(gpu()->fd(), m_id, gamma.size(), red, green, blue); return !isError; diff --git a/src/plugins/platforms/drm/drm_object_crtc.h b/src/plugins/platforms/drm/drm_object_crtc.h index 57b607b9d8..5abc24ee15 100644 --- a/src/plugins/platforms/drm/drm_object_crtc.h +++ b/src/plugins/platforms/drm/drm_object_crtc.h @@ -25,7 +25,7 @@ class DrmGpu; class DrmCrtc : public DrmObject { public: - DrmCrtc(uint32_t crtc_id, DrmBackend *backend, DrmGpu *gpu, int resIndex); + DrmCrtc(DrmGpu *gpu, uint32_t crtc_id, DrmBackend *backend, int resIndex); bool init() override; @@ -57,10 +57,6 @@ public: } bool setGammaRamp(const GammaRamp &gamma); - DrmGpu *gpu() { - return m_gpu; - } - private: DrmScopedPointer m_crtc; int m_resIndex; @@ -69,7 +65,6 @@ private: QSharedPointer m_nextBuffer; DrmDumbBuffer *m_blackBuffer = nullptr; DrmBackend *m_backend; - DrmGpu *m_gpu; }; } diff --git a/src/plugins/platforms/drm/drm_object_plane.cpp b/src/plugins/platforms/drm/drm_object_plane.cpp index d45b3e09f1..cab44dcd8f 100644 --- a/src/plugins/platforms/drm/drm_object_plane.cpp +++ b/src/plugins/platforms/drm/drm_object_plane.cpp @@ -8,21 +8,22 @@ */ #include "drm_object_plane.h" #include "drm_buffer.h" +#include "drm_gpu.h" #include "drm_pointer.h" #include "logging.h" namespace KWin { -DrmPlane::DrmPlane(uint32_t plane_id, int fd) - : DrmObject(plane_id, fd) +DrmPlane::DrmPlane(DrmGpu *gpu, uint32_t plane_id) + : DrmObject(gpu, plane_id) { } bool DrmPlane::init() { qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id; - DrmScopedPointer p(drmModeGetPlane(fd(), m_id)); + DrmScopedPointer p(drmModeGetPlane(gpu()->fd(), m_id)); if (!p) { qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id; diff --git a/src/plugins/platforms/drm/drm_object_plane.h b/src/plugins/platforms/drm/drm_object_plane.h index b18f35110e..71850168d7 100644 --- a/src/plugins/platforms/drm/drm_object_plane.h +++ b/src/plugins/platforms/drm/drm_object_plane.h @@ -23,7 +23,7 @@ class DrmPlane : public DrmObject { Q_GADGET public: - DrmPlane(uint32_t plane_id, int fd); + DrmPlane(DrmGpu *gpu, uint32_t plane_id); enum class PropertyIndex : uint32_t { Type = 0,