summaryrefslogtreecommitdiff
path: root/kms++
diff options
context:
space:
mode:
Diffstat (limited to 'kms++')
-rw-r--r--kms++/src/connector.cpp19
-rw-r--r--kms++/src/modedb.cpp19
-rw-r--r--kms++/src/videomode.cpp4
3 files changed, 39 insertions, 3 deletions
diff --git a/kms++/src/connector.cpp b/kms++/src/connector.cpp
index 92700af..7c6c179 100644
--- a/kms++/src/connector.cpp
+++ b/kms++/src/connector.cpp
@@ -132,7 +132,24 @@ Videomode Connector::get_mode(unsigned xres, unsigned yres, float vrefresh, bool
if (ilace != m.interlace())
continue;
- if (vrefresh && std::abs(m.calculated_vrefresh() - vrefresh) >= 0.001)
+ if (vrefresh && vrefresh != m.calculated_vrefresh())
+ continue;
+
+ return m;
+ }
+
+ // If not found, do another round using rounded vrefresh
+
+ for (int i = 0; i < c->count_modes; i++) {
+ Videomode m = drm_mode_to_video_mode(c->modes[i]);
+
+ if (m.hdisplay != xres || m.vdisplay != yres)
+ continue;
+
+ if (ilace != m.interlace())
+ continue;
+
+ if (vrefresh && vrefresh != roundf(m.calculated_vrefresh()))
continue;
return m;
diff --git a/kms++/src/modedb.cpp b/kms++/src/modedb.cpp
index 858c3d0..5d5d373 100644
--- a/kms++/src/modedb.cpp
+++ b/kms++/src/modedb.cpp
@@ -20,7 +20,24 @@ static const Videomode& find_from_table(const Videomode* modes, uint32_t width,
if (ilace != m.interlace())
continue;
- if (vrefresh && std::abs(m.calculated_vrefresh() - vrefresh) >= 0.001)
+ 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;
diff --git a/kms++/src/videomode.cpp b/kms++/src/videomode.cpp
index 107ee3b..f675914 100644
--- a/kms++/src/videomode.cpp
+++ b/kms++/src/videomode.cpp
@@ -1,5 +1,6 @@
#include <xf86drm.h>
#include <xf86drmMode.h>
+#include <math.h>
#include <kms++/kms++.h>
#include "helpers.h"
@@ -18,7 +19,8 @@ unique_ptr<Blob> Videomode::to_blob(Card& card) const
float Videomode::calculated_vrefresh() const
{
- return (clock * 1000.0) / (htotal * vtotal) * (interlace() ? 2 : 1);
+ float refresh = (clock * 1000.0) / (htotal * vtotal) * (interlace() ? 2 : 1);
+ return roundf(refresh * 100.0) / 100.0;
}
bool Videomode::interlace() const