diff options
Diffstat (limited to 'libkms++')
-rw-r--r-- | libkms++/blob.cpp | 51 | ||||
-rw-r--r-- | libkms++/blob.h | 21 | ||||
-rw-r--r-- | libkms++/decls.h | 1 | ||||
-rw-r--r-- | libkms++/drmpropobject.cpp | 7 | ||||
-rw-r--r-- | libkms++/drmpropobject.h | 2 | ||||
-rw-r--r-- | libkms++/kms++.h | 1 |
6 files changed, 83 insertions, 0 deletions
diff --git a/libkms++/blob.cpp b/libkms++/blob.cpp new file mode 100644 index 0000000..10a71c6 --- /dev/null +++ b/libkms++/blob.cpp @@ -0,0 +1,51 @@ +#include <xf86drm.h> +#include <xf86drmMode.h> + +#include "kms++.h" + +using namespace std; + +namespace kms +{ + +Blob::Blob(Card& card, uint32_t blob_id) + : DrmObject(card, blob_id, DRM_MODE_OBJECT_BLOB), m_created(false) +{ + // XXX should we verify that the blob_id is a blob object? +} + +Blob::Blob(Card& card, void* data, size_t len) + : DrmObject(card, DRM_MODE_OBJECT_BLOB), m_created(true) +{ + uint32_t id; + + int r = drmModeCreatePropertyBlob(card.fd(), data, len, &id); + if (r) + throw invalid_argument("FAILED TO CREATE PROP\n"); + + set_id(id); +} + +Blob::~Blob() +{ + if (m_created) + drmModeDestroyPropertyBlob(card().fd(), id()); +} + +vector<uint8_t> Blob::data() +{ + drmModePropertyBlobPtr blob = drmModeGetPropertyBlob(card().fd(), id()); + + if (!blob) + throw invalid_argument("Blob data not available"); + + uint8_t* data = (uint8_t*)blob->data; + + auto v = vector<uint8_t>(data, data + blob->length); + + drmModeFreePropertyBlob(blob); + + return v; +} + +} diff --git a/libkms++/blob.h b/libkms++/blob.h new file mode 100644 index 0000000..c6c230c --- /dev/null +++ b/libkms++/blob.h @@ -0,0 +1,21 @@ +#pragma once + +#include "drmobject.h" + +namespace kms +{ + +class Blob : public DrmObject +{ +public: + Blob(Card& card, uint32_t blob_id); + Blob(Card& card, void* data, size_t len); + virtual ~Blob(); + + std::vector<uint8_t> data(); + +private: + bool m_created; +}; + +} diff --git a/libkms++/decls.h b/libkms++/decls.h index 1bb968f..e84b29a 100644 --- a/libkms++/decls.h +++ b/libkms++/decls.h @@ -14,5 +14,6 @@ class DrmObject; class PageFlipHandlerBase; class Plane; class Property; +class Blob; struct Videomode; } diff --git a/libkms++/drmpropobject.cpp b/libkms++/drmpropobject.cpp index de9dfe3..50f87a7 100644 --- a/libkms++/drmpropobject.cpp +++ b/libkms++/drmpropobject.cpp @@ -61,6 +61,13 @@ uint64_t DrmPropObject::get_prop_value(const string& name) const throw invalid_argument("property not found: " + name); } +unique_ptr<Blob> DrmPropObject::get_prop_value_as_blob(const string& name) const +{ + uint32_t blob_id = (uint32_t)get_prop_value(name); + + return unique_ptr<Blob>(new Blob(card(), blob_id)); +} + int DrmPropObject::set_prop_value(uint32_t id, uint64_t value) { return drmModeObjectSetProperty(card().fd(), this->id(), this->object_type(), id, value); diff --git a/libkms++/drmpropobject.h b/libkms++/drmpropobject.h index 6dfd2a8..ec28d45 100644 --- a/libkms++/drmpropobject.h +++ b/libkms++/drmpropobject.h @@ -1,6 +1,7 @@ #pragma once #include <map> +#include <memory> #include "drmobject.h" #include "decls.h" @@ -15,6 +16,7 @@ public: void refresh_props(); uint64_t get_prop_value(uint32_t id) const; uint64_t get_prop_value(const std::string& name) const; + std::unique_ptr<Blob> get_prop_value_as_blob(const std::string& name) const; const std::map<uint32_t, uint64_t>& get_prop_map() const { return m_prop_values; } diff --git a/libkms++/kms++.h b/libkms++/kms++.h index 291cf13..3365ef7 100644 --- a/libkms++/kms++.h +++ b/libkms++/kms++.h @@ -10,5 +10,6 @@ #include "extframebuffer.h" #include "plane.h" #include "property.h" +#include "blob.h" #include "pipeline.h" #include "pagefliphandler.h" |