- auto &ss = this->controller->surfaces[*sub_surface_id];
-
- HMI_DEBUG("wm", "surface_set_layout for sub surface %u on layer %u",
- *sub_surface_id, layer_id);
-
- // set destination to the display rectangle
- ss->set_destination_rectangle(x + x_off, y + y_off, w, h);
-
- this->area_info[*sub_surface_id].x = x;
- this->area_info[*sub_surface_id].y = y;
- this->area_info[*sub_surface_id].w = w;
- this->area_info[*sub_surface_id].h = h;
- }
-
- HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id,
- layer_id);
-
- // set destination to the display rectangle
- s->set_destination_rectangle(x, y, w, h);
-
- // update area information
- this->area_info[surface_id].x = x;
- this->area_info[surface_id].y = y;
- this->area_info[surface_id].w = w;
- this->area_info[surface_id].h = h;
-
- HMI_DEBUG("wm", "Surface %u now on layer %u with rect { %d, %d, %d, %d }",
- surface_id, layer_id, x, y, w, h);
-}
-
-void App::layout_commit() {
- this->controller->commit_changes();
- this->display->flush();
-}
-
-char const *App::api_activate_surface(char const *drawing_name, char const *drawing_area) {
- ST();
-
- auto const &surface_id = this->lookup_id(drawing_name);
-
- if (!surface_id) {
- return "Surface does not exist";
- }
-
- if (!this->controller->surface_exists(*surface_id)) {
- return "Surface does not exist in controller!";
- }
-
- auto layer_id = this->layers.get_layer_id(*surface_id);
-
- if (!layer_id) {
- return "Surface is not on any layer!";
- }
-
- auto o_state = *this->layers.get_layout_state(*surface_id);
-
- if (o_state == nullptr) {
- return "Could not find layer for surface";
- }
-
- struct LayoutState &state = *o_state;
-
- // disable layers that are above our current layer
- for (auto const &l : this->layers.mapping) {
- if (l.second.layer_id <= *layer_id) {
- continue;
- }
-
- bool flush = false;
- if (l.second.state.main != -1) {
- this->deactivate(l.second.state.main);
- l.second.state.main = -1;
- flush = true;
- }
-
- if (l.second.state.sub != -1) {
- this->deactivate(l.second.state.sub);
- l.second.state.sub = -1;
- flush = true;
- }
-
- if (flush) {
- this->layout_commit();
- }
- }
-
- auto layer = this->layers.get_layer(*layer_id);
-
- if (state.main == -1) {
- this->try_layout(
- state, LayoutState{*surface_id}, [&] (LayoutState const &nl) {
- HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
- this->surface_set_layout(*surface_id);
- state = nl;
-
- // Commit for configuraton
- this->layout_commit();
-
- std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
- compositor::rect area_rect = this->area_info[*surface_id];
- this->emit_syncdraw(drawing_name, str_area.c_str(),
- area_rect.x, area_rect.y, area_rect.w, area_rect.h);
- this->enqueue_flushdraw(state.main);
- });
- } else {
- if (0 == strcmp(drawing_name, "HomeScreen")) {
- this->try_layout(
- state, LayoutState{*surface_id}, [&] (LayoutState const &nl) {
- HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
- std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
- compositor::rect area_rect = this->area_info[*surface_id];
- this->emit_syncdraw(drawing_name, str_area.c_str(),
- area_rect.x, area_rect.y, area_rect.w, area_rect.h);
- this->enqueue_flushdraw(state.main);
- });
- } else {
- bool can_split = this->can_split(state, *surface_id);
-
- if (can_split) {
- this->try_layout(
- state,
- LayoutState{state.main, *surface_id},
- [&] (LayoutState const &nl) {
- HMI_DEBUG("wm", "Layout: %s", kNameLayoutSplit);
- std::string main =
- std::move(*this->lookup_name(state.main));
-
- this->surface_set_layout(state.main, surface_id);
- if (state.sub != *surface_id) {
- if (state.sub != -1) {
- this->deactivate(state.sub);
- }
- }
- state = nl;
-
- // Commit for configuration and visibility(0)
- this->layout_commit();
-
- std::string str_area_main = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaMain);
- std::string str_area_sub = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaSub);
- compositor::rect area_rect_main = this->area_info[state.main];
- compositor::rect area_rect_sub = this->area_info[*surface_id];
- this->emit_syncdraw(main.c_str(), str_area_main.c_str(),
- area_rect_main.x, area_rect_main.y,
- area_rect_main.w, area_rect_main.h);
- this->emit_syncdraw(drawing_name, str_area_sub.c_str(),
- area_rect_sub.x, area_rect_sub.y,
- area_rect_sub.w, area_rect_sub.h);
- this->enqueue_flushdraw(state.main);
- this->enqueue_flushdraw(state.sub);
- });
- } else {
- this->try_layout(
- state, LayoutState{*surface_id}, [&] (LayoutState const &nl) {
- HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
-
- this->surface_set_layout(*surface_id);
- if (state.main != *surface_id) {
- this->deactivate(state.main);
- }
- if (state.sub != -1) {
- if (state.sub != *surface_id) {
- this->deactivate(state.sub);
- }
- }
- state = nl;
-
- // Commit for configuraton and visibility(0)
- this->layout_commit();
-
- std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
- compositor::rect area_rect = this->area_info[*surface_id];
- this->emit_syncdraw(drawing_name, str_area.c_str(),
- area_rect.x, area_rect.y, area_rect.w, area_rect.h);
- this->enqueue_flushdraw(state.main);
- });
- }
- }
- }
-
- // no error
- return nullptr;
-}
-
-char const *App::api_deactivate_surface(char const *drawing_name) {
- ST();
- auto const &surface_id = this->lookup_id(drawing_name);
-
- if (!surface_id) {
- return "Surface does not exist";
- }
-
- if (*surface_id == this->layers.main_surface) {
- return "Cannot deactivate main_surface";
- }
-
- auto o_state = *this->layers.get_layout_state(*surface_id);
-
- if (o_state == nullptr) {
- return "Could not find layer for surface";
- }
-
- struct LayoutState &state = *o_state;
-
- if (state.main == -1) {
- return "No surface active";
- }
-
- // Check against main_surface, main_surface_name is the configuration item.
- if (*surface_id == this->layers.main_surface) {
- HMI_DEBUG("wm", "Refusing to deactivate main_surface %d", *surface_id);
- return nullptr;
- }
-
- if (state.main == *surface_id) {
- if (state.sub != -1) {
- this->try_layout(
- state, LayoutState{state.sub, -1}, [&] (LayoutState const &nl) {
- std::string sub = std::move(*this->lookup_name(state.sub));
-
- this->deactivate(*surface_id);
- this->surface_set_layout(state.sub);
- state = nl;
-
- this->layout_commit();
- std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
- compositor::rect area_rect = this->area_info[state.sub];
- this->emit_syncdraw(sub.c_str(), str_area.c_str(),
- area_rect.x, area_rect.y, area_rect.w, area_rect.h);
- this->enqueue_flushdraw(state.sub);
- });
- } else {
- this->try_layout(state, LayoutState{-1, -1}, [&] (LayoutState const &nl) {
- this->deactivate(*surface_id);
- state = nl;
- this->layout_commit();
- });
- }
- } else if (state.sub == *surface_id) {
- this->try_layout(
- state, LayoutState{state.main, -1}, [&] (LayoutState const &nl) {
- std::string main = std::move(*this->lookup_name(state.main));
-
- this->deactivate(*surface_id);
- this->surface_set_layout(state.main);
- state = nl;
-
- this->layout_commit();
- std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
- compositor::rect area_rect = this->area_info[state.main];
- this->emit_syncdraw(main.c_str(), str_area.c_str(),
- area_rect.x, area_rect.y, area_rect.w, area_rect.h);
- this->enqueue_flushdraw(state.main);
- });
- } else {
- return "Surface is not active";
- }
-
- return nullptr;
-}
-
-void App::enqueue_flushdraw(int surface_id) {
- this->check_flushdraw(surface_id);
- HMI_DEBUG("wm", "Enqueuing EndDraw for surface_id %d", surface_id);
- this->pending_end_draw.push_back(surface_id);
-}
-
-void App::check_flushdraw(int surface_id) {
- auto i = std::find(std::begin(this->pending_end_draw),
- std::end(this->pending_end_draw), surface_id);
- if (i != std::end(this->pending_end_draw)) {
- auto n = this->lookup_name(surface_id);
- HMI_ERROR("wm", "Application %s (%d) has pending EndDraw call(s)!",
- n ? n->c_str() : "unknown-name", surface_id);
- std::swap(this->pending_end_draw[std::distance(
- std::begin(this->pending_end_draw), i)],
- this->pending_end_draw.back());
- this->pending_end_draw.resize(this->pending_end_draw.size() - 1);
- }
-}
-
-char const *App::api_enddraw(char const *drawing_name) {
- for (unsigned i = 0, iend = this->pending_end_draw.size(); i < iend; i++) {
- auto n = this->lookup_name(this->pending_end_draw[i]);
- if (n && *n == drawing_name) {
- std::swap(this->pending_end_draw[i], this->pending_end_draw[iend - 1]);
- this->pending_end_draw.resize(iend - 1);
- this->activate(this->pending_end_draw[i]);
- this->emit_flushdraw(drawing_name);
- return nullptr;
- }
- }
- return "No EndDraw pending for surface";