From 84e240f64014f1e27dc1b3769f5ea83046f683d0 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 8 Mar 2017 12:11:11 +0200 Subject: New event handling The current event handling relies on the PageFlipHandlerBase class which has to be implemented on the python side. This patch implements a more versatile event handling, where any python object can be passed as data to the commit or page flip, and it's up to the python implementation to decide what to do with that data when receiving the event. Note that when doing the commit or page_flip, the ref count of the given python object is incremented to keep it alive. The ref count is decremented when reading the events with the new helper method card.read_events(). This helper _has_ to be used to ensure the objects get released properly. Signed-off-by: Tomi Valkeinen --- py/pykms/pykmsbase.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'py/pykms/pykmsbase.cpp') diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp index 0d5bb86..1cc91d8 100644 --- a/py/pykms/pykmsbase.cpp +++ b/py/pykms/pykmsbase.cpp @@ -18,7 +18,6 @@ void init_pykmsbase(py::module &m) .def_property_readonly("encoders", &Card::get_encoders) .def_property_readonly("planes", &Card::get_planes) .def_property_readonly("has_atomic", &Card::has_atomic) - .def("call_page_flip_handlers", &Card::call_page_flip_handlers) .def("get_prop", (Property* (Card::*)(uint32_t) const)&Card::get_prop) ; @@ -49,7 +48,14 @@ void init_pykmsbase(py::module &m) py::class_(m, "Crtc", py::base()) .def("set_mode", &Crtc::set_mode) - .def("page_flip", &Crtc::page_flip) + .def("page_flip", + [](Crtc* self, Framebuffer& fb, py::object ob) + { + // This adds a ref to the object, and must be unpacked with __ob_unpack_helper() + PyObject* pob = ob.ptr(); + Py_XINCREF(pob); + self->page_flip(fb, pob); + }) .def("set_plane", &Crtc::set_plane) .def_property_readonly("possible_planes", &Crtc::get_possible_planes) .def_property_readonly("primary_plane", &Crtc::get_primary_plane) @@ -167,7 +173,14 @@ void init_pykmsbase(py::module &m) .def("add", (void (AtomicReq::*)(DrmPropObject*, const string&, uint64_t)) &AtomicReq::add) .def("add", (void (AtomicReq::*)(DrmPropObject*, const map&)) &AtomicReq::add) .def("test", &AtomicReq::test, py::arg("allow_modeset") = false) - .def("commit", &AtomicReq::commit, py::arg("data"), py::arg("allow_modeset") = false) + .def("commit", + [](AtomicReq* self, py::object ob, bool allow) + { + // This adds a ref to the object, and must be unpacked with __ob_unpack_helper() + PyObject* pob = ob.ptr(); + Py_XINCREF(pob); + self->commit(pob, allow); + }, py::arg("data"), py::arg("allow_modeset") = false) .def("commit_sync", &AtomicReq::commit_sync, py::arg("allow_modeset") = false) ; } -- cgit v1.2.3