summaryrefslogtreecommitdiff
path: root/py/tests/plane_hog.py
blob: 906c7586217de5704112e83fd6ebcb4243e1536d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/python3

import pykms
import sys

card = pykms.Card()
res = pykms.ResourceManager(card)

conn1 = False
conn2 = False

for conn in card.connectors:
     if not conn1:
          conn1 = conn
     elif not conn2:
          conn2 = conn
     else:
          break

crtc1 = res.reserve_crtc(conn1)
mode1 = conn1.get_default_mode()
modeb1 = mode1.to_blob(card)
print("CRTC idx %d goes to %s connector" % (crtc1.idx, conn1.fullname))

if conn2:
     crtc2 = res.reserve_crtc(conn2)
     mode2 = conn2.get_default_mode()
     modeb2 = mode2.to_blob(card)
     print("CRTC idx %d goes to %s connector" % (crtc2.idx, conn2.fullname))

fbwidth = 480
fbheight = 270

fb = pykms.DumbFramebuffer(card, fbwidth, fbheight, "AR24");
pykms.draw_test_pattern(fb);

# Disable request
card.disable_planes()

plane_list = []

while True:
     plane = res.reserve_generic_plane(crtc1)
     if plane:
         print("Got plane idx %d" % plane.idx)
         plane_list.append(plane)
     else:
         break

print("Got %d planes" % len(plane_list))

req = pykms.AtomicReq(card)
req.add(conn1, "CRTC_ID", crtc1.id)
req.add(crtc1, {"ACTIVE": 1,
               "MODE_ID": modeb1.id})

input("Press enter to enable crtc idx %d at %s" % (crtc1.idx, conn1.fullname))
r = req.commit_sync(allow_modeset = True)

print("Crtc enable request returned %d\n" % r)

x = 0
y = 0
z = 0

for plane in plane_list:
    input("Press enter to enable plane idx %d on crtc idx %d" %
          (plane.idx, crtc1.idx))
    req = pykms.AtomicReq(card)
    req.add(plane, {"FB_ID": fb.id,
                     "CRTC_ID": crtc1.id,
                     "SRC_X": 0 << 16,
                     "SRC_Y": 0 << 16,
                     "SRC_W": fb.width << 16,
                     "SRC_H": fb.height << 16,
                     "CRTC_X": x,
                     "CRTC_Y": y,
                     "CRTC_W": fb.width,
                     "CRTC_H": fb.height,
                     "zpos": z})
    r = req.commit_sync()
    print("Plane enable request returned %d\n" % r)

    x = x + 50
    y = y + 50
    z = z + 1

if not conn2:
     sys.exit()

req = pykms.AtomicReq(card)
req.add(conn2, "CRTC_ID", crtc2.id)
req.add(crtc2, {"ACTIVE": 1,
                "MODE_ID": modeb2.id})

input("Press enter to enable crtc idx %d at %s" % (crtc2.idx, conn2.fullname))
r = req.commit_sync(allow_modeset = True)
print("Crtc enable request returned %d\n" % r)

x = 0
y = 0
z = 0

# Code assumes that planes for crtc1 also work for crtc2
for plane in reversed(plane_list):

    input("Press enter to disable plane idx %d on crtc idx %d" %
          (plane.idx, crtc1.idx))
    req = pykms.AtomicReq(card)
    req.add(plane, {"FB_ID": 0,
                    "CRTC_ID": 0})
    r = req.commit_sync(allow_modeset = True)
    print("Plane disable request returned %d\n" % r)

    input("Press enter to enable plane idx %d on crtc idx %d" %
          (plane.idx, crtc2.idx))
    req = pykms.AtomicReq(card)
    req.add(plane, {"FB_ID": fb.id,
                    "CRTC_ID": crtc2.id,
                    "SRC_X": 0 << 16,
                    "SRC_Y": 0 << 16,
                    "SRC_W": fb.width << 16,
                    "SRC_H": fb.height << 16,
                    "CRTC_X": x,
                    "CRTC_Y": y,
                    "CRTC_W": fb.width,
                    "CRTC_H": fb.height,
                    "zpos": z})
    r = req.commit_sync(allow_modeset = True)
    print("Plane enable request returned %d\n" % r)

    x = x + 50
    y = y + 50
    z = z + 1

input("press enter to exit\n")