From: Marcus Fritzsch Date: Wed, 2 Aug 2017 14:16:15 +0000 (+0200) Subject: app/wayland: move late-tasks to App X-Git-Tag: 4.99.1~180 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=staging%2Fwindowmanager.git;a=commitdiff_plain;h=93c2a361b2144d82ec70208225c45afd8f355bd3 app/wayland: move late-tasks to App * Move late-tasks to App. * Add add_task() to controller_hooks. * Do not roundtrip at the end of App::execute_pending(), flush() is enough. * Tasks are now void() functions, need to capture what is needed. Signed-off-by: Marcus Fritzsch --- diff --git a/src/app.cpp b/src/app.cpp index e14984e..685f572 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -213,8 +213,7 @@ int App::dispatch_events() { this->display->flush(); // execute pending tasks, that is layout changes etc. - this->controller->execute_pending(); - this->display->roundtrip(); + this->execute_pending(); return 0; } @@ -320,6 +319,22 @@ void App::surface_set_layout(uint32_t surface_id) { surface_id, layer_id, x, y, w, h); } +void App::add_task(char const *name, std::function &&f) { + this->pending.emplace_back(std::make_pair(name, f)); +} + +void App::execute_pending() { + if (!this->pending.empty()) { + for (auto &t : this->pending) { + logdebug("executing task '%s'", t.first); + t.second(); + } + this->pending.clear(); + this->controller->commit_changes(); + this->display->flush(); + } +} + // _ _ _____ _ // _ __ _ __ _____ _(_) ___ __| | | ____|_ _____ _ __ | |_ ___ // | '_ \| '__/ _ \ \/ / |/ _ \/ _` | | _| \ \ / / _ \ '_ \| __/ __| @@ -331,10 +346,8 @@ void App::surface_created(uint32_t surface_id) { // We need to execute the surface setup after its creation. // XXX: perhaps move the late-tasks functionality to App? - this->controller->add_task("surface_set_layout", - [surface_id, this](struct genivi::controller *) { - this->surface_set_layout(surface_id); - }); + this->add_task("surface_set_layout", + [surface_id, this] { this->surface_set_layout(surface_id); }); } void App::surface_removed(uint32_t surface_id) { @@ -401,4 +414,8 @@ void controller_hooks::surface_removed(uint32_t surface_id) { this->app->surface_removed(surface_id); } +void controller_hooks::add_task(char const *name, std::function &&f) { + this->app->add_task(name, std::move(f)); +} + } // namespace wm diff --git a/src/app.hpp b/src/app.hpp index 63334b3..3f899ce 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -57,6 +57,9 @@ struct App { layouts_type layouts; layer_map layers; + typedef std::pair> name_task_pair; + std::vector pending; + App(wl::display *d); ~App(); @@ -68,6 +71,9 @@ struct App { int init_layout(); void surface_set_layout(uint32_t surface_id); + void add_task(char const *name, std::function &&f); + void execute_pending(); + void surface_created(uint32_t surface_id); void surface_removed(uint32_t surface_id); }; diff --git a/src/controller_hooks.hpp b/src/controller_hooks.hpp index 47ab0ec..8618edc 100644 --- a/src/controller_hooks.hpp +++ b/src/controller_hooks.hpp @@ -23,6 +23,8 @@ #include +#include + namespace wm { struct App; @@ -33,6 +35,8 @@ struct controller_hooks { void surface_created(uint32_t surface_id); void surface_removed(uint32_t surface_id); + + void add_task(char const *name, std::function &&); }; } // namespace wm diff --git a/src/wayland.cpp b/src/wayland.cpp index 3be264b..672dab0 100644 --- a/src/wayland.cpp +++ b/src/wayland.cpp @@ -426,9 +426,9 @@ void controller::layer_screen(struct layer * /*l*/, struct wl_output *screen) { void controller::layer_destroyed(struct layer *l) { logdebug("genivi::layer %s @ %p", __func__, this->proxy.get()); - add_task("remove layer", [l](struct controller *c) { - c->lprops.erase(l->id); - c->layers.erase(l->id); + this->chooks->add_task("remove layer", [l, this] { + this->lprops.erase(l->id); + this->layers.erase(l->id); }); } @@ -662,9 +662,9 @@ void controller::surface_content(struct surface *s, int32_t content_state) { if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) { // XXX is this the right thing to do? this->chooks->surface_removed(s->id); - add_task("remove surface", [s](struct controller *c) { - c->sprops.erase(s->id); - c->surfaces.erase(s->id); + this->chooks->add_task("remove surface", [this, s] { + this->sprops.erase(s->id); + this->surfaces.erase(s->id); }); } } @@ -703,23 +703,6 @@ void controller::remove_proxy_to_id_mapping(struct wl_output *p) { this->screen_proxy_to_id.erase(uintptr_t(p)); } -void controller::add_task(char const *name, - std::function &&f) { - this->pending.emplace_back(std::make_pair(name, f)); -} - -void controller::execute_pending() { - if (!this->pending.empty()) { - for (auto &t : this->pending) { - logdebug("executing task '%s'", t.first); - t.second(this); - } - this->pending.clear(); - ivi_controller_commit_changes(this->proxy.get()); - // XXX: No flush here... - } -} - // // ___ ___ _ __ ___ ___ _ __ // / __|/ __| '__/ _ \/ _ \ '_ \ diff --git a/src/wayland.hpp b/src/wayland.hpp index 4191ea0..85423fd 100644 --- a/src/wayland.hpp +++ b/src/wayland.hpp @@ -279,10 +279,6 @@ struct controller : public wayland_proxy { layer_map_type layers; screen_map_type screens; - typedef std::pair> - name_task_pair; - std::vector pending; - size output_size; wm::controller_hooks *chooks; @@ -294,11 +290,6 @@ struct controller : public wayland_proxy { void add_proxy_to_id_mapping(struct wl_output *p, uint32_t id); void remove_proxy_to_id_mapping(struct wl_output *p); - void add_task(char const *name, - std::function &&f); - void execute_pending(); - - bool surface_exists(uint32_t id) const { return this->surfaces.find(id) != this->surfaces.end(); }