py: drop the fancy event handling
[android/external-libkmsxx.git] / py / tests / modeset_event.py
1 #!/usr/bin/python3
3 import pykms
4 import selectors
5 import sys
7 def readdrm(fileobj, mask):
8     for ev in card.read_events():
9         eventhandler(ev)
11 def waitevent(sel):
12     events = sel.select(1)
13     if not events:
14         print("Error: timeout receiving event")
15     else:
16         for key, mask in events:
17             key.data(key.fileobj, mask)
19 def eventhandler(event):
20     print("Received %s event successfully (seq %d time %f)" %
21           (event.type, event.seq, event.time))
23 card = pykms.Card()
24 sel = selectors.DefaultSelector()
25 sel.register(card.fd, selectors.EVENT_READ, readdrm)
27 res = pykms.ResourceManager(card)
28 conn = res.reserve_connector()
29 crtc = res.reserve_crtc(conn)
30 pplane = res.reserve_primary_plane(crtc)
32 mode = conn.get_default_mode()
33 modeb = mode.to_blob(card)
35 for format in pplane.formats:
36     if format == pykms.PixelFormat.XRGB8888:
37         break
38     if format == pykms.PixelFormat.RGB565:
39         break
41 fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, format);
42 pykms.draw_test_pattern(fb);
44 # Disable request
45 card.disable_planes()
47 print("Setting %s to %s using %s" % (conn.fullname, mode.name, format))
49 req = pykms.AtomicReq(card)
51 req.add(conn, "CRTC_ID", crtc.id)
52 req.add(crtc, {"ACTIVE": 1,
53                "MODE_ID": modeb.id})
54 req.add(pplane, {"FB_ID": fb.id,
55                  "CRTC_ID": crtc.id,
56                  "SRC_X": 0 << 16,
57                  "SRC_Y": 0 << 16,
58                  "SRC_W": mode.hdisplay << 16,
59                  "SRC_H": mode.vdisplay << 16,
60                  "CRTC_X": 0,
61                  "CRTC_Y": 0,
62                  "CRTC_W": mode.hdisplay,
63                  "CRTC_H": mode.vdisplay})
65 ret = req.test(True)
66 if ret != 0:
67     print("Atomic test failed: %d" % ret)
68     sys.exit()
70 req.commit(0, allow_modeset = True)
71 waitevent(sel)
73 input("press enter to exit\n")