save & restore mode
authorTomi Valkeinen <tomi.valkeinen@iki.fi>
Fri, 2 Oct 2015 20:23:54 +0000 (23:23 +0300)
committerTomi Valkeinen <tomi.valkeinen@iki.fi>
Sat, 3 Oct 2015 14:49:45 +0000 (17:49 +0300)
libkms++/card.cpp
libkms++/card.h
libkms++/connector.cpp
libkms++/connector.h
libkms++/crtc.cpp
libkms++/crtc.h

index 5f8dbd14fd6da02df86edbf13ea1eff0b43686cb..39a1fb678406b5ff0386e50bbfbcc1e7070a3e13 100644 (file)
@@ -107,12 +107,20 @@ Card::Card()
 
 Card::~Card()
 {
+       restore_modes();
+
        for (auto pair : m_obmap)
                delete pair.second;
 
        close(m_fd);
 }
 
+void Card::restore_modes()
+{
+       for (auto conn : get_connectors())
+               conn->restore_mode();
+}
+
 template <class T> static void print_obs(const map<uint32_t, DrmObject*>& obmap)
 {
        for (auto pair : obmap) {
index a8db76f50697919edcf1785e697c72876b310311..ac0cba4455f09f11d829c41221dba484a7ed8f9e 100644 (file)
@@ -42,6 +42,8 @@ public:
        std::vector<Pipeline> get_connected_pipelines();
 
 private:
+       void restore_modes();
+
        std::map<uint32_t, DrmObject*> m_obmap;
 
        int m_fd;
index 8ff5a5f8f4a264661084ce22289c37d3f54b6b02..06703d676f1d72821637b3ca138ca2a86dbb45bf 100644 (file)
@@ -72,6 +72,14 @@ void Connector::setup()
                if (enc)
                        m_current_crtc = enc->get_crtc();
        }
+
+       m_saved_crtc = m_current_crtc;
+}
+
+void Connector::restore_mode()
+{
+       if (m_saved_crtc)
+               m_saved_crtc->restore_mode(this);
 }
 
 void Connector::print_short() const
index 84845d5326b8c2235ff551b5d5953747150e541e..56ac3152721c754a88856db1894fc850b19116ee 100644 (file)
@@ -42,11 +42,14 @@ private:
        ~Connector();
 
        void setup();
+       void restore_mode();
 
        ConnectorPriv* m_priv;
 
        std::string m_fullname;
 
        Crtc* m_current_crtc;
+
+       Crtc* m_saved_crtc;
 };
 }
index b0a962e2d4af542e2ccb2ab1bc2a7d1b6fba64ab..9716c97c2fa92a324be5a32b209e099b28adbdb9 100644 (file)
@@ -39,6 +39,17 @@ void Crtc::setup()
        }
 }
 
+void Crtc::restore_mode(Connector* conn)
+{
+       auto c = m_priv->drm_crtc;
+
+       uint32_t conns[] = { conn->id() };
+
+       drmModeSetCrtc(card().fd(), id(), c->buffer_id,
+                      c->x, c->y,
+                      conns, 1, &c->mode);
+}
+
 void Crtc::print_short() const
 {
        auto c  = m_priv->drm_crtc;
index d30d4972dda0113fbbbbdf2514b3428ce9d56d29..1cbf4c45b55bdf0cf8e175c99cb8063a2994aadc 100644 (file)
@@ -12,6 +12,7 @@ struct CrtcPriv;
 class Crtc : public DrmObject
 {
        friend class Card;
+       friend class Connector;
 public:
        void print_short() const;
 
@@ -30,6 +31,7 @@ private:
        ~Crtc();
 
        void setup();
+       void restore_mode(Connector *conn);
 
        CrtcPriv* m_priv;