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
|
#!/usr/bin/python3
# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2022 Renesas Electronics Corporation
import kmstest
import pykms
import time
class ColorKeyTest(kmstest.KMSTest):
"""Test color keying with two planes."""
def main(self):
self.start("color keying")
# Find a CRTC with a connected connector and at least one overlay plane
for connector in self.card.connectors:
if not connector.connected():
continue
try:
mode = connector.get_default_mode()
except ValueError:
continue
crtcs = connector.get_possible_crtcs()
for crtc in crtcs:
overlay = None
for plane in self.card.planes:
if plane.supports_crtc(crtc) and plane != crtc.primary_plane:
overlay = plane
if overlay:
break
else:
crtc = None
if crtc:
break
else:
self.skip("no CRTC available with connector and at least one overlay plane")
return
self.logger.log("Testing connector %s, CRTC %u, mode %s" % \
(connector.fullname, crtc.id, mode.name))
# Create the frame buffers
colors = ((255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 255))
width = mode.hdisplay
height = mode.vdisplay
fbs = []
fb = pykms.DumbFramebuffer(self.card, width, height, "XR24")
pykms.draw_test_pattern(fb)
fbs.append(fb)
fb = pykms.DumbFramebuffer(self.card, width, height, "XR24")
pykms.draw_rect(fb, 0, 0, width // 2, height // 2, pykms.RGB(*colors[0]))
pykms.draw_rect(fb, width // 2, 0, width // 2, height // 2, pykms.RGB(*colors[1]))
pykms.draw_rect(fb, 0, height // 2, width // 2, height // 2, pykms.RGB(*colors[2]))
pykms.draw_rect(fb, width // 2, height // 2, width // 2, height // 2, pykms.RGB(*colors[3]))
fbs.append(fb)
# Set the mode with the primary plane and add an overlay plane
ret = self.atomic_crtc_mode_set(crtc, connector, mode, fbs[0])
if ret < 0:
self.fail("atomic mode set failed with %d" % ret)
return
self.logger.log("Initial atomic mode set completed")
# Add the overlay plane to cover the whole CRTC
source = kmstest.Rect(0, 0, fbs[1].width, fbs[1].height)
destination = kmstest.Rect(0, 0, fbs[1].width, fbs[1].height)
ret = self.atomic_plane_set(overlay, crtc, source, destination, fbs[1], sync=True)
if ret < 0:
self.fail("atomic plane set for overlay plane failed with %d" % ret)
return
self.logger.log("Overlay plane enabled")
time.sleep(3)
# Try to set different minimum and maximum values, this should be
# rejected.
req = pykms.AtomicReq(self.card)
req.add(plane, {"colorkey.min": 1, "colorkey.max": 2})
ret = req.commit_sync()
if ret >= 0:
self.fail("Non-equal colorkey min and max not rejected")
return
self.logger.log("Non-equal colorkey min and max correctly rejected")
# Cycle over color keys to make the four rectangles in the overlay plane
# transparent in turn.
for i in range(len(colors)):
color = (colors[i][0] << 40) | (colors[i][1] << 24) | (colors[i][2] << 8)
plane.set_props({
"colorkey.mode": 1,
"colorkey.min": color,
"colorkey.max": color,
"colorkey.value": (255 * (len(colors) - i - 1) // 4) << 56,
})
self.logger.log("Color key set to %s" % repr(colors[i]))
time.sleep(3)
plane.set_prop("colorkey.mode", 0)
self.atomic_crtc_disable(crtc)
self.success()
if __name__ == '__main__':
ColorKeyTest().execute()
|