summaryrefslogtreecommitdiff
path: root/kms++/src/videomode.cpp
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2019-10-02 12:19:10 +0300
committerGitHub <noreply@github.com>2019-10-02 12:19:10 +0300
commit934416e1dfa8222a0a1746a5a0951e2b08d02eae (patch)
treefaec976b3629eaa61335b781d1b0527c66d14c69 /kms++/src/videomode.cpp
parent6140ae4ef4ca98e3dcd9ac4aa5442abcfd44551b (diff)
parent21de1ab0f0ed584ee99b36134f4c44e9fe0fa403 (diff)
Merge pull request #37 from tomba/work
Formatting changes and testmodes.py
Diffstat (limited to 'kms++/src/videomode.cpp')
-rw-r--r--kms++/src/videomode.cpp54
1 files changed, 47 insertions, 7 deletions
diff --git a/kms++/src/videomode.cpp b/kms++/src/videomode.cpp
index b8bd797..7099898 100644
--- a/kms++/src/videomode.cpp
+++ b/kms++/src/videomode.cpp
@@ -2,6 +2,7 @@
#include <xf86drmMode.h>
#include <math.h>
#include <sstream>
+#include <fmt/format.h>
#include <kms++/kms++.h>
#include "helpers.h"
@@ -88,14 +89,53 @@ void Videomode::set_vsync(SyncPolarity pol)
}
}
-string Videomode::to_string() const
+string Videomode::to_string_short() const
{
- std::stringstream ss;
- ss << hdisplay << "x" << vdisplay;
- if (interlace())
- ss << "i";
- ss << "@" << calculated_vrefresh();
- return ss.str();
+ return fmt::format("{}x{}{}@{:.2f}", hdisplay, vdisplay, interlace() ? "i" : "", calculated_vrefresh());
+}
+
+static char sync_to_char(SyncPolarity pol)
+{
+ switch (pol) {
+ case SyncPolarity::Positive:
+ return '+';
+ case SyncPolarity::Negative:
+ return '-';
+ default:
+ return '?';
+ }
+}
+
+string Videomode::to_string_long() const
+{
+ string h = fmt::format("{}/{}/{}/{}/{}", hdisplay, hfp(), hsw(), hbp(), sync_to_char(hsync()));
+ string v = fmt::format("{}/{}/{}/{}/{}", vdisplay, vfp(), vsw(), vbp(), sync_to_char(vsync()));
+
+ string str = fmt::format("{} {:.3f} {} {} {} ({:.2f}) {:#x} {:#x}",
+ to_string_short(),
+ clock / 1000.0,
+ h, v,
+ vrefresh, calculated_vrefresh(),
+ flags,
+ type);
+
+ return str;
+}
+
+string Videomode::to_string_long_padded() const
+{
+ string h = fmt::format("{}/{}/{}/{}/{}", hdisplay, hfp(), hsw(), hbp(), sync_to_char(hsync()));
+ string v = fmt::format("{}/{}/{}/{}/{}", vdisplay, vfp(), vsw(), vbp(), sync_to_char(vsync()));
+
+ string str = fmt::format("{:<16} {:7.3f} {:<18} {:<18} {:2} ({:.2f}) {:#10x} {:#6x}",
+ to_string_short(),
+ clock / 1000.0,
+ h, v,
+ vrefresh, calculated_vrefresh(),
+ flags,
+ type);
+
+ return str;
}
Videomode videomode_from_timings(uint32_t clock_khz,