Fix the rest of the py scripts
[android/external-libkmsxx.git] / py / db.py
1 #!/usr/bin/python3
3 import sys
4 import pykms
5 import selectors
7 bar_width = 20
8 bar_speed = 8
10 class FlipHandler(pykms.PageFlipHandlerBase):
11     def __init__(self):
12         super().__init__()
13         self.bar_xpos = 0
14         self.front_buf = 0
15         self.fb1 = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
16         self.fb2 = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
18     def handle_page_flip(self, frame, time):
19         if self.front_buf == 0:
20             fb = self.fb2
21         else:
22             fb = self.fb1
24         self.front_buf = self.front_buf ^ 1
26         current_xpos = self.bar_xpos;
27         old_xpos = (current_xpos + (fb.width - bar_width - bar_speed)) % (fb.width - bar_width);
28         new_xpos = (current_xpos + bar_speed) % (fb.width - bar_width);
30         self.bar_xpos = new_xpos
32         pykms.draw_color_bar(fb, old_xpos, new_xpos, bar_width)
34         if card.has_atomic:
35             ctx = pykms.AtomicReq(card)
36             ctx.add(crtc.primary_plane, "FB_ID", fb.id)
37             ctx.commit(self)
38         else:
39             crtc.page_flip(fb, self)
42 card = pykms.Card()
43 conn = card.get_first_connected_connector()
44 mode = conn.get_default_mode()
45 crtc = conn.get_current_crtc()
47 fliphandler = FlipHandler()
49 crtc.set_mode(conn, fliphandler.fb1, mode)
51 fliphandler.handle_page_flip(0, 0)
53 def readdrm(conn, mask):
54     #print("EVENT");
55     card.call_page_flip_handlers()
57 def readkey(conn, mask):
58     #print("KEY EVENT");
59     sys.stdin.readline()
60     exit(0)
62 sel = selectors.DefaultSelector()
63 sel.register(card.fd, selectors.EVENT_READ, readdrm)
64 sel.register(sys.stdin, selectors.EVENT_READ, readkey)
66 while True:
67     events = sel.select()
68     for key, mask in events:
69         callback = key.data
70         callback(key.fileobj, mask)