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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "drm_object.h"
|
2019-02-08 19:49:11 +00:00
|
|
|
#include "drm_pointer.h"
|
2017-05-09 19:29:10 +00:00
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
#include "logging.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
2018-08-29 18:02:16 +00:00
|
|
|
* Definitions for class DrmObject
|
2016-08-31 12:00:31 +00:00
|
|
|
*/
|
|
|
|
|
2017-11-12 20:00:02 +00:00
|
|
|
DrmObject::DrmObject(uint32_t object_id, int fd)
|
|
|
|
: m_fd(fd)
|
2016-08-31 12:00:31 +00:00
|
|
|
, m_id(object_id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmObject::~DrmObject()
|
|
|
|
{
|
|
|
|
foreach(Property* p, m_props)
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
|
2017-11-10 19:38:33 +00:00
|
|
|
void DrmObject::setPropertyNames(QVector<QByteArray> &&vector)
|
|
|
|
{
|
|
|
|
m_propsNames = std::move(vector);
|
|
|
|
m_props.fill(nullptr, m_propsNames.size());
|
|
|
|
}
|
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
void DrmObject::initProp(int n, drmModeObjectProperties *properties, QVector<QByteArray> enumNames)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < properties->count_props; ++i) {
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModePropertyRes> prop(
|
2019-02-08 19:49:11 +00:00
|
|
|
drmModeGetProperty(fd(), properties->props[i]));
|
2016-08-31 12:00:31 +00:00
|
|
|
if (!prop) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (prop->name == m_propsNames[n]) {
|
|
|
|
qCDebug(KWIN_DRM).nospace() << m_id << ": " << prop->name << "' (id " << prop->prop_id
|
|
|
|
<< "): " << properties->prop_values[i];
|
2019-02-08 19:49:11 +00:00
|
|
|
m_props[n] = new Property(prop.data(), properties->prop_values[i], enumNames);
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-10 19:38:33 +00:00
|
|
|
bool DrmObject::atomicAddProperty(drmModeAtomicReq *req, Property *property)
|
2016-08-31 12:00:31 +00:00
|
|
|
{
|
2017-11-10 19:38:33 +00:00
|
|
|
if (drmModeAtomicAddProperty(req, m_id, property->propId(), property->value()) <= 0) {
|
|
|
|
qCWarning(KWIN_DRM) << "Adding property" << property->name() << "to atomic commit failed for object" << this;
|
2017-05-09 19:29:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
bool DrmObject::atomicPopulate(drmModeAtomicReq *req)
|
2016-08-31 12:00:31 +00:00
|
|
|
{
|
2017-05-09 19:29:10 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
|
|
|
for (int i = 0; i < m_props.size(); i++) {
|
2017-11-10 19:38:33 +00:00
|
|
|
auto property = m_props.at(i);
|
|
|
|
if (!property) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ret &= atomicAddProperty(req, property);
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to populate atomic plane" << m_id;
|
2016-08-31 12:00:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-08-29 18:02:16 +00:00
|
|
|
* Definitions for struct Prop
|
2016-08-31 12:00:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
DrmObject::Property::Property(drmModePropertyRes *prop, uint64_t val, QVector<QByteArray> enumNames)
|
|
|
|
: m_propId(prop->prop_id)
|
|
|
|
, m_propName(prop->name)
|
|
|
|
, m_value(val)
|
|
|
|
{
|
|
|
|
if (!enumNames.isEmpty()) {
|
|
|
|
qCDebug(KWIN_DRM) << m_propName << " has enums:" << enumNames;
|
|
|
|
m_enumNames = enumNames;
|
|
|
|
initEnumMap(prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmObject::Property::~Property() = default;
|
|
|
|
|
|
|
|
void DrmObject::Property::initEnumMap(drmModePropertyRes *prop)
|
|
|
|
{
|
2017-11-03 17:35:13 +00:00
|
|
|
if (!((prop->flags & DRM_MODE_PROP_ENUM) || (prop->flags & DRM_MODE_PROP_BITMASK)) || prop->count_enums < 1) {
|
2016-08-31 12:00:31 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Property '" << prop->name << "' ( id ="
|
|
|
|
<< m_propId << ") should be enum valued, but it is not.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nameCount = m_enumNames.size();
|
|
|
|
m_enumMap.resize(nameCount);
|
|
|
|
|
|
|
|
qCDebug(KWIN_DRM).nospace() << "Test all " << prop->count_enums <<
|
|
|
|
" possible enums" <<":";
|
|
|
|
|
|
|
|
for (int i = 0; i < prop->count_enums; i++) {
|
|
|
|
|
|
|
|
struct drm_mode_property_enum *en = &prop->enums[i];
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
while (QByteArray(en->name) != m_enumNames[j]) {
|
|
|
|
j++;
|
|
|
|
if (j == nameCount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == nameCount) {
|
|
|
|
qCWarning(KWIN_DRM).nospace() << m_propName << " has unrecognized enum '" << en->name << "'";
|
|
|
|
} else {
|
|
|
|
qCDebug(KWIN_DRM).nospace() << "Enum '"
|
|
|
|
<< en->name << "': runtime-value = " << en->value;
|
|
|
|
m_enumMap[j] = en->value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KWIN_DRM().isDebugEnabled()) {
|
|
|
|
for (int i = 0; i < m_enumMap.size(); i++) {
|
|
|
|
if (m_value == m_enumMap[i]) {
|
|
|
|
qCDebug(KWIN_DRM) << "=>" << m_propName << "with mapped enum value" << m_enumNames[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|