• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3
2
3import pykms
4import sys
5
6card = pykms.Card()
7res = pykms.ResourceManager(card)
8
9conn1 = False
10conn2 = False
11
12for conn in card.connectors:
13     if not conn1:
14          conn1 = conn
15     elif not conn2:
16          conn2 = conn
17     else:
18          break
19
20crtc1 = res.reserve_crtc(conn1)
21mode1 = conn1.get_default_mode()
22modeb1 = mode1.to_blob(card)
23print("CRTC idx %d goes to %s connector" % (crtc1.idx, conn1.fullname))
24
25if conn2:
26     crtc2 = res.reserve_crtc(conn2)
27     mode2 = conn2.get_default_mode()
28     modeb2 = mode2.to_blob(card)
29     print("CRTC idx %d goes to %s connector" % (crtc2.idx, conn2.fullname))
30
31fbwidth = 480
32fbheight = 270
33
34fb = pykms.DumbFramebuffer(card, fbwidth, fbheight, "AR24");
35pykms.draw_test_pattern(fb);
36
37# Disable request
38card.disable_planes()
39
40plane_list = []
41
42while True:
43     plane = res.reserve_generic_plane(crtc1)
44     if plane:
45         print("Got plane idx %d" % plane.idx)
46         plane_list.append(plane)
47     else:
48         break
49
50print("Got %d planes" % len(plane_list))
51
52req = pykms.AtomicReq(card)
53req.add(conn1, "CRTC_ID", crtc1.id)
54req.add(crtc1, {"ACTIVE": 1,
55               "MODE_ID": modeb1.id})
56
57input("Press enter to enable crtc idx %d at %s" % (crtc1.idx, conn1.fullname))
58r = req.commit_sync(allow_modeset = True)
59
60print("Crtc enable request returned %d\n" % r)
61
62x = 0
63y = 0
64z = 0
65
66for plane in plane_list:
67    input("Press enter to enable plane idx %d on crtc idx %d" %
68          (plane.idx, crtc1.idx))
69    req = pykms.AtomicReq(card)
70    req.add(plane, {"FB_ID": fb.id,
71                     "CRTC_ID": crtc1.id,
72                     "SRC_X": 0 << 16,
73                     "SRC_Y": 0 << 16,
74                     "SRC_W": fb.width << 16,
75                     "SRC_H": fb.height << 16,
76                     "CRTC_X": x,
77                     "CRTC_Y": y,
78                     "CRTC_W": fb.width,
79                     "CRTC_H": fb.height,
80                     "zpos": z})
81    r = req.commit_sync()
82    print("Plane enable request returned %d\n" % r)
83
84    x = x + 50
85    y = y + 50
86    z = z + 1
87
88if not conn2:
89     sys.exit()
90
91req = pykms.AtomicReq(card)
92req.add(conn2, "CRTC_ID", crtc2.id)
93req.add(crtc2, {"ACTIVE": 1,
94                "MODE_ID": modeb2.id})
95
96input("Press enter to enable crtc idx %d at %s" % (crtc2.idx, conn2.fullname))
97r = req.commit_sync(allow_modeset = True)
98print("Crtc enable request returned %d\n" % r)
99
100x = 0
101y = 0
102z = 0
103
104# Code assumes that planes for crtc1 also work for crtc2
105for plane in reversed(plane_list):
106
107    input("Press enter to disable plane idx %d on crtc idx %d" %
108          (plane.idx, crtc1.idx))
109    req = pykms.AtomicReq(card)
110    req.add(plane, {"FB_ID": 0,
111                    "CRTC_ID": 0})
112    r = req.commit_sync(allow_modeset = True)
113    print("Plane disable request returned %d\n" % r)
114
115    input("Press enter to enable plane idx %d on crtc idx %d" %
116          (plane.idx, crtc2.idx))
117    req = pykms.AtomicReq(card)
118    req.add(plane, {"FB_ID": fb.id,
119                    "CRTC_ID": crtc2.id,
120                    "SRC_X": 0 << 16,
121                    "SRC_Y": 0 << 16,
122                    "SRC_W": fb.width << 16,
123                    "SRC_H": fb.height << 16,
124                    "CRTC_X": x,
125                    "CRTC_Y": y,
126                    "CRTC_W": fb.width,
127                    "CRTC_H": fb.height,
128                    "zpos": z})
129    r = req.commit_sync(allow_modeset = True)
130    print("Plane enable request returned %d\n" % r)
131
132    x = x + 50
133    y = y + 50
134    z = z + 1
135
136input("press enter to exit\n")
137