From dcb5a8c6c233824b59ce200f656b32e3fcac609d Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 28 Aug 2019 14:48:26 +0300 Subject: wbm2m: add informative prints --- utils/wbm2m.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'utils') diff --git a/utils/wbm2m.cpp b/utils/wbm2m.cpp index b69bb28..07074e5 100644 --- a/utils/wbm2m.cpp +++ b/utils/wbm2m.cpp @@ -101,9 +101,14 @@ int main(int argc, char** argv) exit(-1); } + printf("%ux%u-%s -> %ux%u-%s\n", src_width, src_height, PixelFormatToFourCC(src_fmt).c_str(), + dst_width, dst_height, PixelFormatToFourCC(dst_fmt).c_str()); + const string filename = sformat("wb-out-%ux%u_%4.4s.raw", dst_width, dst_height, PixelFormatToFourCC(dst_fmt).c_str()); + printf("writing to %s\n", filename.c_str()); + VideoDevice vid("/dev/video10"); Card card; -- cgit v1.2.3 From 40bc9d1095228ab1377625be3479491263d696d7 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 24 Sep 2019 12:52:14 +0300 Subject: videomode to_string improvements Add to_string_short() and to_string_long() to videomode (using the fmt library) for easy printing of videomodes. Signed-off-by: Tomi Valkeinen --- utils/kmsprint.cpp | 11 +---------- utils/kmstest.cpp | 28 +--------------------------- utils/wbcap.cpp | 4 ++-- 3 files changed, 4 insertions(+), 39 deletions(-) (limited to 'utils') 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 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& outputs) { for (unsigned i = 0; i < outputs.size(); ++i) { @@ -735,7 +709,7 @@ static void print_outputs(const vector& 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); -- cgit v1.2.3 From 7dd428f5c3eb6e9bf6ab2e1b902568d00f7f418d Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Tue, 24 Sep 2019 17:06:10 +0300 Subject: wbm2m: use fmt::format Signed-off-by: Tomi Valkeinen --- utils/wbm2m.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/wbm2m.cpp b/utils/wbm2m.cpp index 07074e5..71a26a5 100644 --- a/utils/wbm2m.cpp +++ b/utils/wbm2m.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -104,8 +105,8 @@ int main(int argc, char** argv) printf("%ux%u-%s -> %ux%u-%s\n", src_width, src_height, PixelFormatToFourCC(src_fmt).c_str(), dst_width, dst_height, PixelFormatToFourCC(dst_fmt).c_str()); - const string filename = sformat("wb-out-%ux%u_%4.4s.raw", dst_width, dst_height, - PixelFormatToFourCC(dst_fmt).c_str()); + const string filename = fmt::format("wb-out-{}x{}-{}.raw", dst_width, dst_height, + PixelFormatToFourCC(dst_fmt)); printf("writing to %s\n", filename.c_str()); -- cgit v1.2.3 From 9340290f8f36c37e1903cf2ae9d13395338ded91 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 25 Sep 2019 14:44:41 +0300 Subject: kmsprint: use fmt instead of printf and sformat Signed-off-by: Tomi Valkeinen --- utils/kmsprint.cpp | 82 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 39 deletions(-) (limited to 'utils') diff --git a/utils/kmsprint.cpp b/utils/kmsprint.cpp index 01913fb..61baec0 100644 --- a/utils/kmsprint.cpp +++ b/utils/kmsprint.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -22,11 +23,11 @@ static string format_mode(const Videomode& m, unsigned idx) { string str; - str = sformat(" %2u ", idx); + str = fmt::format(" {:2} ", idx); if (s_opts.x_modeline) { - str += sformat("%12s %6u %4u %4u %4u %4u %4u %4u %4u %4u %2u %#x %#x", - m.name.c_str(), + str += fmt::format("{:12} {:6} {:4} {:4} {:4} {:4} {:4} {:4} {:4} {:4} {:3} {:#x} {:#x}", + m.name, m.clock, m.hdisplay, m.hsync_start, m.hsync_end, m.htotal, m.vdisplay, m.vsync_start, m.vsync_end, m.vtotal, @@ -42,13 +43,13 @@ static string format_mode(const Videomode& m, unsigned idx) static string format_mode_short(const Videomode& m) { - 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()); + string h = fmt::format("{}/{}/{}/{}", m.hdisplay, m.hfp(), m.hsw(), m.hbp()); + string v = fmt::format("{}/{}/{}/{}", m.vdisplay, m.vfp(), m.vsw(), m.vbp()); - return sformat("%s %.3f %s %s %u (%.2f)", - m.name.c_str(), + return fmt::format("{} {:.3f} {} {} {} ({:.2f})", + m.name, m.clock / 1000.0, - h.c_str(), v.c_str(), + h, v, m.vrefresh, m.calculated_vrefresh()); } @@ -56,8 +57,8 @@ static string format_connector(Connector& c) { string str; - str = sformat("Connector %u (%u) %s", - c.idx(), c.id(), c.fullname().c_str()); + str = fmt::format("Connector {} ({}) {}", + c.idx(), c.id(), c.fullname()); switch (c.connector_status()) { case ConnectorStatus::Connected: @@ -76,15 +77,15 @@ static string format_connector(Connector& c) static string format_encoder(Encoder& e) { - return sformat("Encoder %u (%u) %s", - e.idx(), e.id(), e.get_encoder_type().c_str()); + return fmt::format("Encoder {} ({}) {}", + e.idx(), e.id(), e.get_encoder_type()); } static string format_crtc(Crtc& c) { string str; - str = sformat("Crtc %u (%u)", c.idx(), c.id()); + str = fmt::format("Crtc {} ({})", c.idx(), c.id()); if (c.mode_valid()) str += " " + format_mode_short(c.mode()); @@ -96,17 +97,17 @@ static string format_plane(Plane& p) { string str; - str = sformat("Plane %u (%u)", p.idx(), p.id()); + str = fmt::format("Plane {} ({})", p.idx(), p.id()); if (p.fb_id()) - str += sformat(" fb-id: %u", p.fb_id()); + str += fmt::format(" fb-id: {}", p.fb_id()); string crtcs = join(p.get_possible_crtcs(), " ", [](Crtc* crtc) { return to_string(crtc->idx()); }); - str += sformat(" (crtcs: %s)", crtcs.c_str()); + str += fmt::format(" (crtcs: {})", crtcs); if (p.card().has_atomic()) { - str += sformat(" %u,%u %ux%u -> %u,%u %ux%u", + str += fmt::format(" {},{} {}x{} -> {},{} {}x{}", (uint32_t)p.get_prop_value("SRC_X") >> 16, (uint32_t)p.get_prop_value("SRC_Y") >> 16, (uint32_t)p.get_prop_value("SRC_W") >> 16, @@ -119,20 +120,20 @@ static string format_plane(Plane& p) string fmts = join(p.get_formats(), " ", [](PixelFormat fmt) { return PixelFormatToFourCC(fmt); }); - str += sformat(" (%s)", fmts.c_str()); + str += fmt::format(" ({})", fmts); return str; } static string format_fb(Framebuffer& fb) { - return sformat("FB %u %ux%u", + return fmt::format("FB {} {}x{}", fb.id(), fb.width(), fb.height()); } static string format_property(const Property* prop, uint64_t val) { - string ret = sformat("%s (%u) = ", prop->name().c_str(), prop->id()); + string ret = fmt::format("{} ({}) = ", prop->name(), prop->id()); switch (prop->type()) { case PropertyType::Bitmask: @@ -142,10 +143,11 @@ static string format_property(const Property* prop, uint64_t val) for (auto kvp : prop->get_enums()) { if (val & (1 << kvp.first)) v.push_back(kvp.second); - vall.push_back(sformat("%s=0x%x", kvp.second.c_str(), 1 << kvp.first)); + vall.push_back(fmt::format("{}={:#x}", kvp.second, 1 << kvp.first)); } - ret += sformat("0x%" PRIx64 " (%s) [%s]", val, join(v, "|").c_str(), join(vall, "|").c_str()); + // XXX + ret += fmt::format("{:#x} ({}) [{}]", val, join(v, "|"), join(vall, "|")); break; } @@ -158,9 +160,9 @@ static string format_property(const Property* prop, uint64_t val) Blob blob(prop->card(), blob_id); auto data = blob.data(); - ret += sformat("blob-id %u len %zu", blob_id, data.size()); + ret += fmt::format("blob-id {} len {}", blob_id, data.size()); } else { - ret += sformat("blob-id %u", blob_id); + ret += fmt::format("blob-id {}", blob_id); } break; @@ -174,17 +176,17 @@ static string format_property(const Property* prop, uint64_t val) for (auto kvp : prop->get_enums()) { if (val == kvp.first) cur = kvp.second; - vall.push_back(sformat("%s=%" PRIu64, kvp.second.c_str(), kvp.first)); + vall.push_back(fmt::format("{}={}", kvp.second, kvp.first)); } - ret += sformat("%" PRIu64 " (%s) [%s]", val, cur.c_str(), join(vall, "|").c_str()); + ret += fmt::format("{} ({}) [{}]", val, cur, join(vall, "|")); break; } case PropertyType::Object: { - ret += sformat("object id %u", (uint32_t)val); + ret += fmt::format("object id {}", val); break; } @@ -192,7 +194,7 @@ static string format_property(const Property* prop, uint64_t val) { auto values = prop->get_values(); - ret += sformat("%" PRIu64 " [%" PRIu64 " - %" PRIu64 "]", + ret += fmt::format("{} [{} - {}]", val, values[0], values[1]); break; @@ -202,7 +204,7 @@ static string format_property(const Property* prop, uint64_t val) { auto values = prop->get_values(); - ret += sformat("%" PRIi64 " [%" PRIi64 " - %" PRIi64 "]", + ret += fmt::format("{} [{} - {}]", (int64_t)val, (int64_t)values[0], (int64_t)values[1]); break; @@ -308,14 +310,16 @@ static const map glyphs_ascii = { }; -const char* get_glyph(TreeGlyph glyph) +const string& get_glyph(TreeGlyph glyph) { + static const string s_empty = " "; + if (s_glyph_mode == TreeGlyphMode::None) - return " "; + return s_empty; const map& glyphs = s_glyph_mode == TreeGlyphMode::UTF8 ? glyphs_utf8 : glyphs_ascii; - return glyphs.at(glyph).c_str(); + return glyphs.at(glyph); } static void print_entry(const Entry& e, const string& prefix, bool is_child, bool is_last) @@ -328,7 +332,7 @@ static void print_entry(const Entry& e, const string& prefix, bool is_child, boo prefix2 = prefix + (is_last ? get_glyph(TreeGlyph::Space) : get_glyph(TreeGlyph::Vertical)); } - printf("%s%s\n", prefix1.c_str(), e.title.c_str()); + fmt::print("{}{}\n", prefix1, e.title); bool has_children = e.children.size() > 0; @@ -336,7 +340,7 @@ static void print_entry(const Entry& e, const string& prefix, bool is_child, boo for (const string& str : e.lines) { string p = data_prefix + get_glyph(TreeGlyph::Space); - printf("%s%s\n", p.c_str(), str.c_str()); + fmt::print("{}{}\n", p, str); } for (const Entry& child : e.children) { @@ -390,16 +394,16 @@ static void print_as_list(Card& card) } for (DrmPropObject* ob: obs) { - printf("%s\n", format_ob(ob).c_str()); + fmt::print("{}\n", format_ob(ob)); if (s_opts.print_props) { for (string str : format_props(ob)) - printf(" %s\n", str.c_str()); + fmt::print(" {}\n", str); } } for (Framebuffer* fb: fbs) { - printf("%s\n", format_ob(fb).c_str()); + fmt::print("{}\n", format_ob(fb)); } } @@ -464,11 +468,11 @@ static void print_modes(Card& card) if (!conn->connected()) continue; - printf("%s\n", format_ob(conn).c_str()); + fmt::print("{}\n", format_ob(conn)); auto modes = conn->get_modes(); for (unsigned i = 0; i < modes.size(); ++i) - printf("%s\n", format_mode(modes[i], i).c_str()); + fmt::print("{}\n", format_mode(modes[i], i)); } } -- cgit v1.2.3