From d9a1ffe56d0beb9cdd048d0e83f7d0177b31411a Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 7 Oct 2020 08:58:35 +0300 Subject: Bulk format of all files --- utils/kmstest.cpp | 314 +++++++++++++++++++++++++----------------------------- 1 file changed, 144 insertions(+), 170 deletions(-) (limited to 'utils/kmstest.cpp') diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp index b4bf24b..981a2fd 100644 --- a/utils/kmstest.cpp +++ b/utils/kmstest.cpp @@ -21,15 +21,15 @@ using namespace std; using namespace kms; struct PropInfo { - PropInfo(string n, uint64_t v) : prop(NULL), name(n), val(v) {} + PropInfo(string n, uint64_t v) + : prop(NULL), name(n), val(v) {} - Property *prop; + Property* prop; string name; uint64_t val; }; -struct PlaneInfo -{ +struct PlaneInfo { Plane* plane; unsigned x; @@ -47,8 +47,7 @@ struct PlaneInfo vector props; }; -struct OutputInfo -{ +struct OutputInfo { Connector* connector; Crtc* crtc; @@ -72,8 +71,7 @@ static bool s_cvt_vid_opt; static unsigned s_max_flips; static bool s_print_crc; -__attribute__ ((unused)) -static void print_regex_match(smatch sm) +__attribute__((unused)) static void print_regex_match(smatch sm) { for (unsigned i = 0; i < sm.size(); ++i) { string str = sm[i].str(); @@ -100,11 +98,10 @@ static void get_default_crtc(ResourceManager& resman, OutputInfo& output) EXIT("Could not find available crtc"); } - -static PlaneInfo *add_default_planeinfo(OutputInfo* output) +static PlaneInfo* add_default_planeinfo(OutputInfo* output) { - output->planes.push_back(PlaneInfo { }); - PlaneInfo *ret = &output->planes.back(); + output->planes.push_back(PlaneInfo{}); + PlaneInfo* ret = &output->planes.back(); ret->w = output->mode.hdisplay; ret->h = output->mode.vdisplay; return ret; @@ -115,16 +112,16 @@ static void parse_crtc(ResourceManager& resman, Card& card, const string& crtc_s // @12:1920x1200i@60 // @12:33000000,800/210/30/16/-,480/22/13/10/-,i - const regex modename_re("(?:(@?)(\\d+):)?" // @12: - "(?:(\\d+)x(\\d+)(i)?)" // 1920x1200i - "(?:@([\\d\\.]+))?"); // @60 + const regex modename_re("(?:(@?)(\\d+):)?" // @12: + "(?:(\\d+)x(\\d+)(i)?)" // 1920x1200i + "(?:@([\\d\\.]+))?"); // @60 - const regex modeline_re("(?:(@?)(\\d+):)?" // @12: - "(\\d+)," // 33000000, - "(\\d+)/(\\d+)/(\\d+)/(\\d+)/([+-])," // 800/210/30/16/-, - "(\\d+)/(\\d+)/(\\d+)/(\\d+)/([+-])" // 480/22/13/10/- - "(?:,([i]+))?" // ,i - ); + const regex modeline_re("(?:(@?)(\\d+):)?" // @12: + "(\\d+)," // 33000000, + "(\\d+)/(\\d+)/(\\d+)/(\\d+)/([+-])," // 800/210/30/16/-, + "(\\d+)/(\\d+)/(\\d+)/(\\d+)/([+-])" // 480/22/13/10/- + "(?:,([i]+))?" // ,i + ); smatch sm; if (regex_match(crtc_str, sm, modename_re)) { @@ -246,9 +243,9 @@ static void parse_crtc(ResourceManager& resman, Card& card, const string& crtc_s static void parse_plane(ResourceManager& resman, Card& card, const string& plane_str, const OutputInfo& output, PlaneInfo& pinfo) { // 3:400,400-400x400 - const regex plane_re("(?:(@?)(\\d+):)?" // 3: - "(?:(\\d+),(\\d+)-)?" // 400,400- - "(\\d+)x(\\d+)"); // 400x400 + const regex plane_re("(?:(@?)(\\d+):)?" // 3: + "(?:(\\d+),(\\d+)-)?" // 400,400- + "(\\d+)x(\\d+)"); // 400x400 smatch sm; if (!regex_match(plane_str, sm, plane_re)) @@ -292,7 +289,7 @@ static void parse_plane(ResourceManager& resman, Card& card, const string& plane pinfo.y = output.mode.vdisplay / 2 - pinfo.h / 2; } -static void parse_prop(const string& prop_str, vector &props) +static void parse_prop(const string& prop_str, vector& props) { string name, val; @@ -302,12 +299,12 @@ static void parse_prop(const string& prop_str, vector &props) EXIT("Equal sign ('=') not found in %s", prop_str.c_str()); name = prop_str.substr(0, split); - val = prop_str.substr(split+1); + val = prop_str.substr(split + 1); props.push_back(PropInfo(name, stoull(val, 0, 0))); } -static void get_props(Card& card, vector &props, const DrmPropObject* propobj) +static void get_props(Card& card, vector& props, const DrmPropObject* propobj) { for (auto& pi : props) pi.prop = propobj->get_prop(pi.name); @@ -339,9 +336,9 @@ static void parse_fb(Card& card, const string& fb_str, OutputInfo* output, Plane if (!fb_str.empty()) { // XXX the regexp is not quite correct // 400x400-NV12 - const regex fb_re("(?:(\\d+)x(\\d+))?" // 400x400 - "(?:-)?" // - - "(\\w\\w\\w\\w)?"); // NV12 + const regex fb_re("(?:(\\d+)x(\\d+))?" // 400x400 + "(?:-)?" // - + "(\\w\\w\\w\\w)?"); // NV12 smatch sm; if (!regex_match(fb_str, sm, fb_re)) @@ -368,7 +365,7 @@ static void parse_fb(Card& card, const string& fb_str, OutputInfo* output, Plane static void parse_view(const string& view_str, PlaneInfo& pinfo) { - const regex view_re("(\\d+),(\\d+)-(\\d+)x(\\d+)"); // 400,400-400x400 + const regex view_re("(\\d+),(\\d+)-(\\d+)x(\\d+)"); // 400,400-400x400 smatch sm; if (!regex_match(view_str, sm, view_re)) @@ -381,56 +378,54 @@ static void parse_view(const string& view_str, PlaneInfo& pinfo) } static const char* usage_str = - "Usage: kmstest [OPTION]...\n\n" - "Show a test pattern on a display or plane\n\n" - "Options:\n" - " --device=DEVICE DEVICE is the path to DRM card to open\n" - " -c, --connector=CONN CONN is \n" - " -r, --crtc=CRTC CRTC is [:]x[@]\n" - " or\n" - " [:],////,////[,i]\n" - " -p, --plane=PLANE PLANE is [:][,-]x\n" - " -f, --fb=FB FB is [x][-][<4cc>]\n" - " -v, --view=VIEW VIEW is ,-x\n" - " -P, --property=PROP=VAL Set PROP to VAL in the previous DRM object\n" - " --dmt Search for the given mode from DMT tables\n" - " --cea Search for the given mode from CEA tables\n" - " --cvt=CVT Create videomode with CVT. CVT is 'v1', 'v2' or 'v2o'\n" - " --flip[=max] Do page flipping for each output with an optional maximum flips count\n" - " --sync Synchronize page flipping\n" - " --crc Print CRC16 for framebuffer contents\n" - "\n" - ", and can be given by index () or id (@).\n" - " can also be given by name.\n" - "\n" - "Options can be given multiple times to set up multiple displays or planes.\n" - "Options may apply to previous options, e.g. a plane will be set on a crtc set in\n" - "an earlier option.\n" - "If you omit parameters, kmstest tries to guess what you mean\n" - "\n" - "Examples:\n" - "\n" - "Set eDP-1 mode to 1920x1080@60, show XR24 framebuffer on the crtc, and a 400x400 XB24 plane:\n" - " kmstest -c eDP-1 -r 1920x1080@60 -f XR24 -p 400x400 -f XB24\n\n" - "XR24 framebuffer on first connected connector in the default mode:\n" - " kmstest -f XR24\n\n" - "XR24 framebuffer on a 400x400 plane on the first connected connector in the default mode:\n" - " kmstest -p 400x400 -f XR24\n\n" - "Test pattern on the second connector with default mode:\n" - " kmstest -c 1\n" - "\n" - "Environmental variables:\n" - " KMSXX_DISABLE_UNIVERSAL_PLANES Don't enable universal planes even if available\n" - " KMSXX_DISABLE_ATOMIC Don't enable atomic modesetting even if available\n" - ; + "Usage: kmstest [OPTION]...\n\n" + "Show a test pattern on a display or plane\n\n" + "Options:\n" + " --device=DEVICE DEVICE is the path to DRM card to open\n" + " -c, --connector=CONN CONN is \n" + " -r, --crtc=CRTC CRTC is [:]x[@]\n" + " or\n" + " [:],////,////[,i]\n" + " -p, --plane=PLANE PLANE is [:][,-]x\n" + " -f, --fb=FB FB is [x][-][<4cc>]\n" + " -v, --view=VIEW VIEW is ,-x\n" + " -P, --property=PROP=VAL Set PROP to VAL in the previous DRM object\n" + " --dmt Search for the given mode from DMT tables\n" + " --cea Search for the given mode from CEA tables\n" + " --cvt=CVT Create videomode with CVT. CVT is 'v1', 'v2' or 'v2o'\n" + " --flip[=max] Do page flipping for each output with an optional maximum flips count\n" + " --sync Synchronize page flipping\n" + " --crc Print CRC16 for framebuffer contents\n" + "\n" + ", and can be given by index () or id (@).\n" + " can also be given by name.\n" + "\n" + "Options can be given multiple times to set up multiple displays or planes.\n" + "Options may apply to previous options, e.g. a plane will be set on a crtc set in\n" + "an earlier option.\n" + "If you omit parameters, kmstest tries to guess what you mean\n" + "\n" + "Examples:\n" + "\n" + "Set eDP-1 mode to 1920x1080@60, show XR24 framebuffer on the crtc, and a 400x400 XB24 plane:\n" + " kmstest -c eDP-1 -r 1920x1080@60 -f XR24 -p 400x400 -f XB24\n\n" + "XR24 framebuffer on first connected connector in the default mode:\n" + " kmstest -f XR24\n\n" + "XR24 framebuffer on a 400x400 plane on the first connected connector in the default mode:\n" + " kmstest -p 400x400 -f XR24\n\n" + "Test pattern on the second connector with default mode:\n" + " kmstest -c 1\n" + "\n" + "Environmental variables:\n" + " KMSXX_DISABLE_UNIVERSAL_PLANES Don't enable universal planes even if available\n" + " KMSXX_DISABLE_ATOMIC Don't enable atomic modesetting even if available\n"; static void usage() { puts(usage_str); } -enum class ArgType -{ +enum class ArgType { Connector, Crtc, Plane, @@ -439,70 +434,57 @@ enum class ArgType Property, }; -struct Arg -{ +struct Arg { ArgType type; string arg; }; static string s_device_path; -static vector parse_cmdline(int argc, char **argv) +static vector parse_cmdline(int argc, char** argv) { vector args; OptionSet optionset = { Option("|device=", - [&](string s) - { - s_device_path = s; - }), + [&](string s) { + s_device_path = s; + }), Option("c|connector=", - [&](string s) - { - args.push_back(Arg { ArgType::Connector, s }); - }), - Option("r|crtc=", [&](string s) - { - args.push_back(Arg { ArgType::Crtc, s }); + [&](string s) { + args.push_back(Arg{ ArgType::Connector, s }); + }), + Option("r|crtc=", [&](string s) { + args.push_back(Arg{ ArgType::Crtc, s }); }), - Option("p|plane=", [&](string s) - { - args.push_back(Arg { ArgType::Plane, s }); + Option("p|plane=", [&](string s) { + args.push_back(Arg{ ArgType::Plane, s }); }), - Option("f|fb=", [&](string s) - { - args.push_back(Arg { ArgType::Framebuffer, s }); + Option("f|fb=", [&](string s) { + args.push_back(Arg{ ArgType::Framebuffer, s }); }), - Option("v|view=", [&](string s) - { - args.push_back(Arg { ArgType::View, s }); + Option("v|view=", [&](string s) { + args.push_back(Arg{ ArgType::View, s }); }), - Option("P|property=", [&](string s) - { - args.push_back(Arg { ArgType::Property, s }); + Option("P|property=", [&](string s) { + args.push_back(Arg{ ArgType::Property, s }); }), - Option("|dmt", []() - { + Option("|dmt", []() { s_use_dmt = true; }), - Option("|cea", []() - { + Option("|cea", []() { s_use_cea = true; }), - Option("|flip?", [&](string s) - { + Option("|flip?", [&](string s) { s_flip_mode = true; s_num_buffers = 2; if (!s.empty()) s_max_flips = stoi(s); }), - Option("|sync", []() - { + Option("|sync", []() { s_flip_sync = true; }), - Option("|cvt=", [&](string s) - { + Option("|cvt=", [&](string s) { if (s == "v1") s_cvt = true; else if (s == "v2") @@ -517,8 +499,7 @@ static vector parse_cmdline(int argc, char **argv) Option("|crc", []() { s_print_crc = true; }), - Option("h|help", [&]() - { + Option("h|help", [&]() { usage(); exit(-1); }), @@ -543,9 +524,8 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, for (auto& arg : output_args) { switch (arg.type) { - case ArgType::Connector: - { - outputs.push_back(OutputInfo { }); + case ArgType::Connector: { + outputs.push_back(OutputInfo{}); current_output = &outputs.back(); get_connector(resman, *current_output, arg.arg); @@ -554,10 +534,9 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::Crtc: - { + case ArgType::Crtc: { if (!current_output) { - outputs.push_back(OutputInfo { }); + outputs.push_back(OutputInfo{}); current_output = &outputs.back(); } @@ -571,10 +550,9 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::Plane: - { + case ArgType::Plane: { if (!current_output) { - outputs.push_back(OutputInfo { }); + outputs.push_back(OutputInfo{}); current_output = &outputs.back(); } @@ -591,10 +569,9 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::Framebuffer: - { + case ArgType::Framebuffer: { if (!current_output) { - outputs.push_back(OutputInfo { }); + outputs.push_back(OutputInfo{}); current_output = &outputs.back(); } @@ -612,8 +589,7 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::View: - { + case ArgType::View: { if (!current_plane || current_plane->fbs.empty()) EXIT("'view' parameter requires a plane and a fb"); @@ -621,8 +597,7 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, break; } - case ArgType::Property: - { + case ArgType::Property: { if (!current_output) EXIT("No object to which set the property"); @@ -646,7 +621,7 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, if (!conn->connected()) continue; - OutputInfo output = { }; + OutputInfo output = {}; output.connector = resman.reserve_connector(conn); EXIT_IF(!output.connector, "Failed to reserve connector %s", conn->fullname().c_str()); output.crtc = resman.reserve_crtc(conn); @@ -676,7 +651,7 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, o.legacy_fbs = get_default_fb(card, o.mode.hdisplay, o.mode.vdisplay); } - for (PlaneInfo &p : o.planes) { + for (PlaneInfo& p : o.planes) { if (p.fbs.empty()) p.fbs = get_default_fb(card, p.w, p.h); } @@ -704,7 +679,7 @@ static uint16_t crc16(uint16_t crc, uint8_t data) for (uint8_t i = 0; i < 8; i++) { if (((crc & 0x8000) >> 8) ^ (data & 0x80)) - crc = (crc << 1) ^ CRC16_IBM; + crc = (crc << 1) ^ CRC16_IBM; else crc = (crc << 1); @@ -714,16 +689,16 @@ static uint16_t crc16(uint16_t crc, uint8_t data) return crc; } -static string fb_crc(IFramebuffer *fb) +static string fb_crc(IFramebuffer* fb) { - uint8_t *p = fb->map(0); + uint8_t* p = fb->map(0); uint16_t r, g, b; r = g = b = 0; for (unsigned y = 0; y < fb->height(); ++y) { for (unsigned x = 0; x < fb->width(); ++x) { - uint32_t *p32 = (uint32_t*)(p + fb->stride(0) * y + x * 4); + uint32_t* p32 = (uint32_t*)(p + fb->stride(0) * y + x * 4); RGB rgb(*p32); r = crc16(r, rgb.r); @@ -748,12 +723,12 @@ static void print_outputs(const vector& outputs) fmt::print("Connector {}/@{}: {}", o.connector->idx(), o.connector->id(), o.connector->fullname()); - for (const PropInfo &prop: o.conn_props) + for (const PropInfo& prop : o.conn_props) fmt::print(" {}={}", prop.prop->name(), prop.val); fmt::print("\n Crtc {}/@{}", o.crtc->idx(), o.crtc->id()); - for (const PropInfo &prop: o.crtc_props) + for (const PropInfo& prop : o.crtc_props) fmt::print(" {}={}", prop.prop->name(), prop.val); fmt::print(": {}\n", o.mode.to_string_long()); @@ -768,7 +743,7 @@ static void print_outputs(const vector& outputs) auto fb = p.fbs[0]; fmt::print(" Plane {}/@{}: {},{}-{}x{}", p.plane->idx(), p.plane->id(), p.x, p.y, p.w, p.h); - for (const PropInfo &prop: p.props) + for (const PropInfo& prop : p.props) fmt::print(" {}={}", prop.prop->name(), prop.val); fmt::print("\n"); @@ -833,8 +808,8 @@ static void set_crtcs_n_planes_legacy(Card& card, const vector& outp auto fb = p.fbs[0]; r = crtc->set_plane(p.plane, *fb, - p.x, p.y, p.w, p.h, - 0, 0, fb->width(), fb->height()); + p.x, p.y, p.w, p.h, + 0, 0, fb->width(), fb->height()); if (r) fmt::print(stderr, "crtc->set_plane() failed for plane {}: {}\n", p.plane->id(), strerror(-r)); @@ -858,22 +833,21 @@ static void set_crtcs_n_planes_atomic(Card& card, const vector& outp // continue; disable_req.add(crtc, { - { "ACTIVE", 0 }, - }); + { "ACTIVE", 0 }, + }); } // Disable unused planes for (Plane* plane : card.get_planes()) disable_req.add(plane, { - { "FB_ID", 0 }, - { "CRTC_ID", 0 }, - }); + { "FB_ID", 0 }, + { "CRTC_ID", 0 }, + }); r = disable_req.commit_sync(true); if (r) EXIT("Atomic commit failed when disabling: %d\n", r); - // Keep blobs here so that we keep ref to them until we have committed the req vector> blobs; @@ -887,37 +861,37 @@ static void set_crtcs_n_planes_atomic(Card& card, const vector& outp Blob* mode_blob = blobs.back().get(); req.add(conn, { - { "CRTC_ID", crtc->id() }, - }); + { "CRTC_ID", crtc->id() }, + }); - for (const PropInfo &prop: o.conn_props) + for (const PropInfo& prop : o.conn_props) req.add(conn, prop.prop, prop.val); req.add(crtc, { - { "ACTIVE", 1 }, - { "MODE_ID", mode_blob->id() }, - }); + { "ACTIVE", 1 }, + { "MODE_ID", mode_blob->id() }, + }); - for (const PropInfo &prop: o.crtc_props) + for (const PropInfo& prop : o.crtc_props) req.add(crtc, prop.prop, prop.val); for (const PlaneInfo& p : o.planes) { auto fb = p.fbs[0]; req.add(p.plane, { - { "FB_ID", fb->id() }, - { "CRTC_ID", crtc->id() }, - { "SRC_X", (p.view_x ?: 0) << 16 }, - { "SRC_Y", (p.view_y ?: 0) << 16 }, - { "SRC_W", (p.view_w ?: fb->width()) << 16 }, - { "SRC_H", (p.view_h ?: fb->height()) << 16 }, - { "CRTC_X", p.x }, - { "CRTC_Y", p.y }, - { "CRTC_W", p.w }, - { "CRTC_H", p.h }, - }); - - for (const PropInfo &prop: p.props) + { "FB_ID", fb->id() }, + { "CRTC_ID", crtc->id() }, + { "SRC_X", (p.view_x ?: 0) << 16 }, + { "SRC_Y", (p.view_y ?: 0) << 16 }, + { "SRC_W", (p.view_w ?: fb->width()) << 16 }, + { "SRC_H", (p.view_h ?: fb->height()) << 16 }, + { "CRTC_X", p.x }, + { "CRTC_Y", p.y }, + { "CRTC_W", p.w }, + { "CRTC_H", p.h }, + }); + + for (const PropInfo& prop : p.props) req.add(p.plane, prop.prop, prop.val); } } @@ -977,7 +951,7 @@ private: if (diff > m_slowest_frame) m_slowest_frame = diff; - if (m_frame_num % 100 == 0) { + if (m_frame_num % 100 == 0) { std::chrono::duration fsec = now - m_prev_print; fmt::print("Connector {}: fps {:.2f}, slowest {:.2f} ms\n", m_name.c_str(), @@ -1016,8 +990,8 @@ private: draw_bar(fb, frame_num); req.add(p.plane, { - { "FB_ID", fb->id() }, - }); + { "FB_ID", fb->id() }, + }); } } @@ -1129,7 +1103,7 @@ static void main_flip(Card& card, const vector& outputs) } } -int main(int argc, char **argv) +int main(int argc, char** argv) { vector output_args = parse_cmdline(argc, argv); -- cgit v1.2.3