diff options
author | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2017-11-01 11:00:08 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@automotivelinux.org> | 2017-11-01 11:00:08 +0000 |
commit | c0f383d989821c61872aaa38932fa7719dc97120 (patch) | |
tree | a0a812ed805803cddb3c4c47abc711134f208130 | |
parent | 022def7c34eff5814ef9b5ba3bba7c7d8b869297 (diff) | |
parent | eb7fc4eb593d723f1ac2ed4e5b523afd34e992ac (diff) |
Merge "Add drawing_area parameter to API"
-rw-r--r-- | generate-binding-glue.py | 2 | ||||
-rw-r--r-- | src/afb_binding_api.cpp | 4 | ||||
-rw-r--r-- | src/app.cpp | 90 | ||||
-rw-r--r-- | src/app.hpp | 15 | ||||
-rwxr-xr-x | src/main.cpp | 20 |
5 files changed, 76 insertions, 55 deletions
diff --git a/generate-binding-glue.py b/generate-binding-glue.py index de78634..dbebbcd 100644 --- a/generate-binding-glue.py +++ b/generate-binding-glue.py @@ -93,6 +93,7 @@ def emit_afb_api(api): p(' typedef wm::result<json_object *> result_type;') p(' struct wm::App *app;') p(' void send_event(char const *evname, char const *label);') + p(' void send_event(char const *evname, char const *label, char const *area);') for f in api['functions']: p(' result_type %(name)s(' % f + ', '.join(map(lambda x: '%(type)s %(name)s' % x, f.get('args', []))) + ');') p('};', '') @@ -116,6 +117,7 @@ API = { 'name': 'activatesurface', 'args': [ { 'name': 'drawing_name', 'type': 'char const*', 'jtype': 'string' }, + { 'name': 'drawing_area', 'type': 'char const*', 'jtype': 'string' }, ], }, { diff --git a/src/afb_binding_api.cpp b/src/afb_binding_api.cpp index 9311700..b608a8a 100644 --- a/src/afb_binding_api.cpp +++ b/src/afb_binding_api.cpp @@ -42,9 +42,9 @@ binding_api::result_type binding_api::requestsurface( } binding_api::result_type binding_api::activatesurface( - char const *drawing_name) { + char const *drawing_name, char const *drawing_area) { logdebug("%s drawing_name %s", __func__, drawing_name); - auto r = this->app->api_activate_surface(drawing_name); + auto r = this->app->api_activate_surface(drawing_name, drawing_area); if (r != nullptr) { logdebug("%s failed with error: %s", __func__, r); return Err<json_object *>(r); diff --git a/src/app.cpp b/src/app.cpp index 8aa7547..f38668f 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -66,12 +66,9 @@ struct result<layer_map> load_layer_map(char const *filename) { } // namespace -// _ _ _ _ -// ___| | __ _ ___ ___ / \ _ __ _ __ (_)_ __ ___ _ __ | | -// / __| |/ _` / __/ __| / _ \ | '_ \| '_ \ | | '_ ` _ \| '_ \| | -// | (__| | (_| \__ \__ \ / ___ \| |_) | |_) | | | | | | | | |_) | | -// \___|_|\__,_|___/___/ /_/ \_\ .__/| .__/ |_|_| |_| |_| .__/|_| -// |_| |_| |_| +/** + * App Impl + */ App::App(wl::display *d) : api{this}, chooks{this}, @@ -158,8 +155,8 @@ int App::dispatch_events() { int App::dispatch_pending_events() { if (this->pop_pending_events()) { this->display->dispatch_pending(); - return 0; -} + return 0; + } return -1; } @@ -180,12 +177,9 @@ optional<std::string> App::lookup_name(int id) { return this->id_alloc.lookup(id); } -// _ _ _ _ _ ____ -// (_)_ __ (_) |_ | | __ _ _ _ ___ _ _| |_ / /\ \ -// | | '_ \| | __| | |/ _` | | | |/ _ \| | | | __| | | | -// | | | | | | |_ | | (_| | |_| | (_) | |_| | |_| | | | -// |_|_| |_|_|\__|___|_|\__,_|\__, |\___/ \__,_|\__| | | | -// |_____| |___/ \_\/_/ +/** + * init_layers() + */ int App::init_layers() { if (!this->controller) { logerror("ivi_controller global not available"); @@ -203,7 +197,7 @@ int App::init_layers() { auto &s = c->screens.begin()->second; auto &layers = c->layers; - // XXX: Write output dimensions to ivi controller... + // Write output dimensions to ivi controller... c->output_size = genivi::size{uint32_t(o->width), uint32_t(o->height)}; // Clear scene @@ -213,8 +207,6 @@ int App::init_layers() { s->clear(); // Quick and dirty setup of layers - // XXX: This likely needs to be sorted by order (note, we don't (yet?) - // do any zorder arrangement). 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]; @@ -224,7 +216,7 @@ int App::init_layers() { i.second.name.c_str(), i.second.layer_id, i.second.role.c_str()); } - // Add layers to screen (XXX: are they sorted correctly?) + // Add layers to screen s->set_render_order(this->layers.layers); this->layout_commit(); @@ -290,7 +282,7 @@ void App::surface_set_layout(int surface_id, optional<int> sub_surface_id) { logdebug("surface_set_layout for sub surface %u on layer %u", *sub_surface_id, layer_id); - // configure surface to wxh dimensions + // configure surface to wxh dimensions ss->set_configuration(w, h); // set source reactangle, even if we should not need to set it. ss->set_source_rectangle(0, 0, w, h); @@ -318,7 +310,7 @@ void App::layout_commit() { this->display->flush(); } -char const *App::api_activate_surface(char const *drawing_name) { +char const *App::api_activate_surface(char const *drawing_name, char const *drawing_area) { ST(); auto const &surface_id = this->lookup_id(drawing_name); @@ -340,7 +332,7 @@ char const *App::api_activate_surface(char const *drawing_name) { if (o_state == nullptr) { return "Could not find layer for surface"; -} + } struct LayoutState &state = *o_state; @@ -355,13 +347,13 @@ char const *App::api_activate_surface(char const *drawing_name) { 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(); @@ -376,9 +368,9 @@ char const *App::api_activate_surface(char const *drawing_name) { this->try_layout( state, LayoutState{*surface_id}, [&] (LayoutState const &nl) { this->surface_set_layout(*surface_id); - // XXX do we need to activate after enddraw? state = nl; - this->emit_syncdraw(drawing_name); + std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull); + this->emit_syncdraw(drawing_name, str_area.c_str()); this->enqueue_flushdraw(state.main); }); } else { @@ -395,11 +387,13 @@ char const *App::api_activate_surface(char const *drawing_name) { this->surface_set_layout(state.main, surface_id); if (state.sub != -1) { this->deactivate(state.sub); - } + } state = nl; - this->emit_syncdraw(drawing_name); - this->emit_syncdraw(main.c_str()); + std::string str_area_main = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaMain); + std::string str_area_sub = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaSub); + this->emit_syncdraw(main.c_str(), str_area_main.c_str()); + this->emit_syncdraw(drawing_name, str_area_sub.c_str()); this->enqueue_flushdraw(state.main); this->enqueue_flushdraw(state.sub); }); @@ -410,10 +404,12 @@ char const *App::api_activate_surface(char const *drawing_name) { this->deactivate(state.main); if (state.sub != -1) { this->deactivate(state.sub); - } + } state = nl; - this->emit_syncdraw(drawing_name); + + std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull); + this->emit_syncdraw(drawing_name, str_area.c_str()); this->enqueue_flushdraw(state.main); }); } @@ -465,7 +461,8 @@ char const *App::api_deactivate_surface(char const *drawing_name) { state = nl; this->layout_commit(); - this->emit_syncdraw(sub.c_str()); + std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull); + this->emit_syncdraw(sub.c_str(), str_area.c_str()); this->enqueue_flushdraw(state.sub); }); } else { @@ -485,7 +482,8 @@ char const *App::api_deactivate_surface(char const *drawing_name) { state = nl; this->layout_commit(); - this->emit_syncdraw(main.c_str()); + std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull); + this->emit_syncdraw(main.c_str(), str_area.c_str()); this->enqueue_flushdraw(state.main); }); } else { @@ -533,12 +531,9 @@ char const *App::api_enddraw(char const *drawing_name) { void App::api_ping() { this->dispatch_pending_events(); } -// _ _ _____ _ -// _ __ _ __ _____ _(_) ___ __| | | ____|_ _____ _ __ | |_ ___ -// | '_ \| '__/ _ \ \/ / |/ _ \/ _` | | _| \ \ / / _ \ '_ \| __/ __| -// | |_) | | | (_) > <| | __/ (_| | | |___ \ V / __/ | | | |_\__ \ -// | .__/|_| \___/_/\_\_|\___|\__,_| |_____| \_/ \___|_| |_|\__|___/ -// |_| +/** + * proxied events + */ void App::surface_created(uint32_t surface_id) { auto layer_id = this->layers.get_layer_id(surface_id); if (!layer_id) { @@ -587,8 +582,8 @@ void App::emit_deactivated(char const *label) { this->api.send_event("inactive", label); } -void App::emit_syncdraw(char const *label) { - this->api.send_event("syncdraw", label); +void App::emit_syncdraw(char const *label, char const *area) { + this->api.send_event("syncdraw", label, area); } void App::emit_flushdraw(char const *label) { @@ -668,7 +663,7 @@ bool App::can_split(struct LayoutState const &state, int new_id) { // surfaces are on separate layers, don't bother. if (new_id_layer != current_id_layer) { return false; -} + } std::string const &new_id_str = this->lookup_name(new_id).value(); std::string const &cur_id_str = this->lookup_name(state.main).value(); @@ -679,7 +674,7 @@ bool App::can_split(struct LayoutState const &state, int new_id) { if (layer->layouts.empty()) { return false; -} + } for (auto i = layer->layouts.cbegin(); i != layer->layouts.cend(); i++) { logdebug("%d main_match '%s'", new_id_layer, i->main_match.c_str()); @@ -691,7 +686,7 @@ bool App::can_split(struct LayoutState const &state, int new_id) { if (std::regex_match(new_id_str, res)) { logdebug("layout matched!"); return true; -} + } } } } @@ -707,12 +702,9 @@ void App::try_layout(struct LayoutState & /*state*/, } } -// _ _ _ _ _ -// ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __ | |__ ___ ___ | | _____ -// / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|| '_ \ / _ \ / _ \| |/ / __| -// | (_| (_) | | | | |_| | | (_) | | | __/ | | | | | (_) | (_) | <\__ \ -// \___\___/|_| |_|\__|_| \___/|_|_|\___|_|___|_| |_|\___/ \___/|_|\_\___/ -// |_____| +/** + * controller_hooks + */ void controller_hooks::surface_created(uint32_t surface_id) { this->app->surface_created(surface_id); } diff --git a/src/app.hpp b/src/app.hpp index 9424d9f..ea3e92b 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -46,6 +46,17 @@ namespace wm { using std::experimental::optional; +/* DrawingArea name used by "{layout}.{area}" */ +static const char *kNameLayoutNormal = "normal"; +static const char *kNameLayoutSplit = "split"; +static const char *kNameAreaFull = "full"; +static const char *kNameAreaMain = "main"; +static const char *kNameAreaSub = "sub"; + +/* Key for json obejct */ +static const char *kKeyDrawingName = "drawing_name"; +static const char *kKeyDrawingArea = "drawing_area"; + struct id_allocator { unsigned next = 1; @@ -141,7 +152,7 @@ struct App { void set_pending_events(); result<int> api_request_surface(char const *drawing_name); - char const *api_activate_surface(char const *drawing_name); + char const *api_activate_surface(char const *drawing_name, char const *drawing_area); char const *api_deactivate_surface(char const *drawing_name); char const *api_enddraw(char const *drawing_name); void api_ping(); @@ -167,7 +178,7 @@ private: // TMC WM Events to clients void emit_activated(char const *label); void emit_deactivated(char const *label); - void emit_syncdraw(char const *label); + void emit_syncdraw(char const *label, char const *area); void emit_flushdraw(char const *label); void emit_visible(char const *label, bool is_visible); void emit_invisible(char const *label); diff --git a/src/main.cpp b/src/main.cpp index a1e3db8..f33b20e 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -160,11 +160,27 @@ int binding_init() noexcept { #include "afb_binding_glue.inl" -// XXX implement send_event right here... namespace wm { void binding_api::send_event(char const *evname, char const *label) { logdebug("%s: %s(%s)", __func__, evname, label); - int ret = afb_daemon_broadcast_event(evname, json_object_new_string(label)); + + json_object *j = json_object_new_object(); + json_object_object_add(j, kKeyDrawingName, json_object_new_string(label)); + + int ret = afb_daemon_broadcast_event(evname, j); + if (ret != 0) { + logdebug("afb_event_broadcast failed: %m"); + } +} + +void binding_api::send_event(char const *evname, char const *label, char const *area) { + logdebug("%s: %s(%s, %s)", __func__, evname, label, area); + + json_object *j = json_object_new_object(); + json_object_object_add(j, kKeyDrawingName, json_object_new_string(label)); + json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area)); + + int ret = afb_daemon_broadcast_event(evname, j); if (ret != 0) { logdebug("afb_event_broadcast failed: %m"); } |