xref: /aosp_15_r20/external/libkmsxx/py/tests/ctm_test.py (revision f0687c8a10b3e371dbe09214db6664e37c283cca)
1#!/usr/bin/python3
2
3import sys
4import pykms
5import argparse
6
7def ctm_to_blob(ctm, card):
8    len=9
9    arr = bytearray(len*8)
10    view = memoryview(arr).cast("I")
11
12    for x in range(len):
13        i, d = divmod(ctm[x], 1)
14        if i < 0:
15            i = -i
16            sign = 1 << 31
17        else:
18            sign = 0
19        view[x * 2 + 0] = int(d * ((2 ** 32) - 1))
20        view[x * 2 + 1] = int(i) | sign
21        #print("%f = %08x.%08x" % (ctm[x], view[x * 2 + 1], view[x * 2 + 0]))
22
23    return pykms.Blob(card, arr);
24
25
26parser = argparse.ArgumentParser(description='Simple CRTC CTM-property test.')
27parser.add_argument('--connector', '-c', dest='connector',
28		    required=False, help='connector to output')
29parser.add_argument('--mode', '-m', dest='modename',
30		    required=False, help='Video mode name to use')
31parser.add_argument('--plane', '-p', dest='plane', type=int,
32		    required=False, help='plane number to use')
33args = parser.parse_args()
34
35card = pykms.Card()
36res = pykms.ResourceManager(card)
37conn = res.reserve_connector(args.connector)
38crtc = res.reserve_crtc(conn)
39format = pykms.PixelFormat.ARGB8888
40if args.modename == None:
41    mode = conn.get_default_mode()
42else:
43    mode = conn.get_mode(args.modename)
44modeb = mode.to_blob(card)
45
46fb = pykms.DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
47pykms.draw_test_pattern(fb);
48
49if args.plane == None:
50	plane = res.reserve_generic_plane(crtc, fb.format)
51else:
52	plane = card.planes[args.plane]
53
54card.disable_planes()
55crtc.disable_mode()
56
57input("press enter to set ctm at the same time with crtc mode\n")
58
59ctm = [ 0.0,	1.0,	0.0,
60        0.0,	0.0,	1.0,
61        1.0,	0.0,	0.0 ]
62
63ctmb = ctm_to_blob(ctm, card)
64
65req = pykms.AtomicReq(card)
66req.add(conn, "CRTC_ID", crtc.id)
67req.add(crtc, {"ACTIVE": 1,
68               "MODE_ID": modeb.id,
69               "CTM": ctmb.id})
70req.add_plane(plane, fb, crtc)
71r = req.commit_sync(allow_modeset = True)
72assert r == 0, "Initial commit failed: %d" % r
73
74print("r->b g->r b->g ctm active\n")
75
76input("press enter to set normal ctm\n")
77
78ctm = [ 1.0,	0.0,	0.0,
79        0.0,	1.0,	0.0,
80        0.0,	0.0,	1.0 ]
81
82ctmb = ctm_to_blob(ctm, card)
83
84crtc.set_prop("CTM", ctmb.id)
85
86input("press enter to set new ctm\n")
87
88ctm = [ 0.0,	0.0,	1.0,
89        1.0,	0.0,	0.0,
90        0.0,	1.0,	0.0 ]
91
92ctmb = ctm_to_blob(ctm, card)
93
94crtc.set_prop("CTM", ctmb.id)
95input("r->g g->b b->r ctm active\n")
96
97input("press enter to turn off the crtc\n")
98
99crtc.disable_mode()
100
101input("press enter to enable crtc again\n")
102
103crtc.set_mode(conn, fb, mode)
104
105input("press enter to remove ctm\n")
106
107crtc.set_prop("CTM", 0)
108
109input("press enter to exit\n")
110