1#!/usr/bin/python3 2 3import pykms 4import random 5import time 6import sys 7import select 8import selectors 9 10if len(sys.argv) != 3: 11 print('Usage: plane_move.py <connector0> <connector1>') 12 sys.exit() 13 14card = pykms.Card() 15 16if not card.has_atomic: 17 print('Atomic modesetting is not supported') 18 sys.exit(-1) 19 20res = pykms.ResourceManager(card) 21 22conn_list = [] 23crtc_list = [] 24mode_list = [] 25rootplane_list = [] 26fb_list = [] 27colors = [] 28 29src_w = 300 30src_h = 300 31 32for i in range(2): 33 conn = res.reserve_connector(sys.argv[i + 1]) 34 if conn is None: 35 print('Invalid connector: {}'.format(sys.argv[i + 1])) 36 sys.exit(-1) 37 38 if conn.connected() == True: 39 conn_list.append(conn) 40 else: 41 print('connector: {} is not connected'.format(sys.argv[i + 1])) 42 sys.exit(-1) 43 44 crtc = res.reserve_crtc(conn) 45 crtc_list.append(crtc) 46 47 mode = conn.get_default_mode() 48 mode_list.append(mode) 49 50 fb_tmp = pykms.DumbFramebuffer(card, src_w, src_h, 'XR24'); 51 fb_list.append(fb_tmp) 52 53 rootplane = res.reserve_primary_plane(crtc, pykms.PixelFormat.XRGB8888) 54 rootplane_list.append(rootplane) 55 56card.disable_planes() 57 58print('Using the following connectors:') 59for i in range(2): 60 print(' {}: {} ({}x{})'.format(conn_list[i].idx, conn_list[i].fullname, 61 mode_list[i].hdisplay, mode_list[i].vdisplay)) 62 63colors.append(pykms.red) 64colors.append(pykms.green) 65 66for i in range(2): 67 pykms.draw_rect(fb_list[i], 0, 0, src_w, src_h, colors[i]) 68 69for i in range(2): 70 req = pykms.AtomicReq(card) 71 modeb = mode_list[i].to_blob(card) 72 req.add(conn_list[i], 'CRTC_ID', crtc_list[i].id) 73 req.add(crtc_list[i], {'ACTIVE': 1, 74 'MODE_ID': modeb.id}) 75 req.add(rootplane_list[i], {'FB_ID': fb_list[i].id, 76 'CRTC_ID': crtc_list[i].id, 77 'SRC_W': src_w << 16, 78 'SRC_H': src_h << 16, 79 'CRTC_W': src_w, 80 'CRTC_H': src_h}) 81 82 req.commit_sync(allow_modeset = True) 83 84print('\nRed box on {}, Green box on {}.'.format(conn_list[0].fullname, 85 conn_list[1].fullname)) 86input('ENTER to continue\n') 87 88# FIXME: it should be possible to move plane without disabling it, but the 89# omapdrm driver does not supports it at the moment. 90req = pykms.AtomicReq(card) 91req.add(rootplane_list[0], {"FB_ID": 0, 92 "CRTC_ID": 0}) 93req.commit_sync(allow_modeset = True) 94 95req = pykms.AtomicReq(card) 96req.add(rootplane_list[0], {'FB_ID': fb_list[0].id, 97 'CRTC_ID': crtc_list[1].id, 98 'SRC_W': src_w << 16, 99 'SRC_H': src_h << 16, 100 'CRTC_X': 150, 101 'CRTC_Y': 150, 102 'CRTC_W': src_w, 103 'CRTC_H': src_h}) 104req.commit_sync(allow_modeset = True) 105 106print('The red box from {} is moved underneath the green box on {}.'.format( 107 conn_list[0].fullname, conn_list[1].fullname)) 108input('ENTER to continue\n') 109 110# FIXME: it should be possible to move plane without disabling it, but the 111# omapdrm driver does not supports it at the moment. 112req = pykms.AtomicReq(card) 113req.add(rootplane_list[1], {"FB_ID": 0, 114 "CRTC_ID": 0}) 115req.commit_sync(allow_modeset = True) 116 117req = pykms.AtomicReq(card) 118req.add(rootplane_list[1], {'FB_ID': fb_list[1].id, 119 'CRTC_ID': crtc_list[0].id, 120 'SRC_W': src_w << 16, 121 'SRC_H': src_h << 16, 122 'CRTC_W': src_w, 123 'CRTC_H': src_h}) 124req.commit_sync(allow_modeset = True) 125 126print('Green box on {}, Red box on {}.'.format(conn_list[0].fullname, 127 conn_list[1].fullname)) 128input('ENTER to exit\n') 129