summaryrefslogtreecommitdiff
path: root/tests/kms-test-planeposition.py
blob: b42de97bba0b673ad0e322d5d01cb84dd778d6be (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
#!/usr/bin/python3

import kmstest
import pykms
import time

class PlanePositionTest(kmstest.KMSTest):
    """Test boundaries of plane positioning."""

    def main(self):
        self.start("plane positioning boundaries")

        # Find a CRTC with a connected connector and at least two planes
        for connector in self.card.connectors:
            if not connector.connected():
                self.skip("unconnected connector")
                continue

            try:
                mode = connector.get_default_mode()
            except ValueError:
                continue

            crtcs = connector.get_possible_crtcs()
            for crtc in crtcs:
                planes = []
                for plane in self.card.planes:
                    if plane.supports_crtc(crtc):
                        planes.append(plane)

                if len(planes) > 1:
                    break
            else:
                crtc = None

            if crtc:
                break

        else:
            self.skip("no CRTC available with connector and at least two planes")
            return

        self.logger.log("Testing connector %s, CRTC %u, mode %s with %u planes" % \
              (connector.fullname, crtc.id, mode.name, len(planes)))

        # Create a frame buffer
        fb = pykms.DumbFramebuffer(self.card, mode.hdisplay, mode.vdisplay, "XR24")
        pykms.draw_test_pattern(fb)

        # Set the mode with no plane, wait 5s for the monitor to wake up
        ret = self.atomic_crtc_mode_set(crtc, connector, mode, sync=True)
        if ret < 0:
            self.fail("atomic mode set failed with %d" % ret)
            return

        self.logger.log("Initial atomic mode set completed")
        time.sleep(5)

        # Add the first plane to cover half of the CRTC
        source = kmstest.Rect(0, 0, fb.width // 2, fb.height)
        destination = kmstest.Rect(0, 0, fb.width // 2, fb.height)
        ret = self.atomic_plane_set(planes[0], crtc, source, destination, fb, sync=True)
        if ret < 0:
            self.fail("atomic plane set for first plane failed with %d" % ret)
            return

        self.logger.log("Root plane enabled")
        time.sleep(3)

        # Add the second plane and move it around to cross all CRTC boundaries
        offsets = ((50, 50), (150, 50), (50, 150), (-50, 50), (50, -50))
        for offset in offsets:
            width = fb.width - 100
            height = fb.height - 100
            source = kmstest.Rect(0, 0, width, height)
            destination = kmstest.Rect(offset[0], offset[1], width, height)

            ret = self.atomic_plane_set(planes[1], crtc, source, destination, fb, sync=True)
            if ret < 0:
                self.fail("atomic plane set with offset %d,%d" % offset)
                return

            self.logger.log("Moved overlay plane to %d,%d" % offset)
            time.sleep(3)

        # Try to move the plane completely off-screen. The device is expected
        # to accept this and not to show the plane on the screen.
        offsets = ((mode.hdisplay, 50), (50, mode.vdisplay),
                   (-mode.hdisplay, 50), (50, -mode.vdisplay))
        for offset in offsets:
            width = fb.width - 100
            height = fb.height - 100
            source = kmstest.Rect(0, 0, width, height)
            destination = kmstest.Rect(offset[0], offset[1], width, height)

            ret = self.atomic_plane_set(planes[1], crtc, source, destination, fb, sync=True)
            if ret < 0:
                self.fail("atomic plane set with offset %d,%d" % offset)
                return

            self.logger.log("Moved overlay plane to %d,%d" % offset)
            time.sleep(3)

        self.success()

PlanePositionTest().execute()