53c73517ade1cb70cbb932b655dfe1de141f0e07
[android/external-libkmsxx.git] / py / pykmsbase.cpp
1 #include <pybind11/pybind11.h>
2 #include <pybind11/stl.h>
3 #include <kms++.h>
5 namespace py = pybind11;
7 using namespace kms;
8 using namespace std;
10 void init_pykmsbase(py::module &m)
11 {
12         py::class_<Card>(m, "Card")
13                         .def(py::init<>())
14                         .def_property_readonly("fd", &Card::fd)
15                         .def("get_first_connected_connector", &Card::get_first_connected_connector)
16                         .def_property_readonly("connectors", &Card::get_connectors)
17                         .def_property_readonly("crtcs", &Card::get_crtcs)
18                         .def_property_readonly("encoders", &Card::get_encoders)
19                         .def_property_readonly("planes", &Card::get_planes)
20                         .def_property_readonly("has_atomic", &Card::has_atomic)
21                         .def("call_page_flip_handlers", &Card::call_page_flip_handlers)
22                         .def("get_prop", (Property* (Card::*)(uint32_t) const)&Card::get_prop)
23                         .def("get_prop", (Property* (Card::*)(const string&) const)&Card::get_prop)
24                         ;
26         py::class_<DrmObject, DrmObject*>(m, "DrmObject")
27                         .def_property_readonly("id", &DrmObject::id)
28                         .def("refresh_props", &DrmObject::refresh_props)
29                         .def_property_readonly("prop_map", &DrmObject::get_prop_map)
30                         .def_property_readonly("card", &DrmObject::card)
31                         ;
33         py::class_<Connector, Connector*>(m, "Connector",  py::base<DrmObject>())
34                         .def_property_readonly("fullname", &Connector::fullname)
35                         .def("get_default_mode", &Connector::get_default_mode)
36                         .def("get_current_crtc", &Connector::get_current_crtc)
37                         .def("get_modes", &Connector::get_modes)
38                         .def("__repr__", [](const Connector& o) { return "<pykms.Connector " + to_string(o.id()) + ">"; })
39                         ;
41         py::class_<Crtc, Crtc*>(m, "Crtc",  py::base<DrmObject>())
42                         .def("set_mode", &Crtc::set_mode)
43                         .def("page_flip", &Crtc::page_flip)
44                         .def("set_plane", &Crtc::set_plane)
45                         .def_property_readonly("possible_planes", &Crtc::get_possible_planes)
46                         .def("__repr__", [](const Crtc& o) { return "<pykms.Crtc " + to_string(o.id()) + ">"; })
47                         ;
49         py::class_<Encoder, Encoder*>(m, "Encoder",  py::base<DrmObject>())
50                         ;
52         py::class_<Plane, Plane*>(m, "Plane",  py::base<DrmObject>())
53                         .def("supports_crtc", &Plane::supports_crtc)
54                         .def_property_readonly("plane_type", &Plane::plane_type)
55                         .def("__repr__", [](const Plane& o) { return "<pykms.Plane " + to_string(o.id()) + ">"; })
56                         ;
58         py::enum_<PlaneType>(m, "PlaneType")
59                         .value("Overlay", PlaneType::Overlay)
60                         .value("Primary", PlaneType::Primary)
61                         .value("Cursor", PlaneType::Cursor)
62                         ;
64         py::class_<Property, Property*>(m, "Property",  py::base<DrmObject>())
65                         .def_property_readonly("name", &Property::name)
66                         ;
68         py::class_<Framebuffer>(m, "Framebuffer",  py::base<DrmObject>())
69                         ;
71         py::class_<DumbFramebuffer>(m, "DumbFramebuffer",  py::base<Framebuffer>())
72                         .def(py::init<Card&, uint32_t, uint32_t, const string&>(),
73                              py::keep_alive<1, 2>())    // Keep Card alive until this is destructed
74                         .def_property_readonly("width", &DumbFramebuffer::width)
75                         .def_property_readonly("height", &DumbFramebuffer::height)
76                         ;
78         py::class_<Videomode>(m, "Videomode")
79                         .def(py::init<>())
81                         .def_readwrite("name", &Videomode::name)
83                         .def_readwrite("clock", &Videomode::clock)
85                         .def_readwrite("hdisplay", &Videomode::hdisplay)
86                         .def_readwrite("hsync_start", &Videomode::hsync_start)
87                         .def_readwrite("hsync_end", &Videomode::hsync_end)
88                         .def_readwrite("htotal", &Videomode::htotal)
90                         .def_readwrite("vdisplay", &Videomode::vdisplay)
91                         .def_readwrite("vsync_start", &Videomode::vsync_start)
92                         .def_readwrite("vsync_end", &Videomode::vsync_end)
93                         .def_readwrite("vtotal", &Videomode::vtotal)
95                         .def_readwrite("vrefresh", &Videomode::vrefresh)
97                         .def_readwrite("flags", &Videomode::flags)
98                         .def_readwrite("type", &Videomode::type)
99                         ;
101         py::class_<AtomicReq>(m, "AtomicReq")
102                         .def(py::init<Card&>(),
103                              py::keep_alive<1, 2>())    // Keep Card alive until this is destructed
104                         .def("add", (void (AtomicReq::*)(DrmObject*, const string&, uint64_t)) &AtomicReq::add)
105                         .def("test", &AtomicReq::test)
106                         .def("commit", &AtomicReq::commit)
107                         .def("commit_sync", &AtomicReq::commit_sync)
108                         ;