Add Card::get_connected_pipelines()
authorTomi Valkeinen <tomi.valkeinen@iki.fi>
Mon, 28 Sep 2015 14:59:52 +0000 (17:59 +0300)
committerTomi Valkeinen <tomi.valkeinen@iki.fi>
Mon, 28 Sep 2015 20:30:55 +0000 (23:30 +0300)
libkms++/card.cpp
libkms++/card.h
libkms++/kms++.h
libkms++/pipeline.h [new file with mode: 0644]
tests/db.cpp
tests/testpat.cpp

index aebd9a1f239207d76aeff69916443ee36849c01b..3dea542d5123c2caac5574bcf0383fcafeab45ca 100644 (file)
@@ -4,6 +4,7 @@
 #include <utility>
 #include <stdexcept>
 #include <string.h>
+#include <algorithm>
 
 #include <xf86drm.h>
 #include <xf86drmMode.h>
@@ -197,4 +198,34 @@ Crtc* Card::get_crtc_by_index(uint32_t idx) const
 Crtc* Card::get_crtc(uint32_t id) const { return dynamic_cast<Crtc*>(get_object(id)); }
 Encoder* Card::get_encoder(uint32_t id) const { return dynamic_cast<Encoder*>(get_object(id)); }
 Property* Card::get_prop(uint32_t id) const { return dynamic_cast<Property*>(get_object(id)); }
+
+std::vector<kms::Pipeline> Card::get_connected_pipelines()
+{
+       vector<Pipeline> outputs;
+
+       for (auto conn : get_connectors())
+       {
+               if (conn->connected() == false)
+                       continue;
+
+               Crtc* crtc = conn->get_current_crtc();
+
+               if (!crtc) {
+                       for (auto possible : conn->get_possible_crtcs()) {
+                               if (find_if(outputs.begin(), outputs.end(), [possible](Pipeline out) { return out.crtc == possible; }) == outputs.end()) {
+                                       crtc = possible;
+                                       break;
+                               }
+                       }
+               }
+
+               if (!crtc)
+                       throw invalid_argument("fob");
+
+               outputs.push_back(Pipeline { crtc, conn });
+       }
+
+       return outputs;
+}
+
 }
index fb45d04ca79a10b2b609d42fc47852c9832a3688..fbfbe74ad5c882f09535d7662f532ad534827144 100644 (file)
@@ -5,10 +5,10 @@
 #include <map>
 
 #include "decls.h"
+#include "pipeline.h"
 
 namespace kms
 {
-
 class Card
 {
 public:
@@ -38,6 +38,8 @@ public:
        std::vector<DrmObject*> get_objects() const;
        std::vector<Plane*> get_planes() const;
 
+       std::vector<Pipeline> get_connected_pipelines();
+
 private:
        std::map<uint32_t, DrmObject*> m_obmap;
 
index f9808ededaa5b46c0d5614c6bd73b4ea120452e4..7d6788d96a5a369f2ac6ec98fef29fde615df46c 100644 (file)
@@ -8,3 +8,4 @@
 #include "framebuffer.h"
 #include "plane.h"
 #include "property.h"
+#include "pipeline.h"
diff --git a/libkms++/pipeline.h b/libkms++/pipeline.h
new file mode 100644 (file)
index 0000000..ef04ec1
--- /dev/null
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "decls.h"
+
+namespace kms
+{
+struct Pipeline {
+       Crtc* crtc;
+       Connector* connector;
+};
+}
index 576896ef792ced4137e8c75fe6fea185cb48aa7b..5df104d87a93c5a2e2b0890dc06831350b6dcc0b 100644 (file)
@@ -84,8 +84,6 @@ public:
                }
        }
 
-       Crtc* crtc() const { return m_crtc; }
-
 private:
        Connector* m_connector;
        Crtc* m_crtc;
@@ -106,28 +104,13 @@ int main()
 
        vector<OutputFlipHandler*> outputs;
 
-       for (auto conn : card.get_connectors())
+       for (auto pipe : card.get_connected_pipelines())
        {
-               if (conn->connected() == false)
-                       continue;
+               auto conn = pipe.connector;
+               auto crtc = pipe.crtc;
 
                auto mode = conn->get_default_mode();
 
-               Crtc* crtc = conn->get_current_crtc();
-               if (!crtc) {
-                       for (auto c : conn->get_possible_crtcs()) {
-                               if (find_if(outputs.begin(), outputs.end(), [c](OutputFlipHandler* o) { return o->crtc() == c; }) == outputs.end()) {
-                                       crtc = c;
-                                       break;
-                               }
-                       }
-               }
-
-               if (!crtc) {
-                       printf("failed to find crtc\n");
-                       return -1;
-               }
-
                auto fb1 = new Framebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
                auto fb2 = new Framebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
 
index 27c1bc35c5277fcdd60fc461a6d32bbfba3e9f58..99804076dfc00bdf1ed89e7ddda9477dd58a7236 100644 (file)
@@ -18,31 +18,14 @@ int main()
 
        //card.print_short();
 
-       auto connectors = card.get_connectors();
+       auto pipes = card.get_connected_pipelines();
 
        vector<Framebuffer*> fbs;
-       vector<Crtc*> used_crtcs;
 
-       for (auto conn : connectors)
+       for (auto pipe : pipes)
        {
-               if (conn->connected() == false)
-                       continue;
-
-               Crtc* crtc = conn->get_current_crtc();
-               if (!crtc) {
-                       vector<Crtc*> list = conn->get_possible_crtcs();
-                       for (auto c : list) {
-                               if (find(used_crtcs.begin(), used_crtcs.end(), c) == used_crtcs.end()) {
-                                       crtc = c;
-                                       break;
-                               }
-                       }
-               }
-               used_crtcs.push_back(crtc);
-
-               ASSERT(crtc);
-
-               int r;
+               auto conn = pipe.connector;
+               auto crtc = pipe.crtc;
 
                // RG16 XR24 UYVY YUYV NV12
 
@@ -52,10 +35,15 @@ int main()
                draw_test_pattern(*fb);
                fbs.push_back(fb);
 
-               r = crtc->set_mode(conn, *fb, mode);
-               ASSERT(r == 0);
+               printf("conn %u, crtc %u, fb %u\n", conn->id(), crtc->id(), fb->id());
 
+               int r = crtc->set_mode(conn, *fb, mode);
+               ASSERT(r == 0);
+       }
 
+       for (auto pipe: pipes)
+       {
+               auto crtc = pipe.crtc;
 
                Plane* plane = 0;
 
@@ -71,7 +59,7 @@ int main()
                        draw_test_pattern(*planefb);
                        fbs.push_back(planefb);
 
-                       r = crtc->set_plane(plane, *planefb,
+                       int r = crtc->set_plane(plane, *planefb,
                                            0, 0, planefb->width(), planefb->height(),
                                            0, 0, planefb->width(), planefb->height());