Fix the rest of the py scripts
[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_property_readonly("primary_plane", &Crtc::get_primary_plane)
47                         .def("__repr__", [](const Crtc& o) { return "<pykms.Crtc " + to_string(o.id()) + ">"; })
48                         ;
50         py::class_<Encoder, Encoder*>(m, "Encoder",  py::base<DrmObject>())
51                         ;
53         py::class_<Plane, Plane*>(m, "Plane",  py::base<DrmObject>())
54                         .def("supports_crtc", &Plane::supports_crtc)
55                         .def_property_readonly("plane_type", &Plane::plane_type)
56                         .def("__repr__", [](const Plane& o) { return "<pykms.Plane " + to_string(o.id()) + ">"; })
57                         ;
59         py::enum_<PlaneType>(m, "PlaneType")
60                         .value("Overlay", PlaneType::Overlay)
61                         .value("Primary", PlaneType::Primary)
62                         .value("Cursor", PlaneType::Cursor)
63                         ;
65         py::class_<Property, Property*>(m, "Property",  py::base<DrmObject>())
66                         .def_property_readonly("name", &Property::name)
67                         ;
69         py::class_<Framebuffer>(m, "Framebuffer",  py::base<DrmObject>())
70                         ;
72         py::class_<DumbFramebuffer>(m, "DumbFramebuffer",  py::base<Framebuffer>())
73                         .def(py::init<Card&, uint32_t, uint32_t, const string&>(),
74                              py::keep_alive<1, 2>())    // Keep Card alive until this is destructed
75                         .def_property_readonly("width", &DumbFramebuffer::width)
76                         .def_property_readonly("height", &DumbFramebuffer::height)
77                         ;
79         py::class_<Videomode>(m, "Videomode")
80                         .def(py::init<>())
82                         .def_readwrite("name", &Videomode::name)
84                         .def_readwrite("clock", &Videomode::clock)
86                         .def_readwrite("hdisplay", &Videomode::hdisplay)
87                         .def_readwrite("hsync_start", &Videomode::hsync_start)
88                         .def_readwrite("hsync_end", &Videomode::hsync_end)
89                         .def_readwrite("htotal", &Videomode::htotal)
91                         .def_readwrite("vdisplay", &Videomode::vdisplay)
92                         .def_readwrite("vsync_start", &Videomode::vsync_start)
93                         .def_readwrite("vsync_end", &Videomode::vsync_end)
94                         .def_readwrite("vtotal", &Videomode::vtotal)
96                         .def_readwrite("vrefresh", &Videomode::vrefresh)
98                         .def_readwrite("flags", &Videomode::flags)
99                         .def_readwrite("type", &Videomode::type)
100                         ;
102         py::class_<AtomicReq>(m, "AtomicReq")
103                         .def(py::init<Card&>(),
104                              py::keep_alive<1, 2>())    // Keep Card alive until this is destructed
105                         .def("add", (void (AtomicReq::*)(DrmObject*, const string&, uint64_t)) &AtomicReq::add)
106                         .def("test", &AtomicReq::test)
107                         .def("commit", &AtomicReq::commit)
108                         .def("commit_sync", &AtomicReq::commit_sync)
109                         ;