From 03a040ad80c40cca33b0dc21e50bddf7d72689c1 Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Wed, 12 Sep 2018 14:05:08 +0900 Subject: Remove wayland part from Window Manager [1/2] Change-Id: Icc3c0d3460ee88620e4c2f910536d66928085cbb Signed-off-by: Kazumasa Mitsunari --- src/main.cpp | 11 +- src/window_manager.cpp | 553 ++----------------------------------------------- src/window_manager.hpp | 26 --- 3 files changed, 14 insertions(+), 576 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6b4fef6..6238ddc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -520,19 +520,10 @@ void windowmanager_ping(afb_req req) noexcept afb_req_fail(req, "failed", "Binding not initialized, did the compositor die?"); return; } - - try + else { - - g_afb_instance->wmgr.api_ping(); - afb_req_success(req, NULL, "success"); } - catch (std::exception &e) - { - afb_req_fail_f(req, "failed", "Uncaught exception while calling ping: %s", e.what()); - return; - } } void windowmanager_debug_status(afb_req req) noexcept diff --git a/src/window_manager.cpp b/src/window_manager.cpp index e4083d5..2a50e76 100644 --- a/src/window_manager.cpp +++ b/src/window_manager.cpp @@ -63,39 +63,6 @@ static WindowManager *g_context; namespace { -// using nlohmann::json; - -/* result file_to_json(char const *filename) -{ - json j; - std::ifstream i(filename); - if (i.fail()) - { - HMI_DEBUG("Could not open config file, so use default layer information"); - j = default_layers_json; - } - else - { - i >> j; - } - - return Ok(j); -} - -struct result load_layer_map(char const *filename) -{ - HMI_DEBUG("loading IDs from %s", filename); - - auto j = file_to_json(filename); - if (j.is_err()) - { - return Err(j.unwrap_err()); - } - json jids = j.unwrap(); - - return to_layer_map(jids); -} */ - static int processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata) { HMI_NOTICE("Time out occurs because the client replys endDraw slow, so revert the request"); @@ -118,8 +85,7 @@ static void onError() * WindowManager Impl */ WindowManager::WindowManager() - : chooks{this}, - id_alloc{} + : id_alloc{} { const char *path = getenv("AFM_APP_INSTALL_DIR"); if (!path) @@ -131,40 +97,10 @@ WindowManager::WindowManager() this->lc = std::make_shared(root); HMI_DEBUG("Layer Controller initialized"); - -/* try - { - { - auto l = load_layer_map(path.c_str()); - if (l.is_ok()) - { - this->layers = l.unwrap(); - } - else - { - HMI_ERROR("%s", l.err().value()); - } - } - } - catch (std::exception &e) - { - HMI_ERROR("Loading of configuration failed: %s", e.what()); - } */ } int WindowManager::init() { - /* if (!this->display->ok()) - { - return -1; - } - - if (this->layers.mapping.empty()) - { - HMI_ERROR("No surface -> layer mapping loaded"); - return -1; - } */ - // TODO: application requests by old role, // so create role map (old, new) // Load old_role.db @@ -206,57 +142,9 @@ int WindowManager::init() double scale = static_cast(dp_bg.height()) / css_bg.h; this->lc->setupArea(dp_bg, scale); - /* this->display->add_global_handler( - "wl_output", [this](wl_registry *r, uint32_t name, uint32_t v) { - this->outputs.emplace_back(std::make_unique(r, name, v)); - }); - - this->display->add_global_handler( - "ivi_wm", [this](wl_registry *r, uint32_t name, uint32_t v) { - this->controller = - std::make_unique(r, name, v); - - // Init controller hooks - this->controller->chooks = &this->chooks; - - // This protocol needs the output, so lets just add our mapping here... - this->controller->add_proxy_to_id_mapping( - this->outputs.front()->proxy.get(), - wl_proxy_get_id(reinterpret_cast( - this->outputs.front()->proxy.get()))); - - // Create screen - this->controller->create_screen(this->outputs.front()->proxy.get()); - - // Set display to controller - this->controller->display = this->display; - }); - - // First level objects - this->display->roundtrip(); - // Second level objects - this->display->roundtrip(); - // Third level objects - this->display->roundtrip(); */ - return 0; //init_layers(); } -/* int WindowManager::dispatch_pending_events() -{ - if (this->pop_pending_events()) - { - this->display->dispatch_pending(); - return 0; - } - return -1; -} - -void WindowManager::set_pending_events() -{ - this->pending_events.store(true, std::memory_order_release); -} */ - result WindowManager::api_request_surface(char const *appid, char const *drawing_name) { // TODO: application requests by old role, @@ -273,9 +161,8 @@ result WindowManager::api_request_surface(char const *appid, char const *dr if (l_id == 0) { /** - * register drawing_name as fallback and make it displayed. - */ - // lid = this->layers.get_layer_id(string("fallback")); + * register drawing_name as fallback and make it displayed. + */ l_id = this->lc->getNewLayerID("fallback", &l_name); HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role); if (l_id == 0) @@ -297,29 +184,6 @@ result WindowManager::api_request_surface(char const *appid, char const *dr auto id = int(this->id_alloc.generate_id(role)); this->tmp_surface2app[id] = s_appid; - // this->layers.add_surface(id, *lid); - - // set the main_surface[_name] here and now - // if (!this->layers.main_surface_name.empty() && - // this->layers.main_surface_name == drawing_name) - // { - // this->layers.main_surface = id; - // HMI_DEBUG("Set main_surface id to %u", id); - // } - - - - /* if(g_app_list.contains(appid_str)) - { - // add surface into app - auto client = g_app_list.lookUpClient(appid_str); - // client.addSurface(id); - } - else - { - g_app_list.addClient(appid_str, l_id, id, string(role)); - } */ - // Set role map of (new, old) this->rolenew2old[role] = string(drawing_name); @@ -383,17 +247,6 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr return nullptr; } -/** - * This function is substitute of requestSurface - * If surface creation is faster than application request of this function, - * WM will bind surfaceID with application and role. - * If surface creation is slower than application request of thie function, - * WM will put Client into pending list. - * - * Note : - * Application can request with pid but this is temporary solution for now. - * This will be removed. - * */ bool WindowManager::api_set_role(char const *appid, char const *drawing_name, unsigned pid){ string id = appid; string role = drawing_name; @@ -448,33 +301,16 @@ bool WindowManager::api_set_role(char const *appid, char const *drawing_name, un // register pair drawing_name and ivi_id this->id_alloc.register_name_id(role.c_str(), surface); - // this->layers.add_surface(surface, *lid); // this surface is already created HMI_DEBUG("surface_id is %u, layer_id is %u", surface, lid); - // const auto &o_layer = this->layers.get_layer(*lid); - /* auto rect = o_layer.value().rect; - if(rect.w < 0) - { - rect.w = this->controller->output_size.w + 1 + rect.w; - } - if(rect.h < 0) - { - rect.h = this->controller->output_size.h + 1 + rect.h; - } */ - - // this->controller->layers[*lid]->add_surface(surface); - // this->layout_commit(); - return ret; } void WindowManager::api_activate_surface(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply) { - ; - // TODO: application requests by old role, // so convert role old to new const char *c_role = this->convertRoleOldToNew(drawing_name); @@ -537,8 +373,6 @@ void WindowManager::api_activate_surface(char const *appid, char const *drawing_ void WindowManager::api_deactivate_surface(char const *appid, char const *drawing_name, const reply_func &reply) { - ; - // TODO: application requests by old role, // so convert role old to new const char *c_role = this->convertRoleOldToNew(drawing_name); @@ -554,8 +388,6 @@ void WindowManager::api_deactivate_surface(char const *appid, char const *drawin WMError ret = WMError::UNKNOWN; ret = this->setRequest(id, role, area, task, &req_num); - //vector current_states = this->lc->getCurrentStates(); - // ret = this->setRequest(id, role, area, task, current_states, &req_num); if (ret != WMError::SUCCESS) { @@ -633,14 +465,6 @@ void WindowManager::api_enddraw(char const *appid, char const *drawing_name) result WindowManager::api_get_display_info() { - /* if (!this->display->ok()) - { - return Err("Wayland compositor is not available"); - } */ - - // Set display info -/* size o_size = this->controller->output_size; - size p_size = this->controller->physical_size; */ Screen screen = this->lc->getScreenInfo(); json_object *object = json_object_new_object(); @@ -669,17 +493,6 @@ result WindowManager::api_get_area_info(char const *drawing_name) return Err("Surface does not exist"); } - /* if (!this->controller->surface_exists(*surface_id)) - { - return Err("Surface does not exist in controller!"); - } */ - - /* // auto layer_id = this->layers.get_layer_id(*surface_id); - if (!layer_id) - { - return Err("Surface is not on any layer!"); - } */ - // Set area rectangle rect area_info = this->area_info[*surface_id]; json_object *object = json_object_new_object(); @@ -691,8 +504,6 @@ result WindowManager::api_get_area_info(char const *drawing_name) return Ok(object); } -void WindowManager::api_ping() { /* this->dispatch_pending_events(); */ } - void WindowManager::send_event(char const *evname, char const *label) { HMI_DEBUG("%s: %s(%s)", __func__, evname, label); @@ -755,20 +566,6 @@ void WindowManager::surface_created(uint32_t surface_id) { HMI_NOTICE("Unknown surface %d", surface_id); } - /* this->controller->get_surface_properties(surface_id, IVI_WM_PARAM_SIZE); - - auto layer_id = this->layers.get_layer_id(surface_id); - if (!layer_id) - { - HMI_DEBUG("Newly created surfce %d is not associated with any layer!", - surface_id); - return; - } - - HMI_DEBUG("surface_id is %u, layer_id is %u", surface_id, *layer_id); - - this->controller->layers[*layer_id]->add_surface(surface_id); - this->layout_commit(); */ } void WindowManager::surface_removed(uint32_t surface_id) @@ -779,45 +576,6 @@ void WindowManager::surface_removed(uint32_t surface_id) g_app_list.removeSurface(surface_id); } -void WindowManager::surface_properties(unsigned surface_id, unsigned pid) -{ - HMI_DEBUG("get surface properties"); - - // search pid from surfaceID - /*json_object *response; - afb_service_call_sync("afm-main", "runners", nullptr, &response); - - // retrieve appid from pid from application manager - string appid = ""; - if(response == nullptr) - { - HMI_ERROR("No runners"); - } - else - { - // check appid then add it to the client - HMI_INFO("Runners:%s", json_object_get_string(response)); - int size = json_object_array_length(response); - for(int i = 0; i < size; i++) - { - json_object *j = json_object_array_get_idx(response, i); - const char* id = jh::getStringFromJson(j, "id"); - int runid = jh::getIntFromJson(j, "runid"); - if(id && (runid > 0)) - { - if(runid == pid) - { - appid = id; - break; - } - } - } - } - json_object_put(response); - - g_app_list.addFloatingSurface(appid, surface_id, pid);*/ -} - void WindowManager::removeClient(const string &appid) { HMI_DEBUG("Remove clinet %s from list", appid.c_str()); @@ -943,128 +701,6 @@ void WindowManager::processError(WMError error) ******* Private Functions ******* */ -/** - * init_layers() - */ -int WindowManager::init_layers() -{ - /* if (!this->controller) - { - HMI_ERROR("ivi_controller global not available"); - return -1; - } - - if (this->outputs.empty()) - { - HMI_ERROR("no output was set up!"); - return -1; - } - - auto &c = this->controller; - - auto &o = this->outputs.front(); - auto &s = c->screens.begin()->second; - auto &layers = c->layers; - - // Write output dimensions to ivi controller... - c->output_size = compositor::size{uint32_t(o->width), uint32_t(o->height)}; - c->physical_size = compositor::size{uint32_t(o->physical_width), - uint32_t(o->physical_height)}; - - - HMI_DEBUG("SCALING: screen (%dx%d), physical (%dx%d)", - o->width, o->height, o->physical_width, o->physical_height); - - // this->layers.loadAreaDb(); - - const compositor::rect css_bg = this->layers.getAreaSize("fullscreen"); - rectangle dp_bg(o->width, o->height); - - dp_bg.set_aspect(static_cast(css_bg.w) / css_bg.h); - dp_bg.fit(o->width, o->height); - dp_bg.center(o->width, o->height); - HMI_DEBUG("SCALING: CSS BG(%dx%d) -> DDP %dx%d,(%dx%d)", - css_bg.w, css_bg.h, dp_bg.left(), dp_bg.top(), dp_bg.width(), dp_bg.height()); - - // Clear scene - // layers.clear(); - - // Clear screen - // s->clear(); - - // Quick and dirty setup of layers - for (auto const &i : this->layers.mapping) - { - c->layer_create(i.second.layer_id, dp_bg.width(), dp_bg.height()); - auto &l = layers[i.second.layer_id]; - l->set_destination_rectangle(dp_bg.left(), dp_bg.top(), dp_bg.width(), dp_bg.height()); - l->set_visibility(1); - HMI_DEBUG("Setting up layer %s (%d) for surface role match \"%s\"", - i.second.name.c_str(), i.second.layer_id, i.second.role.c_str()); - } - - // Add layers to screen - s->set_render_order(this->layers.layers); - - this->layout_commit(); - - c->scale = static_cast(dp_bg.height()) / css_bg.h; - this->layers.setupArea(c->scale); - */ - return 0; -} - -void WindowManager::surface_set_layout(int surface_id, const string& area) -{ - /* if (!this->controller->surface_exists(surface_id)) - { - HMI_ERROR("Surface %d does not exist", surface_id); - return; - } - - auto o_layer_id = this->layers.get_layer_id(surface_id); - - if (!o_layer_id) - { - HMI_ERROR("Surface %d is not associated with any layer!", surface_id); - return; - } - - uint32_t layer_id = *o_layer_id; - - auto const &layer = this->layers.get_layer(layer_id); - auto rect = this->layers.getAreaSize(area); - HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "%s : x:%d y:%d w:%d h:%d", area.c_str(), - rect.x, rect.y, rect.w, rect.h); - auto &s = this->controller->surfaces[surface_id]; - - int x = rect.x; - int y = rect.y; - int w = rect.w; - int h = rect.h; - - HMI_DEBUG("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("Surface %u now on layer %u with rect { %d, %d, %d, %d }", - surface_id, layer_id, x, y, w, h); */ -} - -void WindowManager::layout_commit() -{ -/* this->controller->commit_changes(); - this->display->flush(); */ -} - void WindowManager::emit_activated(char const *label) { this->send_event(kListEventName[Event_Active], label); @@ -1106,102 +742,22 @@ void WindowManager::emit_visible(char const *label) { return emit_visible(label, void WindowManager::activate(int id) { - /* auto ip = this->controller->sprops.find(id); - if (ip != this->controller->sprops.end()) - { - this->controller->surfaces[id]->set_visibility(1); - */ - char const *label = - this->id_alloc.lookup(id).value_or("unknown-name").c_str(); - - /* // FOR CES DEMO >>> - if ((0 == strcmp(label, "radio")) || - (0 == strcmp(label, "music")) || - (0 == strcmp(label, "video")) || - (0 == strcmp(label, "map"))) - { - for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i) - { - if (id == *i) - { - // Remove id - this->surface_bg.erase(i); - - // Remove from BG layer (999) - HMI_DEBUG("Remove %s(%d) from BG layer", label, id); - this->controller->layers[999]->remove_surface(id); - - // Add to FG layer (1001) - HMI_DEBUG("Add %s(%d) to FG layer", label, id); - this->controller->layers[1001]->add_surface(id); - - for (int j : this->surface_bg) - { - HMI_DEBUG("Stored id:%d", j); - } - break; - } - } - } - // <<< FOR CES DEMO - - this->layout_commit(); */ - - // TODO: application requests by old role, - // so convert role new to old for emitting event - const char* old_role = this->rolenew2old[label].c_str(); + // TODO: application requests by old role, + // so convert role new to old for emitting event + /* const char* old_role = this->rolenew2old[label].c_str(); - this->emit_visible(old_role); - this->emit_activated(old_role); - // } + this->emit_visible(old_role); + this->emit_activated(old_role); */ } void WindowManager::deactivate(int id) { - /* auto ip = this->controller->sprops.find(id); - if (ip != this->controller->sprops.end()) - {*/ - char const *label = - this->id_alloc.lookup(id).value_or("unknown-name").c_str(); - - /*// FOR CES DEMO >>> - if ((0 == strcmp(label, "radio")) || - (0 == strcmp(label, "music")) || - (0 == strcmp(label, "video")) || - (0 == strcmp(label, "map"))) - { - - // Store id - this->surface_bg.push_back(id); - - // Remove from FG layer (1001) - HMI_DEBUG("Remove %s(%d) from FG layer", label, id); - this->controller->layers[1001]->remove_surface(id); - - // Add to BG layer (999) - HMI_DEBUG("Add %s(%d) to BG layer", label, id); - this->controller->layers[999]->add_surface(id); - - for (int j : surface_bg) - { - HMI_DEBUG("Stored id:%d", j); - } - } - else - { - this->controller->surfaces[id]->set_visibility(0); - } - // <<< FOR CES DEMO - - this->layout_commit(); */ - - // TODO: application requests by old role, - // so convert role new to old for emitting event - const char* old_role = this->rolenew2old[label].c_str(); + // TODO: application requests by old role, + // so convert role new to old for emitting event + /* const char* old_role = this->rolenew2old[label].c_str(); - this->emit_deactivated(old_role); - this->emit_invisible(old_role); - // } + this->emit_deactivated(old_role); + this->emit_invisible(old_role); */ } WMError WindowManager::setRequest(const string& appid, const string &role, const string &area, @@ -1374,7 +930,6 @@ WMError WindowManager::doEndDraw(unsigned req_num) return ret; } HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str()); - //this->lc_enddraw(act.role.c_str()); } } this->lc->renderLayers(); @@ -1396,61 +951,6 @@ WMError WindowManager::doEndDraw(unsigned req_num) return ret; } -WMError WindowManager::layoutChange(const WMAction &action) -{ - if (action.visible == TaskVisible::INVISIBLE) - { - // Visibility is not change -> no redraw is required - return WMError::SUCCESS; - } - WMError ret = this->lc->layoutChange(action); - /* auto client = g_app_list.lookUpClient(action.appid); - unsigned surface = client->surfaceID(action.role); - if (surface == 0) - { - HMI_SEQ_ERROR(g_app_list.currentRequestNumber(), - "client doesn't have surface with role(%s)", action.role.c_str()); - return WMError::NOT_REGISTERED; - } - // Layout Manager - WMError ret = this->setSurfaceSize(surface, action.area); */ - return ret; -} - -WMError WindowManager::visibilityChange(const WMAction &action) -{ - HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "Change visibility"); - /* if(!g_app_list.contains(action.appid)){ - return WMError::NOT_REGISTERED; - } - auto client = g_app_list.lookUpClient(action.appid); - unsigned surface = client->surfaceID(action.role); - if(surface == 0) - { - HMI_SEQ_ERROR(g_app_list.currentRequestNumber(), - "client doesn't have surface with role(%s)", action.role.c_str()); - return WMError::NOT_REGISTERED; - } */ - WMError ret = this->lc->visibilityChange(action); - -/* if (action.visible != TaskVisible::INVISIBLE) - { - this->activate(surface); // Layout Manager task - } - else - { - this->deactivate(surface); // Layout Manager task - } */ - return ret; -} - -WMError WindowManager::setSurfaceSize(unsigned surface, const string &area) -{ - this->surface_set_layout(surface, area); - - return WMError::SUCCESS; -} - void WindowManager::emitScreenUpdated(unsigned req_num) { // Get visible apps @@ -1730,31 +1230,4 @@ const char* WindowManager::kDefaultOldRoleDb = "{ \ ] \ }"; -/** - * controller_hooks - */ -void controller_hooks::surface_created(uint32_t surface_id) -{ - this->wmgr->surface_created(surface_id); -} - -void controller_hooks::surface_removed(uint32_t surface_id) -{ - this->wmgr->surface_removed(surface_id); -} - -void controller_hooks::surface_visibility(uint32_t /*surface_id*/, - uint32_t /*v*/) {} - -void controller_hooks::surface_destination_rectangle(uint32_t /*surface_id*/, - uint32_t /*x*/, - uint32_t /*y*/, - uint32_t /*w*/, - uint32_t /*h*/) {} - -void controller_hooks::surface_properties(uint32_t surface_id, uint32_t pid) -{ - this->wmgr->surface_properties(surface_id, pid); -} - } // namespace wm diff --git a/src/window_manager.hpp b/src/window_manager.hpp index 189d249..546e771 100644 --- a/src/window_manager.hpp +++ b/src/window_manager.hpp @@ -21,10 +21,6 @@ #include #include #include -#include "controller_hooks.hpp" -//#include "layers.hpp" -// #include "layout.hpp" -//#include "wayland_ivi_wm.hpp" #include "result.hpp" #include "pm_wrapper.hpp" #include "util.hpp" @@ -38,16 +34,6 @@ extern "C" struct json_object; -namespace wl -{ -struct display; -} - -namespace compositor -{ -struct controller; -} - namespace wm { @@ -187,14 +173,12 @@ class WindowManager void api_enddraw(char const *appid, char const *role); result api_get_display_info(); result api_get_area_info(char const *role); - void api_ping(); void send_event(char const *evname, char const *label); void send_event(char const *evname, char const *label, char const *area, int x, int y, int w, int h); // Events from the compositor we are interested in void surface_created(uint32_t surface_id); void surface_removed(uint32_t surface_id); - void surface_properties(uint32_t surface_id, uint32_t pid); void removeClient(const std::string &appid); void exceptionProcessForTransition(); @@ -217,10 +201,6 @@ class WindowManager std::map map_afb_event; private: - int init_layers(); - void surface_set_layout(int surface_id, const std::string& area = ""); - void layout_commit(); - // WM Events to clients void emit_activated(char const *label); void emit_deactivated(char const *label); @@ -239,9 +219,6 @@ class WindowManager WMError startTransition(unsigned req_num); WMError doEndDraw(unsigned req_num); - WMError layoutChange(const WMAction &action); - WMError visibilityChange(const WMAction &action); - WMError setSurfaceSize(unsigned surface, const std::string& area); void emitScreenUpdated(unsigned req_num); void setTimer(); @@ -253,19 +230,16 @@ class WindowManager const char *check_surface_exist(const char *role); private: - std::unordered_map area2size; std::unordered_map roleold2new; std::unordered_map rolenew2old; std::shared_ptr lc; PMWrapper pmw; - struct controller_hooks chooks; // ID allocation and proxy methods for lookup struct id_allocator id_alloc; // Surface are info (x, y, w, h) rect_map area_info; // FOR CES DEMO - std::vector surface_bg; std::unordered_map tmp_surface2app; static const char* kDefaultOldRoleDb; -- cgit 1.2.3-korg