Connector: add get_mode(xres, yres, refresh)
[android/external-libkmsxx.git] / libkms++ / connector.cpp
index e507c9e91cb159c17683882f0c798657d44cda58..5a6fdd93108f90bb9e14438a430a838786f92966 100644 (file)
@@ -114,6 +114,25 @@ Videomode Connector::get_mode(const string& mode) const
         throw invalid_argument(mode + ": mode not found");
 }
 
+Videomode Connector::get_mode(unsigned xres, unsigned yres, unsigned refresh) const
+{
+       auto c = m_priv->drm_connector;
+
+       for (int i = 0; i < c->count_modes; i++) {
+               drmModeModeInfo& m = c->modes[i];
+
+               if (m.hdisplay != xres || m.vdisplay != yres)
+                       continue;
+
+               if (refresh && m.vrefresh != refresh)
+                       continue;
+
+               return drm_mode_to_video_mode(c->modes[i]);
+       }
+
+       throw invalid_argument("mode not found");
+}
+
 bool Connector::connected() const
 {
        return m_priv->drm_connector->connection == DRM_MODE_CONNECTED ||