+ 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);
+ });
+ }
+ }
+ }
+}
+
+const char* App::check_surface_exist(unsigned req_num, const char* drawing_name)
+{
+ auto const &surface_id = this->lookup_id(drawing_name);
+ if (!surface_id)
+ {
+ //reply("Surface does not exist");
+ return "Surface does not exist";
+ }
+
+ if (!this->controller->surface_exists(*surface_id))
+ {
+ //reply("Surface does not exist in controller!");
+ return "Surface does not exist in controller!";
+ }
+
+ auto layer_id = this->layers.get_layer_id(*surface_id);
+
+ if (!layer_id)
+ {
+ //reply("Surface is not on any layer!");
+ return "Surface is not on any layer!";
+ }
+
+ auto o_state = *this->layers.get_layout_state(*surface_id);
+
+ if (o_state == nullptr)
+ {
+ //reply("Could not find layer for surface");
+ return "Could not find layer for surface";
+ }
+
+ HMI_DEBUG("wm", "surface %d is detected", *surface_id);
+ return nullptr;
+ //reply(nullptr);
+}
+
+void App::api_activate_surface(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply)
+{
+ ST();
+
+ /*
+ * Check Phase
+ */
+
+ std::string id = appid;
+ std::string role = drawing_name;
+ std::string area = drawing_area;
+
+ if(!app_list.contains(id)){
+ reply("app doesn't request 'requestSurface' yet");
+ return;
+ }
+
+ auto client = app_list.lookUpClient(id);
+
+ /*
+ * Queueing Phase
+ */
+ unsigned current = app_list.currentSequenceNumber();
+ unsigned requested_num = app_list.getSequenceNumber(id);
+ if (requested_num != 0)
+ {
+ HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", id.c_str(), role.c_str(), area.c_str());
+ reply("already requested");
+ return;
+ }
+
+ WMRequest req = WMRequest(id, role, area, Task::TASK_ALLOCATE);
+ unsigned new_req = app_list.addAllocateRequest(req);
+ app_list.req_dump();
+
+ HMI_SEQ_DEBUG(current, "%s start sequence with %s, %s", id.c_str(), role.c_str(), area.c_str());
+
+ reply(nullptr);
+ if (new_req != current)
+ {
+ // Add request, then invoked after the previous task is finished
+ HMI_SEQ_DEBUG(new_req, "request is accepted");
+ return;
+ }
+
+ /*
+ * Do allocate tasks
+ */
+ bool ret = this->do_allocate_window_resource(new_req);
+
+ if(!ret){
+ HMI_SEQ_ERROR(new_req, "failed to do_allocate_window_resource");
+ //this->emit_error()
+ }
+}
+
+void App::api_deactivate_surface(char const *appid, char const *drawing_name, const reply_func &reply)
+{
+ ST();
+
+ /*
+ * Check Phase
+ */
+ std::string id = appid;
+ std::string role = drawing_name;
+ std::string area = ""; //drawing_area;
+
+ if(!app_list.contains(id)){
+ reply("app doesn't request 'requestSurface' yet");
+ return;
+ }
+ auto client = app_list.lookUpClient(id);
+
+ /*
+ * Queueing Phase
+ */
+ unsigned current = app_list.currentSequenceNumber();
+ unsigned requested_num = app_list.getSequenceNumber(id);
+ if (requested_num != 0)
+ {
+ HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", id.c_str(), role.c_str(), area.c_str());
+ reply("already requested");
+ return;
+ }
+
+ WMRequest req = WMRequest(id, role, area, Task::TASK_RELEASE);
+ unsigned new_req = app_list.addAllocateRequest(req);
+ app_list.req_dump();
+
+ HMI_SEQ_DEBUG(current, "%s start sequence with %s, %s", id.c_str(), role.c_str(), area.c_str());
+
+ if (new_req != current)
+ {
+ // Add request, then invoked after the previous task is finished
+ HMI_SEQ_DEBUG(new_req, "request is accepted");
+ reply(nullptr);
+ return;
+ }
+
+ /*
+ * Do allocate tasks
+ */
+ //bool ret = this->do_allocate_window_resource(new_req);
+
+ auto const &surface_id = this->lookup_id(drawing_name);
+ if (!surface_id)
+ {
+ reply("Surface does not exist");
+ return;
+ }
+
+ if (*surface_id == this->layers.main_surface)
+ {
+ reply("Cannot deactivate main_surface");
+ return;
+ }
+
+ auto o_state = *this->layers.get_layout_state(*surface_id);
+
+ if (o_state == nullptr)
+ {
+ reply("Could not find layer for surface");
+ return;
+ }
+
+ struct LayoutState &state = *o_state;
+
+ if (state.main == -1)
+ {
+ reply("No surface active");
+ return;
+ }
+
+ // 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);
+ reply(nullptr);
+ return;
+ }
+ if ((state.main == *surface_id) && (state.sub == *surface_id))
+ {
+ reply("Surface is not active");
+ return;
+ }
+ reply(nullptr);
+
+ if (state.main == *surface_id)
+ {
+ if (state.sub != -1)
+ {