Merge branch 'universal-planes2' of git://github.com/jsarha/kmsxx
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Tue, 21 Mar 2017 13:04:24 +0000 (15:04 +0200)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Tue, 21 Mar 2017 13:04:24 +0000 (15:04 +0200)
kms++util/inc/kms++util/resourcemanager.h
kms++util/src/resourcemanager.cpp
py/pykms/pykmsutil.cpp
py/tests/plane_hog.py [new file with mode: 0755]

index dac6c9eb6c464a1a4c56ace98ebb693afd482c06..b4a210df01348e41f803cbb8000dd66ad84c30c2 100644 (file)
@@ -16,6 +16,7 @@ public:
        Connector* reserve_connector(Connector* conn);
        Crtc* reserve_crtc(Connector* conn);
        Plane* reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format = PixelFormat::Undefined);
+       Plane* reserve_generic_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined);
        Plane* reserve_primary_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined);
        Plane* reserve_overlay_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined);
 
index 5c83ad77758ca7a1e0086484d219c88bdb9d9925..23a1480de2903ac2a07dee4196e65d069079fdf4 100644 (file)
@@ -129,7 +129,26 @@ Crtc* ResourceManager::reserve_crtc(Connector* conn)
 Plane* ResourceManager::reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format)
 {
        for (Plane* plane : crtc->get_possible_planes()) {
-               if (plane->plane_type() != type)
+               if (plane->plane_type() == type)
+                       continue;
+
+               if (format != PixelFormat::Undefined && !plane->supports_format(format))
+                       continue;
+
+               if (contains(m_reserved_planes, plane))
+                       continue;
+
+               m_reserved_planes.push_back(plane);
+               return plane;
+       }
+
+       return nullptr;
+}
+
+Plane* ResourceManager::reserve_generic_plane(Crtc* crtc, PixelFormat format)
+{
+       for (Plane* plane : crtc->get_possible_planes()) {
+               if (plane->plane_type() == PlaneType::Cursor)
                        continue;
 
                if (format != PixelFormat::Undefined && !plane->supports_format(format))
index 8421cc59315895cf1d077f53c42a8e7529395ba0..46b7765e59e351755f7ddabd4c253a5188a96a20 100644 (file)
@@ -30,6 +30,9 @@ void init_pykmstest(py::module &m)
                             py::arg("crtc"),
                             py::arg("type"),
                             py::arg("format") = PixelFormat::Undefined)
+                       .def("reserve_generic_plane", &ResourceManager::reserve_generic_plane,
+                            py::arg("crtc"),
+                            py::arg("format") = PixelFormat::Undefined)
                        .def("reserve_primary_plane", &ResourceManager::reserve_primary_plane,
                             py::arg("crtc"),
                             py::arg("format") = PixelFormat::Undefined)
diff --git a/py/tests/plane_hog.py b/py/tests/plane_hog.py
new file mode 100755 (executable)
index 0000000..5bdc937
--- /dev/null
@@ -0,0 +1,136 @@
+#!/usr/bin/python3
+
+import pykms
+import sys
+
+card = pykms.Card()
+res = pykms.ResourceManager(card)
+
+conn1 = False
+conn2 = False
+
+for conn in card.connectors:
+     if not conn1:
+          conn1 = conn
+     elif not conn2:
+          conn2 = conn
+     else:
+          break
+
+crtc1 = res.reserve_crtc(conn1)
+mode1 = conn1.get_default_mode()
+modeb1 = mode1.to_blob(card)
+print("CRTC idx %d goes to %s connector" % (crtc1.idx, conn1.fullname))
+
+if conn2:
+     crtc2 = res.reserve_crtc(conn2)
+     mode2 = conn2.get_default_mode()
+     modeb2 = mode2.to_blob(card)
+     print("CRTC idx %d goes to %s connector" % (crtc2.idx, conn2.fullname))
+
+fbwidth = 480
+fbheight = 270
+
+fb = pykms.DumbFramebuffer(card, fbwidth, fbheight, "AR24");
+pykms.draw_test_pattern(fb);
+
+# Disable request
+card.disable_planes()
+
+plane_list = []
+
+while True:
+     plane = res.reserve_generic_plane(crtc1)
+     if plane:
+         print("Got plane idx %d" % plane.idx)
+         plane_list.append(plane)
+     else:
+         break
+
+print("Got %d planes" % len(plane_list))
+
+req = pykms.AtomicReq(card)
+req.add(conn1, "CRTC_ID", crtc1.id)
+req.add(crtc1, {"ACTIVE": 1,
+               "MODE_ID": modeb1.id})
+
+input("Press enter to enable crtc idx %d at %s" % (crtc1.idx, conn1.fullname))
+r = req.commit_sync(allow_modeset = True)
+
+print("Crtc enable request returned %d\n" % r)
+
+x = 0
+y = 0
+z = 0
+
+for plane in plane_list:
+    input("Press enter to enable plane idx %d on crtc idx %d" %
+          (plane.idx, crtc1.idx))
+    req = pykms.AtomicReq(card)
+    req.add(plane, {"FB_ID": fb.id,
+                     "CRTC_ID": crtc1.id,
+                     "SRC_X": 0 << 16,
+                     "SRC_Y": 0 << 16,
+                     "SRC_W": fb.width << 16,
+                     "SRC_H": fb.height << 16,
+                     "CRTC_X": x,
+                     "CRTC_Y": y,
+                     "CRTC_W": fb.width,
+                     "CRTC_H": fb.height,
+                     "zorder": z})
+    r = req.commit_sync()
+    print("Plane enable request returned %d\n" % r)
+
+    x = x + 50
+    y = y + 50
+    z = z + 1
+
+if not conn2:
+     sys.exit()
+
+req = pykms.AtomicReq(card)
+req.add(conn2, "CRTC_ID", crtc2.id)
+req.add(crtc2, {"ACTIVE": 1,
+                "MODE_ID": modeb2.id})
+
+input("Press enter to enable crtc idx %d at %s" % (crtc2.idx, conn2.fullname))
+r = req.commit_sync(allow_modeset = True)
+print("Crtc enable request returned %d\n" % r)
+
+x = 0
+y = 0
+z = 0
+
+# Code assumes that planes for crtc1 also work for crtc2
+for plane in reversed(plane_list):
+
+    input("Press enter to disable plane idx %d on crtc idx %d" %
+          (plane.idx, crtc1.idx))
+    req = pykms.AtomicReq(card)
+    req.add(plane, {"FB_ID": 0,
+                    "CRTC_ID": 0})
+    r = req.commit_sync(allow_modeset = True)
+    print("Plane disable request returned %d\n" % r)
+
+    input("Press enter to enable plane idx %d on crtc idx %d" %
+          (plane.idx, crtc2.idx))
+    req = pykms.AtomicReq(card)
+    req.add(plane, {"FB_ID": fb.id,
+                    "CRTC_ID": crtc2.id,
+                    "SRC_X": 0 << 16,
+                    "SRC_Y": 0 << 16,
+                    "SRC_W": fb.width << 16,
+                    "SRC_H": fb.height << 16,
+                    "CRTC_X": x,
+                    "CRTC_Y": y,
+                    "CRTC_W": fb.width,
+                    "CRTC_H": fb.height,
+                    "zorder": z})
+    r = req.commit_sync(allow_modeset = True)
+    print("Plane enable request returned %d\n" % r)
+
+    x = x + 50
+    y = y + 50
+    z = z + 1
+
+input("press enter to exit\n")