kwin/src/backends/drm/drm_object.h

122 lines
2.8 KiB
C
Raw Normal View History

2020-08-02 22:22:19 +00:00
/*
KWin - the KDE window manager
This file is part of the KDE project.
2020-08-02 22:22:19 +00:00
SPDX-FileCopyrightText: 2016 Roman Gilg <subdiff@gmail.com>
2020-08-02 22:22:19 +00:00
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QVector>
#include <QByteArray>
#include <QMap>
// drm
#include <xf86drmMode.h>
2021-03-10 21:04:32 +00:00
#include "drm_pointer.h"
#include "drm_property.h"
namespace KWin
{
class DrmBackend;
class DrmGpu;
class DrmOutput;
class DrmObject
{
public:
virtual ~DrmObject();
/**
* Must be called to query necessary data directly after creation.
* @return true when initializing was successful
*/
virtual bool init() = 0;
/**
* Set the properties in such a way that this resource won't be used anymore
*/
virtual void disable() = 0;
uint32_t id() const;
DrmGpu *gpu() const;
uint32_t type() const;
QString typeName() const;
QVector<DrmProperty*> properties();
void commit();
void commitPending();
void rollbackPending();
2021-03-10 21:04:32 +00:00
bool atomicPopulate(drmModeAtomicReq *req) const;
bool needsCommit() const;
virtual bool needsModeset() const = 0;
virtual bool updateProperties();
2021-03-10 21:04:32 +00:00
template <typename T>
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))) {
property->setPending(new_value);
return true;
2021-03-10 21:04:32 +00:00
}
return false;
2021-03-10 21:04:32 +00:00
}
template <typename T>
bool propHasEnum(T prop, uint64_t value) const
2021-03-10 21:04:32 +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
}
template <typename T>
DrmProperty *getProp(T propIndex) const {
return m_props[static_cast<uint32_t>(propIndex)];
}
protected:
enum class Requirement {
Required,
RequiredForLegacy,
Optional,
};
struct PropertyDefinition
{
PropertyDefinition(const QByteArray &name, Requirement requirement, const QVector<QByteArray> &&enumNames = {})
: name(name)
, requirement(requirement)
, enumNames(enumNames)
{
}
QByteArray name;
Requirement requirement;
QVector<QByteArray> enumNames;
};
DrmObject(DrmGpu *gpu, uint32_t objectId, const QVector<PropertyDefinition> &&vector, uint32_t objectType);
bool initProps();
template <typename T>
void deleteProp(T prop)
{
delete m_props[static_cast<uint32_t>(prop)];
m_props[static_cast<uint32_t>(prop)] = nullptr;
}
QVector<DrmProperty *> m_props;
private:
DrmGpu *m_gpu;
const uint32_t m_id;
const uint32_t m_objectType;
const QVector<PropertyDefinition> m_propertyDefinitions;
};
}
QDebug operator<<(QDebug stream, const KWin::DrmObject*);