KWin
Loading...
Searching...
No Matches
drm_object.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
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "drm_object.h"
10
11#include <errno.h>
12
13#include "drm_commit.h"
14#include "drm_gpu.h"
15#include "drm_logging.h"
16#include "drm_pointer.h"
17
18namespace KWin
19{
20
21DrmObject::DrmObject(DrmGpu *gpu, uint32_t objectId, uint32_t objectType)
22 : m_gpu(gpu)
23 , m_id(objectId)
24 , m_objectType(objectType)
25{
26}
27
29{
30 return updateProperties();
31}
32
34{
35 DrmUniquePtr<drmModeObjectProperties> properties(drmModeObjectGetProperties(m_gpu->fd(), m_id, m_objectType));
36 if (!properties) {
37 qCWarning(KWIN_DRM) << "Failed to get properties for object" << m_id;
38 return {};
39 }
41 for (uint32_t i = 0; i < properties->count_props; i++) {
42 DrmUniquePtr<drmModePropertyRes> prop(drmModeGetProperty(m_gpu->fd(), properties->props[i]));
43 if (!prop) {
44 qCWarning(KWIN_DRM, "Getting property %d of object %d failed!", properties->props[i], m_id);
45 continue;
46 }
47 ret.addProperty(std::move(prop), properties->prop_values[i]);
48 }
49 return ret;
50}
51
52uint32_t DrmObject::id() const
53{
54 return m_id;
55}
56
58{
59 return m_gpu;
60}
61
62uint32_t DrmObject::type() const
63{
64 return m_objectType;
65}
66
67QString DrmObject::typeName() const
68{
69 switch (m_objectType) {
70 case DRM_MODE_OBJECT_CONNECTOR:
71 return QStringLiteral("connector");
72 case DRM_MODE_OBJECT_CRTC:
73 return QStringLiteral("crtc");
74 case DRM_MODE_OBJECT_PLANE:
75 return QStringLiteral("plane");
76 default:
77 return QStringLiteral("unknown?");
78 }
79}
80
82{
83 m_properties.push_back(std::make_pair(std::move(prop), value));
84}
85
86std::optional<std::pair<DrmUniquePtr<drmModePropertyRes>, uint64_t>> DrmPropertyList::takeProperty(const QByteArray &name)
87{
88 const auto it = std::find_if(m_properties.begin(), m_properties.end(), [&name](const auto &pair) {
89 return pair.first->name == name;
90 });
91 if (it != m_properties.end()) {
92 auto ret = std::move(*it);
93 m_properties.erase(it);
94 return ret;
95 } else {
96 return std::nullopt;
97 }
98}
99}
100
101QDebug operator<<(QDebug s, const KWin::DrmObject *obj)
102{
103 QDebugStateSaver saver(s);
104 if (obj) {
105 s.nospace() << "DrmObject(id=" << obj->id() << ", gpu=" << obj->gpu() << ')';
106 } else {
107 s << "DrmObject(0x0)";
108 }
109 return s;
110}
int fd() const
Definition drm_gpu.cpp:648
DrmPropertyList queryProperties() const
uint32_t id() const
virtual bool updateProperties()=0
QString typeName() const
DrmObject(const DrmObject &)=delete
DrmGpu * gpu() const
uint32_t type() const
void addProperty(DrmUniquePtr< drmModePropertyRes > &&prop, uint64_t value)
std::optional< std::pair< DrmUniquePtr< drmModePropertyRes >, uint64_t > > takeProperty(const QByteArray &name)
QDebug operator<<(QDebug s, const KWin::DrmObject *obj)
drmModeObjectPropertiesPtr drmModeObjectGetProperties(int fd, uint32_t object_id, uint32_t object_type)
Definition mock_drm.cpp:844
drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId)
Definition mock_drm.cpp:730
std::unique_ptr< T, DrmDeleter< T > > DrmUniquePtr