summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2016-05-25 14:34:23 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2016-05-25 14:34:42 +0300
commit2d14233bdb2302bffc1a241681f34933cb99c157 (patch)
tree8144b28596c5a3cc4e6b4755de489a126d4278c0
parentd30ec339a102acd479e4327f319416886c7a3473 (diff)
Add support for DRM blobs
-rw-r--r--libkms++/blob.cpp51
-rw-r--r--libkms++/blob.h21
-rw-r--r--libkms++/decls.h1
-rw-r--r--libkms++/drmpropobject.cpp7
-rw-r--r--libkms++/drmpropobject.h2
-rw-r--r--libkms++/kms++.h1
-rw-r--r--py/pykmsbase.cpp14
7 files changed, 97 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"
diff --git a/py/pykmsbase.cpp b/py/pykmsbase.cpp
index aa86d9f..83be9d2 100644
--- a/py/pykmsbase.cpp
+++ b/py/pykmsbase.cpp
@@ -31,6 +31,9 @@ void init_pykmsbase(py::module &m)
py::class_<DrmPropObject, DrmPropObject*>(m, "DrmPropObject", py::base<DrmObject>())
.def("refresh_props", &DrmPropObject::refresh_props)
.def_property_readonly("prop_map", &DrmPropObject::get_prop_map)
+ .def("get_prop_value", (uint64_t (DrmPropObject::*)(const string&) const)&DrmPropObject::get_prop_value)
+ .def("set_prop_value",(int (DrmPropObject::*)(const string&, uint64_t)) &DrmPropObject::set_prop_value)
+ .def("get_prop_value_as_blob", &DrmPropObject::get_prop_value_as_blob)
;
py::class_<Connector, Connector*>(m, "Connector", py::base<DrmPropObject>())
@@ -69,6 +72,17 @@ void init_pykmsbase(py::module &m)
.def_property_readonly("name", &Property::name)
;
+ py::class_<Blob>(m, "Blob", py::base<DrmObject>())
+ .def("__init__", [](Blob& instance, Card& card, py::buffer buf) {
+ py::buffer_info info = buf.request();
+ if (info.ndim != 1)
+ throw std::runtime_error("Incompatible buffer dimension!");
+
+ new (&instance) Blob(card, info.ptr, info.size * info.itemsize);
+ })
+ .def_property_readonly("data", &Blob::data)
+ ;
+
py::class_<Framebuffer>(m, "Framebuffer", py::base<DrmObject>())
;