summaryrefslogtreecommitdiff
path: root/py/tests/rottest.py
blob: c568e17b678af60da2518197ebf0c3735f69aca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/python3

import pykms
from enum import Enum

import termios, sys, os, tty

card = pykms.OmapCard()

res = pykms.ResourceManager(card)
conn = res.reserve_connector()
crtc = res.reserve_crtc(conn)
mode = conn.get_default_mode()
modeb = mode.to_blob(card)
rootplane = res.reserve_primary_plane(crtc, pykms.PixelFormat.XRGB8888)
plane = res.reserve_overlay_plane(crtc, pykms.PixelFormat.NV12)

card.disable_planes()

req = pykms.AtomicReq(card)

req.add(conn, "CRTC_ID", crtc.id)

req.add(crtc, {"ACTIVE": 1,
		"MODE_ID": modeb.id})

# This enables the root plane

#rootfb = pykms.OmapFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
#pykms.draw_test_pattern(rootfb);
#
#req.add(rootplane, {"FB_ID": rootfb.id,
#		"CRTC_ID": crtc.id,
#		"SRC_X": 0 << 16,
#		"SRC_Y": 0 << 16,
#		"SRC_W": mode.hdisplay << 16,
#		"SRC_H": mode.vdisplay << 16,
#		"CRTC_X": 0,
#		"CRTC_Y": 0,
#		"CRTC_W": mode.hdisplay,
#		"CRTC_H": mode.vdisplay,
#		"zpos": 0})

req.commit_sync(allow_modeset = True)

def show_rot_plane(crtc, plane, fb, rot, x_scale, y_scale):

	crtc_w = int(fb_w * x_scale)
	crtc_h = int(fb_h * y_scale)

	if (rot & pykms.Rotation.ROTATE_90) or (rot & pykms.Rotation.ROTATE_270):
		tmp = crtc_w
		crtc_w = crtc_h
		crtc_h = tmp

	crtc_x = int(mode.hdisplay / 2 - crtc_w / 2)
	crtc_y = int(mode.vdisplay / 2 - crtc_h / 2)

	req = pykms.AtomicReq(card)

	src_x = 0
	src_y = 0
	src_w = fb_w - src_x
	src_h = fb_h - src_y

	print("SRC {},{}-{}x{}  DST {},{}-{}x{}".format(
		src_x, src_y, src_w, src_h,
		crtc_x, crtc_y, crtc_w, crtc_h))

	angle_str = pykms.Rotation(rot & pykms.Rotation.ROTATE_MASK).name
	reflect_x_str = "REFLECT_X" if rot & pykms.Rotation.REFLECT_X else ""
	reflect_y_str = "REFLECT_Y" if rot & pykms.Rotation.REFLECT_Y else ""

	print("{} {} {}".format(angle_str, reflect_x_str, reflect_y_str))

	sys.stdout.flush()

	req.add(plane, {"FB_ID": fb.id,
			"CRTC_ID": crtc.id,
			"SRC_X": src_x << 16,
			"SRC_Y": src_y << 16,
			"SRC_W": src_w << 16,
			"SRC_H": src_h << 16,
			"CRTC_X": crtc_x,
			"CRTC_Y": crtc_y,
			"CRTC_W": crtc_w,
			"CRTC_H": crtc_h,
			"rotation": rot,
			"zpos": 2})

	req.commit_sync(allow_modeset = True)


fb_w = 480
fb_h = 150
x_scale = 1
y_scale = 1

fb = pykms.OmapFramebuffer(card, fb_w, fb_h, "NV12", flags = pykms.OmapFramebuffer.Tiled);
#fb = pykms.DumbFramebuffer(card, fb_w, fb_h, "NV12")
pykms.draw_test_pattern(fb);

def even(i):
	return i & ~1

pykms.draw_text(fb, even((fb_w // 2) - (8 * 3) // 2), 4, "TOP", pykms.white)
pykms.draw_text(fb, even((fb_w // 2) - (8 * 6) // 2), fb_h - 8 - 4, "BOTTOM", pykms.white)
pykms.draw_text(fb, 4, even(((fb_h // 2) - 4)), "L", pykms.white)
pykms.draw_text(fb, fb_w - 8 - 4, even(((fb_h // 2) - 4)), "R", pykms.white)

rots = [ pykms.Rotation.ROTATE_0, pykms.Rotation.ROTATE_90, pykms.Rotation.ROTATE_180, pykms.Rotation.ROTATE_270 ]
cursors = [ "A", "D", "B", "C" ]

print("Use the cursor keys, x and y to change rotation. Press q to quit.")

fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
tty.setcbreak(fd)

try:
	esc_seq = 0

	current_rot = pykms.Rotation.ROTATE_0

	show_rot_plane(crtc, plane, fb, current_rot, x_scale, y_scale)

	while True:
		c = sys.stdin.read(1)
		#print("Got character {}".format(repr(c)))

		changed = False
		handled = False

		if esc_seq == 0:
			if c == "\x1b":
				esc_seq = 1
				handled = True
		elif esc_seq == 1:
			if c == "[":
				esc_seq = 2
				handled = True
			else:
				esc_seq = 0
		elif esc_seq == 2:
			esc_seq = 0

			if c in cursors:
				handled = True

				rot = rots[cursors.index(c)]

				current_rot &= ~pykms.Rotation.ROTATE_MASK
				current_rot |= rot

				changed = True

		if not handled:
			if c == "q":
				break
			elif c == "x":
				current_rot ^= pykms.Rotation.REFLECT_X
				changed = True
			elif c == "y":
				current_rot ^= pykms.Rotation.REFLECT_Y
				changed = True

		if changed:
			show_rot_plane(crtc, plane, fb, current_rot, x_scale, y_scale)

finally:
	termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)