2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "utils/log.h"
16 using namespace KODI::WINDOWING::GBM
;
21 constexpr std::array
<std::pair
<uint32_t, const char*>, 8> DrmModeObjectTypes
= {
22 {{DRM_MODE_OBJECT_CRTC
, "crtc"},
23 {DRM_MODE_OBJECT_CONNECTOR
, "connector"},
24 {DRM_MODE_OBJECT_ENCODER
, "encoder"},
25 {DRM_MODE_OBJECT_MODE
, "mode"},
26 {DRM_MODE_OBJECT_PROPERTY
, "property"},
27 {DRM_MODE_OBJECT_FB
, "framebuffer"},
28 {DRM_MODE_OBJECT_BLOB
, "blob"},
29 {DRM_MODE_OBJECT_PLANE
, "plane"}}};
32 CDRMObject::CDRMObject(int fd
) : m_fd(fd
)
36 std::string
CDRMObject::GetTypeName() const
38 auto name
= std::find_if(DrmModeObjectTypes
.begin(), DrmModeObjectTypes
.end(),
39 [this](const auto& p
) { return p
.first
== m_type
; });
40 if (name
!= DrmModeObjectTypes
.end())
43 return "invalid type";
46 std::string
CDRMObject::GetPropertyName(uint32_t propertyId
) const
48 auto prop
= std::find_if(m_propsInfo
.begin(), m_propsInfo
.end(),
49 [&propertyId
](const auto& p
) { return p
->prop_id
== propertyId
; });
50 if (prop
!= m_propsInfo
.end())
51 return prop
->get()->name
;
53 return "invalid property";
56 uint32_t CDRMObject::GetPropertyId(const std::string
& name
) const
58 auto property
= std::find_if(m_propsInfo
.begin(), m_propsInfo
.end(),
59 [&name
](const auto& prop
) { return prop
->name
== name
; });
61 if (property
!= m_propsInfo
.end())
62 return property
->get()->prop_id
;
67 bool CDRMObject::GetProperties(uint32_t id
, uint32_t type
)
69 m_props
.reset(drmModeObjectGetProperties(m_fd
, id
, type
));
76 for (uint32_t i
= 0; i
< m_props
->count_props
; i
++)
77 m_propsInfo
.emplace_back(std::unique_ptr
<drmModePropertyRes
, DrmModePropertyResDeleter
>(
78 drmModeGetProperty(m_fd
, m_props
->props
[i
])));
83 std::optional
<uint64_t> CDRMObject::GetPropertyValue(std::string_view name
,
84 std::string_view valueName
) const
86 auto property
= std::find_if(m_propsInfo
.begin(), m_propsInfo
.end(),
87 [&name
](const auto& prop
) { return prop
->name
== name
; });
89 if (property
== m_propsInfo
.end())
92 auto prop
= property
->get();
94 if (!static_cast<bool>(drm_property_type_is(prop
, DRM_MODE_PROP_ENUM
)))
97 for (int j
= 0; j
< prop
->count_enums
; j
++)
99 if (prop
->enums
[j
].name
!= valueName
)
102 return std::make_optional
<uint64_t>(prop
->enums
[j
].value
);
108 bool CDRMObject::SetProperty(const std::string
& name
, uint64_t value
)
110 auto property
= std::find_if(m_propsInfo
.begin(), m_propsInfo
.end(),
111 [&name
](const auto& prop
) { return prop
->name
== name
; });
113 if (property
!= m_propsInfo
.end())
115 int ret
= drmModeObjectSetProperty(m_fd
, m_id
, m_type
, property
->get()->prop_id
, value
);
123 bool CDRMObject::SupportsProperty(const std::string
& name
)
125 auto property
= std::find_if(m_propsInfo
.begin(), m_propsInfo
.end(),
126 [&name
](const auto& prop
) { return prop
->name
== name
; });
128 if (property
!= m_propsInfo
.end())