From 04c82944ea3592a7c533427cee1c9cb3482a960c Mon Sep 17 00:00:00 2001 From: Marcus Fritzsch Date: Mon, 26 Jun 2017 16:37:52 +0200 Subject: [PATCH] wayland: introduce reverse mappings of proxy-ptr to id Needed to lookup the objects when we receive calls like e.g. surface::layer(). Signed-off-by: Marcus Fritzsch --- src/wayland.cpp | 13 +++++++++++-- src/wayland.hpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/wayland.cpp b/src/wayland.cpp index 7be89c5..c2c5cbe 100644 --- a/src/wayland.cpp +++ b/src/wayland.cpp @@ -198,15 +198,19 @@ constexpr struct ivi_controller_listener listener = { controller::controller(struct wl_registry *r, uint32_t name, uint32_t version) : wayland_proxy( wl_registry_bind(r, name, &ivi_controller_interface, version)), + surface_proxy_to_id{}, surfaces{}, + layer_proxy_to_id{}, layers{}, + screen_proxy_to_id{}, screens{}, pending{}, output_size{} { ivi_controller_add_listener(this->proxy, &listener, this); } -controller::~controller() {} +controller::~controller() { +} void controller::layer_create(uint32_t id, int32_t w, int32_t h) { this->layers[id] = std::make_unique(id, w, h, this); @@ -331,11 +335,13 @@ layer::layer(uint32_t i, int32_t w, int32_t h, struct controller *c) orientation{}, visibility{}, opacity{} { + this->parent->add_proxy_to_id_mapping(this->proxy, i); ivi_controller_layer_add_listener(this->proxy, &layer_listener, this); } layer::~layer() { logdebug("%s layer %i @ %p", __func__, this->id, this->proxy); + this->parent->remove_proxy_to_id_mapping(this->proxy); ivi_controller_layer_destroy(this->proxy, 1); this->proxy = nullptr; } @@ -496,11 +502,13 @@ surface::surface(uint32_t i, struct controller *c) orientation{}, visibility{}, opacity{1.f} { + this->parent->add_proxy_to_id_mapping(this->proxy, i); ivi_controller_surface_add_listener(this->proxy, &surface_listener, this); } surface::~surface() { logdebug("%s surface %i @ %p", __func__, this->id, this->proxy); + this->parent->remove_proxy_to_id_mapping(this->proxy); ivi_controller_surface_destroy(this->proxy, 1); this->proxy = nullptr; } @@ -548,7 +556,8 @@ void controller::surface_pixelformat(uint32_t id, int32_t pixelformat) { void controller::surface_layer(uint32_t id, struct ivi_controller_layer *layer) { - logdebug("genivi::surface %s @ %p l @ %p", __func__, this->proxy, layer); + logdebug("genivi::surface %s @ %p l %u @ %p", __func__, this->proxy, + this->layer_proxy_to_id[uintptr_t(layer)], layer); } void controller::surface_stats(uint32_t id, uint32_t redraw_count, diff --git a/src/wayland.hpp b/src/wayland.hpp index fbb9704..699763e 100644 --- a/src/wayland.hpp +++ b/src/wayland.hpp @@ -295,8 +295,11 @@ struct screen : public wayland_proxy, // \___\___/|_| |_|\__|_| \___/|_|_|\___|_| // struct controller : public wayland_proxy { + std::unordered_map surface_proxy_to_id; std::unordered_map> surfaces; + std::unordered_map layer_proxy_to_id; std::unordered_map> layers; + std::unordered_map screen_proxy_to_id; std::unordered_map> screens; typedef std::pair> @@ -305,6 +308,36 @@ struct controller : public wayland_proxy { size output_size; + void add_proxy_to_id_mapping(struct ivi_controller_surface *p, uint32_t id) { + this->surface_proxy_to_id[uintptr_t(p)] = id; + logdebug("Add surface proxy mapping for %p (%u)", p, id); + } + + void remove_proxy_to_id_mapping(struct ivi_controller_surface *p) { + logdebug("Remove surface proxy mapping for %p", p); + this->surface_proxy_to_id.erase(uintptr_t(p)); + } + + void add_proxy_to_id_mapping(struct ivi_controller_layer *p, uint32_t id) { + logdebug("Add layer proxy mapping for %p (%u)", p, id); + this->layer_proxy_to_id[uintptr_t(p)] = id; + } + + void remove_proxy_to_id_mapping(struct ivi_controller_layer *p) { + logdebug("Remove layer proxy mapping for %p", p); + this->layer_proxy_to_id.erase(uintptr_t(p)); + } + + void add_proxy_to_id_mapping(struct wl_output *p, uint32_t id) { + logdebug("Add screen proxy mapping for %p (%u)", p, id); + this->screen_proxy_to_id[uintptr_t(p)] = id; + } + + void remove_proxy_to_id_mapping(struct wl_output *p) { + logdebug("Remove screen proxy mapping for %p", p); + this->screen_proxy_to_id.erase(uintptr_t(p)); + } + void add_task(char const *name, std::function &&f) { this->pending.emplace_back(std::make_pair(name, f)); -- 2.16.6