X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Flayers.cpp;h=7cc2f00eb9e7a8c7ce5a6629465985f5bca6672a;hb=d16426164142cdddeaf16cb18a6ac5f191c8e0e4;hp=d3ec7cf1ec60aac93b28c8ae1a2215ef4b47ea8a;hpb=397ad714d8a0ddc3f0b9d5cbcbd68aec9cbe55d0;p=staging%2Fwindowmanager.git diff --git a/src/layers.cpp b/src/layers.cpp index d3ec7cf..7cc2f00 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -10,8 +10,10 @@ namespace wm { +using json = nlohmann::json; + surface_id_to_layer::surface_id_to_layer(nlohmann::json const &j) { - // DB(j); + DB(j); if (j["type"] == "range") { this->id_min = get(j["first_surface_id"]); this->id_max = get(j["last_surface_id"]); @@ -20,6 +22,14 @@ surface_id_to_layer::surface_id_to_layer(nlohmann::json const &j) { } this->name = j["name"].get(); this->layer_id = get(j["layer_id"]); + this->rect = genivi::rect{-1, -1, 0, 0}; + if (j["area"]["type"] == "rect") { + auto jr = j["area"]["rect"]; + this->rect = genivi::rect{ + get(jr["width"]), get(jr["height"]), + get(jr["x"]), get(jr["y"]), + }; + } } struct result to_surface_id_to_layer_map( @@ -27,10 +37,16 @@ struct result to_surface_id_to_layer_map( DB(j); try { surface_id_to_layer_map stl{}; - std::transform( - std::cbegin(j), std::cend(j), - std::inserter(stl.mapping, stl.mapping.end()), - [](nlohmann::json const &j) { return surface_id_to_layer(j); }); + auto m = j["mappings"]; + stl.layers.reserve(m.size()); + std::transform(std::cbegin(m), std::cend(m), + std::inserter(stl.mapping, stl.mapping.end()), + [&stl](nlohmann::json const &j) { + auto k = surface_id_to_layer(j); + stl.layers.push_back(unsigned(k.layer_id)); + return k; + }); + // XXX need to sort layers? for (auto i : stl.mapping) { if (i.name.empty()) { return Err( @@ -41,6 +57,32 @@ struct result to_surface_id_to_layer_map( "Found invalid/unset IDs in mapping"); } } + + // Check lookup + auto jtests = j.value("tests", json()); + + if (!jtests.empty()) { + DB("Embedded tests..."); + std::vector> tests; + tests.reserve(jtests.size()); + std::transform(std::cbegin(jtests), std::cend(jtests), + std::back_inserter(tests), [](json const &j) { + return std::make_pair( + get(j["surface_id"]), + get(j["expect_layer_id"])); + }); + + for (auto sid : tests) { + int lid = stl.get_layer_for_surface(sid.first).value_or(-1); + DB("this=" << sid.first << ", that=" << lid + << ", expect=" << sid.second); + if (lid != sid.second) { + return Err( + "ID Map embedded test failed!"); + } + } + } + return Ok(stl); } catch (std::exception &e) { return Err(e.what()); @@ -53,19 +95,33 @@ inline bool return a.id_max < b; } -optional surface_id_to_layer_map::get_layer_for_surface(int surface_id) { - auto i = std::lower_bound(std::cbegin(this->mapping), - std::cend(this->mapping), surface_id); +namespace { +optional get_surface_id_to_layer( + struct surface_id_to_layer_map const *s2l, int surface_id) { + auto i = std::lower_bound(std::cbegin(s2l->mapping), std::cend(s2l->mapping), + surface_id); - if (i != this->mapping.end()) { + if (i != s2l->mapping.end()) { // std::less only checks for surface_id_to_layer::id_max, so check // that we are actually inside of an interval here. if (i->id_min <= surface_id) { - return optional(i->layer_id); + return optional(*i); } } return nullopt; } +} + +optional surface_id_to_layer_map::get_layer_for_surface(int surface_id) { + auto e = get_surface_id_to_layer(this, surface_id); + return e ? optional(e->layer_id) : nullopt; +} + +optional surface_id_to_layer_map::get_rect_for_surface( + int surface_id) { + auto e = get_surface_id_to_layer(this, surface_id); + return e ? optional(e->rect) : nullopt; +} } // namespace wm