Commit 32c2ae15 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

backends/drm: manage drm properties with std::unique_ptr

parent aa739c59
......@@ -26,11 +26,6 @@ DrmObject::DrmObject(DrmGpu *gpu, uint32_t objectId, const QVector<PropertyDefin
m_props.resize(m_propertyDefinitions.count());
}
DrmObject::~DrmObject()
{
qDeleteAll(m_props);
}
bool DrmObject::initProps()
{
if (!updateProperties()) {
......@@ -52,7 +47,7 @@ bool DrmObject::initProps()
Q_UNREACHABLE();
}
debug << m_id << " has properties ";
for (int i = 0; i < m_props.count(); i++) {
for (size_t i = 0; i < m_props.size(); i++) {
if (i > 0) {
debug << ", ";
}
......@@ -90,11 +85,6 @@ bool DrmObject::atomicPopulate(drmModeAtomicReq *req) const
return true;
}
QVector<DrmProperty *> DrmObject::properties()
{
return m_props;
}
void DrmObject::commit()
{
for (const auto &prop : qAsConst(m_props)) {
......@@ -152,14 +142,14 @@ bool DrmObject::updateProperties()
if (m_props[propIndex]) {
m_props[propIndex]->setCurrent(properties->prop_values[drmPropIndex]);
} else {
m_props[propIndex] = new DrmProperty(this, prop.get(), properties->prop_values[drmPropIndex], def.enumNames);
m_props[propIndex] = std::make_unique<DrmProperty>(this, prop.get(), properties->prop_values[drmPropIndex], def.enumNames);
}
found = true;
break;
}
}
if (!found) {
deleteProp(propIndex);
m_props[propIndex].reset();
}
}
for (int i = 0; i < m_propertyDefinitions.count(); i++) {
......@@ -202,6 +192,29 @@ QString DrmObject::typeName() const
}
}
void DrmObject::printProps(PrintMode mode)
{
bool any = mode == PrintMode::All || std::any_of(m_props.begin(), m_props.end(), [](const auto &prop) {
return prop && !prop->isImmutable() && prop->needsCommit();
});
if (!any) {
return;
}
qCDebug(KWIN_DRM) << typeName() << id();
for (const auto &prop : m_props) {
if (prop) {
uint64_t current = prop->name().startsWith("SRC_") ? prop->current() >> 16 : prop->current();
if (prop->isImmutable() || !prop->needsCommit()) {
if (mode == PrintMode::All) {
qCDebug(KWIN_DRM).nospace() << "\t" << prop->name() << ": " << current;
}
} else {
uint64_t pending = prop->name().startsWith("SRC_") ? prop->pending() >> 16 : prop->pending();
qCDebug(KWIN_DRM).nospace() << "\t" << prop->name() << ": " << current << "->" << pending;
}
}
}
}
}
QDebug operator<<(QDebug s, const KWin::DrmObject *obj)
......
......@@ -28,7 +28,7 @@ class DrmOutput;
class DrmObject
{
public:
virtual ~DrmObject();
virtual ~DrmObject() = default;
/**
* Must be called to query necessary data directly after creation.
......@@ -45,7 +45,6 @@ public:
DrmGpu *gpu() const;
uint32_t type() const;
QString typeName() const;
QVector<DrmProperty *> properties();
void commit();
void commitPending();
......@@ -75,9 +74,15 @@ public:
template<typename T>
DrmProperty *getProp(T propIndex) const
{
return m_props[static_cast<uint32_t>(propIndex)];
return m_props[static_cast<uint32_t>(propIndex)].get();
}
enum class PrintMode {
OnlyChanged,
All
};
void printProps(PrintMode mode);
protected:
enum class Requirement {
Required,
......@@ -101,14 +106,7 @@ protected:
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;
std::vector<std::unique_ptr<DrmProperty>> m_props;
private:
DrmGpu *m_gpu;
......
......@@ -295,15 +295,15 @@ bool DrmConnector::updateProperties()
dpms->setLegacy();
}
auto underscan = m_props[static_cast<uint32_t>(PropertyIndex::Underscan)];
auto vborder = m_props[static_cast<uint32_t>(PropertyIndex::Underscan_vborder)];
auto hborder = m_props[static_cast<uint32_t>(PropertyIndex::Underscan_hborder)];
auto &underscan = m_props[static_cast<uint32_t>(PropertyIndex::Underscan)];
auto &vborder = m_props[static_cast<uint32_t>(PropertyIndex::Underscan_vborder)];
auto &hborder = m_props[static_cast<uint32_t>(PropertyIndex::Underscan_hborder)];
if (underscan && vborder && hborder) {
underscan->setEnum(vborder->current() > 0 ? UnderscanOptions::On : UnderscanOptions::Off);
} else {
deleteProp(PropertyIndex::Underscan);
deleteProp(PropertyIndex::Underscan_vborder);
deleteProp(PropertyIndex::Underscan_hborder);
underscan.reset();
vborder.reset();
hborder.reset();
}
// parse edid
......
......@@ -107,7 +107,7 @@ DrmPipeline::Error DrmPipeline::commitPipelinesAtomic(const QVector<DrmPipeline
pipeline->atomicCommitFailed();
}
for (const auto &obj : unusedObjects) {
printProps(obj, PrintMode::OnlyChanged);
obj->printProps(DrmObject::PrintMode::OnlyChanged);
obj->rollbackPending();
}
};
......@@ -556,42 +556,17 @@ void DrmPipeline::printFlags(uint32_t flags)
}
}
void DrmPipeline::printProps(DrmObject *object, PrintMode mode)
{
auto list = object->properties();
bool any = mode == PrintMode::All || std::any_of(list.constBegin(), list.constEnd(), [](const auto &prop) {
return prop && !prop->isImmutable() && prop->needsCommit();
});
if (!any) {
return;
}
qCDebug(KWIN_DRM) << object->typeName() << object->id();
for (const auto &prop : list) {
if (prop) {
uint64_t current = prop->name().startsWith("SRC_") ? prop->current() >> 16 : prop->current();
if (prop->isImmutable() || !prop->needsCommit()) {
if (mode == PrintMode::All) {
qCDebug(KWIN_DRM).nospace() << "\t" << prop->name() << ": " << current;
}
} else {
uint64_t pending = prop->name().startsWith("SRC_") ? prop->pending() >> 16 : prop->pending();
qCDebug(KWIN_DRM).nospace() << "\t" << prop->name() << ": " << current << "->" << pending;
}
}
}
}
void DrmPipeline::printDebugInfo() const
{
qCDebug(KWIN_DRM) << "Drm objects:";
printProps(m_connector, PrintMode::All);
m_connector->printProps(DrmObject::PrintMode::All);
if (m_pending.crtc) {
printProps(m_pending.crtc, PrintMode::All);
m_pending.crtc->printProps(DrmObject::PrintMode::All);
if (m_pending.crtc->primaryPlane()) {
printProps(m_pending.crtc->primaryPlane(), PrintMode::All);
m_pending.crtc->primaryPlane()->printProps(DrmObject::PrintMode::All);
}
if (m_pending.crtc->cursorPlane()) {
printProps(m_pending.crtc->cursorPlane(), PrintMode::All);
m_pending.crtc->cursorPlane()->printProps(DrmObject::PrintMode::All);
}
}
}
......
......@@ -159,7 +159,6 @@ private:
All,
};
static void printFlags(uint32_t flags);
static void printProps(DrmObject *object, PrintMode mode);
DrmOutput *m_output = nullptr;
DrmConnector *m_connector = nullptr;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment