omapfb: add enum Flags for OmapFB
[android/external-libkmsxx.git] / py / tests / rottest.py
1 #!/usr/bin/python3
3 import pykms
4 from enum import Enum
6 import termios, sys, os, tty
8 card = pykms.OmapCard()
10 res = pykms.ResourceManager(card)
11 conn = res.reserve_connector()
12 crtc = res.reserve_crtc(conn)
13 mode = conn.get_default_mode()
14 modeb = mode.to_blob(card)
15 rootplane = res.reserve_primary_plane(crtc, pykms.PixelFormat.XRGB8888)
16 plane = res.reserve_overlay_plane(crtc, pykms.PixelFormat.NV12)
18 card.disable_planes()
20 req = pykms.AtomicReq(card)
22 req.add(conn, "CRTC_ID", crtc.id)
24 req.add(crtc, {"ACTIVE": 1,
25                 "MODE_ID": modeb.id})
27 # This enables the root plane
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})
44 req.commit_sync(allow_modeset = True)
46 def show_rot_plane(crtc, plane, fb, rot, x_scale, y_scale):
48         crtc_w = int(fb_w * x_scale)
49         crtc_h = int(fb_h * y_scale)
51         if (rot & pykms.Rotation.ROTATE_90) or (rot & pykms.Rotation.ROTATE_270):
52                 tmp = crtc_w
53                 crtc_w = crtc_h
54                 crtc_h = tmp
56         crtc_x = int(mode.hdisplay / 2 - crtc_w / 2)
57         crtc_y = int(mode.vdisplay / 2 - crtc_h / 2)
59         req = pykms.AtomicReq(card)
61         src_x = 0
62         src_y = 0
63         src_w = fb_w - src_x
64         src_h = fb_h - src_y
66         print("SRC {},{}-{}x{}  DST {},{}-{}x{}".format(
67                 src_x, src_y, src_w, src_h,
68                 crtc_x, crtc_y, crtc_w, crtc_h))
70         angle_str = pykms.Rotation(rot & pykms.Rotation.ROTATE_MASK).name
71         reflect_x_str = "REFLECT_X" if rot & pykms.Rotation.REFLECT_X else ""
72         reflect_y_str = "REFLECT_Y" if rot & pykms.Rotation.REFLECT_Y else ""
74         print("{} {} {}".format(angle_str, reflect_x_str, reflect_y_str))
76         sys.stdout.flush()
78         req.add(plane, {"FB_ID": fb.id,
79                         "CRTC_ID": crtc.id,
80                         "SRC_X": src_x << 16,
81                         "SRC_Y": src_y << 16,
82                         "SRC_W": src_w << 16,
83                         "SRC_H": src_h << 16,
84                         "CRTC_X": crtc_x,
85                         "CRTC_Y": crtc_y,
86                         "CRTC_W": crtc_w,
87                         "CRTC_H": crtc_h,
88                         "rotation": rot,
89                         "zorder": 2})
91         req.commit_sync(allow_modeset = True)
94 fb_w = 480
95 fb_h = 150
96 x_scale = 1
97 y_scale = 1
99 fb = pykms.OmapFramebuffer(card, fb_w, fb_h, "NV12", flags = pykms.OmapFramebuffer.Tiled);
100 #fb = pykms.DumbFramebuffer(card, fb_w, fb_h, "NV12")
101 pykms.draw_test_pattern(fb);
103 def even(i):
104         return i & ~1
106 pykms.draw_text(fb, even((fb_w // 2) - (8 * 3) // 2), 4, "TOP", pykms.white)
107 pykms.draw_text(fb, even((fb_w // 2) - (8 * 6) // 2), fb_h - 8 - 4, "BOTTOM", pykms.white)
108 pykms.draw_text(fb, 4, even(((fb_h // 2) - 4)), "L", pykms.white)
109 pykms.draw_text(fb, fb_w - 8 - 4, even(((fb_h // 2) - 4)), "R", pykms.white)
111 rots = [ pykms.Rotation.ROTATE_0, pykms.Rotation.ROTATE_90, pykms.Rotation.ROTATE_180, pykms.Rotation.ROTATE_270 ]
112 cursors = [ "A", "D", "B", "C" ]
114 print("Use the cursor keys, x and y to change rotation. Press q to quit.")
116 fd = sys.stdin.fileno()
117 oldterm = termios.tcgetattr(fd)
118 tty.setcbreak(fd)
120 try:
121         esc_seq = 0
123         current_rot = pykms.Rotation.ROTATE_0
125         show_rot_plane(crtc, plane, fb, current_rot, x_scale, y_scale)
127         while True:
128                 c = sys.stdin.read(1)
129                 #print("Got character {}".format(repr(c)))
131                 changed = False
132                 handled = False
134                 if esc_seq == 0:
135                         if c == "\x1b":
136                                 esc_seq = 1
137                                 handled = True
138                 elif esc_seq == 1:
139                         if c == "[":
140                                 esc_seq = 2
141                                 handled = True
142                         else:
143                                 esc_seq = 0
144                 elif esc_seq == 2:
145                         esc_seq = 0
147                         if c in cursors:
148                                 handled = True
150                                 rot = rots[cursors.index(c)]
152                                 current_rot &= ~pykms.Rotation.ROTATE_MASK
153                                 current_rot |= rot
155                                 changed = True
157                 if not handled:
158                         if c == "q":
159                                 break
160                         elif c == "x":
161                                 current_rot ^= pykms.Rotation.REFLECT_X
162                                 changed = True
163                         elif c == "y":
164                                 current_rot ^= pykms.Rotation.REFLECT_Y
165                                 changed = True
167                 if changed:
168                         show_rot_plane(crtc, plane, fb, current_rot, x_scale, y_scale)
170 finally:
171         termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)