6 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
7 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
8 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
9 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
14 // __| (_)___ _ __ | | __ _ _ _
15 // / _` | / __| '_ \| |/ _` | | | |
16 // | (_| | \__ \ |_) | | (_| | |_| |
17 // \__,_|_|___/ .__/|_|\__,_|\__, |
20 : d(std::unique_ptr<struct wl_display, void (*)(struct wl_display *)>(
21 wl_display_connect(nullptr),
23 [](struct wl_display *d) {
24 logdebug("wl::display ~display @ %p", d);
25 wl_display_disconnect(d);
28 &wl_display_disconnect)),
33 display::~display() = default;
35 bool display::ok() const { return d && wl_display_get_error(d.get()) == 0; }
37 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
39 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
41 void display::flush() { wl_display_flush(this->d.get()); }
43 int display::get_fd() const { return wl_display_get_fd(this->d.get()); }
46 // _ __ ___ __ _(_)___| |_ _ __ _ _
47 // | '__/ _ \/ _` | / __| __| '__| | | |
48 // | | | __/ (_| | \__ \ |_| | | |_| |
49 // |_| \___|\__, |_|___/\__|_| \__, |
52 void registry_global(void *data, struct wl_registry * /*r*/, uint32_t name,
53 char const *iface, uint32_t v) {
54 static_cast<struct registry *>(data)->global(name, iface, v);
57 void registry_global_remove(void *data, struct wl_registry * /*r*/,
59 static_cast<struct registry *>(data)->global_remove(name);
62 constexpr struct wl_registry_listener registry_listener = {
63 registry_global, registry_global_remove};
66 registry::registry(struct wl_display *d)
67 : wayland_proxy(d == nullptr ? nullptr : wl_display_get_registry(d)) {
68 if (this->proxy != nullptr) {
69 wl_registry_add_listener(this->proxy, ®istry_listener, this);
73 registry::~registry() {
74 logdebug("wl::registry %s @ %p", __func__, this->proxy);
77 void registry::add_global_handler(char const *iface, binder bind) {
78 this->bindings[iface] = std::move(bind);
81 void registry::global(uint32_t name, char const *iface, uint32_t v) {
82 auto b = this->bindings.find(iface);
83 if (b != this->bindings.end()) {
84 b->second(this->proxy, name, v);
86 logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name, iface,
90 void registry::global_remove(uint32_t /*name*/) {}
93 // ___ _ _| |_ _ __ _ _| |_
94 // / _ \| | | | __| '_ \| | | | __|
95 // | (_) | |_| | |_| |_) | |_| | |_
96 // \___/ \__,_|\__| .__/ \__,_|\__|
99 void output_geometry(void *data, struct wl_output * /*wl_output*/, int32_t x,
100 int32_t y, int32_t physical_width, int32_t physical_height,
101 int32_t subpixel, const char *make, const char *model,
103 static_cast<struct output *>(data)->geometry(
104 x, y, physical_width, physical_height, subpixel, make, model, transform);
107 void output_mode(void *data, struct wl_output * /*wl_output*/, uint32_t flags,
108 int32_t width, int32_t height, int32_t refresh) {
109 static_cast<struct output *>(data)->mode(flags, width, height, refresh);
112 void output_done(void *data, struct wl_output * /*wl_output*/) {
113 static_cast<struct output *>(data)->done();
116 void output_scale(void *data, struct wl_output * /*wl_output*/,
118 static_cast<struct output *>(data)->scale(factor);
121 constexpr struct wl_output_listener output_listener = {
122 output_geometry, output_mode, output_done, output_scale};
125 output::output(struct wl_registry *r, uint32_t name, uint32_t v)
126 : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
127 wl_output_add_listener(this->proxy, &output_listener, this);
130 void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
131 int32_t subpel, char const *make, char const *model,
134 "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
135 __func__, this->proxy, x, y, pw, ph, subpel, make, model, tx);
138 void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
139 logdebug("wl::output %s @ %p f %x w %i h %i r %i", __func__, this->proxy,
141 if ((flags & WL_OUTPUT_MODE_CURRENT) != 0u) {
148 void output::done() {
149 logdebug("wl::output %s @ %p done", __func__, this->proxy);
152 void output::scale(int32_t factor) {
153 logdebug("wl::output %s @ %p f %i", __func__, this->proxy, factor);
157 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
158 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
159 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
160 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
163 // __ _ ___ _ __ (_)_ _(_)
164 // / _` |/ _ \ '_ \| \ \ / / |
165 // | (_| | __/ | | | |\ V /| |
166 // \__, |\___|_| |_|_| \_/ |_|
171 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
172 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
173 // | (_| (_) | | | | |_| | | (_) | | | __/ |
174 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
177 void controller_screen(void *data, struct ivi_controller * /*ivi_controller*/,
179 struct ivi_controller_screen *screen) {
180 static_cast<struct controller *>(data)->controller_screen(id_screen, screen);
183 void controller_layer(void *data, struct ivi_controller * /*ivi_controller*/,
185 static_cast<struct controller *>(data)->controller_layer(id_layer);
188 void controller_surface(void *data, struct ivi_controller * /*ivi_controller*/,
189 uint32_t id_surface) {
190 static_cast<struct controller *>(data)->controller_surface(id_surface);
193 void controller_error(void *data, struct ivi_controller * /*ivi_controller*/,
194 int32_t object_id, int32_t object_type,
195 int32_t error_code, const char *error_text) {
196 static_cast<struct controller *>(data)->controller_error(
197 object_id, object_type, error_code, error_text);
200 constexpr struct ivi_controller_listener listener = {
201 controller_screen, controller_layer, controller_surface, controller_error};
204 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
206 wl_registry_bind(r, name, &ivi_controller_interface, version)),
207 surface_proxy_to_id{},
211 screen_proxy_to_id{},
215 ivi_controller_add_listener(this->proxy, &listener, this);
218 controller::~controller() = default;
220 void controller::layer_create(uint32_t id, int32_t w, int32_t h) {
221 this->layers[id] = std::make_unique<layer>(id, w, h, this);
224 void controller::surface_create(uint32_t id) {
225 this->surfaces[id] = std::make_unique<surface>(id, this);
228 void controller::controller_screen(uint32_t id,
229 struct ivi_controller_screen *screen) {
230 logdebug("genivi::controller @ %p screen %u (%x) @ %p", this->proxy, id, id,
232 this->screens[id] = std::make_unique<struct screen>(id, this, screen);
235 void controller::controller_layer(uint32_t id) {
236 logdebug("genivi::controller @ %p layer %u (%x)", this->proxy, id, id);
237 auto &l = this->layers[id] = std::make_unique<struct layer>(id, this);
241 void controller::controller_surface(uint32_t id) {
242 logdebug("genivi::controller @ %p surface %u (%x)", this->proxy, id, id);
243 this->surfaces[id] = std::make_unique<struct surface>(id, this);
245 add_task("fullscreen surface", [id](struct controller *c) {
246 auto &s = c->surfaces[id];
247 s->set_destination_rectangle(0, 0, c->output_size.w, c->output_size.h);
248 s->set_visibility(1);
249 uint32_t lid = id == 0x16180 ? 1000 : 100;
250 c->layers[lid]->add_surface(s.get());
251 logdebug("Surface %u now fullscreen on layer %u", id, lid);
255 void controller::controller_error(int32_t object_id, int32_t object_type,
256 int32_t error_code, const char *error_text) {
257 logdebug("genivi::controller @ %p error o %i t %i c %i text %s", this->proxy,
258 object_id, object_type, error_code, error_text);
262 // | | __ _ _ _ ___ _ __
263 // | |/ _` | | | |/ _ \ '__|
264 // | | (_| | |_| | __/ |
265 // |_|\__,_|\__, |\___|_|
268 void layer_visibility(void *data,
269 struct ivi_controller_layer * /*ivi_controller_layer*/,
270 int32_t visibility) {
271 auto l = static_cast<struct layer *>(data);
272 l->parent->layer_visibility(l->id, visibility);
275 void layer_opacity(void *data,
276 struct ivi_controller_layer * /*ivi_controller_layer*/,
277 wl_fixed_t opacity) {
278 auto l = static_cast<struct layer *>(data);
279 l->parent->layer_opacity(l->id, float(wl_fixed_to_double(opacity)));
282 void layer_source_rectangle(
283 void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
284 int32_t x, int32_t y, int32_t width, int32_t height) {
285 auto l = static_cast<struct layer *>(data);
286 l->parent->layer_source_rectangle(l->id, x, y, width, height);
289 void layer_destination_rectangle(
290 void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
291 int32_t x, int32_t y, int32_t width, int32_t height) {
292 auto l = static_cast<struct layer *>(data);
293 l->parent->layer_destination_rectangle(l->id, x, y, width, height);
296 void layer_configuration(void *data,
297 struct ivi_controller_layer * /*ivi_controller_layer*/,
298 int32_t width, int32_t height) {
299 auto l = static_cast<struct layer *>(data);
300 l->parent->layer_configuration(l->id, width, height);
303 void layer_orientation(void *data,
304 struct ivi_controller_layer * /*ivi_controller_layer*/,
305 int32_t orientation) {
306 auto l = static_cast<struct layer *>(data);
307 l->parent->layer_orientation(l->id, orientation);
310 void layer_screen(void *data,
311 struct ivi_controller_layer * /*ivi_controller_layer*/,
312 struct wl_output *screen) {
313 auto l = static_cast<struct layer *>(data);
314 l->parent->layer_screen(l->id, screen);
317 void layer_destroyed(void *data,
318 struct ivi_controller_layer * /*ivi_controller_layer*/) {
319 auto l = static_cast<struct layer *>(data);
320 l->parent->layer_destroyed(l->id);
323 constexpr struct ivi_controller_layer_listener layer_listener = {
324 layer_visibility, layer_opacity,
325 layer_source_rectangle, layer_destination_rectangle,
326 layer_configuration, layer_orientation,
327 layer_screen, layer_destroyed,
331 layer::layer(uint32_t i, struct controller *c) : layer(i, 0, 0, c) {}
333 layer::layer(uint32_t i, int32_t w, int32_t h, struct controller *c)
334 : wayland_proxy(ivi_controller_layer_create(c->proxy, i, w, h)),
335 controller_child(c, i),
342 this->parent->add_proxy_to_id_mapping(this->proxy, i);
343 ivi_controller_layer_add_listener(this->proxy, &layer_listener, this);
347 logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
348 this->parent->remove_proxy_to_id_mapping(this->proxy);
349 ivi_controller_layer_destroy(this->proxy, 1);
350 this->proxy = nullptr;
353 void controller::layer_visibility(uint32_t id, int32_t visibility) {
354 logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
355 this->layers[id]->visibility = visibility;
358 void controller::layer_opacity(uint32_t id, float opacity) {
359 logdebug("genivi::layer %s @ %p o %f", __func__, this->proxy, opacity);
360 this->layers[id]->opacity = opacity;
363 void controller::layer_source_rectangle(uint32_t id, int32_t x, int32_t y,
364 int32_t width, int32_t height) {
365 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
366 x, y, width, height);
367 this->layers[id]->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
370 void controller::layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
371 int32_t width, int32_t height) {
372 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
373 x, y, width, height);
374 this->layers[id]->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
377 void controller::layer_configuration(uint32_t id, int32_t width,
379 logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
381 this->layers[id]->size = size{uint32_t(width), uint32_t(height)};
384 void controller::layer_orientation(uint32_t id, int32_t orientation) {
385 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
386 this->layers[id]->orientation = orientation;
389 void controller::layer_screen(uint32_t /*id*/, struct wl_output *screen) {
390 logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
393 void controller::layer_destroyed(uint32_t id) {
394 logdebug("genivi::layer %s @ %p", __func__, this->proxy);
395 add_task("remove layer",
396 [id](struct controller *c) { c->layers.erase(id); });
400 // ___ _ _ _ __ / _| __ _ ___ ___
401 // / __| | | | '__| |_ / _` |/ __/ _ \
402 // \__ \ |_| | | | _| (_| | (_| __/
403 // |___/\__,_|_| |_| \__,_|\___\___|
407 void surface_visibility(
408 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
409 int32_t visibility) {
410 auto s = static_cast<struct surface *>(data);
411 s->parent->surface_visibility(s->id, visibility);
414 void surface_opacity(void *data,
415 struct ivi_controller_surface * /*ivi_controller_surface*/,
416 wl_fixed_t opacity) {
417 auto s = static_cast<struct surface *>(data);
418 s->parent->surface_opacity(s->id, float(wl_fixed_to_double(opacity)));
421 void surface_source_rectangle(
422 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
423 int32_t x, int32_t y, int32_t width, int32_t height) {
424 auto s = static_cast<struct surface *>(data);
425 s->parent->surface_source_rectangle(s->id, x, y, width, height);
428 void surface_destination_rectangle(
429 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
430 int32_t x, int32_t y, int32_t width, int32_t height) {
431 auto s = static_cast<struct surface *>(data);
432 s->parent->surface_destination_rectangle(s->id, x, y, width, height);
435 void surface_configuration(
436 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
437 int32_t width, int32_t height) {
438 auto s = static_cast<struct surface *>(data);
439 s->parent->surface_configuration(s->id, width, height);
442 void surface_orientation(
443 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
444 int32_t orientation) {
445 auto s = static_cast<struct surface *>(data);
446 s->parent->surface_orientation(s->id, orientation);
449 void surface_pixelformat(
450 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
451 int32_t pixelformat) {
452 auto s = static_cast<struct surface *>(data);
453 s->parent->surface_pixelformat(s->id, pixelformat);
456 void surface_layer(void *data,
457 struct ivi_controller_surface * /*ivi_controller_surface*/,
458 struct ivi_controller_layer *layer) {
459 auto s = static_cast<struct surface *>(data);
460 s->parent->surface_layer(s->id, layer);
463 void surface_stats(void *data,
464 struct ivi_controller_surface * /*ivi_controller_surface*/,
465 uint32_t redraw_count, uint32_t frame_count,
466 uint32_t update_count, uint32_t pid,
467 const char *process_name) {
468 auto s = static_cast<struct surface *>(data);
469 s->parent->surface_stats(s->id, redraw_count, frame_count,
470 update_count, pid, process_name);
473 void surface_destroyed(
474 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/) {
475 auto s = static_cast<struct surface *>(data);
476 s->parent->surface_destroyed(s->id);
479 void surface_content(void *data,
480 struct ivi_controller_surface * /*ivi_controller_surface*/,
481 int32_t content_state) {
482 auto s = static_cast<struct surface *>(data);
483 s->parent->surface_content(s->id, content_state);
486 constexpr struct ivi_controller_surface_listener surface_listener = {
489 surface_source_rectangle,
490 surface_destination_rectangle,
491 surface_configuration,
501 surface::surface(uint32_t i, struct controller *c)
502 : wayland_proxy(ivi_controller_surface_create(c->proxy, i)),
503 controller_child(c, i),
510 this->parent->add_proxy_to_id_mapping(this->proxy, i);
511 ivi_controller_surface_add_listener(this->proxy, &surface_listener, this);
514 surface::~surface() {
515 logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
516 this->parent->remove_proxy_to_id_mapping(this->proxy);
517 ivi_controller_surface_destroy(this->proxy, 1);
518 this->proxy = nullptr;
521 void controller::surface_visibility(uint32_t id, int32_t visibility) {
522 logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
523 this->surfaces[id]->visibility = visibility;
526 void controller::surface_opacity(uint32_t id, float opacity) {
527 logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy, opacity);
528 this->surfaces[id]->opacity = opacity;
531 void controller::surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
532 int32_t width, int32_t height) {
533 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
534 this->proxy, x, y, width, height);
535 this->surfaces[id]->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
538 void controller::surface_destination_rectangle(uint32_t id, int32_t x,
539 int32_t y, int32_t width,
541 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
542 this->proxy, x, y, width, height);
543 this->surfaces[id]->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
546 void controller::surface_configuration(uint32_t id, int32_t width,
548 logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
550 this->surfaces[id]->size = size{uint32_t(width), uint32_t(height)};
553 void controller::surface_orientation(uint32_t id, int32_t orientation) {
554 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
555 this->surfaces[id]->orientation = orientation;
558 void controller::surface_pixelformat(uint32_t /*id*/, int32_t pixelformat) {
559 logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
562 void controller::surface_layer(uint32_t /*id*/,
563 struct ivi_controller_layer *layer) {
564 logdebug("genivi::surface %s @ %p l %u @ %p", __func__, this->proxy,
565 this->layer_proxy_to_id[uintptr_t(layer)], layer);
568 void controller::surface_stats(uint32_t /*id*/, uint32_t redraw_count,
569 uint32_t frame_count, uint32_t update_count,
570 uint32_t pid, const char *process_name) {
571 logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
572 this->proxy, redraw_count, frame_count, update_count, pid,
576 void controller::surface_destroyed(uint32_t id) {
577 logdebug("genivi::surface %s @ %p", __func__, this->proxy);
578 this->surfaces.erase(id);
581 void controller::surface_content(uint32_t id, int32_t content_state) {
582 logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
584 if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
585 add_task("remove surface",
586 [id](struct controller *c) { c->surfaces.erase(id); });
591 // ___ ___ _ __ ___ ___ _ __
592 // / __|/ __| '__/ _ \/ _ \ '_ \
593 // \__ \ (__| | | __/ __/ | | |
594 // |___/\___|_| \___|\___|_| |_|
596 screen::screen(uint32_t i, struct controller *c,
597 struct ivi_controller_screen *p)
598 : wayland_proxy(p), controller_child(c, i) {
599 logdebug("genivi::screen @ %p id %u", p, i);
601 } // namespace genivi