From b11baff09f78a4a383f817ec35208ae8966ab832 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 2 Jan 2017 16:42:08 +0200 Subject: py: Reorganize source directory Separate the Python bindings sources from the test scripts. While at it, remove the unneeded run.sh script. Signed-off-by: Laurent Pinchart --- py/tests/db.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 py/tests/db.py (limited to 'py/tests/db.py') diff --git a/py/tests/db.py b/py/tests/db.py new file mode 100755 index 0000000..3ffb716 --- /dev/null +++ b/py/tests/db.py @@ -0,0 +1,72 @@ +#!/usr/bin/python3 + +import sys +import pykms +import selectors +from helpers import * + +bar_width = 20 +bar_speed = 8 + +class FlipHandler(pykms.PageFlipHandlerBase): + def __init__(self): + super().__init__() + self.bar_xpos = 0 + self.front_buf = 0 + self.fb1 = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24"); + self.fb2 = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24"); + + def handle_page_flip(self, frame, time): + if self.front_buf == 0: + fb = self.fb2 + else: + fb = self.fb1 + + self.front_buf = self.front_buf ^ 1 + + current_xpos = self.bar_xpos; + old_xpos = (current_xpos + (fb.width - bar_width - bar_speed)) % (fb.width - bar_width); + new_xpos = (current_xpos + bar_speed) % (fb.width - bar_width); + + self.bar_xpos = new_xpos + + pykms.draw_color_bar(fb, old_xpos, new_xpos, bar_width) + + if card.has_atomic: + ctx = pykms.AtomicReq(card) + ctx.add(crtc.primary_plane, "FB_ID", fb.id) + ctx.commit(self) + else: + crtc.page_flip(fb, self) + + +card = pykms.Card() +res = pykms.ResourceManager(card) +conn = res.reserve_connector() +crtc = res.reserve_crtc(conn) +mode = conn.get_default_mode() + +fliphandler = FlipHandler() + +crtc.set_mode(conn, fliphandler.fb1, mode) + +fliphandler.handle_page_flip(0, 0) + +def readdrm(conn, mask): + #print("EVENT"); + card.call_page_flip_handlers() + +def readkey(conn, mask): + #print("KEY EVENT"); + sys.stdin.readline() + exit(0) + +sel = selectors.DefaultSelector() +sel.register(card.fd, selectors.EVENT_READ, readdrm) +sel.register(sys.stdin, selectors.EVENT_READ, readkey) + +while True: + events = sel.select() + for key, mask in events: + callback = key.data + callback(key.fileobj, mask) -- cgit v1.2.3