aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Valkeinen2017-05-18 02:39:39 -0500
committerTomi Valkeinen2017-05-24 05:23:26 -0500
commita53d19fccc8656f5190385e028261e4bcff84531 (patch)
treec90bdb9c734667a9924752679d5826e4b2f29f55
parent513766368980cda9adc613f690550cc42dfc85c0 (diff)
downloadexternal-kmsxx-a53d19fccc8656f5190385e028261e4bcff84531.tar.gz
external-kmsxx-a53d19fccc8656f5190385e028261e4bcff84531.tar.xz
external-kmsxx-a53d19fccc8656f5190385e028261e4bcff84531.zip
py: add rottest.py
Add a test tool for rotation Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
-rwxr-xr-xpy/tests/rottest.py182
1 files changed, 182 insertions, 0 deletions
diff --git a/py/tests/rottest.py b/py/tests/rottest.py
new file mode 100755
index 0000000..4dae95e
--- /dev/null
+++ b/py/tests/rottest.py
@@ -0,0 +1,182 @@
1#!/usr/bin/python3
2
3import pykms
4from enum import Enum
5
6import termios, sys, os, tty
7
8card = pykms.OmapCard()
9
10res = pykms.ResourceManager(card)
11conn = res.reserve_connector()
12crtc = res.reserve_crtc(conn)
13mode = conn.get_default_mode()
14modeb = mode.to_blob(card)
15rootplane = res.reserve_primary_plane(crtc, pykms.PixelFormat.XRGB8888)
16plane = res.reserve_overlay_plane(crtc, pykms.PixelFormat.NV12)
17
18card.disable_planes()
19
20req = pykms.AtomicReq(card)
21
22req.add(conn, "CRTC_ID", crtc.id)
23
24req.add(crtc, {"ACTIVE": 1,
25 "MODE_ID": modeb.id})
26
27# This enables the root plane
28
29#rootfb = pykms.OmapFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
30#pykms.draw_test_pattern(rootfb);
31#
32#req.add(rootplane, {"FB_ID": rootfb.id,
33# "CRTC_ID": crtc.id,
34# "SRC_X": 0 << 16,
35# "SRC_Y": 0 << 16,
36# "SRC_W": mode.hdisplay << 16,
37# "SRC_H": mode.vdisplay << 16,
38# "CRTC_X": 0,
39# "CRTC_Y": 0,
40# "CRTC_W": mode.hdisplay,
41# "CRTC_H": mode.vdisplay,
42# "zorder": 0})
43
44req.commit_sync(allow_modeset = True)
45
46class Rotation(int, Enum):
47 ROTATE_0 = 1 << 0
48 ROTATE_90 = 1 << 1
49 ROTATE_180 = 1 << 2
50 ROTATE_270 = 1 << 3
51 ROTATE_MASK = ROTATE_0 | ROTATE_90 | ROTATE_180 | ROTATE_270
52 REFLECT_X = 1 << 4
53 REFLECT_Y = 1 << 5
54 REFLECT_MASK = REFLECT_X | REFLECT_Y
55
56
57def show_rot_plane(crtc, plane, fb, rot, x_scale, y_scale):
58
59 crtc_w = int(fb_w * x_scale)
60 crtc_h = int(fb_h * y_scale)
61
62 if (rot & Rotation.ROTATE_90) or (rot & Rotation.ROTATE_270):
63 tmp = crtc_w
64 crtc_w = crtc_h
65 crtc_h = tmp
66
67 crtc_x = int(mode.hdisplay / 2 - crtc_w / 2)
68 crtc_y = int(mode.vdisplay / 2 - crtc_h / 2)
69
70 req = pykms.AtomicReq(card)
71
72 src_x = 0
73 src_y = 0
74 src_w = fb_w - src_x
75 src_h = fb_h - src_y
76
77 print("SRC {},{}-{}x{} DST {},{}-{}x{}".format(
78 src_x, src_y, src_w, src_h,
79 crtc_x, crtc_y, crtc_w, crtc_h))
80
81 angle_str = Rotation(rot & Rotation.ROTATE_MASK).name
82 reflect_x_str = "REFLECT_X" if rot & Rotation.REFLECT_X else ""
83 reflect_y_str = "REFLECT_Y" if rot & Rotation.REFLECT_Y else ""
84
85 print("{} {} {}".format(angle_str, reflect_x_str, reflect_y_str))
86
87 sys.stdout.flush()
88
89 req.add(plane, {"FB_ID": fb.id,
90 "CRTC_ID": crtc.id,
91 "SRC_X": src_x << 16,
92 "SRC_Y": src_y << 16,
93 "SRC_W": src_w << 16,
94 "SRC_H": src_h << 16,
95 "CRTC_X": crtc_x,
96 "CRTC_Y": crtc_y,
97 "CRTC_W": crtc_w,
98 "CRTC_H": crtc_h,
99 "rotation": rot,
100 "zorder": 2})
101
102 req.commit_sync(allow_modeset = True)
103
104
105fb_w = 480
106fb_h = 150
107x_scale = 1
108y_scale = 1
109
110fb = pykms.OmapFramebuffer(card, fb_w, fb_h, "NV12", tiled = True);
111#fb = pykms.DumbFramebuffer(card, fb_w, fb_h, "NV12")
112pykms.draw_test_pattern(fb);
113
114def even(i):
115 return i & ~1
116
117pykms.draw_text(fb, even((fb_w // 2) - (8 * 3) // 2), 4, "TOP", pykms.white)
118pykms.draw_text(fb, even((fb_w // 2) - (8 * 6) // 2), fb_h - 8 - 4, "BOTTOM", pykms.white)
119pykms.draw_text(fb, 4, even(((fb_h // 2) - 4)), "L", pykms.white)
120pykms.draw_text(fb, fb_w - 8 - 4, even(((fb_h // 2) - 4)), "R", pykms.white)
121
122rots = [ Rotation.ROTATE_0, Rotation.ROTATE_90, Rotation.ROTATE_180, Rotation.ROTATE_270 ]
123cursors = [ "A", "D", "B", "C" ]
124
125print("Use the cursor keys, x and y to change rotation. Press q to quit.")
126
127fd = sys.stdin.fileno()
128oldterm = termios.tcgetattr(fd)
129tty.setcbreak(fd)
130
131try:
132 esc_seq = 0
133
134 current_rot = Rotation.ROTATE_0
135
136 show_rot_plane(crtc, plane, fb, current_rot, x_scale, y_scale)
137
138 while True:
139 c = sys.stdin.read(1)
140 #print("Got character {}".format(repr(c)))
141
142 changed = False
143 handled = False
144
145 if esc_seq == 0:
146 if c == "\x1b":
147 esc_seq = 1
148 handled = True
149 elif esc_seq == 1:
150 if c == "[":
151 esc_seq = 2
152 handled = True
153 else:
154 esc_seq = 0
155 elif esc_seq == 2:
156 esc_seq = 0
157
158 if c in cursors:
159 handled = True
160
161 rot = rots[cursors.index(c)]
162
163 current_rot &= ~Rotation.ROTATE_MASK
164 current_rot |= rot
165
166 changed = True
167
168 if not handled:
169 if c == "q":
170 break
171 elif c == "x":
172 current_rot ^= Rotation.REFLECT_X
173 changed = True
174 elif c == "y":
175 current_rot ^= Rotation.REFLECT_Y
176 changed = True
177
178 if changed:
179 show_rot_plane(crtc, plane, fb, current_rot, x_scale, y_scale)
180
181finally:
182 termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)