kmstest: use resman
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Wed, 22 Nov 2017 08:05:53 +0000 (10:05 +0200)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Wed, 22 Nov 2017 10:47:15 +0000 (12:47 +0200)
kms++util/inc/kms++util/resourcemanager.h
kms++util/src/resourcemanager.cpp
py/pykms/pykmsutil.cpp
utils/kmstest.cpp

index b4a210df01348e41f803cbb8000dd66ad84c30c2..002b4c912824bf23301010ad85a00ec7e4d88bf5 100644 (file)
@@ -15,7 +15,9 @@ public:
        Connector* reserve_connector(const std::string& name = "");
        Connector* reserve_connector(Connector* conn);
        Crtc* reserve_crtc(Connector* conn);
+       Crtc* reserve_crtc(Crtc* crtc);
        Plane* reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format = PixelFormat::Undefined);
+       Plane* reserve_plane(Plane* plane);
        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 c4bf7f86a7e9d188ff5435067150149641635724..465d817c6e1c6ca3155cce0fead5e2694ebd1ebb 100644 (file)
@@ -132,6 +132,19 @@ Crtc* ResourceManager::reserve_crtc(Connector* conn)
        return nullptr;
 }
 
+Crtc* ResourceManager::reserve_crtc(Crtc* crtc)
+{
+       if (!crtc)
+               return nullptr;
+
+       if (contains(m_reserved_crtcs, crtc))
+               return nullptr;
+
+       m_reserved_crtcs.push_back(crtc);
+
+       return crtc;
+}
+
 Plane* ResourceManager::reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format)
 {
        if (!crtc)
@@ -154,6 +167,19 @@ Plane* ResourceManager::reserve_plane(Crtc* crtc, PlaneType type, PixelFormat fo
        return nullptr;
 }
 
+Plane* ResourceManager::reserve_plane(Plane* plane)
+{
+       if (!plane)
+               return nullptr;
+
+       if (contains(m_reserved_planes, plane))
+               return nullptr;
+
+       m_reserved_planes.push_back(plane);
+
+       return plane;
+}
+
 Plane* ResourceManager::reserve_generic_plane(Crtc* crtc, PixelFormat format)
 {
        if (!crtc)
index 10dee8136fe7f5de1185e64af208d4e80355008f..518d5eaa88f035fa295a76eaa03b1b22f237899c 100644 (file)
@@ -25,8 +25,8 @@ void init_pykmstest(py::module &m)
                        .def("reset", &ResourceManager::reset)
                        .def("reserve_connector", (Connector* (ResourceManager::*)(const string& name))&ResourceManager::reserve_connector,
                             py::arg("name") = string())
-                       .def("reserve_crtc", &ResourceManager::reserve_crtc)
-                       .def("reserve_plane", &ResourceManager::reserve_plane,
+                       .def("reserve_crtc", (Crtc* (ResourceManager::*)(Connector*))&ResourceManager::reserve_crtc)
+                       .def("reserve_plane", (Plane* (ResourceManager::*)(Crtc*, PlaneType, PixelFormat))&ResourceManager::reserve_plane,
                             py::arg("crtc"),
                             py::arg("type"),
                             py::arg("format") = PixelFormat::Undefined)
index 21309d695802a07851f2e703d334630bd9c74042..fee30705c79e1f6fef58159f9b09a34231c4e0c5 100644 (file)
@@ -56,9 +56,6 @@ static bool s_cvt_v2;
 static bool s_cvt_vid_opt;
 static unsigned s_max_flips;
 
-static set<Crtc*> s_used_crtcs;
-static set<Plane*> s_used_planes;
-
 __attribute__ ((unused))
 static void print_regex_match(smatch sm)
 {
@@ -82,28 +79,15 @@ static void get_connector(ResourceManager& resman, OutputInfo& output, const str
        output.mode = output.connector->get_default_mode();
 }
 
-static void get_default_crtc(Card& card, OutputInfo& output)
+static void get_default_crtc(ResourceManager& resman, OutputInfo& output)
 {
-       Crtc* crtc = output.connector->get_current_crtc();
-
-       if (crtc && s_used_crtcs.find(crtc) == s_used_crtcs.end()) {
-               s_used_crtcs.insert(crtc);
-               output.crtc = crtc;
-               return;
-       }
-
-       for (const auto& possible : output.connector->get_possible_crtcs()) {
-               if (s_used_crtcs.find(possible) == s_used_crtcs.end()) {
-                       s_used_crtcs.insert(possible);
-                       output.crtc = possible;
-                       return;
-               }
-       }
+       output.crtc = resman.reserve_crtc(output.connector);
 
-       EXIT("Could not find available crtc");
+       if (!output.crtc)
+               EXIT("Could not find available crtc");
 }
 
-static void parse_crtc(Card& card, const string& crtc_str, OutputInfo& output)
+static void parse_crtc(ResourceManager& resman, Card& card, const string& crtc_str, OutputInfo& output)
 {
        // @12:1920x1200i@60
        // @12:33000000,800/210/30/16/-,480/22/13/10/-,i
@@ -226,9 +210,12 @@ static void parse_crtc(Card& card, const string& crtc_str, OutputInfo& output)
        } else {
                EXIT("Failed to parse crtc option '%s'", crtc_str.c_str());
        }
+
+       if (!resman.reserve_crtc(output.crtc))
+               EXIT("Could not find available crtc");
 }
 
-static void parse_plane(Card& card, const string& plane_str, const OutputInfo& output, PlaneInfo& pinfo)
+static void parse_plane(ResourceManager& resman, Card& card, const string& plane_str, const OutputInfo& output, PlaneInfo& pinfo)
 {
        // 3:400,400-400x400
        const regex plane_re("(?:(@?)(\\d+):)?"         // 3:
@@ -257,22 +244,14 @@ static void parse_plane(Card& card, const string& plane_str, const OutputInfo& o
 
                        pinfo.plane = planes[num];
                }
-       } else {
-               for (Plane* p : output.crtc->get_possible_planes()) {
-                       if (s_used_planes.find(p) != s_used_planes.end())
-                               continue;
-
-                       if (p->plane_type() != PlaneType::Overlay)
-                               continue;
 
-                       pinfo.plane = p;
-               }
-
-               if (!pinfo.plane)
-                       EXIT("Failed to find available plane");
+               pinfo.plane = resman.reserve_plane(pinfo.plane);
+       } else {
+               pinfo.plane = resman.reserve_overlay_plane(output.crtc);
        }
 
-       s_used_planes.insert(pinfo.plane);
+       if (!pinfo.plane)
+               EXIT("Failed to find available plane");
 
        pinfo.w = stoul(sm[5]);
        pinfo.h = stoul(sm[6]);
@@ -540,7 +519,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman,
                        if (!current_output->connector)
                                get_connector(resman, *current_output);
 
-                       parse_crtc(card, arg.arg, *current_output);
+                       parse_crtc(resman, card, arg.arg, *current_output);
 
                        current_output->user_set_crtc = true;
 
@@ -560,12 +539,12 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman,
                                get_connector(resman, *current_output);
 
                        if (!current_output->crtc)
-                               get_default_crtc(card, *current_output);
+                               get_default_crtc(resman, *current_output);
 
                        current_output->planes.push_back(PlaneInfo { });
                        current_plane = &current_output->planes.back();
 
-                       parse_plane(card, arg.arg, *current_output, *current_plane);
+                       parse_plane(resman, card, arg.arg, *current_output, *current_plane);
 
                        break;
                }
@@ -581,7 +560,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman,
                                get_connector(resman, *current_output);
 
                        if (!current_output->crtc)
-                               get_default_crtc(card, *current_output);
+                               get_default_crtc(resman, *current_output);
 
                        int def_w, def_h;
 
@@ -617,7 +596,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman,
        // create default framebuffers if needed
        for (OutputInfo& o : outputs) {
                if (!o.crtc) {
-                       get_default_crtc(card, o);
+                       get_default_crtc(resman, o);
                        o.user_set_crtc = true;
                }
 
@@ -1048,7 +1027,7 @@ int main(int argc, char **argv)
                        if (o.fbs.empty())
                                continue;
 
-                       o.primary_plane = resman.reserve_primary_plane(o.crtc);
+                       o.primary_plane = resman.reserve_primary_plane(o.crtc, o.fbs[0]->format());
 
                        if (!o.primary_plane)
                                EXIT("Could not get primary plane for crtc '%u'", o.crtc->id());