• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3
2
3import pykms
4import selectors
5import sys
6
7def readdrm(fileobj, mask):
8    for ev in card.read_events():
9        eventhandler(ev)
10
11def 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)
18
19def eventhandler(event):
20    print("Received %s event successfully (seq %d time %f)" %
21          (event.type, event.seq, event.time))
22
23card = pykms.Card()
24sel = selectors.DefaultSelector()
25sel.register(card.fd, selectors.EVENT_READ, readdrm)
26
27res = pykms.ResourceManager(card)
28conn = res.reserve_connector()
29crtc = res.reserve_crtc(conn)
30pplane = res.reserve_primary_plane(crtc)
31
32mode = conn.get_default_mode()
33modeb = mode.to_blob(card)
34
35for format in pplane.formats:
36    if format == pykms.PixelFormat.XRGB8888:
37        break
38    if format == pykms.PixelFormat.RGB565:
39        break
40
41fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, format);
42pykms.draw_test_pattern(fb);
43
44# Disable request
45card.disable_planes()
46
47print("Setting %s to %s using %s" % (conn.fullname, mode.name, format))
48
49req = pykms.AtomicReq(card)
50
51req.add(conn, "CRTC_ID", crtc.id)
52req.add(crtc, {"ACTIVE": 1,
53               "MODE_ID": modeb.id})
54req.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})
64
65ret = req.test(True)
66if ret != 0:
67    print("Atomic test failed: %d" % ret)
68    sys.exit()
69
70req.commit(0, allow_modeset = True)
71waitevent(sel)
72
73input("press enter to exit\n")
74