kmscube: fix resource leaks & freeing
[android/external-libkmsxx.git] / py / db.py
1 #!/usr/bin/python3.4
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, "FB_ID", fb.id())
37             ctx.commit(self)
38         else:
39             crtc.page_flip(fb, self)
43 card = pykms.Card()
44 conn = card.get_first_connected_connector()
45 mode = conn.get_default_mode()
46 crtc = conn.get_current_crtc()
48 fliphandler = FlipHandler()
50 crtc.set_mode(conn, fliphandler.fb1, mode)
52 fliphandler.handle_page_flip(0, 0)
54 def readdrm(conn, mask):
55     #print("EVENT");
56     card.call_page_flip_handlers()
58 def readkey(conn, mask):
59     #print("KEY EVENT");
60     sys.stdin.readline()
61     exit(0)
63 sel = selectors.DefaultSelector()
64 sel.register(card.fd(), selectors.EVENT_READ, readdrm)
65 sel.register(sys.stdin, selectors.EVENT_READ, readkey)
67 while True:
68     events = sel.select()
69     for key, mask in events:
70         callback = key.data
71         callback(key.fileobj, mask)