From 307b5ce3caafc8359aaa2cebab5be19067298a9d Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 22 Sep 2021 13:26:19 +0200 Subject: [PATCH] platforms/drm: prettify some headers Makes them much more readable --- src/plugins/platforms/drm/drm_gpu.cpp | 71 +++++++++++++-- src/plugins/platforms/drm/drm_gpu.h | 88 ++++++------------- src/plugins/platforms/drm/drm_object.cpp | 10 +++ src/plugins/platforms/drm/drm_object.h | 28 ++---- .../platforms/drm/drm_object_connector.cpp | 16 ++++ .../platforms/drm/drm_object_connector.h | 39 ++------ src/plugins/platforms/drm/drm_object_crtc.cpp | 30 ++++++- src/plugins/platforms/drm/drm_object_crtc.h | 35 ++------ .../platforms/drm/drm_object_plane.cpp | 30 +++++++ src/plugins/platforms/drm/drm_object_plane.h | 34 +++---- 10 files changed, 206 insertions(+), 175 deletions(-) diff --git a/src/plugins/platforms/drm/drm_gpu.cpp b/src/plugins/platforms/drm/drm_gpu.cpp index 520f6fc5f8..f3f9784cc7 100644 --- a/src/plugins/platforms/drm/drm_gpu.cpp +++ b/src/plugins/platforms/drm/drm_gpu.cpp @@ -46,12 +46,12 @@ namespace KWin { DrmGpu::DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t deviceId) - : m_backend(backend) - , m_devNode(devNode) - , m_fd(fd) + : m_fd(fd) , m_deviceId(deviceId) + , m_devNode(devNode) , m_atomicModeSetting(false) , m_gbmDevice(nullptr) + , m_platform(backend) { uint64_t capability = 0; @@ -108,7 +108,7 @@ DrmGpu::DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t device }); connect(m_leaseDevice, &KWaylandServer::DrmLeaseDeviceV1Interface::leaseRequested, this, &DrmGpu::handleLeaseRequest); connect(m_leaseDevice, &KWaylandServer::DrmLeaseDeviceV1Interface::leaseRevoked, this, &DrmGpu::handleLeaseRevoked); - connect(m_backend->session(), &Session::activeChanged, m_leaseDevice, [this](bool active){ + connect(m_platform->session(), &Session::activeChanged, m_leaseDevice, [this](bool active){ if (!active) { // when we gain drm master we want to update outputs first and only then notify the lease device m_leaseDevice->setDrmMaster(active); @@ -144,7 +144,7 @@ DrmGpu::~DrmGpu() gbm_device_destroy(m_gbmDevice); } #endif - m_backend->session()->closeRestricted(m_fd); + m_platform->session()->closeRestricted(m_fd); } clockid_t DrmGpu::presentationClock() const @@ -356,7 +356,7 @@ bool DrmGpu::updateOutputs() } else { qCDebug(KWIN_DRM).nospace() << "New output on GPU " << m_devNode << ": " << pipeline->connector()->modelName(); if (!output->initCursor(m_cursorSize)) { - m_backend->setSoftwareCursorForced(true); + m_platform->setSoftwareCursorForced(true); } m_outputs << output; m_drmOutputs << output; @@ -558,7 +558,7 @@ static void pageFlipHandler(int fd, unsigned int frame, unsigned int sec, unsign void DrmGpu::dispatchEvents() { - if (!m_backend->session()->isActive()) { + if (!m_platform->session()->isActive()) { return; } drmEventContext context = {}; @@ -592,7 +592,7 @@ void DrmGpu::setEglBackend(AbstractEglDrmBackend *eglBackend) } DrmBackend *DrmGpu::platform() const { - return m_backend; + return m_platform; } const QVector DrmGpu::pipelines() const @@ -701,4 +701,59 @@ void DrmGpu::removeLeaseOutput(DrmLeaseOutput *output) delete pipeline; } +QVector DrmGpu::outputs() const +{ + return m_outputs; +} + +int DrmGpu::fd() const +{ + return m_fd; +} + +dev_t DrmGpu::deviceId() const +{ + return m_deviceId; +} + +bool DrmGpu::atomicModeSetting() const +{ + return m_atomicModeSetting; +} + +bool DrmGpu::useEglStreams() const +{ + return m_useEglStreams; +} + +QString DrmGpu::devNode() const +{ + return m_devNode; +} + +gbm_device *DrmGpu::gbmDevice() const +{ + return m_gbmDevice; +} + +EGLDisplay DrmGpu::eglDisplay() const +{ + return m_eglDisplay; +} + +void DrmGpu::setGbmDevice(gbm_device *d) +{ + m_gbmDevice = d; +} + +void DrmGpu::setEglDisplay(EGLDisplay display) +{ + m_eglDisplay = display; +} + +bool DrmGpu::addFB2ModifiersSupported() const +{ + return m_addFB2ModifiersSupported; +} + } diff --git a/src/plugins/platforms/drm/drm_gpu.h b/src/plugins/platforms/drm/drm_gpu.h index c96d95083c..aef21da8f6 100644 --- a/src/plugins/platforms/drm/drm_gpu.h +++ b/src/plugins/platforms/drm/drm_gpu.h @@ -48,65 +48,33 @@ public: DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t deviceId); ~DrmGpu(); - // getters - QVector outputs() const { - return m_outputs; - } - - int fd() const { - return m_fd; - } - - dev_t deviceId() const { - return m_deviceId; - } - - bool atomicModeSetting() const { - return m_atomicModeSetting; - } - - bool useEglStreams() const { - return m_useEglStreams; - } - - QString devNode() const { - return m_devNode; - } - - gbm_device *gbmDevice() const { - return m_gbmDevice; - } - - EGLDisplay eglDisplay() const { - return m_eglDisplay; - } + int fd() const; + dev_t deviceId() const; + QString devNode() const; + bool atomicModeSetting() const; + bool addFB2ModifiersSupported() const; + bool useEglStreams() const; + bool isFormatSupported(uint32_t drmFormat) const; + gbm_device *gbmDevice() const; + EGLDisplay eglDisplay() const; AbstractEglDrmBackend *eglBackend() const; - void setEglBackend(AbstractEglDrmBackend *eglBackend); - - void setGbmDevice(gbm_device *d) { - m_gbmDevice = d; - } - - void setEglDisplay(EGLDisplay display) { - m_eglDisplay = display; - } - + DrmBackend *platform() const; /** * Returns the clock from which presentation timestamps are sourced. The returned value * can be either CLOCK_MONOTONIC or CLOCK_REALTIME. */ clockid_t presentationClock() const; - bool addFB2ModifiersSupported() const { - return m_addFB2ModifiersSupported; - } + QVector outputs() const; + const QVector pipelines() const; + + void setGbmDevice(gbm_device *d); + void setEglDisplay(EGLDisplay display); + void setEglBackend(AbstractEglDrmBackend *eglBackend); void waitIdle(); - DrmBackend *platform() const; - const QVector pipelines() const; - bool isFormatSupported(uint32_t drmFormat) const; - + bool updateOutputs(); DrmVirtualOutput *createVirtualOutput(); void removeVirtualOutput(DrmVirtualOutput *output); @@ -116,10 +84,6 @@ Q_SIGNALS: void outputEnabled(DrmAbstractOutput *output); void outputDisabled(DrmAbstractOutput *output); -protected: - friend class DrmBackend; - bool updateOutputs(); - private: void dispatchEvents(); DrmOutput *findOutput(quint32 connector); @@ -134,20 +98,17 @@ private: void handleLeaseRequest(KWaylandServer::DrmLeaseV1Interface *leaseRequest); void handleLeaseRevoked(KWaylandServer::DrmLeaseV1Interface *lease); - DrmBackend* const m_backend; - QPointer m_eglBackend; - - const QString m_devNode; - QSize m_cursorSize; const int m_fd; const dev_t m_deviceId; + const QString m_devNode; bool m_atomicModeSetting; bool m_useEglStreams; + bool m_addFB2ModifiersSupported = false; + clockid_t m_presentationClock; gbm_device* m_gbmDevice; EGLDisplay m_eglDisplay = EGL_NO_DISPLAY; - clockid_t m_presentationClock; - QSocketNotifier *m_socketNotifier = nullptr; - bool m_addFB2ModifiersSupported = false; + QPointer m_eglBackend; + DrmBackend* const m_platform; QVector m_planes; QVector m_crtcs; @@ -155,11 +116,12 @@ private: QVector m_pipelines; QVector m_drmOutputs; - // includes virtual outputs QVector m_outputs; - // for DRM leasing: QVector m_leaseOutputs; KWaylandServer::DrmLeaseDeviceV1Interface *m_leaseDevice = nullptr; + + QSocketNotifier *m_socketNotifier = nullptr; + QSize m_cursorSize; }; } diff --git a/src/plugins/platforms/drm/drm_object.cpp b/src/plugins/platforms/drm/drm_object.cpp index 6202f5488b..e4b58fd04c 100644 --- a/src/plugins/platforms/drm/drm_object.cpp +++ b/src/plugins/platforms/drm/drm_object.cpp @@ -177,6 +177,16 @@ bool DrmObject::updateProperties() return true; } +uint32_t DrmObject::id() const +{ + return m_id; +} + +DrmGpu *DrmObject::gpu() const +{ + return m_gpu; +} + /* * Definitions for DrmObject::Property */ diff --git a/src/plugins/platforms/drm/drm_object.h b/src/plugins/platforms/drm/drm_object.h index 889279dbfa..f889064313 100644 --- a/src/plugins/platforms/drm/drm_object.h +++ b/src/plugins/platforms/drm/drm_object.h @@ -35,20 +35,16 @@ public: */ virtual bool init() = 0; - uint32_t id() const { - return m_id; - } + uint32_t id() const; + DrmGpu *gpu() const; - DrmGpu *gpu() const { - return m_gpu; - } - - /** - * Populate an atomic request with data of this object. - * @param req the atomic request - * @return true when the request was successfully populated - */ + void commit(); + void commitPending(); + void rollbackPending(); bool atomicPopulate(drmModeAtomicReq *req) const; + bool needsCommit() const; + virtual bool needsModeset() const = 0; + virtual bool updateProperties(); template bool setPending(T prop, uint64_t new_value) @@ -169,14 +165,6 @@ public: } QVector properties(); - void commit(); - void commitPending(); - void rollbackPending(); - - bool needsCommit() const; - virtual bool needsModeset() const = 0; - - virtual bool updateProperties(); protected: enum class Requirement { diff --git a/src/plugins/platforms/drm/drm_object_connector.cpp b/src/plugins/platforms/drm/drm_object_connector.cpp index f52da65bf9..0c0e4308d8 100644 --- a/src/plugins/platforms/drm/drm_object_connector.cpp +++ b/src/plugins/platforms/drm/drm_object_connector.cpp @@ -347,4 +347,20 @@ bool DrmConnector::updateProperties() return m_conn != nullptr; } +QVector DrmConnector::encoders() const +{ + return m_encoders; +} + +bool DrmConnector::isNonDesktop() const +{ + const auto &prop = getProp(PropertyIndex::NonDesktop); + return prop && prop->current(); +} + +const Edid *DrmConnector::edid() const +{ + return &m_edid; +} + } diff --git a/src/plugins/platforms/drm/drm_object_connector.h b/src/plugins/platforms/drm/drm_object_connector.h index bed82e021d..13715f264e 100644 --- a/src/plugins/platforms/drm/drm_object_connector.h +++ b/src/plugins/platforms/drm/drm_object_connector.h @@ -28,8 +28,6 @@ public: DrmConnector(DrmGpu *gpu, uint32_t connectorId); ~DrmConnector() override; - bool init() override; - enum class PropertyIndex : uint32_t { CrtcId = 0, NonDesktop = 1, @@ -50,32 +48,18 @@ public: Auto = 2, }; - QVector encoders() { - return m_encoders; - } + bool init() override; + bool needsModeset() const override; + bool updateProperties() override; + QVector encoders() const; bool isConnected() const; + bool isNonDesktop() const; + bool isInternal() const; - bool isNonDesktop() const { - auto prop = m_props.at(static_cast(PropertyIndex::NonDesktop)); - if (!prop) { - return false; - } - return prop->pending(); - } - - Property *dpms() const { - return m_props[static_cast(PropertyIndex::Dpms)]; - } - - const Edid *edid() const { - return &m_edid; - } - + const Edid *edid() const; QString connectorName() const; QString modelName() const; - - bool isInternal() const; QSize physicalSize() const; struct Mode { @@ -88,23 +72,16 @@ public: const QVector &modes(); void setModeIndex(int index); void findCurrentMode(drmModeModeInfo currentMode); - - AbstractWaylandOutput::SubPixel subpixel() const; - void updateModes(); + AbstractWaylandOutput::SubPixel subpixel() const; bool hasOverscan() const; uint32_t overscan() const; void setOverscan(uint32_t overscan, const QSize &modeSize); - bool vrrCapable() const; - bool hasRgbRange() const; AbstractWaylandOutput::RgbRange rgbRange() const; - bool needsModeset() const override; - bool updateProperties() override; - private: DrmScopedPointer m_conn; QVector m_encoders; diff --git a/src/plugins/platforms/drm/drm_object_crtc.cpp b/src/plugins/platforms/drm/drm_object_crtc.cpp index 64ce864989..577e547e62 100644 --- a/src/plugins/platforms/drm/drm_object_crtc.cpp +++ b/src/plugins/platforms/drm/drm_object_crtc.cpp @@ -41,9 +41,6 @@ void DrmCrtc::flipBuffer() { m_currentBuffer = m_nextBuffer; m_nextBuffer = nullptr; - - delete m_blackBuffer; - m_blackBuffer = nullptr; } drmModeModeInfo DrmCrtc::queryCurrentMode() @@ -58,4 +55,31 @@ bool DrmCrtc::needsModeset() const || getProp(PropertyIndex::ModeId)->needsCommit(); } +int DrmCrtc::pipeIndex() const +{ + return m_pipeIndex; +} + +QSharedPointer DrmCrtc::current() const +{ + return m_currentBuffer; +} +QSharedPointer DrmCrtc::next() const +{ + return m_nextBuffer; +} +void DrmCrtc::setCurrent(const QSharedPointer &buffer) +{ + m_currentBuffer = buffer; +} +void DrmCrtc::setNext(const QSharedPointer &buffer) +{ + m_nextBuffer = buffer; +} + +int DrmCrtc::gammaRampSize() const +{ + return m_crtc->gamma_size; +} + } diff --git a/src/plugins/platforms/drm/drm_object_crtc.h b/src/plugins/platforms/drm/drm_object_crtc.h index f9d961c49e..7a5efedd23 100644 --- a/src/plugins/platforms/drm/drm_object_crtc.h +++ b/src/plugins/platforms/drm/drm_object_crtc.h @@ -27,8 +27,6 @@ class DrmCrtc : public DrmObject public: DrmCrtc(DrmGpu *gpu, uint32_t crtcId, int pipeIndex); - bool init() override; - enum class PropertyIndex : uint32_t { ModeId = 0, Active, @@ -37,38 +35,23 @@ public: Count }; - int pipeIndex() const { - return m_pipeIndex; - } - - QSharedPointer current() const { - return m_currentBuffer; - } - QSharedPointer next() const { - return m_nextBuffer; - } - void setCurrent(const QSharedPointer &buffer) { - m_currentBuffer = buffer; - } - void setNext(const QSharedPointer &buffer) { - m_nextBuffer = buffer; - } - - void flipBuffer(); - - int gammaRampSize() const { - return m_crtc->gamma_size; - } + bool init() override; + bool needsModeset() const override; + int pipeIndex() const; + int gammaRampSize() const; drmModeModeInfo queryCurrentMode(); - bool needsModeset() const override; + QSharedPointer current() const; + QSharedPointer next() const; + void setCurrent(const QSharedPointer &buffer); + void setNext(const QSharedPointer &buffer); + void flipBuffer(); private: DrmScopedPointer m_crtc; QSharedPointer m_currentBuffer; QSharedPointer m_nextBuffer; - DrmDumbBuffer *m_blackBuffer = nullptr; int m_pipeIndex; }; diff --git a/src/plugins/platforms/drm/drm_object_plane.cpp b/src/plugins/platforms/drm/drm_object_plane.cpp index 000b28ef5a..ffa433c582 100644 --- a/src/plugins/platforms/drm/drm_object_plane.cpp +++ b/src/plugins/platforms/drm/drm_object_plane.cpp @@ -172,4 +172,34 @@ bool DrmPlane::needsModeset() const return getProp(PropertyIndex::CrtcId)->needsCommit(); } +bool DrmPlane::isCrtcSupported(int pipeIndex) const +{ + return (m_possibleCrtcs & (1 << pipeIndex)); +} + +QMap> DrmPlane::formats() const +{ + return m_supportedFormats; +} + +QSharedPointer DrmPlane::current() const +{ + return m_current; +} + +QSharedPointer DrmPlane::next() const +{ + return m_next; +} + +void DrmPlane::setCurrent(const QSharedPointer &b) +{ + m_current = b; +} + +DrmPlane::Transformations DrmPlane::supportedTransformations() const +{ + return m_supportedTransformations; +} + } diff --git a/src/plugins/platforms/drm/drm_object_plane.h b/src/plugins/platforms/drm/drm_object_plane.h index 9f17e20d59..3c0d72a3e3 100644 --- a/src/plugins/platforms/drm/drm_object_plane.h +++ b/src/plugins/platforms/drm/drm_object_plane.h @@ -63,38 +63,24 @@ public: Q_DECLARE_FLAGS(Transformations, Transformation); bool init() override; + bool needsModeset() const override; TypeIndex type(); - bool isCrtcSupported(int pipeIndex) const { - return (m_possibleCrtcs & (1 << pipeIndex)); - } - QMap> formats() const { - return m_supportedFormats; - } + bool isCrtcSupported(int pipeIndex) const; + QMap> formats() const; - QSharedPointer current() const { - return m_current; - } - QSharedPointer next() const { - return m_next; - } - void setCurrent(const QSharedPointer &b) { - m_current = b; - } + QSharedPointer current() const; + QSharedPointer next() const; + void setCurrent(const QSharedPointer &b); void setNext(const QSharedPointer &b); - bool setTransformation(Transformations t); - Transformations transformation(); - void flipBuffer(); - Transformations supportedTransformations() const { - return m_supportedTransformations; - } - - void set(const QPoint &srcPos, const QSize &srcSize, const QPoint &dstPos, const QSize &dstSize); void setBuffer(DrmBuffer *buffer); + void set(const QPoint &srcPos, const QSize &srcSize, const QPoint &dstPos, const QSize &dstSize); - bool needsModeset() const override; + bool setTransformation(Transformations t); + Transformations transformation(); + Transformations supportedTransformations() const; private: QSharedPointer m_current;