]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-kmsxx.git/commitdiff
Connector: improve get_mode(string)
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Fri, 20 Oct 2017 08:33:31 +0000 (11:33 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Fri, 20 Oct 2017 08:33:31 +0000 (11:33 +0300)
kms++/src/connector.cpp

index 91414317556b32f5f3c8bd59f6c2f89ac4b8d68c..47759be108b830aa1a9dc2efbe102c3f656dde86 100644 (file)
@@ -130,11 +130,24 @@ Videomode Connector::get_mode(const string& mode) const
 {
        auto c = m_priv->drm_connector;
 
-       for (int i = 0; i < c->count_modes; i++)
-                if (mode == c->modes[i].name)
-                        return drm_mode_to_video_mode(c->modes[i]);
+       size_t idx = mode.find('@');
 
-        throw invalid_argument(mode + ": mode not found");
+       string name = idx == string::npos ? mode : mode.substr(0, idx);
+       float vrefresh = idx == string::npos ? 0.0 : stod(mode.substr(idx + 1));
+
+       for (int i = 0; i < c->count_modes; i++) {
+               Videomode m = drm_mode_to_video_mode(c->modes[i]);
+
+               if (m.name != name)
+                       continue;
+
+               if (vrefresh && vrefresh != m.calculated_vrefresh())
+                       continue;
+
+               return m;
+       }
+
+       throw invalid_argument(mode + ": mode not found");
 }
 
 Videomode Connector::get_mode(unsigned xres, unsigned yres, float vrefresh, bool ilace) const