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/pykms.cpp | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'py/pykms/pykms.cpp') diff --git a/py/pykms/pykms.cpp b/py/pykms/pykms.cpp index 2199039..7752f19 100644 --- a/py/pykms/pykms.cpp +++ b/py/pykms/pykms.cpp @@ -15,32 +15,15 @@ void init_pyvid(py::module &m); void init_pykmsomap(py::module &m); #endif -class PyPageFlipHandlerBase : PageFlipHandlerBase -{ -public: - using PageFlipHandlerBase::PageFlipHandlerBase; - - virtual void handle_page_flip(uint32_t frame, double time) - { - PYBIND11_OVERLOAD_PURE( - void, /* Return type */ - PageFlipHandlerBase, /* Parent class */ - handle_page_flip, /* Name of function */ - frame, time - ); - } -}; - PYBIND11_PLUGIN(pykms) { py::module m("pykms", "kms bindings"); init_pykmsbase(m); - py::class_(m, "PageFlipHandlerBase") - .alias() - .def(py::init<>()) - .def("handle_page_flip", &PageFlipHandlerBase::handle_page_flip) - ; + m.def("__ob_unpack_helper", [](uint64_t v) { + // AtomicReq::commit or Crtc::page_flip added a ref, so we can use borrowed = false + return py::object((PyObject*)v, false); + }); init_pykmstest(m); -- cgit v1.2.3