2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Roman Gilg <subdiff@gmail.com>
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-12-11 16:50:07 +00:00
|
|
|
#pragma once
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
#include <QByteArray>
|
|
|
|
|
|
|
|
// drm
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
|
2021-03-10 21:04:32 +00:00
|
|
|
#include "drm_pointer.h"
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
class DrmBackend;
|
2021-04-01 11:15:42 +00:00
|
|
|
class DrmGpu;
|
2016-08-31 12:00:31 +00:00
|
|
|
class DrmOutput;
|
|
|
|
|
|
|
|
class DrmObject
|
|
|
|
{
|
|
|
|
public:
|
2019-12-11 16:50:07 +00:00
|
|
|
/**
|
|
|
|
* Create DRM object representation.
|
|
|
|
* @param object_id provided by the kernel
|
|
|
|
* @param fd of the DRM device
|
|
|
|
*/
|
2021-04-01 11:15:42 +00:00
|
|
|
DrmObject(DrmGpu *gpu, uint32_t object_id);
|
2017-11-12 20:00:02 +00:00
|
|
|
virtual ~DrmObject();
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2019-12-11 16:50:07 +00:00
|
|
|
/**
|
|
|
|
* Must be called to query necessary data directly after creation.
|
|
|
|
* @return true when initializing was successful
|
|
|
|
*/
|
2021-01-26 20:23:44 +00:00
|
|
|
virtual bool init() = 0;
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
uint32_t id() const {
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
2021-04-01 11:15:42 +00:00
|
|
|
DrmGpu *gpu() const {
|
|
|
|
return m_gpu;
|
2017-11-12 20:00:02 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 16:50:07 +00:00
|
|
|
/**
|
|
|
|
* Populate an atomic request with data of this object.
|
|
|
|
* @param req the atomic request
|
|
|
|
* @return true when the request was successfully populated
|
|
|
|
*/
|
2021-03-10 21:04:32 +00:00
|
|
|
bool atomicPopulate(drmModeAtomicReq *req) const;
|
2019-12-11 16:50:07 +00:00
|
|
|
|
2021-03-10 21:04:32 +00:00
|
|
|
template <typename T>
|
|
|
|
void setValue(T prop, uint64_t new_value)
|
|
|
|
{
|
|
|
|
if (auto &property = m_props.at(static_cast<uint32_t>(prop))) {
|
|
|
|
property->setValue(new_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool propHasEnum(T prop, uint64_t value) const
|
|
|
|
{
|
|
|
|
const auto &property = m_props.at(static_cast<uint32_t>(prop));
|
|
|
|
return property ? property->hasEnum(value) : false;
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
protected:
|
2021-03-10 21:04:32 +00:00
|
|
|
struct PropertyDefinition
|
|
|
|
{
|
|
|
|
PropertyDefinition(const QByteArray &name, const QVector<QByteArray> &&enumNames = {})
|
|
|
|
: name(name), enumNames(enumNames)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
QByteArray name;
|
|
|
|
QVector<QByteArray> enumNames;
|
|
|
|
};
|
2019-12-11 16:50:07 +00:00
|
|
|
/**
|
|
|
|
* Initialize properties of object. Only derived classes know names and quantities of
|
|
|
|
* properties.
|
|
|
|
*
|
|
|
|
* @return true when properties have been initialized successfully
|
|
|
|
*/
|
2021-03-10 21:04:32 +00:00
|
|
|
bool initProps(const QVector<PropertyDefinition> &&vector, uint32_t objectType);
|
2019-12-11 16:50:07 +00:00
|
|
|
|
2021-03-10 21:04:32 +00:00
|
|
|
template <typename T>
|
|
|
|
void deleteProp(T prop)
|
|
|
|
{
|
|
|
|
delete m_props[static_cast<uint32_t>(prop)];
|
|
|
|
m_props[static_cast<uint32_t>(prop)] = nullptr;
|
|
|
|
}
|
2019-12-11 16:50:07 +00:00
|
|
|
|
2017-11-10 19:38:33 +00:00
|
|
|
class Property;
|
2019-12-11 16:50:07 +00:00
|
|
|
bool atomicAddProperty(drmModeAtomicReq *req, Property *property) const;
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2018-08-29 18:02:16 +00:00
|
|
|
// for comparison with received name of DRM object
|
2017-05-09 19:29:10 +00:00
|
|
|
QVector<Property *> m_props;
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
class Property
|
|
|
|
{
|
|
|
|
public:
|
2021-03-10 21:04:32 +00:00
|
|
|
Property(drmModePropertyRes *prop, uint64_t val, const QVector<QByteArray> &enumNames, drmModePropertyBlobRes *blob);
|
2016-08-31 12:00:31 +00:00
|
|
|
virtual ~Property();
|
|
|
|
|
|
|
|
void initEnumMap(drmModePropertyRes *prop);
|
|
|
|
|
2019-12-11 16:50:07 +00:00
|
|
|
/**
|
|
|
|
* For properties of enum type the enum map identifies the kernel runtime values,
|
|
|
|
* which must be queried beforehand.
|
|
|
|
*
|
|
|
|
* @param n the index to the enum
|
|
|
|
* @return the runtime enum value corresponding with enum index @param n
|
|
|
|
*/
|
|
|
|
uint64_t enumMap(int n) const {
|
2016-08-31 12:00:31 +00:00
|
|
|
return m_enumMap[n]; // TODO: test on index out of bounds?
|
|
|
|
}
|
2017-11-03 17:35:13 +00:00
|
|
|
bool hasEnum(uint64_t value) const {
|
|
|
|
return m_enumMap.contains(value);
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2017-11-10 19:38:33 +00:00
|
|
|
uint32_t propId() const {
|
2016-08-31 12:00:31 +00:00
|
|
|
return m_propId;
|
|
|
|
}
|
2017-11-10 19:38:33 +00:00
|
|
|
uint64_t value() const {
|
2016-08-31 12:00:31 +00:00
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
void setValue(uint64_t new_value) {
|
|
|
|
m_value = new_value;
|
|
|
|
}
|
2017-11-10 19:38:33 +00:00
|
|
|
const QByteArray &name() const {
|
|
|
|
return m_propName;
|
|
|
|
}
|
2021-03-31 11:22:23 +00:00
|
|
|
/**
|
|
|
|
* while this is usually automatically set, some properties
|
|
|
|
* (like DPMS) are not meant to be used in AMS
|
|
|
|
*/
|
|
|
|
void setImmutable() {
|
|
|
|
m_immutable = true;
|
|
|
|
}
|
2020-10-25 19:18:06 +00:00
|
|
|
bool isImmutable() const {
|
|
|
|
return m_immutable;
|
|
|
|
}
|
2021-03-10 21:04:32 +00:00
|
|
|
drmModePropertyBlobRes *blob() const {
|
|
|
|
return m_blob.data();
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t m_propId = 0;
|
|
|
|
QByteArray m_propName;
|
|
|
|
|
|
|
|
uint64_t m_value = 0;
|
|
|
|
QVector<uint64_t> m_enumMap;
|
|
|
|
QVector<QByteArray> m_enumNames;
|
2020-10-25 19:18:06 +00:00
|
|
|
bool m_immutable = false;
|
2021-03-10 21:04:32 +00:00
|
|
|
DrmScopedPointer<drmModePropertyBlobRes> m_blob;
|
2016-08-31 12:00:31 +00:00
|
|
|
};
|
2017-11-10 19:38:33 +00:00
|
|
|
|
|
|
|
private:
|
2021-04-01 11:15:42 +00:00
|
|
|
DrmGpu *m_gpu;
|
2017-11-10 19:38:33 +00:00
|
|
|
QVector<QByteArray> m_propsNames;
|
2021-04-01 11:19:48 +00:00
|
|
|
const uint32_t m_id;
|
2016-08-31 12:00:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-07 11:22:38 +00:00
|
|
|
QDebug& operator<<(QDebug& stream, const KWin::DrmObject*);
|