+void surface_destination_rectangle(
+ void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
+ int32_t x, int32_t y, int32_t width, int32_t height) {
+ auto s = static_cast<struct surface *>(data);
+ s->parent->surface_destination_rectangle(s, x, y, width, height);
+}
+
+void surface_configuration(
+ void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
+ int32_t width, int32_t height) {
+ auto s = static_cast<struct surface *>(data);
+ s->parent->surface_configuration(s, width, height);
+}
+
+void surface_orientation(
+ void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
+ int32_t orientation) {
+ auto s = static_cast<struct surface *>(data);
+ s->parent->surface_orientation(s, orientation);
+}
+
+void surface_pixelformat(
+ void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
+ int32_t pixelformat) {
+ auto s = static_cast<struct surface *>(data);
+ s->parent->surface_pixelformat(s, pixelformat);
+}
+
+void surface_layer(void *data,
+ struct ivi_controller_surface * /*ivi_controller_surface*/,
+ struct ivi_controller_layer *layer) {
+ auto s = static_cast<struct surface *>(data);
+ s->parent->surface_layer(s, layer);
+}
+
+void surface_stats(void *data,
+ struct ivi_controller_surface * /*ivi_controller_surface*/,
+ uint32_t redraw_count, uint32_t frame_count,
+ uint32_t update_count, uint32_t pid,
+ const char *process_name) {
+ auto s = static_cast<struct surface *>(data);
+ s->parent->surface_stats(s, redraw_count, frame_count, update_count, pid,
+ process_name);
+}
+
+void surface_destroyed(
+ void *data, struct ivi_controller_surface * /*ivi_controller_surface*/) {
+ auto s = static_cast<struct surface *>(data);
+ s->parent->surface_destroyed(s);
+}
+
+void surface_content(void *data,
+ struct ivi_controller_surface * /*ivi_controller_surface*/,
+ int32_t content_state) {
+ auto s = static_cast<struct surface *>(data);
+ s->parent->surface_content(s, content_state);
+}
+
+constexpr struct ivi_controller_surface_listener surface_listener = {
+ surface_visibility,
+ surface_opacity,
+ surface_source_rectangle,
+ surface_destination_rectangle,
+ surface_configuration,
+ surface_orientation,
+ surface_pixelformat,
+ surface_layer,
+ surface_stats,
+ surface_destroyed,
+ surface_content,
+};
+} // namespace
+
+surface::surface(uint32_t i, struct controller *c)
+ : wayland_proxy(ivi_controller_surface_create(c->proxy.get(), i),
+ [c, i](ivi_controller_surface *s) {
+ logdebug("~surface surface %i @ %p", i, s);
+ c->remove_proxy_to_id_mapping(s);
+ ivi_controller_surface_destroy(s, 1);
+ }),
+ controller_child(c, i),
+ dst_rect{},
+ src_rect{},
+ size{},
+ orientation{},
+ visibility{},
+ opacity{1.f} {
+ this->parent->add_proxy_to_id_mapping(this->proxy.get(), i);
+ ivi_controller_surface_add_listener(this->proxy.get(), &surface_listener,
+ this);
+}
+
+void surface::set_visibility(uint32_t visibility) {
+ ivi_controller_surface_set_visibility(this->proxy.get(), visibility);
+}
+
+void surface::set_opacity(wl_fixed_t opacity) {
+ ivi_controller_surface_set_opacity(this->proxy.get(), opacity);
+}
+
+void surface::set_source_rectangle(int32_t x, int32_t y, int32_t width,
+ int32_t height) {
+ ivi_controller_surface_set_source_rectangle(this->proxy.get(), x, y, width,
+ height);
+}
+
+void surface::set_destination_rectangle(int32_t x, int32_t y, int32_t width,
+ int32_t height) {
+ ivi_controller_surface_set_destination_rectangle(this->proxy.get(), x, y,
+ width, height);
+}
+
+void surface::set_configuration(int32_t width, int32_t height) {
+ ivi_controller_surface_set_configuration(this->proxy.get(), width, height);
+}
+
+void surface::set_orientation(int32_t orientation) {
+ ivi_controller_surface_set_orientation(this->proxy.get(), orientation);
+}
+
+void surface::screenshot(const char *filename) {
+ ivi_controller_surface_screenshot(this->proxy.get(), filename);
+}
+
+void surface::send_stats() {
+ ivi_controller_surface_send_stats(this->proxy.get());
+}
+
+void surface::destroy(int32_t destroy_scene_object) {
+ ivi_controller_surface_destroy(this->proxy.get(), destroy_scene_object);
+}
+
+void controller::surface_visibility(struct surface *s, int32_t visibility) {
+ logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy.get(),
+ visibility);
+ s->visibility = visibility;
+}
+
+void controller::surface_opacity(struct surface *s, float opacity) {
+ logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy.get(),
+ opacity);
+ s->opacity = opacity;
+}
+
+void controller::surface_source_rectangle(struct surface *s, int32_t x,
+ int32_t y, int32_t width,
+ int32_t height) {
+ logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
+ this->proxy.get(), x, y, width, height);
+ s->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
+}
+
+void controller::surface_destination_rectangle(struct surface *s, int32_t x,
+ int32_t y, int32_t width,
+ int32_t height) {
+ logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
+ this->proxy.get(), x, y, width, height);
+ s->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
+}
+
+void controller::surface_configuration(struct surface *s, int32_t width,
+ int32_t height) {
+ logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy.get(),
+ width, height);
+ s->size = size{uint32_t(width), uint32_t(height)};
+}
+
+void controller::surface_orientation(struct surface *s, int32_t orientation) {
+ logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy.get(),
+ orientation);
+ s->orientation = orientation;
+}
+
+void controller::surface_pixelformat(struct surface *s, int32_t pixelformat) {
+ logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy.get(),
+ pixelformat);
+}
+
+void controller::surface_layer(struct surface *s,
+ struct ivi_controller_layer *layer) {
+ logdebug("genivi::surface %s @ %p l %u @ %p", __func__, this->proxy.get(),
+ this->layer_proxy_to_id[uintptr_t(layer)], layer);
+}
+
+void controller::surface_stats(struct surface *s, uint32_t redraw_count,
+ uint32_t frame_count, uint32_t update_count,
+ uint32_t pid, const char *process_name) {
+ logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
+ this->proxy.get(), redraw_count, frame_count, update_count, pid,
+ process_name);
+}
+
+void controller::surface_destroyed(struct surface *s) {
+ logdebug("genivi::surface %s @ %p", __func__, this->proxy.get());
+ this->surfaces.erase(s->id);
+}
+
+void controller::surface_content(struct surface *s, int32_t content_state) {
+ logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy.get(),
+ content_state);
+ if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
+ add_task("remove surface",
+ [s](struct controller *c) { c->surfaces.erase(s->id); });
+ }
+}
+
+void controller::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 controller::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 controller::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 controller::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 controller::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 controller::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 controller::add_task(char const *name,
+ std::function<void(struct controller *)> &&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...
+ }
+}
+
+void controller::debug_dump_current_status() {
+ if (!this->surfaces.empty()) {
+ puts("Surfaces:");
+ for (auto const &i : this->surfaces) {
+ auto const &r = i.second->dst_rect;
+ auto const &s = i.second->size;
+ printf("%d [%ux%u] (%ux%u@%dx%d), ", i.first, s.w, s.h, r.w, r.h,
+ r.x, r.y);
+ }
+ puts("\b\b ");
+ }
+
+ if (!this->layers.empty()) {
+ puts("Layers:");
+ for (auto const &i : this->layers) {
+ auto const &r = i.second->dst_rect;
+ auto const &s = i.second->size;
+ printf("%d [%ux%u] (%ux%u@%dx%d), ", i.first, s.w, s.h, r.w, r.h,
+ r.x, r.y);
+ }
+ puts("\b\b ");
+ }
+}