Commit f534b64e authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

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.
parent 75e75629
......@@ -111,7 +111,7 @@ void DrmGpu::tryAMS()
// create the plane objects
for (unsigned int i = 0; i < planeResources->count_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()) {
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;
......
......@@ -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<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) {
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<drmModePropertyRes> prop(drmModeGetProperty(fd(), properties->props[i]));
DrmScopedPointer<drmModePropertyRes> 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<PropertyDefinition> &&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() << ')';
}
......@@ -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<QByteArray> m_propsNames;
};
......
......@@ -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<drmModeConnector> con(drmModeGetConnector(fd(), m_id));
DrmScopedPointer<drmModeConnector> con(drmModeGetConnector(gpu()->fd(), m_id));
if (!con) {
return false;
}
......
......@@ -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;
......
......@@ -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<uint16_t *>(gamma.green());
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);
return !isError;
......
......@@ -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<drmModeCrtc> m_crtc;
int m_resIndex;
......@@ -69,7 +65,6 @@ private:
QSharedPointer<DrmBuffer> m_nextBuffer;
DrmDumbBuffer *m_blackBuffer = nullptr;
DrmBackend *m_backend;
DrmGpu *m_gpu;
};
}
......
......@@ -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<drmModePlane> p(drmModeGetPlane(fd(), m_id));
DrmScopedPointer<drmModePlane> p(drmModeGetPlane(gpu()->fd(), m_id));
if (!p) {
qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id;
......
......@@ -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,
......
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