KWin
Loading...
Searching...
No Matches
drm_property.h
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#pragma once
12#include "drm_pointer.h"
13#include "drm_logging.h"
14
15#include <QByteArray>
16#include <QList>
17#include <QMap>
18
19#include <xf86drmMode.h>
20
21namespace KWin
22{
23
24class DrmObject;
25class DrmPropertyList;
26
28{
29public:
30 DrmProperty(DrmObject *obj, const QByteArray &name, const QList<QByteArray> &enumNames = {});
31
32 const QByteArray &name() const;
33 DrmObject *drmObject() const;
34
35 uint32_t propId() const;
36 bool isImmutable() const;
37 bool isBitmask() const;
38 bool hasAllEnums() const;
39 uint64_t value() const;
40 drmModePropertyBlobRes *immutableBlob() const;
41 uint64_t minValue() const;
42 uint64_t maxValue() const;
43 bool isValid() const;
44
45 void update(DrmPropertyList &propertyList);
46 bool setPropertyLegacy(uint64_t value);
47
48protected:
50 const QByteArray m_propName;
51 const QList<QByteArray> m_enumNames;
52
53 uint32_t m_propId = 0;
54 // the last known value from the kernel
55 uint64_t m_current = 0;
57
58 uint64_t m_minValue = -1;
59 uint64_t m_maxValue = -1;
60
61 QMap<uint64_t, uint64_t> m_enumToPropertyMap;
62 QMap<uint64_t, uint64_t> m_propertyToEnumMap;
63 bool m_immutable = false;
64 bool m_isBlob = false;
65 bool m_isBitmask = false;
66};
67
68template<typename Enum>
70{
71public:
72 DrmEnumProperty(DrmObject *obj, const QByteArray &name, const QList<QByteArray> &enumNames)
73 : DrmProperty(obj, name, enumNames)
74 {
75 }
76
77 Enum enumValue() const
78 {
79 return enumForValue(value());
80 }
81
82 bool hasEnum(Enum value) const
83 {
84 const uint64_t integerValue = static_cast<uint64_t>(value);
85 if (m_isBitmask) {
86 for (uint64_t mask = 1; integerValue >= mask && mask != 0; mask <<= 1) {
87 if ((integerValue & mask) && !m_enumToPropertyMap.contains(mask)) {
88 return false;
89 }
90 }
91 return true;
92 } else {
93 return m_enumToPropertyMap.contains(integerValue);
94 }
95 }
96
97 Enum enumForValue(uint64_t value) const
98 {
99 if (m_isBitmask) {
100 uint64_t ret = 0;
101 for (uint64_t mask = 1; value >= mask && mask != 0; mask <<= 1) {
102 if (value & mask) {
103 ret |= m_propertyToEnumMap[mask];
104 }
105 }
106 return static_cast<Enum>(ret);
107 } else {
108 return static_cast<Enum>(m_propertyToEnumMap[value]);
109 }
110 }
111
112 uint64_t valueForEnum(Enum enumValue) const
113 {
114 const uint64_t integer = static_cast<uint64_t>(enumValue);
115 if (m_isBitmask) {
116 uint64_t set = 0;
117 for (uint64_t mask = 1; integer >= mask && mask != 0; mask <<= 1) {
118 if (integer & mask) {
119 set |= m_enumToPropertyMap[mask];
120 }
121 }
122 return set;
123 } else {
124 return m_enumToPropertyMap[integer];
125 }
126 }
127
129 {
130 if (hasEnum(value)) {
132 } else {
133 return false;
134 }
135 }
136};
137}
Enum enumValue() const
Enum enumForValue(uint64_t value) const
bool setEnumLegacy(Enum value)
bool hasEnum(Enum value) const
uint64_t valueForEnum(Enum enumValue) const
DrmEnumProperty(DrmObject *obj, const QByteArray &name, const QList< QByteArray > &enumNames)
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::unique_ptr< T, DrmDeleter< T > > DrmUniquePtr