[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / windowing / gbm / drm / DRMObject.cpp
blob5ffce40fa31df28f900cb06060c08a154442c05b
1 /*
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.
7 */
9 #include "DRMObject.h"
11 #include "utils/log.h"
13 #include <algorithm>
14 #include <array>
16 using namespace KODI::WINDOWING::GBM;
18 namespace
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())
41 return name->second;
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;
64 return 0;
67 bool CDRMObject::GetProperties(uint32_t id, uint32_t type)
69 m_props.reset(drmModeObjectGetProperties(m_fd, id, type));
70 if (!m_props)
71 return false;
73 m_id = id;
74 m_type = 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])));
80 return true;
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())
90 return {};
92 auto prop = property->get();
94 if (!static_cast<bool>(drm_property_type_is(prop, DRM_MODE_PROP_ENUM)))
95 return {};
97 for (int j = 0; j < prop->count_enums; j++)
99 if (prop->enums[j].name != valueName)
100 continue;
102 return std::make_optional<uint64_t>(prop->enums[j].value);
105 return {};
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);
116 if (ret == 0)
117 return true;
120 return false;
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())
129 return true;
131 return false;