diff options
Diffstat (limited to 'src/window_manager.cpp')
-rw-r--r-- | src/window_manager.cpp | 668 |
1 files changed, 336 insertions, 332 deletions
diff --git a/src/window_manager.cpp b/src/window_manager.cpp index c66d4cf..28ef868 100644 --- a/src/window_manager.cpp +++ b/src/window_manager.cpp @@ -208,142 +208,98 @@ int WindowManager::dispatch_pending_events() return -1; } -bool WindowManager::pop_pending_events() -{ - bool x{true}; - return this->pending_events.compare_exchange_strong( - x, false, std::memory_order_consume); -} - void WindowManager::set_pending_events() { this->pending_events.store(true, std::memory_order_release); } -optional<int> WindowManager::lookup_id(char const *name) -{ - return this->id_alloc.lookup(std::string(name)); -} -optional<std::string> WindowManager::lookup_name(int id) -{ - return this->id_alloc.lookup(id); -} - -/** - * init_layers() - */ -int WindowManager::init_layers() +result<int> WindowManager::api_request_surface(char const *appid, char const *drawing_name) { - if (!this->controller) + auto lid = this->layers.get_layer_id(std::string(drawing_name)); + if (!lid) { - HMI_ERROR("wm", "ivi_controller global not available"); - return -1; + /** + * register drawing_name as fallback and make it displayed. + */ + lid = this->layers.get_layer_id(std::string("Fallback")); + HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name); + if (!lid) + { + return Err<int>("Drawing name does not match any role, Fallback is disabled"); + } } - if (this->outputs.empty()) + auto rname = this->lookup_id(drawing_name); + if (!rname) { - HMI_ERROR("wm", "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)}; + // name does not exist yet, allocate surface id... + auto id = int(this->id_alloc.generate_id(drawing_name)); + this->layers.add_surface(id, *lid); - // Clear scene - layers.clear(); + // 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("wm", "Set main_surface id to %u", id); + } - // Clear screen - s->clear(); + // add client into the db + std::string appid_str(appid); + std::string role(drawing_name); + g_app_list.addClient(appid_str, *lid, id, role); - // Quick and dirty setup of layers - for (auto const &i : this->layers.mapping) - { - c->layer_create(i.second.layer_id, o->width, o->height); - auto &l = layers[i.second.layer_id]; - l->set_destination_rectangle(0, 0, o->width, o->height); - l->set_visibility(1); - HMI_DEBUG("wm", "Setting up layer %s (%d) for surface role match \"%s\"", - i.second.name.c_str(), i.second.layer_id, i.second.role.c_str()); + return Ok<int>(id); } - // Add layers to screen - s->set_render_order(this->layers.layers); - - this->layout_commit(); - - this->layers.setupArea(o->width, o->height); - - return 0; + // Check currently registered drawing names if it is already there. + return Err<int>("Surface already present"); } -void WindowManager::surface_set_layout(int surface_id, const std::string& area) +char const *WindowManager::api_request_surface(char const *appid, char const *drawing_name, + char const *ivi_id) { - if (!this->controller->surface_exists(surface_id)) - { - HMI_ERROR("wm", "Surface %d does not exist", surface_id); - return; - } + ST(); - auto o_layer_id = this->layers.get_layer_id(surface_id); + auto lid = this->layers.get_layer_id(std::string(drawing_name)); + unsigned sid = std::stol(ivi_id); - if (!o_layer_id) + if (!lid) { - HMI_ERROR("wm", "Surface %d is not associated with any layer!", surface_id); - return; + /** + * register drawing_name as fallback and make it displayed. + */ + lid = this->layers.get_layer_id(std::string("Fallback")); + HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name); + if (!lid) + { + return "Drawing name does not match any role, Fallback is disabled"; + } } - 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; + auto rname = this->lookup_id(drawing_name); - // less-than-0 values refer to MAX + 1 - $VALUE - // e.g. MAX is either screen width or height - if (w < 0) - { - w = this->controller->output_size.w + 1 + w; - } - if (h < 0) + if (rname) { - h = this->controller->output_size.h + 1 + h; + return "Surface already present"; } - HMI_DEBUG("wm", "surface_set_layout for surface %u on layer %u", surface_id, - layer_id); + // register pair drawing_name and ivi_id + this->id_alloc.register_name_id(drawing_name, sid); + this->layers.add_surface(sid, *lid); - // set destination to the display rectangle - s->set_destination_rectangle(x, y, w, h); + // this surface is already created + HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", sid, *lid); - // 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; + this->controller->layers[*lid]->add_surface(sid); + this->layout_commit(); - HMI_DEBUG("wm", "Surface %u now on layer %u with rect { %d, %d, %d, %d }", - surface_id, layer_id, x, y, w, h); -} + // add client into the db + std::string appid_str(appid); + std::string role(drawing_name); + g_app_list.addClient(appid_str, *lid, sid, role); -void WindowManager::layout_commit() -{ - this->controller->commit_changes(); - this->display->flush(); + return nullptr; } void WindowManager::api_activate_surface(char const *appid, char const *drawing_name, @@ -471,6 +427,72 @@ void WindowManager::api_enddraw(char const *appid, char const *drawing_name) } } +result<json_object *> WindowManager::api_get_display_info() +{ + // Check controller + if (!this->controller) + { + return Err<json_object *>("ivi_controller global not available"); + } + + // Set display info + compositor::size o_size = this->controller->output_size; + compositor::size p_size = this->controller->physical_size; + + json_object *object = json_object_new_object(); + json_object_object_add(object, kKeyWidthPixel, json_object_new_int(o_size.w)); + json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h)); + json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w)); + json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h)); + + return Ok<json_object *>(object); +} + +result<json_object *> WindowManager::api_get_area_info(char const *drawing_name) +{ + HMI_DEBUG("wm", "called"); + + // Check drawing name, surface/layer id + auto const &surface_id = this->lookup_id(drawing_name); + if (!surface_id) + { + return Err<json_object *>("Surface does not exist"); + } + + if (!this->controller->surface_exists(*surface_id)) + { + return Err<json_object *>("Surface does not exist in controller!"); + } + + auto layer_id = this->layers.get_layer_id(*surface_id); + if (!layer_id) + { + return Err<json_object *>("Surface is not on any layer!"); + } + + auto o_state = *this->layers.get_layout_state(*surface_id); + if (o_state == nullptr) + { + return Err<json_object *>("Could not find layer for surface"); + } + + struct LayoutState &state = *o_state; + if ((state.main != *surface_id) && (state.sub != *surface_id)) + { + return Err<json_object *>("Surface is inactive"); + } + + // Set area rectangle + compositor::rect area_info = this->area_info[*surface_id]; + json_object *object = json_object_new_object(); + json_object_object_add(object, kKeyX, json_object_new_int(area_info.x)); + json_object_object_add(object, kKeyY, json_object_new_int(area_info.y)); + json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w)); + json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h)); + + return Ok<json_object *>(object); +} + void WindowManager::api_ping() { this->dispatch_pending_events(); } void WindowManager::send_event(char const *evname, char const *label) @@ -560,6 +582,143 @@ void WindowManager::timerHandler() this->processNextRequest(); } +/* + ******* Private Functions ******* + */ + +bool WindowManager::pop_pending_events() +{ + bool x{true}; + return this->pending_events.compare_exchange_strong( + x, false, std::memory_order_consume); +} + +optional<int> WindowManager::lookup_id(char const *name) +{ + return this->id_alloc.lookup(std::string(name)); +} +optional<std::string> WindowManager::lookup_name(int id) +{ + return this->id_alloc.lookup(id); +} + +/** + * init_layers() + */ +int WindowManager::init_layers() +{ + if (!this->controller) + { + HMI_ERROR("wm", "ivi_controller global not available"); + return -1; + } + + if (this->outputs.empty()) + { + HMI_ERROR("wm", "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)}; + + // 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, o->width, o->height); + auto &l = layers[i.second.layer_id]; + l->set_destination_rectangle(0, 0, o->width, o->height); + l->set_visibility(1); + HMI_DEBUG("wm", "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(); + + this->layers.setupArea(o->width, o->height); + + return 0; +} + +void WindowManager::surface_set_layout(int surface_id, const std::string& area) +{ + if (!this->controller->surface_exists(surface_id)) + { + HMI_ERROR("wm", "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("wm", "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; + + // less-than-0 values refer to MAX + 1 - $VALUE + // e.g. MAX is either screen width or height + if (w < 0) + { + w = this->controller->output_size.w + 1 + w; + } + if (h < 0) + { + h = this->controller->output_size.h + 1 + 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 WindowManager::layout_commit() +{ + this->controller->commit_changes(); + this->display->flush(); +} + void WindowManager::emit_activated(char const *label) { this->send_event(kListEventName[Event_Active], label); @@ -599,159 +758,92 @@ void WindowManager::emit_invisible(char const *label) void WindowManager::emit_visible(char const *label) { return emit_visible(label, true); } -result<int> WindowManager::api_request_surface(char const *appid, char const *drawing_name) +void WindowManager::activate(int id) { - auto lid = this->layers.get_layer_id(std::string(drawing_name)); - if (!lid) - { - /** - * register drawing_name as fallback and make it displayed. - */ - lid = this->layers.get_layer_id(std::string("Fallback")); - HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name); - if (!lid) - { - return Err<int>("Drawing name does not match any role, Fallback is disabled"); - } - } - - auto rname = this->lookup_id(drawing_name); - if (!rname) + auto ip = this->controller->sprops.find(id); + if (ip != this->controller->sprops.end()) { - // name does not exist yet, allocate surface id... - auto id = int(this->id_alloc.generate_id(drawing_name)); - this->layers.add_surface(id, *lid); + this->controller->surfaces[id]->set_visibility(1); + char const *label = + this->lookup_name(id).value_or("unknown-name").c_str(); - // set the main_surface[_name] here and now - if (!this->layers.main_surface_name.empty() && - this->layers.main_surface_name == drawing_name) + // FOR CES DEMO >>> + if ((0 == strcmp(label, "Radio")) || + (0 == strcmp(label, "MediaPlayer")) || + (0 == strcmp(label, "Music")) || + (0 == strcmp(label, "Navigation"))) { - this->layers.main_surface = id; - HMI_DEBUG("wm", "Set main_surface id to %u", id); - } - - // add client into the db - std::string appid_str(appid); - std::string role(drawing_name); - g_app_list.addClient(appid_str, *lid, id, role); - - return Ok<int>(id); - } - - // Check currently registered drawing names if it is already there. - return Err<int>("Surface already present"); -} + for (auto i = surface_bg.begin(); i != surface_bg.end(); ++i) + { + if (id == *i) + { + // Remove id + this->surface_bg.erase(i); -char const *WindowManager::api_request_surface(char const *appid, char const *drawing_name, - char const *ivi_id) -{ - ST(); + // Remove from BG layer (999) + HMI_DEBUG("wm", "Remove %s(%d) from BG layer", label, id); + this->controller->layers[999]->remove_surface(id); - auto lid = this->layers.get_layer_id(std::string(drawing_name)); - unsigned sid = std::stol(ivi_id); + // Add to FG layer (1001) + HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id); + this->controller->layers[1001]->add_surface(id); - if (!lid) - { - /** - * register drawing_name as fallback and make it displayed. - */ - lid = this->layers.get_layer_id(std::string("Fallback")); - HMI_DEBUG("wm", "%s is not registered in layers.json, then fallback as normal app", drawing_name); - if (!lid) - { - return "Drawing name does not match any role, Fallback is disabled"; + for (int j : this->surface_bg) + { + HMI_DEBUG("wm", "Stored id:%d", j); + } + break; + } + } } - } - - auto rname = this->lookup_id(drawing_name); + // <<< FOR CES DEMO + this->layout_commit(); - if (rname) - { - return "Surface already present"; + this->emit_visible(label); + this->emit_activated(label); } - - // register pair drawing_name and ivi_id - this->id_alloc.register_name_id(drawing_name, sid); - this->layers.add_surface(sid, *lid); - - // this surface is already created - HMI_DEBUG("wm", "surface_id is %u, layer_id is %u", sid, *lid); - - this->controller->layers[*lid]->add_surface(sid); - this->layout_commit(); - - // add client into the db - std::string appid_str(appid); - std::string role(drawing_name); - g_app_list.addClient(appid_str, *lid, sid, role); - - return nullptr; } -result<json_object *> WindowManager::api_get_display_info() +void WindowManager::deactivate(int id) { - // Check controller - if (!this->controller) + auto ip = this->controller->sprops.find(id); + if (ip != this->controller->sprops.end()) { - return Err<json_object *>("ivi_controller global not available"); - } - - // Set display info - compositor::size o_size = this->controller->output_size; - compositor::size p_size = this->controller->physical_size; - - json_object *object = json_object_new_object(); - json_object_object_add(object, kKeyWidthPixel, json_object_new_int(o_size.w)); - json_object_object_add(object, kKeyHeightPixel, json_object_new_int(o_size.h)); - json_object_object_add(object, kKeyWidthMm, json_object_new_int(p_size.w)); - json_object_object_add(object, kKeyHeightMm, json_object_new_int(p_size.h)); - - return Ok<json_object *>(object); -} + char const *label = + this->lookup_name(id).value_or("unknown-name").c_str(); -result<json_object *> WindowManager::api_get_area_info(char const *drawing_name) -{ - HMI_DEBUG("wm", "called"); + // FOR CES DEMO >>> + if ((0 == strcmp(label, "Radio")) || + (0 == strcmp(label, "MediaPlayer")) || + (0 == strcmp(label, "Music")) || + (0 == strcmp(label, "Navigation"))) + { - // Check drawing name, surface/layer id - auto const &surface_id = this->lookup_id(drawing_name); - if (!surface_id) - { - return Err<json_object *>("Surface does not exist"); - } + // Store id + this->surface_bg.push_back(id); - if (!this->controller->surface_exists(*surface_id)) - { - return Err<json_object *>("Surface does not exist in controller!"); - } + // Remove from FG layer (1001) + HMI_DEBUG("wm", "Remove %s(%d) from FG layer", label, id); + this->controller->layers[1001]->remove_surface(id); - auto layer_id = this->layers.get_layer_id(*surface_id); - if (!layer_id) - { - return Err<json_object *>("Surface is not on any layer!"); - } + // Add to BG layer (999) + HMI_DEBUG("wm", "Add %s(%d) to BG layer", label, id); + this->controller->layers[999]->add_surface(id); - auto o_state = *this->layers.get_layout_state(*surface_id); - if (o_state == nullptr) - { - return Err<json_object *>("Could not find layer for surface"); - } + for (int j : surface_bg) + { + HMI_DEBUG("wm", "Stored id:%d", j); + } + } + else + { + this->controller->surfaces[id]->set_visibility(0); + } + // <<< FOR CES DEMO - struct LayoutState &state = *o_state; - if ((state.main != *surface_id) && (state.sub != *surface_id)) - { - return Err<json_object *>("Surface is inactive"); + this->emit_deactivated(label); + this->emit_invisible(label); } - - // Set area rectangle - compositor::rect area_info = this->area_info[*surface_id]; - json_object *object = json_object_new_object(); - json_object_object_add(object, kKeyX, json_object_new_int(area_info.x)); - json_object_object_add(object, kKeyY, json_object_new_int(area_info.y)); - json_object_object_add(object, kKeyWidth, json_object_new_int(area_info.w)); - json_object_object_add(object, kKeyHeight, json_object_new_int(area_info.h)); - - return Ok<json_object *>(object); } WMError WindowManager::setRequest(const std::string& appid, const std::string &role, const std::string &area, @@ -1150,13 +1242,6 @@ WMError WindowManager::doEndDraw(unsigned req_num) return ret; } -WMError WindowManager::setSurfaceSize(unsigned surface, const std::string &area) -{ - this->surface_set_layout(surface, area); - - return WMError::SUCCESS; -} - WMError WindowManager::layoutChange(const WMAction &action) { if (action.visible == TaskVisible::INVISIBLE) @@ -1203,6 +1288,13 @@ WMError WindowManager::visibilityChange(const WMAction &action) return WMError::SUCCESS; } +WMError WindowManager::setSurfaceSize(unsigned surface, const std::string &area) +{ + this->surface_set_layout(surface, area); + + return WMError::SUCCESS; +} + WMError WindowManager::changeCurrentState(unsigned req_num) { HMI_SEQ_DEBUG(req_num, "Change current layout state"); @@ -1354,94 +1446,6 @@ const char *WindowManager::check_surface_exist(const char *drawing_name) return nullptr; } -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->lookup_name(id).value_or("unknown-name").c_str(); - - // FOR CES DEMO >>> - if ((0 == strcmp(label, "Radio")) || - (0 == strcmp(label, "MediaPlayer")) || - (0 == strcmp(label, "Music")) || - (0 == strcmp(label, "Navigation"))) - { - 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("wm", "Remove %s(%d) from BG layer", label, id); - this->controller->layers[999]->remove_surface(id); - - // Add to FG layer (1001) - HMI_DEBUG("wm", "Add %s(%d) to FG layer", label, id); - this->controller->layers[1001]->add_surface(id); - - for (int j : this->surface_bg) - { - HMI_DEBUG("wm", "Stored id:%d", j); - } - break; - } - } - } - // <<< FOR CES DEMO - this->layout_commit(); - - this->emit_visible(label); - this->emit_activated(label); - } -} - -void WindowManager::deactivate(int id) -{ - auto ip = this->controller->sprops.find(id); - if (ip != this->controller->sprops.end()) - { - char const *label = - this->lookup_name(id).value_or("unknown-name").c_str(); - - // FOR CES DEMO >>> - if ((0 == strcmp(label, "Radio")) || - (0 == strcmp(label, "MediaPlayer")) || - (0 == strcmp(label, "Music")) || - (0 == strcmp(label, "Navigation"))) - { - - // Store id - this->surface_bg.push_back(id); - - // Remove from FG layer (1001) - HMI_DEBUG("wm", "Remove %s(%d) from FG layer", label, id); - this->controller->layers[1001]->remove_surface(id); - - // Add to BG layer (999) - HMI_DEBUG("wm", "Add %s(%d) to BG layer", label, id); - this->controller->layers[999]->add_surface(id); - - for (int j : surface_bg) - { - HMI_DEBUG("wm", "Stored id:%d", j); - } - } - else - { - this->controller->surfaces[id]->set_visibility(0); - } - // <<< FOR CES DEMO - - this->emit_deactivated(label); - this->emit_invisible(label); - } -} - bool WindowManager::can_split(struct LayoutState const &state, int new_id) { if (state.main != -1 && state.main != new_id) |