Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_object.h
Show All 11 Lines | |||||
12 | This program is distributed in the hope that it will be useful, | 12 | This program is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #ifndef KWIN_DRM_OBJECT_H | 20 | #pragma once | ||
21 | #define KWIN_DRM_OBJECT_H | | |||
22 | 21 | | |||
23 | #include <QVector> | 22 | #include <QVector> | ||
24 | #include <QByteArray> | 23 | #include <QByteArray> | ||
25 | 24 | | |||
26 | // drm | 25 | // drm | ||
27 | #include <xf86drmMode.h> | 26 | #include <xf86drmMode.h> | ||
28 | 27 | | |||
29 | 28 | | |||
30 | namespace KWin | 29 | namespace KWin | ||
31 | { | 30 | { | ||
32 | 31 | | |||
33 | class DrmBackend; | 32 | class DrmBackend; | ||
34 | class DrmOutput; | 33 | class DrmOutput; | ||
35 | 34 | | |||
36 | class DrmObject | 35 | class DrmObject | ||
37 | { | 36 | { | ||
38 | public: | 37 | public: | ||
39 | // creates drm object by its id delivered by the kernel | 38 | /** | ||
39 | * Create DRM object representation. | ||||
40 | * @param object_id provided by the kernel | ||||
41 | * @param fd of the DRM device | ||||
42 | */ | ||||
40 | DrmObject(uint32_t object_id, int fd); | 43 | DrmObject(uint32_t object_id, int fd); | ||
41 | | ||||
42 | virtual ~DrmObject(); | 44 | virtual ~DrmObject(); | ||
43 | 45 | | |||
46 | /** | ||||
47 | * Must be called to query necessary data directly after creation. | ||||
48 | * @return true when initializing was successful | ||||
49 | */ | ||||
44 | virtual bool atomicInit() = 0; | 50 | virtual bool atomicInit() = 0; | ||
45 | 51 | | |||
46 | uint32_t id() const { | 52 | uint32_t id() const { | ||
47 | return m_id; | 53 | return m_id; | ||
48 | } | 54 | } | ||
49 | 55 | | |||
50 | DrmOutput *output() const { | 56 | DrmOutput *output() const { | ||
51 | return m_output; | 57 | return m_output; | ||
52 | } | 58 | } | ||
53 | void setOutput(DrmOutput* output) { | 59 | void setOutput(DrmOutput* output) { | ||
54 | m_output = output; | 60 | m_output = output; | ||
55 | } | 61 | } | ||
56 | 62 | | |||
57 | bool propHasEnum(int prop, uint64_t value) const { | | |||
58 | auto property = m_props.at(prop); | | |||
59 | return property ? property->hasEnum(value) : false; | | |||
60 | } | | |||
61 | | ||||
62 | void setValue(int prop, uint64_t new_value) | | |||
63 | { | | |||
64 | Q_ASSERT(prop < m_props.size()); | | |||
65 | auto property = m_props.at(prop); | | |||
66 | if (property) { | | |||
67 | property->setValue(new_value); | | |||
68 | } | | |||
69 | } | | |||
70 | | ||||
71 | int fd() const { | 63 | int fd() const { | ||
72 | return m_fd; | 64 | return m_fd; | ||
73 | } | 65 | } | ||
74 | 66 | | |||
75 | virtual bool atomicPopulate(drmModeAtomicReq *req); | 67 | /** | ||
68 | * Populate an atomic request with data of this object. | ||||
69 | * @param req the atomic request | ||||
70 | * @return true when the request was successfully populated | ||||
71 | */ | ||||
72 | virtual bool atomicPopulate(drmModeAtomicReq *req) const; | ||||
73 | | ||||
74 | void setValue(int prop, uint64_t new_value); | ||||
75 | bool propHasEnum(int prop, uint64_t value) const; | ||||
76 | 76 | | |||
77 | protected: | 77 | protected: | ||
78 | virtual bool initProps() = 0; // only derived classes know names and quantity of properties | 78 | /** | ||
79 | * Initialize properties of object. Only derived classes know names and quantities of | ||||
80 | * properties. | ||||
81 | * | ||||
82 | * @return true when properties have been initialized successfully | ||||
83 | */ | ||||
84 | virtual bool initProps() = 0; | ||||
85 | | ||||
79 | void setPropertyNames(QVector<QByteArray> &&vector); | 86 | void setPropertyNames(QVector<QByteArray> &&vector); | ||
80 | void initProp(int n, drmModeObjectProperties *properties, QVector<QByteArray> enumNames = QVector<QByteArray>(0)); | 87 | void initProp(int n, drmModeObjectProperties *properties, | ||
88 | QVector<QByteArray> enumNames = QVector<QByteArray>(0)); | ||||
89 | | ||||
90 | bool doAtomicPopulate(drmModeAtomicReq *req, int firstProperty) const; | ||||
91 | | ||||
81 | class Property; | 92 | class Property; | ||
82 | bool atomicAddProperty(drmModeAtomicReq *req, Property *property); | 93 | bool atomicAddProperty(drmModeAtomicReq *req, Property *property) const; | ||
83 | 94 | | |||
84 | int m_fd; | 95 | int m_fd; | ||
85 | const uint32_t m_id; | 96 | const uint32_t m_id; | ||
86 | DrmOutput *m_output = nullptr; | 97 | DrmOutput *m_output = nullptr; | ||
87 | 98 | | |||
88 | // for comparison with received name of DRM object | 99 | // for comparison with received name of DRM object | ||
89 | QVector<Property *> m_props; | 100 | QVector<Property *> m_props; | ||
90 | 101 | | |||
91 | class Property | 102 | class Property | ||
92 | { | 103 | { | ||
93 | public: | 104 | public: | ||
94 | Property(drmModePropertyRes *prop, uint64_t val, QVector<QByteArray> enumNames); | 105 | Property(drmModePropertyRes *prop, uint64_t val, QVector<QByteArray> enumNames); | ||
95 | virtual ~Property(); | 106 | virtual ~Property(); | ||
96 | 107 | | |||
97 | void initEnumMap(drmModePropertyRes *prop); | 108 | void initEnumMap(drmModePropertyRes *prop); | ||
98 | 109 | | |||
99 | uint64_t enumMap(int n) { | 110 | /** | ||
111 | * For properties of enum type the enum map identifies the kernel runtime values, | ||||
112 | * which must be queried beforehand. | ||||
113 | * | ||||
114 | * @param n the index to the enum | ||||
115 | * @return the runtime enum value corresponding with enum index @param n | ||||
116 | */ | ||||
117 | uint64_t enumMap(int n) const { | ||||
100 | return m_enumMap[n]; // TODO: test on index out of bounds? | 118 | return m_enumMap[n]; // TODO: test on index out of bounds? | ||
101 | } | 119 | } | ||
102 | bool hasEnum(uint64_t value) const { | 120 | bool hasEnum(uint64_t value) const { | ||
103 | return m_enumMap.contains(value); | 121 | return m_enumMap.contains(value); | ||
104 | } | 122 | } | ||
105 | 123 | | |||
106 | uint32_t propId() const { | 124 | uint32_t propId() const { | ||
107 | return m_propId; | 125 | return m_propId; | ||
Show All 16 Lines | 137 | private: | |||
124 | QVector<uint64_t> m_enumMap; | 142 | QVector<uint64_t> m_enumMap; | ||
125 | QVector<QByteArray> m_enumNames; | 143 | QVector<QByteArray> m_enumNames; | ||
126 | }; | 144 | }; | ||
127 | 145 | | |||
128 | private: | 146 | private: | ||
129 | QVector<QByteArray> m_propsNames; | 147 | QVector<QByteArray> m_propsNames; | ||
130 | }; | 148 | }; | ||
131 | 149 | | |||
132 | | ||||
133 | } | 150 | } | ||
134 | 151 | | |||
135 | #endif | | |||
136 | |