xref: /aosp_15_r20/external/libkmsxx/kms++/src/property.cpp (revision f0687c8a10b3e371dbe09214db6664e37c283cca)
1 #include <xf86drm.h>
2 #include <xf86drmMode.h>
3 
4 #include <kms++/kms++.h>
5 
6 using namespace std;
7 
8 namespace kms
9 {
10 struct PropertyPriv {
11 	drmModePropertyPtr drm_prop;
12 };
13 
Property(Card & card,uint32_t id)14 Property::Property(Card& card, uint32_t id)
15 	: DrmObject(card, id, DRM_MODE_OBJECT_PROPERTY)
16 {
17 	m_priv = new PropertyPriv();
18 	m_priv->drm_prop = drmModeGetProperty(card.fd(), id);
19 	m_name = m_priv->drm_prop->name;
20 
21 	PropertyType t;
22 	drmModePropertyPtr p = m_priv->drm_prop;
23 	if (drm_property_type_is(p, DRM_MODE_PROP_BITMASK))
24 		t = PropertyType::Bitmask;
25 	else if (drm_property_type_is(p, DRM_MODE_PROP_BLOB))
26 		t = PropertyType::Blob;
27 	else if (drm_property_type_is(p, DRM_MODE_PROP_ENUM))
28 		t = PropertyType::Enum;
29 	else if (drm_property_type_is(p, DRM_MODE_PROP_OBJECT))
30 		t = PropertyType::Object;
31 	else if (drm_property_type_is(p, DRM_MODE_PROP_RANGE))
32 		t = PropertyType::Range;
33 	else if (drm_property_type_is(p, DRM_MODE_PROP_SIGNED_RANGE))
34 		t = PropertyType::SignedRange;
35 	else
36 		throw invalid_argument("Invalid property type");
37 
38 	m_type = t;
39 }
40 
~Property()41 Property::~Property()
42 {
43 	drmModeFreeProperty(m_priv->drm_prop);
44 	delete m_priv;
45 }
46 
name() const47 const string& Property::name() const
48 {
49 	return m_name;
50 }
51 
is_immutable() const52 bool Property::is_immutable() const
53 {
54 	return m_priv->drm_prop->flags & DRM_MODE_PROP_IMMUTABLE;
55 }
56 
is_pending() const57 bool Property::is_pending() const
58 {
59 	return m_priv->drm_prop->flags & DRM_MODE_PROP_PENDING;
60 }
61 
get_values() const62 vector<uint64_t> Property::get_values() const
63 {
64 	drmModePropertyPtr p = m_priv->drm_prop;
65 	return vector<uint64_t>(p->values, p->values + p->count_values);
66 }
67 
get_enums() const68 map<uint64_t, string> Property::get_enums() const
69 {
70 	drmModePropertyPtr p = m_priv->drm_prop;
71 
72 	map<uint64_t, string> map;
73 
74 	for (int i = 0; i < p->count_enums; ++i)
75 		map[p->enums[i].value] = string(p->enums[i].name);
76 
77 	return map;
78 }
79 
get_blob_ids() const80 vector<uint32_t> Property::get_blob_ids() const
81 {
82 	drmModePropertyPtr p = m_priv->drm_prop;
83 	return vector<uint32_t>(p->blob_ids, p->blob_ids + p->count_blobs);
84 }
85 } // namespace kms
86