2016-08-31 12:00:31 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2016 Roman Gilg <subdiff@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#ifndef KWIN_DRM_OBJECT_H
|
|
|
|
#define KWIN_DRM_OBJECT_H
|
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
#include <QByteArray>
|
|
|
|
|
|
|
|
// drm
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
class DrmBackend;
|
2016-08-31 12:00:31 +00:00
|
|
|
class DrmOutput;
|
|
|
|
|
|
|
|
class DrmObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// creates drm object by its id delivered by the kernel
|
2017-05-09 19:29:10 +00:00
|
|
|
DrmObject(uint32_t object_id, DrmBackend *backend);
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
virtual ~DrmObject() = 0;
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
virtual bool atomicInit() = 0;
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
uint32_t id() const {
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
DrmOutput *output() const {
|
2016-08-31 12:00:31 +00:00
|
|
|
return m_output;
|
|
|
|
}
|
|
|
|
void setOutput(DrmOutput* output) {
|
|
|
|
m_output = output;
|
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
uint32_t propId(int prop) {
|
|
|
|
return m_props[prop]->propId();
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
uint64_t value(int prop) {
|
|
|
|
return m_props[prop]->value();
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
void setValue(int prop, uint64_t new_value)
|
|
|
|
{
|
|
|
|
Q_ASSERT(prop < m_props.size());
|
|
|
|
m_props[prop]->setValue(new_value);
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
virtual bool atomicPopulate(drmModeAtomicReq *req);
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
protected:
|
2017-05-09 19:29:10 +00:00
|
|
|
virtual bool initProps() = 0; // only derived classes know names and quantity of properties
|
|
|
|
void initProp(int n, drmModeObjectProperties *properties, QVector<QByteArray> enumNames = QVector<QByteArray>(0));
|
|
|
|
bool atomicAddProperty(drmModeAtomicReq *req, int prop, uint64_t value);
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
DrmBackend *m_backend;
|
|
|
|
const uint32_t m_id = 0;
|
2016-08-31 12:00:31 +00:00
|
|
|
DrmOutput *m_output = nullptr;
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
// for comparision with received name of DRM object
|
|
|
|
QVector<QByteArray> m_propsNames;
|
2016-08-31 12:00:31 +00:00
|
|
|
class Property;
|
2017-05-09 19:29:10 +00:00
|
|
|
QVector<Property *> m_props;
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
class Property
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Property(drmModePropertyRes *prop, uint64_t val, QVector<QByteArray> enumNames);
|
|
|
|
virtual ~Property();
|
|
|
|
|
|
|
|
void initEnumMap(drmModePropertyRes *prop);
|
|
|
|
|
|
|
|
uint64_t enumMap(int n) {
|
|
|
|
return m_enumMap[n]; // TODO: test on index out of bounds?
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t propId() {
|
|
|
|
return m_propId;
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
uint64_t value() {
|
2016-08-31 12:00:31 +00:00
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
void setValue(uint64_t new_value) {
|
|
|
|
m_value = new_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t m_propId = 0;
|
|
|
|
QByteArray m_propName;
|
|
|
|
|
|
|
|
uint64_t m_value = 0;
|
|
|
|
QVector<uint64_t> m_enumMap;
|
|
|
|
QVector<QByteArray> m_enumNames;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|