py: add db test
authorTomi Valkeinen <tomi.valkeinen@iki.fi>
Sat, 3 Oct 2015 18:14:55 +0000 (21:14 +0300)
committerTomi Valkeinen <tomi.valkeinen@iki.fi>
Sat, 3 Oct 2015 19:42:03 +0000 (22:42 +0300)
py/CMakeLists.txt
py/db.py [new file with mode: 0755]
py/pykms.i

index 8ad476b2ce9be54dcc1629a00543e2043a418326..42dae209f06f7fe2cdaed6a7480ca3659672e72d 100644 (file)
@@ -17,7 +17,7 @@ set_source_files_properties(pykms.i PROPERTIES CPLUSPLUS ON)
 swig_add_module(pykms python pykms.i)
 swig_link_libraries(pykms kms++ kmstest ${LIBDRM_LIBRARIES} ${PYTHON_LIBRARIES})
 
-add_custom_target(pyextras SOURCES test.py functest.py)
+add_custom_target(pyextras SOURCES test.py functest.py db.py)
 
 add_test(NAME pytest COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/functest.py")
 set_property(TEST pytest PROPERTY
diff --git a/py/db.py b/py/db.py
new file mode 100755 (executable)
index 0000000..fbc1998
--- /dev/null
+++ b/py/db.py
@@ -0,0 +1,71 @@
+#!/usr/bin/python3.4
+
+import sys
+import pykms
+import selectors
+
+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, "FB_ID", fb.id())
+            ctx.commit(self)
+        else:
+            crtc.page_flip(fb, self)
+
+
+
+card = pykms.Card()
+conn = card.get_first_connected_connector()
+mode = conn.get_default_mode()
+crtc = conn.get_current_crtc()
+
+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)
index 1dcd0ca0339f9a101b99482e1ada61e98bde2419..6d8de675e00f62ed346ec40f3219c54d8ab3a504 100644 (file)
@@ -1,4 +1,4 @@
-%module pykms
+%module(directors="1") pykms
 %{
 #include "kms++.h"
 
@@ -10,6 +10,8 @@ using namespace kms;
 %include "std_string.i"
 %include "stdint.i"
 
+%feature("director") PageFlipHandlerBase;
+
 %include "decls.h"
 %include "drmobject.h"
 %include "atomicreq.h"
@@ -21,5 +23,6 @@ using namespace kms;
 %include "plane.h"
 %include "connector.h"
 %include "encoder.h"
+%include "pagefliphandler.h"
 
 %include "kmstest.h"