use reserve_connector from ResourceManager
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Tue, 7 Feb 2017 11:39:15 +0000 (13:39 +0200)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Fri, 10 Feb 2017 05:04:02 +0000 (07:04 +0200)
kms++util/inc/kms++util/kms++util.h
kms++util/inc/kms++util/resourcemanager.h
kms++util/src/helpers.cpp [deleted file]
kms++util/src/resourcemanager.cpp
py/pykms/pykmsutil.cpp
utils/kmsblank.cpp
utils/kmstest.cpp

index 5a688f6052abb82ef5fc9c6cb49fa5be1f3a56c1..3745a3181446131f80cdc9ccef7d93bd400330f0 100644 (file)
@@ -27,8 +27,6 @@ void draw_text(IMappedFramebuffer& buf, uint32_t x, uint32_t y, const std::strin
 void draw_color_bar(IMappedFramebuffer& buf, int old_xpos, int xpos, int width);
 
 void draw_test_pattern(IMappedFramebuffer &fb);
-
-Connector* resolve_connector(Card& card, const std::string& str);
 }
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
index 42e50001de6be3c2386e6cf142d29e608f2d5dee..dac6c9eb6c464a1a4c56ace98ebb693afd482c06 100644 (file)
@@ -13,6 +13,7 @@ public:
 
        Card& card() const { return m_card; }
        Connector* reserve_connector(const std::string& name = "");
+       Connector* reserve_connector(Connector* conn);
        Crtc* reserve_crtc(Connector* conn);
        Plane* reserve_plane(Crtc* crtc, PlaneType type, PixelFormat format = PixelFormat::Undefined);
        Plane* reserve_primary_plane(Crtc* crtc, PixelFormat format = PixelFormat::Undefined);
diff --git a/kms++util/src/helpers.cpp b/kms++util/src/helpers.cpp
deleted file mode 100644 (file)
index 2bf3a4f..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <kms++util/kms++util.h>
-
-using namespace std;
-
-namespace kms {
-
-Connector* resolve_connector(Card& card, const string& str)
-{
-       if (str.length() == 0)
-               return nullptr;
-
-       auto connectors = card.get_connectors();
-
-       if (str[0] == '@') {
-               char* endptr;
-               unsigned id = strtoul(str.c_str() + 1, &endptr, 10);
-               if (*endptr == 0) {
-                       Connector* c = card.get_connector(id);
-                       if (!c)
-                               return nullptr;
-                       else
-                               return c;
-               }
-       } else {
-               char* endptr;
-               unsigned idx = strtoul(str.c_str(), &endptr, 10);
-               if (*endptr == 0) {
-                       if (idx >= connectors.size())
-                               return nullptr;
-                       else
-                               return connectors[idx];
-               }
-       }
-
-       for (Connector* conn : connectors) {
-               if (to_lower(conn->fullname()).find(to_lower(str)) != string::npos)
-                       return conn;
-       }
-
-       return nullptr;
-}
-
-}
index cdd3e40440a98b4bd2bbb5de9debb41d330e1661..5c83ad77758ca7a1e0086484d219c88bdb9d9925 100644 (file)
@@ -99,6 +99,15 @@ Connector* ResourceManager::reserve_connector(const string& name)
        return conn;
 }
 
+Connector* ResourceManager::reserve_connector(Connector* conn)
+{
+       if (contains(m_reserved_connectors, conn))
+               return nullptr;
+
+       m_reserved_connectors.push_back(conn);
+       return conn;
+}
+
 Crtc* ResourceManager::reserve_crtc(Connector* conn)
 {
        if (Crtc* crtc = conn->get_current_crtc()) {
index b3b7594fad3b35be50bb92dbc9fab85eb04948bc..8421cc59315895cf1d077f53c42a8e7529395ba0 100644 (file)
@@ -23,7 +23,7 @@ void init_pykmstest(py::module &m)
        py::class_<ResourceManager>(m, "ResourceManager")
                        .def(py::init<Card&>())
                        .def("reset", &ResourceManager::reset)
-                       .def("reserve_connector", &ResourceManager::reserve_connector,
+                       .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,
index 4909826b5184bb1a5fc6c4894fbb04c5664b210f..0b51810ad35adda489254ba0cace2bb1f25e44ff 100644 (file)
@@ -60,12 +60,13 @@ int main(int argc, char **argv)
        }
 
        Card card(dev_path);
+       ResourceManager resman(card);
 
        vector<Connector*> conns;
 
        if (conn_strs.size() > 0) {
                for (string s : conn_strs) {
-                       auto c = resolve_connector(card, s);
+                       auto c = resman.reserve_connector(s);
                        if (!c)
                                EXIT("Failed to resolve connector '%s'", s.c_str());
                        conns.push_back(c);
index 733523eb81d735741bba2f2179b7e555cafdccf4..3fb4b28bbbe614a1cbb5f2a16a452959028b4fde 100644 (file)
@@ -73,9 +73,9 @@ static void get_default_connector(Card& card, OutputInfo& output)
        output.mode = output.connector->get_default_mode();
 }
 
-static void parse_connector(Card& card, const string& str, OutputInfo& output)
+static void parse_connector(Card& card, ResourceManager& resman, const string& str, OutputInfo& output)
 {
-       Connector* conn = resolve_connector(card, str);
+       Connector* conn = resman.reserve_connector(str);
 
        if (!conn)
                EXIT("No connector '%s'", str.c_str());
@@ -488,16 +488,19 @@ static vector<Arg> parse_cmdline(int argc, char **argv)
        return args;
 }
 
-static vector<OutputInfo> setups_to_outputs(Card& card, const vector<Arg>& output_args)
+static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman, const vector<Arg>& output_args)
 {
        vector<OutputInfo> outputs;
 
        if (output_args.size() == 0) {
                // no output args, show a pattern on all screens
-               for (auto& pipe : card.get_connected_pipelines()) {
+               for (Connector* conn : card.get_connectors()) {
+                       if (!conn->connected())
+                               continue;
+
                        OutputInfo output = { };
-                       output.connector = pipe.connector;
-                       output.crtc = pipe.crtc;
+                       output.connector = resman.reserve_connector(conn);
+                       output.crtc = resman.reserve_crtc(conn);
                        output.mode = output.connector->get_default_mode();
 
                        output.fbs = get_default_fb(card, output.mode.hdisplay, output.mode.vdisplay);
@@ -518,7 +521,7 @@ static vector<OutputInfo> setups_to_outputs(Card& card, const vector<Arg>& outpu
                        outputs.push_back(OutputInfo { });
                        current_output = &outputs.back();
 
-                       parse_connector(card, arg.arg, *current_output);
+                       parse_connector(card, resman, arg.arg, *current_output);
                        current_plane = 0;
 
                        break;
@@ -1019,10 +1022,10 @@ int main(int argc, char **argv)
        if (!card.has_atomic() && s_flip_sync)
                EXIT("Synchronized flipping requires atomic modesetting");
 
-       vector<OutputInfo> outputs = setups_to_outputs(card, output_args);
-
        ResourceManager resman(card);
 
+       vector<OutputInfo> outputs = setups_to_outputs(card, resman, output_args);
+
        if (card.has_atomic()) {
                for (OutputInfo& o : outputs) {
                        if (o.fbs.empty())