KWin
Loading...
Searching...
No Matches
drm_property.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016 Roman Gilg <subdiff@gmail.com>
6 SPDX-FileCopyrightText: 2021-2022 Xaver Hugl <xaver.hugl@gmail.com>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9*/
10
11#include "drm_property.h"
12#include "drm_gpu.h"
13#include "drm_logging.h"
14#include "drm_object.h"
15#include <cerrno>
16
17namespace KWin
18{
19
20DrmProperty::DrmProperty(DrmObject *obj, const QByteArray &name, const QList<QByteArray> &enumNames)
21 : m_obj(obj)
22 , m_propName(name)
23 , m_enumNames(enumNames)
24{
25}
26
28{
29 if (m_current == value) {
30 return true;
31 } else if (drmModeObjectSetProperty(m_obj->gpu()->fd(), m_obj->id(), m_obj->type(), m_propId, value) == 0) {
33 return true;
34 } else {
35 return false;
36 }
37}
38
40{
41 if (const auto opt = propertyList.takeProperty(m_propName)) {
42 const auto &[prop, value] = *opt;
43 m_propId = prop->prop_id;
45 m_immutable = prop->flags & DRM_MODE_PROP_IMMUTABLE;
46 m_isBlob = prop->flags & DRM_MODE_PROP_BLOB;
47 m_isBitmask = prop->flags & DRM_MODE_PROP_BITMASK;
48 if (prop->flags & DRM_MODE_PROP_RANGE) {
49 Q_ASSERT(prop->count_values > 1);
50 m_minValue = prop->values[0];
51 m_maxValue = prop->values[1];
52 }
53 m_enumToPropertyMap.clear();
54 m_propertyToEnumMap.clear();
55 // bitmasks need translation too, not just enums
56 if (prop->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) {
57 for (int i = 0; i < prop->count_enums; i++) {
58 struct drm_mode_property_enum *en = &prop->enums[i];
59 int j = m_enumNames.indexOf(QByteArray(en->name));
60 if (j >= 0) {
61 if (m_isBitmask) {
62 m_enumToPropertyMap[1 << j] = 1 << en->value;
63 m_propertyToEnumMap[1 << en->value] = 1 << j;
64 } else {
65 m_enumToPropertyMap[j] = en->value;
66 m_propertyToEnumMap[en->value] = j;
67 }
68 }
69 }
70 }
71 if (m_immutable && m_isBlob) {
72 if (m_current != 0) {
74 if (m_immutableBlob && (!m_immutableBlob->data || !m_immutableBlob->length)) {
75 m_immutableBlob.reset();
76 }
77 } else {
78 m_immutableBlob.reset();
79 }
80 }
81 } else {
82 m_propId = 0;
83 m_immutableBlob.reset();
84 m_enumToPropertyMap.clear();
85 m_propertyToEnumMap.clear();
86 }
87}
88
89uint64_t DrmProperty::value() const
90{
91 return m_current;
92}
93
95{
96 return m_enumToPropertyMap.count() == m_enumNames.count();
97}
98
99uint32_t DrmProperty::propId() const
100{
101 return m_propId;
102}
103
104const QByteArray &DrmProperty::name() const
105{
106 return m_propName;
107}
108
110{
111 return m_immutable;
112}
113
115{
116 return m_isBitmask;
117}
118
119uint64_t DrmProperty::minValue() const
120{
121 return m_minValue;
122}
123
124uint64_t DrmProperty::maxValue() const
125{
126 return m_maxValue;
127}
128
129drmModePropertyBlobRes *DrmProperty::immutableBlob() const
130{
131 return m_immutableBlob.get();
132}
133
135{
136 return m_obj;
137}
138
140{
141 return m_propId != 0;
142}
143}
int fd() const
Definition drm_gpu.cpp:648
uint32_t id() const
DrmGpu * gpu() const
uint32_t type() const
uint64_t minValue() const
bool setPropertyLegacy(uint64_t value)
bool isImmutable() const
uint64_t maxValue() const
void update(DrmPropertyList &propertyList)
const QByteArray & name() const
QMap< uint64_t, uint64_t > m_enumToPropertyMap
DrmProperty(DrmObject *obj, const QByteArray &name, const QList< QByteArray > &enumNames={})
DrmObject * drmObject() const
const QList< QByteArray > m_enumNames
drmModePropertyBlobRes * immutableBlob() const
uint64_t value() const
bool hasAllEnums() const
QMap< uint64_t, uint64_t > m_propertyToEnumMap
uint32_t propId() const
bool isBitmask() const
DrmObject *const m_obj
bool isValid() const
DrmUniquePtr< drmModePropertyBlobRes > m_immutableBlob
const QByteArray m_propName
std::optional< std::pair< DrmUniquePtr< drmModePropertyRes >, uint64_t > > takeProperty(const QByteArray &name)
drmModePropertyBlobPtr drmModeGetPropertyBlob(int fd, uint32_t blob_id)
Definition mock_drm.cpp:789
int drmModeObjectSetProperty(int fd, uint32_t object_id, uint32_t object_type, uint32_t property_id, uint64_t value)
Definition mock_drm.cpp:893