platforms/drm: prettify some headers

Makes them much more readable
This commit is contained in:
Xaver Hugl 2021-09-22 13:26:19 +02:00
parent 72af309317
commit 307b5ce3ca
10 changed files with 206 additions and 175 deletions

View file

@ -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<DrmPipeline*> DrmGpu::pipelines() const
@ -701,4 +701,59 @@ void DrmGpu::removeLeaseOutput(DrmLeaseOutput *output)
delete pipeline;
}
QVector<DrmAbstractOutput*> 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;
}
}

View file

@ -48,65 +48,33 @@ public:
DrmGpu(DrmBackend *backend, const QString &devNode, int fd, dev_t deviceId);
~DrmGpu();
// getters
QVector<DrmAbstractOutput*> 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<DrmAbstractOutput*> outputs() const;
const QVector<DrmPipeline*> pipelines() const;
void setGbmDevice(gbm_device *d);
void setEglDisplay(EGLDisplay display);
void setEglBackend(AbstractEglDrmBackend *eglBackend);
void waitIdle();
DrmBackend *platform() const;
const QVector<DrmPipeline*> 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<AbstractEglDrmBackend> 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<AbstractEglDrmBackend> m_eglBackend;
DrmBackend* const m_platform;
QVector<DrmPlane*> m_planes;
QVector<DrmCrtc*> m_crtcs;
@ -155,11 +116,12 @@ private:
QVector<DrmPipeline*> m_pipelines;
QVector<DrmOutput*> m_drmOutputs;
// includes virtual outputs
QVector<DrmAbstractOutput*> m_outputs;
// for DRM leasing:
QVector<DrmLeaseOutput*> m_leaseOutputs;
KWaylandServer::DrmLeaseDeviceV1Interface *m_leaseDevice = nullptr;
QSocketNotifier *m_socketNotifier = nullptr;
QSize m_cursorSize;
};
}

View file

@ -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
*/

View file

@ -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 <typename T>
bool setPending(T prop, uint64_t new_value)
@ -169,14 +165,6 @@ public:
}
QVector<Property*> properties();
void commit();
void commitPending();
void rollbackPending();
bool needsCommit() const;
virtual bool needsModeset() const = 0;
virtual bool updateProperties();
protected:
enum class Requirement {

View file

@ -347,4 +347,20 @@ bool DrmConnector::updateProperties()
return m_conn != nullptr;
}
QVector<uint32_t> 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;
}
}

View file

@ -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<uint32_t> encoders() {
return m_encoders;
}
bool init() override;
bool needsModeset() const override;
bool updateProperties() override;
QVector<uint32_t> encoders() const;
bool isConnected() const;
bool isNonDesktop() const;
bool isInternal() const;
bool isNonDesktop() const {
auto prop = m_props.at(static_cast<uint32_t>(PropertyIndex::NonDesktop));
if (!prop) {
return false;
}
return prop->pending();
}
Property *dpms() const {
return m_props[static_cast<uint32_t>(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<Mode> &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<drmModeConnector> m_conn;
QVector<uint32_t> m_encoders;

View file

@ -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<DrmBuffer> DrmCrtc::current() const
{
return m_currentBuffer;
}
QSharedPointer<DrmBuffer> DrmCrtc::next() const
{
return m_nextBuffer;
}
void DrmCrtc::setCurrent(const QSharedPointer<DrmBuffer> &buffer)
{
m_currentBuffer = buffer;
}
void DrmCrtc::setNext(const QSharedPointer<DrmBuffer> &buffer)
{
m_nextBuffer = buffer;
}
int DrmCrtc::gammaRampSize() const
{
return m_crtc->gamma_size;
}
}

View file

@ -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<DrmBuffer> current() const {
return m_currentBuffer;
}
QSharedPointer<DrmBuffer> next() const {
return m_nextBuffer;
}
void setCurrent(const QSharedPointer<DrmBuffer> &buffer) {
m_currentBuffer = buffer;
}
void setNext(const QSharedPointer<DrmBuffer> &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<DrmBuffer> current() const;
QSharedPointer<DrmBuffer> next() const;
void setCurrent(const QSharedPointer<DrmBuffer> &buffer);
void setNext(const QSharedPointer<DrmBuffer> &buffer);
void flipBuffer();
private:
DrmScopedPointer<drmModeCrtc> m_crtc;
QSharedPointer<DrmBuffer> m_currentBuffer;
QSharedPointer<DrmBuffer> m_nextBuffer;
DrmDumbBuffer *m_blackBuffer = nullptr;
int m_pipeIndex;
};

View file

@ -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<uint32_t, QVector<uint64_t>> DrmPlane::formats() const
{
return m_supportedFormats;
}
QSharedPointer<DrmBuffer> DrmPlane::current() const
{
return m_current;
}
QSharedPointer<DrmBuffer> DrmPlane::next() const
{
return m_next;
}
void DrmPlane::setCurrent(const QSharedPointer<DrmBuffer> &b)
{
m_current = b;
}
DrmPlane::Transformations DrmPlane::supportedTransformations() const
{
return m_supportedTransformations;
}
}

View file

@ -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<uint32_t, QVector<uint64_t>> formats() const {
return m_supportedFormats;
}
bool isCrtcSupported(int pipeIndex) const;
QMap<uint32_t, QVector<uint64_t>> formats() const;
QSharedPointer<DrmBuffer> current() const {
return m_current;
}
QSharedPointer<DrmBuffer> next() const {
return m_next;
}
void setCurrent(const QSharedPointer<DrmBuffer> &b) {
m_current = b;
}
QSharedPointer<DrmBuffer> current() const;
QSharedPointer<DrmBuffer> next() const;
void setCurrent(const QSharedPointer<DrmBuffer> &b);
void setNext(const QSharedPointer<DrmBuffer> &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<DrmBuffer> m_current;