kmscube: fix resource leaks & freeing
[android/external-libkmsxx.git] / py / trans-test.py
1 #!/usr/bin/python3.4
3 import pykms
4 from helpers import *
5 import time
7 # This hack makes drm initialize the fbcon, setting up the default connector
8 card = pykms.Card()
9 card = 0
11 card = pykms.Card()
13 conn = card.get_first_connected_connector()
14 mode = conn.get_default_mode()
15 crtc = conn.get_current_crtc()
17 planes = []
18 for p in card.get_planes():
19     if p.supports_crtc(crtc) == False:
20         continue
21     planes.append(p)
23 disable_planes(card)
25 w = mode.hdisplay
26 h = mode.vdisplay
28 fbs=[]
30 def test_am5_trans_dest():
31     fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24"))
32     fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24"))
34     fb = fbs[0]
35     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), purple)
36     pykms.draw_rect(fb, 100, 100, 100, 200, green)
37     pykms.draw_rect(fb, 300, 100, 100, 200, red)
38     pykms.draw_rect(fb, 500, 100, 100, 200, white)
40     fb = fbs[1]
41     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), cyan)
42     pykms.draw_rect(fb, 250, 100, 200, 200, yellow)
44     set_props(crtc, {
45         "trans-key-mode": 1,
46         "trans-key": purple.rgb888(),
47         "background": 0,
48         "alpha_blender": 0,
49     })
51     plane = 0
53     for i in range(0,2):
54         print("set crtc {}, plane {}, fb {}".format(crtc.id(), planes[i].id(), fbs[i].id()))
56         plane = planes[i]
57         fb = fbs[i]
58         set_props(plane, {
59             "FB_ID": fb.id(),
60             "CRTC_ID": crtc.id(),
61             "SRC_W": fb.width() << 16,
62             "SRC_H": fb.height() << 16,
63             "CRTC_W": fb.width(),
64             "CRTC_H": fb.height(),
65             "zorder": i,
66         })
68         time.sleep(1)
70 def test_am5_trans_src():
71     fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24"))
72     fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24"))
74     fb = fbs[0]
75     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), white)
76     pykms.draw_rect(fb, 200, 200, 100, 100, red)
77     pykms.draw_rect(fb, fb.width() - 300, 200, 100, 100, green)
79     fb = fbs[1]
80     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), cyan)
81     pykms.draw_rect(fb, 100, 100, 500, 500, purple)
83     set_props(crtc, {
84         "trans-key-mode": 2,
85         "trans-key": purple.rgb888(),
86         "background": 0,
87         "alpha_blender": 0,
88     })
90     plane = 0
92     for i in range(0,2):
93         print("set crtc {}, plane {}, fb {}".format(crtc.id(), planes[i].id(), fbs[i].id()))
95         plane = planes[i]
96         fb = fbs[i]
97         set_props(plane, {
98             "FB_ID": fb.id(),
99             "CRTC_ID": crtc.id(),
100             "SRC_W": fb.width() << 16,
101             "SRC_H": fb.height() << 16,
102             "CRTC_W": fb.width(),
103             "CRTC_H": fb.height(),
104             "zorder": 3 if i == 1 else 0,
105         })
107         time.sleep(1)
109 def test_am4_normal_trans_dst():
110     fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24"))
111     fbs.append(pykms.DumbFramebuffer(card, w * 2 // 3, h, "XR24"))
112     fbs.append(pykms.DumbFramebuffer(card, w * 2 // 3, h, "XR24"))
114     fb = fbs[0]
115     pykms.draw_rect(fb, 0, 0, w, h, purple)
116     pykms.draw_rect(fb, 100, 50, 50, 200, green)
117     pykms.draw_rect(fb, 200, 50, 50, 200, red)
118     pykms.draw_rect(fb, 300, 50, 50, 200, white)
120     fb = fbs[1]
121     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), blue)
123     fb = fbs[2]
124     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), cyan)
126     set_props(crtc, {
127         "trans-key-mode": 1,
128         "trans-key": purple.rgb888(),
129         "background": 0,
130         "alpha_blender": 0,
131     })
133     time.sleep(1)
135     plane = planes[0]
136     fb = fbs[0]
137     set_props(plane, {
138         "FB_ID": fb.id(),
139         "CRTC_ID": crtc.id(),
140         "SRC_W": fb.width() << 16,
141         "SRC_H": fb.height() << 16,
142         "CRTC_W": w,
143         "CRTC_H": h,
144     })
146     time.sleep(1)
148     plane = planes[1]
149     fb = fbs[1]
150     set_props(plane, {
151         "FB_ID": fb.id(),
152         "CRTC_ID": crtc.id(),
153         "SRC_X": 0 << 16,
154         "SRC_Y": 0 << 16,
155         "SRC_W": fb.width() << 16,
156         "SRC_H": fb.height() << 16,
157         "CRTC_X": 0,
158         "CRTC_Y": 0,
159         "CRTC_W": fb.width(),
160         "CRTC_H": fb.height(),
161     })
163     time.sleep(1)
165     plane = planes[2]
166     fb = fbs[2]
167     set_props(plane, {
168         "FB_ID": fb.id(),
169         "CRTC_ID": crtc.id(),
170         "SRC_X": 0 << 16,
171         "SRC_Y": 0 << 16,
172         "SRC_W": fb.width() << 16,
173         "SRC_H": fb.height() << 16,
174         "CRTC_X": w // 3,
175         "CRTC_Y": 0,
176         "CRTC_W": fb.width(),
177         "CRTC_H": fb.height(),
178     })
180 def test_am4_normal_trans_src():
181     fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24"))
182     fbs.append(pykms.DumbFramebuffer(card, w // 2, h, "XR24"))
183     fbs.append(pykms.DumbFramebuffer(card, w // 2, h, "XR24"))
185     fb = fbs[0]
186     pykms.draw_rect(fb, 0, 0, w, h, pykms.RGB(128, 255, 255))
187     pykms.draw_rect(fb, 200, 100, 50, 200, red)
188     pykms.draw_rect(fb, w - 200 - 50, 100, 50, 200, green)
190     fb = fbs[1]
191     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), blue)
192     pykms.draw_rect(fb, 100, 100, fb.width() - 200, fb.height() - 200, purple)
194     fb = fbs[2]
195     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), cyan)
196     pykms.draw_rect(fb, 100, 100, fb.width() - 200, fb.height() - 200, purple)
198     set_props(crtc, {
199         "trans-key-mode": 2,
200         "trans-key": purple.rgb888(),
201         "background": 0,
202         "alpha_blender": 0,
203     })
205     time.sleep(1)
207     plane = planes[0]
208     fb = fbs[0]
209     set_props(plane, {
210         "FB_ID": fb.id(),
211         "CRTC_ID": crtc.id(),
212         "SRC_W": fb.width() << 16,
213         "SRC_H": fb.height() << 16,
214         "CRTC_W": w,
215         "CRTC_H": h,
216     })
218     time.sleep(1)
220     plane = planes[1]
221     fb = fbs[1]
222     set_props(plane, {
223         "FB_ID": fb.id(),
224         "CRTC_ID": crtc.id(),
225         "SRC_X": 0 << 16,
226         "SRC_Y": 0 << 16,
227         "SRC_W": fb.width() << 16,
228         "SRC_H": fb.height() << 16,
229         "CRTC_X": 0,
230         "CRTC_Y": 0,
231         "CRTC_W": fb.width(),
232         "CRTC_H": fb.height(),
233     })
235     time.sleep(1)
237     plane = planes[2]
238     fb = fbs[2]
239     set_props(plane, {
240         "FB_ID": fb.id(),
241         "CRTC_ID": crtc.id(),
242         "SRC_X": 0 << 16,
243         "SRC_Y": 0 << 16,
244         "SRC_W": fb.width() << 16,
245         "SRC_H": fb.height() << 16,
246         "CRTC_X": w - fb.width(),
247         "CRTC_Y": 0,
248         "CRTC_W": fb.width(),
249         "CRTC_H": fb.height(),
250     })
252 def test_am4_alpha_trans_src():
253     fbs.append(pykms.DumbFramebuffer(card, w, h, "XR24"))
254     fbs.append(pykms.DumbFramebuffer(card, w // 2, h, "XR24"))
255     fbs.append(pykms.DumbFramebuffer(card, w // 2, h, "XR24"))
257     fb = fbs[0]
258     pykms.draw_rect(fb, 0, 0, w, h, purple)
259     pykms.draw_rect(fb, 200, 100, 50, 200, red)
260     pykms.draw_rect(fb, w - 200 - 50, 100, 50, 200, green)
262     fb = fbs[1]
263     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), blue)
264     pykms.draw_rect(fb, 100, 100, fb.width() - 200, fb.height() - 200, purple)
266     fb = fbs[2]
267     pykms.draw_rect(fb, 0, 0, fb.width(), fb.height(), cyan)
268     pykms.draw_rect(fb, 100, 100, fb.width() - 200, fb.height() - 200, purple)
270     set_props(crtc, {
271         "trans-key-mode": 1,
272         "trans-key": purple.rgb888(),
273         "background": 0,
274         "alpha_blender": 1,
275     })
277     time.sleep(1)
279     plane = planes[0]
280     fb = fbs[0]
281     set_props(plane, {
282         "FB_ID": fb.id(),
283         "CRTC_ID": crtc.id(),
284         "SRC_W": fb.width() << 16,
285         "SRC_H": fb.height() << 16,
286         "CRTC_W": w,
287         "CRTC_H": h,
288     })
290     time.sleep(1)
292     plane = planes[1]
293     fb = fbs[1]
294     set_props(plane, {
295         "FB_ID": fb.id(),
296         "CRTC_ID": crtc.id(),
297         "SRC_X": 0 << 16,
298         "SRC_Y": 0 << 16,
299         "SRC_W": fb.width() << 16,
300         "SRC_H": fb.height() << 16,
301         "CRTC_X": 0,
302         "CRTC_Y": 0,
303         "CRTC_W": fb.width(),
304         "CRTC_H": fb.height(),
305     })
307     time.sleep(1)
309     plane = planes[2]
310     fb = fbs[2]
311     set_props(plane, {
312         "FB_ID": fb.id(),
313         "CRTC_ID": crtc.id(),
314         "SRC_X": 0 << 16,
315         "SRC_Y": 0 << 16,
316         "SRC_W": fb.width() << 16,
317         "SRC_H": fb.height() << 16,
318         "CRTC_X": w - fb.width(),
319         "CRTC_Y": 0,
320         "CRTC_W": fb.width(),
321         "CRTC_H": fb.height(),
322     })
326 #test_am5_trans_dest()
327 test_am5_trans_src()
328 #test_am4_normal_trans_dst()
329 #test_am4_normal_trans_src()
330 #test_am4_alpha_trans_src()
332 input("press enter to exit\n")