]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blobdiff - kms++/src/modedb.cpp
Improve mode finding
[android/external-libkmsxx.git] / kms++ / src / modedb.cpp
index 24d6f63d1d22de2e9e64d9ddf0734f00fcda2be2..5d5d373ba95ca64bd7aa01c947094280b13e3679 100644 (file)
@@ -1,5 +1,6 @@
 #include <xf86drm.h>
 #include <stdexcept>
+#include <cmath>
 
 #include <kms++/modedb.h>
 
@@ -8,7 +9,7 @@ using namespace std;
 namespace kms
 {
 
-static const Videomode& find_from_table(const Videomode* modes, uint32_t width, uint32_t height, uint32_t refresh, bool ilace)
+static const Videomode& find_from_table(const Videomode* modes, uint32_t width, uint32_t height, float vrefresh, bool ilace)
 {
        for (unsigned i = 0; modes[i].clock; ++i) {
                const Videomode& m = modes[i];
@@ -16,10 +17,27 @@ static const Videomode& find_from_table(const Videomode* modes, uint32_t width,
                if (m.hdisplay != width || m.vdisplay != height)
                        continue;
 
-               if (refresh && m.vrefresh != refresh)
+               if (ilace != m.interlace())
                        continue;
 
-               if (ilace != !!(m.flags & DRM_MODE_FLAG_INTERLACE))
+               if (vrefresh && vrefresh != m.calculated_vrefresh())
+                       continue;
+
+               return m;
+       }
+
+       // If not found, do another round using rounded vrefresh
+
+       for (unsigned i = 0; modes[i].clock; ++i) {
+               const Videomode& m = modes[i];
+
+               if (m.hdisplay != width || m.vdisplay != height)
+                       continue;
+
+               if (ilace != m.interlace())
+                       continue;
+
+               if (vrefresh && vrefresh != roundf(m.calculated_vrefresh()))
                        continue;
 
                return m;
@@ -28,14 +46,14 @@ static const Videomode& find_from_table(const Videomode* modes, uint32_t width,
        throw invalid_argument("mode not found");
 }
 
-const Videomode& find_dmt(uint32_t width, uint32_t height, uint32_t refresh, bool ilace)
+const Videomode& find_dmt(uint32_t width, uint32_t height, float vrefresh, bool ilace)
 {
-       return find_from_table(dmt_modes, width, height, refresh, ilace);
+       return find_from_table(dmt_modes, width, height, vrefresh, ilace);
 }
 
-const Videomode& find_cea(uint32_t width, uint32_t height, uint32_t refresh, bool ilace)
+const Videomode& find_cea(uint32_t width, uint32_t height, float vrefresh, bool ilace)
 {
-       return find_from_table(cea_modes, width, height, refresh, ilace);
+       return find_from_table(cea_modes, width, height, vrefresh, ilace);
 }
 
 }