platforms/drm: Associate drm objects with their gpus
This makes the code more consistent. At the moment, we initialize drm objects either with the corresponding gpu object or with its fd.
This commit is contained in:
parent
75e7562953
commit
f534b64e5c
9 changed files with 33 additions and 35 deletions
|
@ -111,7 +111,7 @@ void DrmGpu::tryAMS()
|
||||||
// create the plane objects
|
// create the plane objects
|
||||||
for (unsigned int i = 0; i < planeResources->count_planes; ++i) {
|
for (unsigned int i = 0; i < planeResources->count_planes; ++i) {
|
||||||
DrmScopedPointer<drmModePlane> kplane(drmModeGetPlane(m_fd, planeResources->planes[i]));
|
DrmScopedPointer<drmModePlane> 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()) {
|
if (p->init()) {
|
||||||
m_planes << p;
|
m_planes << p;
|
||||||
} else {
|
} else {
|
||||||
|
@ -142,7 +142,7 @@ bool DrmGpu::updateOutputs()
|
||||||
const uint32_t currentConnector = resources->connectors[i];
|
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; });
|
auto it = std::find_if(m_connectors.constBegin(), m_connectors.constEnd(), [currentConnector] (DrmConnector *c) { return c->id() == currentConnector; });
|
||||||
if (it == m_connectors.constEnd()) {
|
if (it == m_connectors.constEnd()) {
|
||||||
auto c = new DrmConnector(currentConnector, m_fd);
|
auto c = new DrmConnector(this, currentConnector);
|
||||||
if (!c->init()) {
|
if (!c->init()) {
|
||||||
delete c;
|
delete c;
|
||||||
continue;
|
continue;
|
||||||
|
@ -165,7 +165,7 @@ bool DrmGpu::updateOutputs()
|
||||||
const uint32_t currentCrtc = resources->crtcs[i];
|
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; });
|
auto it = std::find_if(m_crtcs.constBegin(), m_crtcs.constEnd(), [currentCrtc] (DrmCrtc *c) { return c->id() == currentCrtc; });
|
||||||
if (it == m_crtcs.constEnd()) {
|
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()) {
|
if (!c->init()) {
|
||||||
delete c;
|
delete c;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
#include "drm_object.h"
|
#include "drm_object.h"
|
||||||
|
#include "drm_gpu.h"
|
||||||
#include "drm_pointer.h"
|
#include "drm_pointer.h"
|
||||||
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
@ -18,8 +19,8 @@ namespace KWin
|
||||||
* Definitions for class DrmObject
|
* Definitions for class DrmObject
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DrmObject::DrmObject(uint32_t object_id, int fd)
|
DrmObject::DrmObject(DrmGpu *gpu, uint32_t object_id)
|
||||||
: m_fd(fd)
|
: m_gpu(gpu)
|
||||||
, m_id(object_id)
|
, m_id(object_id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -33,14 +34,14 @@ DrmObject::~DrmObject()
|
||||||
|
|
||||||
bool DrmObject::initProps(const QVector<PropertyDefinition> &&vector, uint32_t objectType)
|
bool DrmObject::initProps(const QVector<PropertyDefinition> &&vector, uint32_t objectType)
|
||||||
{
|
{
|
||||||
DrmScopedPointer<drmModeObjectProperties> properties(drmModeObjectGetProperties(fd(), m_id, objectType));
|
DrmScopedPointer<drmModeObjectProperties> properties(drmModeObjectGetProperties(m_gpu->fd(), m_id, objectType));
|
||||||
if (!properties) {
|
if (!properties) {
|
||||||
qCWarning(KWIN_DRM) << "Failed to get properties for object" << m_id;
|
qCWarning(KWIN_DRM) << "Failed to get properties for object" << m_id;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_props.resize(vector.count());
|
m_props.resize(vector.count());
|
||||||
for (uint32_t i = 0; i < properties->count_props; i++) {
|
for (uint32_t i = 0; i < properties->count_props; i++) {
|
||||||
DrmScopedPointer<drmModePropertyRes> prop(drmModeGetProperty(fd(), properties->props[i]));
|
DrmScopedPointer<drmModePropertyRes> prop(drmModeGetProperty(m_gpu->fd(), properties->props[i]));
|
||||||
if (!prop) {
|
if (!prop) {
|
||||||
qCWarning(KWIN_DRM, "Getting property %d of object %d failed!", i, m_id);
|
qCWarning(KWIN_DRM, "Getting property %d of object %d failed!", i, m_id);
|
||||||
continue;
|
continue;
|
||||||
|
@ -50,7 +51,7 @@ bool DrmObject::initProps(const QVector<PropertyDefinition> &&vector, uint32_t o
|
||||||
if (def.name == prop->name) {
|
if (def.name == prop->name) {
|
||||||
drmModePropertyBlobRes *blob = nullptr;
|
drmModePropertyBlobRes *blob = nullptr;
|
||||||
if (prop->flags & DRM_MODE_PROP_BLOB) {
|
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) {
|
if (!blob) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -171,5 +172,5 @@ void DrmObject::Property::initEnumMap(drmModePropertyRes *prop)
|
||||||
|
|
||||||
QDebug& operator<<(QDebug& s, const KWin::DrmObject *obj)
|
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() << ')';
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
class DrmBackend;
|
class DrmBackend;
|
||||||
|
class DrmGpu;
|
||||||
class DrmOutput;
|
class DrmOutput;
|
||||||
|
|
||||||
class DrmObject
|
class DrmObject
|
||||||
|
@ -30,7 +31,7 @@ public:
|
||||||
* @param object_id provided by the kernel
|
* @param object_id provided by the kernel
|
||||||
* @param fd of the DRM device
|
* @param fd of the DRM device
|
||||||
*/
|
*/
|
||||||
DrmObject(uint32_t object_id, int fd);
|
DrmObject(DrmGpu *gpu, uint32_t object_id);
|
||||||
virtual ~DrmObject();
|
virtual ~DrmObject();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,8 +44,8 @@ public:
|
||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd() const {
|
DrmGpu *gpu() const {
|
||||||
return m_fd;
|
return m_gpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,6 +164,7 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DrmGpu *m_gpu;
|
||||||
QVector<QByteArray> m_propsNames;
|
QVector<QByteArray> m_propsNames;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
#include "drm_object_connector.h"
|
#include "drm_object_connector.h"
|
||||||
|
#include "drm_gpu.h"
|
||||||
#include "drm_pointer.h"
|
#include "drm_pointer.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
@ -17,9 +18,9 @@
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
DrmConnector::DrmConnector(uint32_t connector_id, int fd)
|
DrmConnector::DrmConnector(DrmGpu *gpu, uint32_t connector_id)
|
||||||
: DrmObject(connector_id, fd)
|
: DrmObject(gpu, connector_id)
|
||||||
, m_conn(drmModeGetConnector(fd, connector_id))
|
, m_conn(drmModeGetConnector(gpu->fd(), connector_id))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_conn->count_encoders; ++i) {
|
for (int i = 0; i < m_conn->count_encoders; ++i) {
|
||||||
m_encoders << m_conn->encoders[i];
|
m_encoders << m_conn->encoders[i];
|
||||||
|
@ -84,7 +85,7 @@ bool DrmConnector::init()
|
||||||
|
|
||||||
bool DrmConnector::isConnected()
|
bool DrmConnector::isConnected()
|
||||||
{
|
{
|
||||||
DrmScopedPointer<drmModeConnector> con(drmModeGetConnector(fd(), m_id));
|
DrmScopedPointer<drmModeConnector> con(drmModeGetConnector(gpu()->fd(), m_id));
|
||||||
if (!con) {
|
if (!con) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@ namespace KWin
|
||||||
class DrmConnector : public DrmObject
|
class DrmConnector : public DrmObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DrmConnector(uint32_t connector_id, int fd);
|
DrmConnector(DrmGpu *gpu, uint32_t connector_id);
|
||||||
|
|
||||||
~DrmConnector() override;
|
~DrmConnector() override;
|
||||||
|
|
||||||
bool init() override;
|
bool init() override;
|
||||||
|
|
|
@ -17,12 +17,11 @@
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
DrmCrtc::DrmCrtc(uint32_t crtc_id, DrmBackend *backend, DrmGpu *gpu, int resIndex)
|
DrmCrtc::DrmCrtc(DrmGpu *gpu, uint32_t crtc_id, DrmBackend *backend, int resIndex)
|
||||||
: DrmObject(crtc_id, gpu->fd()),
|
: DrmObject(gpu, crtc_id),
|
||||||
m_crtc(drmModeGetCrtc(gpu->fd(), crtc_id)),
|
m_crtc(drmModeGetCrtc(gpu->fd(), crtc_id)),
|
||||||
m_resIndex(resIndex),
|
m_resIndex(resIndex),
|
||||||
m_backend(backend),
|
m_backend(backend)
|
||||||
m_gpu(gpu)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,12 +48,12 @@ void DrmCrtc::flipBuffer()
|
||||||
|
|
||||||
bool DrmCrtc::blank(DrmOutput *output)
|
bool DrmCrtc::blank(DrmOutput *output)
|
||||||
{
|
{
|
||||||
if (m_gpu->atomicModeSetting()) {
|
if (gpu()->atomicModeSetting()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_blackBuffer) {
|
if (!m_blackBuffer) {
|
||||||
DrmDumbBuffer *blackBuffer = new DrmDumbBuffer(m_gpu, output->pixelSize());
|
DrmDumbBuffer *blackBuffer = new DrmDumbBuffer(gpu(), output->pixelSize());
|
||||||
if (!blackBuffer->map()) {
|
if (!blackBuffer->map()) {
|
||||||
delete blackBuffer;
|
delete blackBuffer;
|
||||||
return false;
|
return false;
|
||||||
|
@ -77,7 +76,7 @@ bool DrmCrtc::setGammaRamp(const GammaRamp &gamma)
|
||||||
uint16_t *green = const_cast<uint16_t *>(gamma.green());
|
uint16_t *green = const_cast<uint16_t *>(gamma.green());
|
||||||
uint16_t *blue = const_cast<uint16_t *>(gamma.blue());
|
uint16_t *blue = const_cast<uint16_t *>(gamma.blue());
|
||||||
|
|
||||||
const bool isError = drmModeCrtcSetGamma(m_gpu->fd(), m_id,
|
const bool isError = drmModeCrtcSetGamma(gpu()->fd(), m_id,
|
||||||
gamma.size(), red, green, blue);
|
gamma.size(), red, green, blue);
|
||||||
|
|
||||||
return !isError;
|
return !isError;
|
||||||
|
|
|
@ -25,7 +25,7 @@ class DrmGpu;
|
||||||
class DrmCrtc : public DrmObject
|
class DrmCrtc : public DrmObject
|
||||||
{
|
{
|
||||||
public:
|
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;
|
bool init() override;
|
||||||
|
|
||||||
|
@ -57,10 +57,6 @@ public:
|
||||||
}
|
}
|
||||||
bool setGammaRamp(const GammaRamp &gamma);
|
bool setGammaRamp(const GammaRamp &gamma);
|
||||||
|
|
||||||
DrmGpu *gpu() {
|
|
||||||
return m_gpu;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DrmScopedPointer<drmModeCrtc> m_crtc;
|
DrmScopedPointer<drmModeCrtc> m_crtc;
|
||||||
int m_resIndex;
|
int m_resIndex;
|
||||||
|
@ -69,7 +65,6 @@ private:
|
||||||
QSharedPointer<DrmBuffer> m_nextBuffer;
|
QSharedPointer<DrmBuffer> m_nextBuffer;
|
||||||
DrmDumbBuffer *m_blackBuffer = nullptr;
|
DrmDumbBuffer *m_blackBuffer = nullptr;
|
||||||
DrmBackend *m_backend;
|
DrmBackend *m_backend;
|
||||||
DrmGpu *m_gpu;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,21 +8,22 @@
|
||||||
*/
|
*/
|
||||||
#include "drm_object_plane.h"
|
#include "drm_object_plane.h"
|
||||||
#include "drm_buffer.h"
|
#include "drm_buffer.h"
|
||||||
|
#include "drm_gpu.h"
|
||||||
#include "drm_pointer.h"
|
#include "drm_pointer.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
|
||||||
DrmPlane::DrmPlane(uint32_t plane_id, int fd)
|
DrmPlane::DrmPlane(DrmGpu *gpu, uint32_t plane_id)
|
||||||
: DrmObject(plane_id, fd)
|
: DrmObject(gpu, plane_id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DrmPlane::init()
|
bool DrmPlane::init()
|
||||||
{
|
{
|
||||||
qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id;
|
qCDebug(KWIN_DRM) << "Atomic init for plane:" << m_id;
|
||||||
DrmScopedPointer<drmModePlane> p(drmModeGetPlane(fd(), m_id));
|
DrmScopedPointer<drmModePlane> p(drmModeGetPlane(gpu()->fd(), m_id));
|
||||||
|
|
||||||
if (!p) {
|
if (!p) {
|
||||||
qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id;
|
qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id;
|
||||||
|
|
|
@ -23,7 +23,7 @@ class DrmPlane : public DrmObject
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
public:
|
public:
|
||||||
DrmPlane(uint32_t plane_id, int fd);
|
DrmPlane(DrmGpu *gpu, uint32_t plane_id);
|
||||||
|
|
||||||
enum class PropertyIndex : uint32_t {
|
enum class PropertyIndex : uint32_t {
|
||||||
Type = 0,
|
Type = 0,
|
||||||
|
|
Loading…
Reference in a new issue