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>
|
2021-08-31 01:40:18 +00:00
|
|
|
#include <QMap>
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
// drm
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
|
2021-03-10 21:04:32 +00:00
|
|
|
#include "drm_pointer.h"
|
2021-09-22 12:01:01 +00:00
|
|
|
#include "drm_property.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:
|
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
|
|
|
|
2021-10-08 09:22:02 +00:00
|
|
|
/**
|
|
|
|
* Set the properties in such a way that this resource won't be used anymore
|
|
|
|
*/
|
|
|
|
virtual void disable() = 0;
|
|
|
|
|
2021-09-22 11:26:19 +00:00
|
|
|
uint32_t id() const;
|
|
|
|
DrmGpu *gpu() const;
|
2021-09-22 12:01:01 +00:00
|
|
|
uint32_t type() const;
|
|
|
|
QVector<DrmProperty*> properties();
|
2017-11-12 20:00:02 +00:00
|
|
|
|
2021-09-22 11:26:19 +00:00
|
|
|
void commit();
|
|
|
|
void commitPending();
|
|
|
|
void rollbackPending();
|
2021-03-10 21:04:32 +00:00
|
|
|
bool atomicPopulate(drmModeAtomicReq *req) const;
|
2021-09-22 11:26:19 +00:00
|
|
|
bool needsCommit() const;
|
|
|
|
virtual bool needsModeset() const = 0;
|
|
|
|
virtual bool updateProperties();
|
2019-12-11 16:50:07 +00:00
|
|
|
|
2021-03-10 21:04:32 +00:00
|
|
|
template <typename T>
|
2021-05-25 22:05:17 +00:00
|
|
|
bool setPending(T prop, uint64_t new_value)
|
2021-03-10 21:04:32 +00:00
|
|
|
{
|
|
|
|
if (auto &property = m_props.at(static_cast<uint32_t>(prop))) {
|
2021-05-25 22:05:17 +00:00
|
|
|
property->setPending(new_value);
|
|
|
|
return true;
|
2021-03-10 21:04:32 +00:00
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
return false;
|
2021-03-10 21:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2021-05-25 22:05:17 +00:00
|
|
|
bool setPendingBlob(T prop, void *data, size_t length)
|
2021-03-10 21:04:32 +00:00
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
if (auto &property = m_props.at(static_cast<uint32_t>(prop))) {
|
|
|
|
return property->setPendingBlob(data, length);
|
2021-03-10 21:04:32 +00:00
|
|
|
}
|
2021-05-25 22:05:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-12-11 16:50:07 +00:00
|
|
|
|
2021-03-10 21:04:32 +00:00
|
|
|
template <typename T>
|
2021-05-25 22:05:17 +00:00
|
|
|
bool propHasEnum(T prop, uint64_t value) const
|
2021-03-10 21:04:32 +00:00
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
const auto &property = m_props.at(static_cast<uint32_t>(prop));
|
|
|
|
return property ? property->hasEnum(value) : false;
|
2021-03-10 21:04:32 +00:00
|
|
|
}
|
2019-12-11 16:50:07 +00:00
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
template <typename T>
|
2021-09-22 12:01:01 +00:00
|
|
|
DrmProperty *getProp(T propIndex) const {
|
2021-05-25 22:05:17 +00:00
|
|
|
return m_props[static_cast<uint32_t>(propIndex)];
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2021-08-27 16:56:05 +00:00
|
|
|
enum class Requirement {
|
|
|
|
Required,
|
2021-09-16 12:03:10 +00:00
|
|
|
RequiredForLegacy,
|
|
|
|
Optional,
|
2021-08-27 16:56:05 +00:00
|
|
|
};
|
2021-05-25 22:05:17 +00:00
|
|
|
struct PropertyDefinition
|
|
|
|
{
|
2021-08-27 16:56:05 +00:00
|
|
|
PropertyDefinition(const QByteArray &name, Requirement requirement, const QVector<QByteArray> &&enumNames = {})
|
|
|
|
: name(name)
|
|
|
|
, requirement(requirement)
|
|
|
|
, enumNames(enumNames)
|
2021-05-25 22:05:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
QByteArray name;
|
2021-08-27 16:56:05 +00:00
|
|
|
Requirement requirement;
|
2021-05-25 22:05:17 +00:00
|
|
|
QVector<QByteArray> enumNames;
|
|
|
|
};
|
2021-06-03 13:50:37 +00:00
|
|
|
|
|
|
|
DrmObject(DrmGpu *gpu, uint32_t objectId, const QVector<PropertyDefinition> &&vector, uint32_t objectType);
|
|
|
|
|
|
|
|
bool initProps();
|
2021-05-25 22:05:17 +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;
|
|
|
|
}
|
|
|
|
|
2021-09-22 12:01:01 +00:00
|
|
|
QVector<DrmProperty *> m_props;
|
2021-05-25 22:05:17 +00:00
|
|
|
|
2017-11-10 19:38:33 +00:00
|
|
|
private:
|
2021-04-01 11:15:42 +00:00
|
|
|
DrmGpu *m_gpu;
|
2021-04-01 11:19:48 +00:00
|
|
|
const uint32_t m_id;
|
2021-06-03 13:50:37 +00:00
|
|
|
const uint32_t m_objectType;
|
|
|
|
const QVector<PropertyDefinition> m_propertyDefinitions;
|
2016-08-31 12:00:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-08-16 01:11:30 +00:00
|
|
|
QDebug operator<<(QDebug stream, const KWin::DrmObject*);
|