diff options
author | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2016-05-25 11:37:17 +0300 |
---|---|---|
committer | Tomi Valkeinen <tomi.valkeinen@ti.com> | 2016-05-25 11:37:17 +0300 |
commit | d30ec339a102acd479e4327f319416886c7a3473 (patch) | |
tree | 3fcd54b466fab8bf5577268cefd4ea84503f2672 /libkms++ | |
parent | 11a1c56d4b78c731d84dcf4f2e93ce4675353c7b (diff) |
Split properties from DrmObject into DrmPropObject
Diffstat (limited to 'libkms++')
-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 |
12 files changed, 124 insertions, 72 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: |