summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--kms++/CMakeLists.txt2
-rw-r--r--kms++/inc/kms++/videomode.h4
-rw-r--r--kms++/src/videomode.cpp54
-rw-r--r--py/pykms/pykmsbase.cpp3
-rw-r--r--utils/kmsprint.cpp11
-rw-r--r--utils/kmstest.cpp28
-rw-r--r--utils/wbcap.cpp4
8 files changed, 60 insertions, 48 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f2f24fe..216f537 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,6 +79,8 @@ add_subdirectory(kms++)
add_subdirectory(kms++util)
add_subdirectory(utils)
+add_subdirectory(ext/fmt)
+
if(KMSXX_ENABLE_KMSCUBE)
add_subdirectory(kmscube)
endif()
diff --git a/kms++/CMakeLists.txt b/kms++/CMakeLists.txt
index 10352a2..1ca8815 100644
--- a/kms++/CMakeLists.txt
+++ b/kms++/CMakeLists.txt
@@ -22,7 +22,7 @@ target_include_directories(kms++ PUBLIC
$<INSTALL_INTERFACE:include>
PRIVATE src)
-target_link_libraries(kms++ ${LIBDRM_LIBRARIES} ${LIBDRM_OMAP_LIBRARIES})
+target_link_libraries(kms++ ${LIBDRM_LIBRARIES} ${LIBDRM_OMAP_LIBRARIES} fmt::fmt)
set_target_properties(kms++ PROPERTIES
PUBLIC_HEADER "${PUB_HDRS}")
diff --git a/kms++/inc/kms++/videomode.h b/kms++/inc/kms++/videomode.h
index d7f5258..74aa8f1 100644
--- a/kms++/inc/kms++/videomode.h
+++ b/kms++/inc/kms++/videomode.h
@@ -49,7 +49,9 @@ struct Videomode
void set_hsync(SyncPolarity pol);
void set_vsync(SyncPolarity pol);
- std::string to_string() const;
+ std::string to_string_short() const;
+ std::string to_string_long() const;
+ std::string to_string_long_padded() const;
};
struct Videomode videomode_from_timings(uint32_t clock_khz,
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,
diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp
index 668e6e3..b4dc090 100644
--- a/py/pykms/pykmsbase.cpp
+++ b/py/pykms/pykmsbase.cpp
@@ -229,6 +229,9 @@ void init_pykmsbase(py::module &m)
.def_property("hsync", &Videomode::hsync, &Videomode::set_hsync)
.def_property("vsync", &Videomode::vsync, &Videomode::set_vsync)
+
+ .def("to_string_short", &Videomode::to_string_short)
+ .def("to_string_long", &Videomode::to_string_long)
;
diff --git a/utils/kmsprint.cpp b/utils/kmsprint.cpp
index 116fead..01913fb 100644
--- a/utils/kmsprint.cpp
+++ b/utils/kmsprint.cpp
@@ -34,16 +34,7 @@ static string format_mode(const Videomode& m, unsigned idx)
m.flags,
m.type);
} else {
- string h = sformat("%u/%u/%u/%u", m.hdisplay, m.hfp(), m.hsw(), m.hbp());
- string v = sformat("%u/%u/%u/%u", m.vdisplay, m.vfp(), m.vsw(), m.vbp());
-
- str += sformat("%-12s %7.3f %-16s %-16s %2u (%.2f) %#10x %#6x",
- m.name.c_str(),
- m.clock / 1000.0,
- h.c_str(), v.c_str(),
- m.vrefresh, m.calculated_vrefresh(),
- m.flags,
- m.type);
+ str += m.to_string_long_padded();
}
return str;
diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp
index 8144117..2e3d054 100644
--- a/utils/kmstest.cpp
+++ b/utils/kmstest.cpp
@@ -691,32 +691,6 @@ static vector<OutputInfo> setups_to_outputs(Card& card, ResourceManager& resman,
return outputs;
}
-static char sync_to_char(SyncPolarity pol)
-{
- switch (pol) {
- case SyncPolarity::Positive:
- return '+';
- case SyncPolarity::Negative:
- return '-';
- default:
- return '?';
- }
-}
-
-static std::string videomode_to_string(const Videomode& m)
-{
- string h = sformat("%u/%u/%u/%u/%c", m.hdisplay, m.hfp(), m.hsw(), m.hbp(), sync_to_char(m.hsync()));
- string v = sformat("%u/%u/%u/%u/%c", m.vdisplay, m.vfp(), m.vsw(), m.vbp(), sync_to_char(m.vsync()));
-
- return sformat("%s %.3f %s %s %u (%.2f) %#x %#x",
- m.name.c_str(),
- m.clock / 1000.0,
- h.c_str(), v.c_str(),
- m.vrefresh, m.calculated_vrefresh(),
- m.flags,
- m.type);
-}
-
static void print_outputs(const vector<OutputInfo>& outputs)
{
for (unsigned i = 0; i < outputs.size(); ++i) {
@@ -735,7 +709,7 @@ static void print_outputs(const vector<OutputInfo>& outputs)
printf(" %s=%" PRIu64, prop.prop->name().c_str(),
prop.val);
- printf(": %s\n", videomode_to_string(o.mode).c_str());
+ printf(": %s\n", o.mode.to_string_long().c_str());
if (!o.legacy_fbs.empty()) {
auto fb = o.legacy_fbs[0];
diff --git a/utils/wbcap.cpp b/utils/wbcap.cpp
index 5a94a70..886fe36 100644
--- a/utils/wbcap.cpp
+++ b/utils/wbcap.cpp
@@ -342,9 +342,9 @@ int main(int argc, char** argv)
if (src_mode.interlace())
dst_height /= 2;
- printf("src %s, crtc %s\n", src_conn->fullname().c_str(), src_mode.to_string().c_str());
+ printf("src %s, crtc %s\n", src_conn->fullname().c_str(), src_mode.to_string_short().c_str());
- printf("dst %s, crtc %s\n", dst_conn->fullname().c_str(), dst_mode.to_string().c_str());
+ printf("dst %s, crtc %s\n", dst_conn->fullname().c_str(), dst_mode.to_string_short().c_str());
printf("src_fb %ux%u, dst_fb %ux%u\n", src_width, src_height, dst_width, dst_height);