xref: /aosp_15_r20/external/libkmsxx/py/tests/scale.py (revision f0687c8a10b3e371dbe09214db6664e37c283cca)
1#!/usr/bin/python3
2
3import pykms
4import time
5import random
6import argparse
7
8def plane_commit(card, crtc, plane, fb, x, y, w, h) :
9	req = pykms.AtomicReq(card)
10	req.add_plane(plane, fb, crtc, None, (x, y, w, h))
11	r = req.commit_sync()
12	assert r == 0, "Plane commit failed: %d" % r
13
14
15parser = argparse.ArgumentParser(description='Simple scaling stress test.')
16parser.add_argument('--plane', '-p', dest='plane', default="",
17		    required=False, help='plane number to use')
18parser.add_argument('--connector', '-c', dest='connector', default="",
19		    required=False, help='connector to output')
20
21args = parser.parse_args()
22
23card = pykms.Card()
24res = pykms.ResourceManager(card)
25conn = res.reserve_connector(args.connector)
26crtc = res.reserve_crtc(conn)
27format = pykms.PixelFormat.NV12
28
29if args.plane == "":
30	plane = res.reserve_generic_plane(crtc, format)
31else:
32	plane = card.planes[int(args.plane)]
33
34mode = conn.get_default_mode()
35modeb = mode.to_blob(card)
36req = pykms.AtomicReq(card)
37req.add(conn, "CRTC_ID", crtc.id)
38req.add(crtc, {"ACTIVE": 1,
39               "MODE_ID": modeb.id})
40r = req.commit_sync(allow_modeset = True)
41assert r == 0, "Initial commit failed: %d" % r
42
43# Initialize framebuffer for the scaled plane
44fbX = 1920
45fbY = 1080
46fb = pykms.DumbFramebuffer(card, fbX, fbY, format);
47pykms.draw_test_pattern(fb);
48
49# max downscale.
50# The values bellow are for DSS5. For DSS7 use 64 for both.
51max_downscale_x=5
52max_downscale_y=8
53
54# Plane's initial scaled size
55W = 640
56H = 480
57
58# Plane's initial position
59X = 0
60Y = 0
61
62# initialize increments
63Winc = 1
64Hinc = 1
65Xinc = 1
66Yinc = 1
67
68while True:
69	print("+%d+%d %dx%d" % (X, Y, W, H))
70	plane_commit(card, crtc, plane, fb, X, Y, W, H)
71	W = W + Winc
72	H = H + Hinc
73	if (Winc == 1 and W >= mode.hdisplay - X):
74		Winc = -1
75	if (Winc == -1 and W <= fbX/max_downscale_x):
76		Winc = 1
77	if (Hinc == 1 and H >= mode.vdisplay - Y):
78		Hinc = -1
79	if (Hinc == -1 and H <= fbY/max_downscale_y):
80		Hinc = 1
81	X = X + Xinc
82	Y = Y + Yinc
83	if (Xinc == 1 and X >= mode.hdisplay - W):
84		Xinc = -1
85	if (Xinc == -1 and X <= 0):
86		Xinc = 1
87	if (Yinc == 1 and Y >= mode.vdisplay - H):
88		Yinc = -1
89	if (Yinc == -1 and Y <= 0):
90		Yinc = 1
91