diff options
-rw-r--r-- | libkms++/connector.cpp | 2 | ||||
-rw-r--r-- | libkms++/connector.h | 4 | ||||
-rw-r--r-- | libkms++/crtc.cpp | 2 | ||||
-rw-r--r-- | libkms++/crtc.h | 4 | ||||
-rw-r--r-- | libkms++/drmobject.cpp | 49 | ||||
-rw-r--r-- | libkms++/drmobject.h | 11 | ||||
-rw-r--r-- | libkms++/drmpropobject.cpp | 79 | ||||
-rw-r--r-- | libkms++/drmpropobject.h | 33 | ||||
-rw-r--r-- | libkms++/encoder.cpp | 2 | ||||
-rw-r--r-- | libkms++/encoder.h | 4 | ||||
-rw-r--r-- | libkms++/plane.cpp | 2 | ||||
-rw-r--r-- | libkms++/plane.h | 4 | ||||
-rw-r--r-- | py/pykmsbase.cpp | 15 | ||||
-rw-r--r-- | utils/kmsprint.cpp | 2 |
14 files changed, 134 insertions, 79 deletions
diff --git a/libkms++/connector.cpp b/libkms++/connector.cpp index e108410..b64cdf7 100644 --- a/libkms++/connector.cpp +++ b/libkms++/connector.cpp @@ -57,7 +57,7 @@ struct ConnectorPriv }; Connector::Connector(Card &card, uint32_t id, uint32_t idx) - :DrmObject(card, id, DRM_MODE_OBJECT_CONNECTOR, idx) + :DrmPropObject(card, id, DRM_MODE_OBJECT_CONNECTOR, idx) { m_priv = new ConnectorPriv(); diff --git a/libkms++/connector.h b/libkms++/connector.h index 1759af1..6ccc959 100644 --- a/libkms++/connector.h +++ b/libkms++/connector.h @@ -2,7 +2,7 @@ #include <vector> -#include "drmobject.h" +#include "drmpropobject.h" #include "videomode.h" namespace kms @@ -10,7 +10,7 @@ namespace kms struct ConnectorPriv; -class Connector : public DrmObject +class Connector : public DrmPropObject { friend class Card; public: diff --git a/libkms++/crtc.cpp b/libkms++/crtc.cpp index deadd62..d50a78d 100644 --- a/libkms++/crtc.cpp +++ b/libkms++/crtc.cpp @@ -18,7 +18,7 @@ struct CrtcPriv }; Crtc::Crtc(Card &card, uint32_t id, uint32_t idx) - :DrmObject(card, id, DRM_MODE_OBJECT_CRTC, idx) + :DrmPropObject(card, id, DRM_MODE_OBJECT_CRTC, idx) { m_priv = new CrtcPriv(); m_priv->drm_crtc = drmModeGetCrtc(this->card().fd(), this->id()); diff --git a/libkms++/crtc.h b/libkms++/crtc.h index 5e0f15a..f3b525a 100644 --- a/libkms++/crtc.h +++ b/libkms++/crtc.h @@ -2,14 +2,14 @@ #include <vector> -#include "drmobject.h" +#include "drmpropobject.h" namespace kms { struct CrtcPriv; -class Crtc : public DrmObject +class Crtc : public DrmPropObject { friend class Card; friend class Connector; diff --git a/libkms++/drmobject.cpp b/libkms++/drmobject.cpp index 76a7e8c..8abecc7 100644 --- a/libkms++/drmobject.cpp +++ b/libkms++/drmobject.cpp @@ -20,7 +20,6 @@ DrmObject::DrmObject(Card& card, uint32_t object_type) DrmObject::DrmObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx) :m_card(card), m_id(id), m_object_type(object_type), m_idx(idx) { - refresh_props(); } DrmObject::~DrmObject() @@ -28,54 +27,6 @@ DrmObject::~DrmObject() } -void DrmObject::refresh_props() -{ - auto props = drmModeObjectGetProperties(card().fd(), this->id(), this->object_type()); - - if (props == nullptr) - return; - - for (unsigned i = 0; i < props->count_props; ++i) { - uint32_t prop_id = props->props[i]; - uint64_t prop_value = props->prop_values[i]; - - m_prop_values[prop_id] = prop_value; - } - - drmModeFreeObjectProperties(props); -} - -uint64_t DrmObject::get_prop_value(uint32_t id) const -{ - return m_prop_values.at(id); -} - -uint64_t DrmObject::get_prop_value(const string& name) const -{ - for (auto pair : m_prop_values) { - auto prop = card().get_prop(pair.first); - if (name == prop->name()) - return m_prop_values.at(prop->id()); - } - - throw invalid_argument("property not found: " + name); -} - -int DrmObject::set_prop_value(uint32_t id, uint64_t value) -{ - return drmModeObjectSetProperty(card().fd(), this->id(), this->object_type(), id, value); -} - -int DrmObject::set_prop_value(const string &name, uint64_t value) -{ - Property* prop = card().get_prop(name); - - if (prop == nullptr) - throw invalid_argument("property not found: " + name); - - return set_prop_value(prop->id(), value); -} - void DrmObject::set_id(uint32_t id) { m_id = id; diff --git a/libkms++/drmobject.h b/libkms++/drmobject.h index b7d16cc..a939aa7 100644 --- a/libkms++/drmobject.h +++ b/libkms++/drmobject.h @@ -20,15 +20,6 @@ public: uint32_t object_type() const { return m_object_type; } uint32_t idx() const { return m_idx; } - void refresh_props(); - uint64_t get_prop_value(uint32_t id) const; - uint64_t get_prop_value(const std::string& name) const; - - const std::map<uint32_t, uint64_t>& get_prop_map() const { return m_prop_values; } - - int set_prop_value(uint32_t id, uint64_t value); - int set_prop_value(const std::string& name, uint64_t value); - protected: DrmObject(Card& card, uint32_t object_type); DrmObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx = 0); @@ -45,7 +36,5 @@ private: uint32_t m_id; uint32_t m_object_type; uint32_t m_idx; - - std::map<uint32_t, uint64_t> m_prop_values; }; } diff --git a/libkms++/drmpropobject.cpp b/libkms++/drmpropobject.cpp new file mode 100644 index 0000000..de9dfe3 --- /dev/null +++ b/libkms++/drmpropobject.cpp @@ -0,0 +1,79 @@ +#include <string.h> +#include <iostream> +#include <stdexcept> + +#include <xf86drm.h> +#include <xf86drmMode.h> + +#include "kms++.h" + +using namespace std; + +namespace kms +{ + +DrmPropObject::DrmPropObject(Card& card, uint32_t object_type) + : DrmObject(card, object_type) +{ +} + +DrmPropObject::DrmPropObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx) + : DrmObject(card, id, object_type, idx) +{ + refresh_props(); +} + +DrmPropObject::~DrmPropObject() +{ + +} + +void DrmPropObject::refresh_props() +{ + auto props = drmModeObjectGetProperties(card().fd(), this->id(), this->object_type()); + + if (props == nullptr) + return; + + for (unsigned i = 0; i < props->count_props; ++i) { + uint32_t prop_id = props->props[i]; + uint64_t prop_value = props->prop_values[i]; + + m_prop_values[prop_id] = prop_value; + } + + drmModeFreeObjectProperties(props); +} + +uint64_t DrmPropObject::get_prop_value(uint32_t id) const +{ + return m_prop_values.at(id); +} + +uint64_t DrmPropObject::get_prop_value(const string& name) const +{ + for (auto pair : m_prop_values) { + auto prop = card().get_prop(pair.first); + if (name == prop->name()) + return m_prop_values.at(prop->id()); + } + + throw invalid_argument("property not found: " + name); +} + +int DrmPropObject::set_prop_value(uint32_t id, uint64_t value) +{ + return drmModeObjectSetProperty(card().fd(), this->id(), this->object_type(), id, value); +} + +int DrmPropObject::set_prop_value(const string &name, uint64_t value) +{ + Property* prop = card().get_prop(name); + + if (prop == nullptr) + throw invalid_argument("property not found: " + name); + + return set_prop_value(prop->id(), value); +} + +} diff --git a/libkms++/drmpropobject.h b/libkms++/drmpropobject.h new file mode 100644 index 0000000..6dfd2a8 --- /dev/null +++ b/libkms++/drmpropobject.h @@ -0,0 +1,33 @@ +#pragma once + +#include <map> + +#include "drmobject.h" +#include "decls.h" + +namespace kms +{ + +class DrmPropObject : public DrmObject +{ + friend class Card; +public: + void refresh_props(); + uint64_t get_prop_value(uint32_t id) const; + uint64_t get_prop_value(const std::string& name) const; + + const std::map<uint32_t, uint64_t>& get_prop_map() const { return m_prop_values; } + + int set_prop_value(uint32_t id, uint64_t value); + int set_prop_value(const std::string& name, uint64_t value); + +protected: + DrmPropObject(Card& card, uint32_t object_type); + DrmPropObject(Card& card, uint32_t id, uint32_t object_type, uint32_t idx = 0); + + virtual ~DrmPropObject(); + +private: + std::map<uint32_t, uint64_t> m_prop_values; +}; +} diff --git a/libkms++/encoder.cpp b/libkms++/encoder.cpp index ffef897..ba6b076 100644 --- a/libkms++/encoder.cpp +++ b/libkms++/encoder.cpp @@ -31,7 +31,7 @@ static const map<int, string> encoder_types = { }; Encoder::Encoder(Card &card, uint32_t id) - :DrmObject(card, id, DRM_MODE_OBJECT_ENCODER) + :DrmPropObject(card, id, DRM_MODE_OBJECT_ENCODER) { m_priv = new EncoderPriv(); m_priv->drm_encoder = drmModeGetEncoder(this->card().fd(), this->id()); diff --git a/libkms++/encoder.h b/libkms++/encoder.h index 956a4c7..1b54572 100644 --- a/libkms++/encoder.h +++ b/libkms++/encoder.h @@ -1,14 +1,14 @@ #pragma once #include <vector> -#include "drmobject.h" +#include "drmpropobject.h" namespace kms { struct EncoderPriv; -class Encoder : public DrmObject +class Encoder : public DrmPropObject { friend class Card; public: diff --git a/libkms++/plane.cpp b/libkms++/plane.cpp index b4934b8..b82c1b4 100644 --- a/libkms++/plane.cpp +++ b/libkms++/plane.cpp @@ -19,7 +19,7 @@ struct PlanePriv }; Plane::Plane(Card &card, uint32_t id) - :DrmObject(card, id, DRM_MODE_OBJECT_PLANE) + :DrmPropObject(card, id, DRM_MODE_OBJECT_PLANE) { m_priv = new PlanePriv(); m_priv->drm_plane = drmModeGetPlane(this->card().fd(), this->id()); diff --git a/libkms++/plane.h b/libkms++/plane.h index 91c403f..3d9d4cd 100644 --- a/libkms++/plane.h +++ b/libkms++/plane.h @@ -1,6 +1,6 @@ #pragma once -#include "drmobject.h" +#include "drmpropobject.h" namespace kms { @@ -14,7 +14,7 @@ enum class PlaneType struct PlanePriv; -class Plane : public DrmObject +class Plane : public DrmPropObject { friend class Card; public: diff --git a/py/pykmsbase.cpp b/py/pykmsbase.cpp index b27ed3c..aa86d9f 100644 --- a/py/pykmsbase.cpp +++ b/py/pykmsbase.cpp @@ -25,12 +25,15 @@ void init_pykmsbase(py::module &m) py::class_<DrmObject, DrmObject*>(m, "DrmObject") .def_property_readonly("id", &DrmObject::id) - .def("refresh_props", &DrmObject::refresh_props) - .def_property_readonly("prop_map", &DrmObject::get_prop_map) .def_property_readonly("card", &DrmObject::card) ; - py::class_<Connector, Connector*>(m, "Connector", py::base<DrmObject>()) + py::class_<DrmPropObject, DrmPropObject*>(m, "DrmPropObject", py::base<DrmObject>()) + .def("refresh_props", &DrmPropObject::refresh_props) + .def_property_readonly("prop_map", &DrmPropObject::get_prop_map) + ; + + py::class_<Connector, Connector*>(m, "Connector", py::base<DrmPropObject>()) .def_property_readonly("fullname", &Connector::fullname) .def("get_default_mode", &Connector::get_default_mode) .def("get_current_crtc", &Connector::get_current_crtc) @@ -38,7 +41,7 @@ void init_pykmsbase(py::module &m) .def("__repr__", [](const Connector& o) { return "<pykms.Connector " + to_string(o.id()) + ">"; }) ; - py::class_<Crtc, Crtc*>(m, "Crtc", py::base<DrmObject>()) + py::class_<Crtc, Crtc*>(m, "Crtc", py::base<DrmPropObject>()) .def("set_mode", &Crtc::set_mode) .def("page_flip", &Crtc::page_flip) .def("set_plane", &Crtc::set_plane) @@ -47,10 +50,10 @@ void init_pykmsbase(py::module &m) .def("__repr__", [](const Crtc& o) { return "<pykms.Crtc " + to_string(o.id()) + ">"; }) ; - py::class_<Encoder, Encoder*>(m, "Encoder", py::base<DrmObject>()) + py::class_<Encoder, Encoder*>(m, "Encoder", py::base<DrmPropObject>()) ; - py::class_<Plane, Plane*>(m, "Plane", py::base<DrmObject>()) + py::class_<Plane, Plane*>(m, "Plane", py::base<DrmPropObject>()) .def("supports_crtc", &Plane::supports_crtc) .def_property_readonly("plane_type", &Plane::plane_type) .def("__repr__", [](const Plane& o) { return "<pykms.Plane " + to_string(o.id()) + ">"; }) diff --git a/utils/kmsprint.cpp b/utils/kmsprint.cpp index 7b9de8c..a57d33f 100644 --- a/utils/kmsprint.cpp +++ b/utils/kmsprint.cpp @@ -49,7 +49,7 @@ void print_property(uint64_t val, const Property& p, int ind) p.name().c_str(), p.id(), p.to_str(val).c_str()); } -void print_properties(DrmObject& o, int ind) +void print_properties(DrmPropObject& o, int ind) { auto pmap = o.get_prop_map(); printf("%sProperties, %u in total:\n", width(ind, "").c_str(), |