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 static_cast<struct layer *>(data)->parent->layer_visibility(
272 static_cast<struct layer *>(data)->id, visibility);
275 void layer_opacity(void *data,
276 struct ivi_controller_layer * /*ivi_controller_layer*/,
277 wl_fixed_t opacity) {
278 static_cast<struct layer *>(data)->parent->layer_opacity(
279 static_cast<struct layer *>(data)->id,
280 float(wl_fixed_to_double(opacity)));
283 void layer_source_rectangle(
284 void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
285 int32_t x, int32_t y, int32_t width, int32_t height) {
286 static_cast<struct layer *>(data)->parent->layer_source_rectangle(
287 static_cast<struct layer *>(data)->id, x, y, width, height);
290 void layer_destination_rectangle(
291 void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
292 int32_t x, int32_t y, int32_t width, int32_t height) {
293 static_cast<struct layer *>(data)->parent->layer_destination_rectangle(
294 static_cast<struct layer *>(data)->id, x, y, width, height);
297 void layer_configuration(void *data,
298 struct ivi_controller_layer * /*ivi_controller_layer*/,
299 int32_t width, int32_t height) {
300 static_cast<struct layer *>(data)->parent->layer_configuration(
301 static_cast<struct layer *>(data)->id, width, height);
304 void layer_orientation(void *data,
305 struct ivi_controller_layer * /*ivi_controller_layer*/,
306 int32_t orientation) {
307 static_cast<struct layer *>(data)->parent->layer_orientation(
308 static_cast<struct layer *>(data)->id, orientation);
311 void layer_screen(void *data,
312 struct ivi_controller_layer * /*ivi_controller_layer*/,
313 struct wl_output *screen) {
314 static_cast<struct layer *>(data)->parent->layer_screen(
315 static_cast<struct layer *>(data)->id, screen);
318 void layer_destroyed(void *data,
319 struct ivi_controller_layer * /*ivi_controller_layer*/) {
320 static_cast<struct layer *>(data)->parent->layer_destroyed(
321 static_cast<struct layer *>(data)->id);
324 constexpr struct ivi_controller_layer_listener layer_listener = {
325 layer_visibility, layer_opacity,
326 layer_source_rectangle, layer_destination_rectangle,
327 layer_configuration, layer_orientation,
328 layer_screen, layer_destroyed,
332 layer::layer(uint32_t i, struct controller *c) : layer(i, 0, 0, c) {}
334 layer::layer(uint32_t i, int32_t w, int32_t h, struct controller *c)
335 : wayland_proxy(ivi_controller_layer_create(c->proxy, i, w, h)),
336 controller_child(c, i),
343 this->parent->add_proxy_to_id_mapping(this->proxy, i);
344 ivi_controller_layer_add_listener(this->proxy, &layer_listener, this);
348 logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
349 this->parent->remove_proxy_to_id_mapping(this->proxy);
350 ivi_controller_layer_destroy(this->proxy, 1);
351 this->proxy = nullptr;
354 void controller::layer_visibility(uint32_t id, int32_t visibility) {
355 logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
356 this->layers[id]->visibility = visibility;
359 void controller::layer_opacity(uint32_t id, float opacity) {
360 logdebug("genivi::layer %s @ %p o %f", __func__, this->proxy, opacity);
361 this->layers[id]->opacity = opacity;
364 void controller::layer_source_rectangle(uint32_t id, int32_t x, int32_t y,
365 int32_t width, int32_t height) {
366 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
367 x, y, width, height);
368 this->layers[id]->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
371 void controller::layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
372 int32_t width, int32_t height) {
373 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
374 x, y, width, height);
375 this->layers[id]->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
378 void controller::layer_configuration(uint32_t id, int32_t width,
380 logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
382 this->layers[id]->size = size{uint32_t(width), uint32_t(height)};
385 void controller::layer_orientation(uint32_t id, int32_t orientation) {
386 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
387 this->layers[id]->orientation = orientation;
390 void controller::layer_screen(uint32_t /*id*/, struct wl_output *screen) {
391 logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
394 void controller::layer_destroyed(uint32_t id) {
395 logdebug("genivi::layer %s @ %p", __func__, this->proxy);
396 add_task("remove layer",
397 [id](struct controller *c) { c->layers.erase(id); });
401 // ___ _ _ _ __ / _| __ _ ___ ___
402 // / __| | | | '__| |_ / _` |/ __/ _ \
403 // \__ \ |_| | | | _| (_| | (_| __/
404 // |___/\__,_|_| |_| \__,_|\___\___|
408 void surface_visibility(
409 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
410 int32_t visibility) {
411 static_cast<struct surface *>(data)->parent->surface_visibility(
412 static_cast<struct surface *>(data)->id, visibility);
415 void surface_opacity(void *data,
416 struct ivi_controller_surface * /*ivi_controller_surface*/,
417 wl_fixed_t opacity) {
418 static_cast<struct surface *>(data)->parent->surface_opacity(
419 static_cast<struct surface *>(data)->id,
420 float(wl_fixed_to_double(opacity)));
423 void surface_source_rectangle(
424 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
425 int32_t x, int32_t y, int32_t width, int32_t height) {
426 static_cast<struct surface *>(data)->parent->surface_source_rectangle(
427 static_cast<struct surface *>(data)->id, x, y, width, height);
430 void surface_destination_rectangle(
431 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
432 int32_t x, int32_t y, int32_t width, int32_t height) {
433 static_cast<struct surface *>(data)->parent->surface_destination_rectangle(
434 static_cast<struct surface *>(data)->id, x, y, width, height);
437 void surface_configuration(
438 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
439 int32_t width, int32_t height) {
440 static_cast<struct surface *>(data)->parent->surface_configuration(
441 static_cast<struct surface *>(data)->id, width, height);
444 void surface_orientation(
445 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
446 int32_t orientation) {
447 static_cast<struct surface *>(data)->parent->surface_orientation(
448 static_cast<struct surface *>(data)->id, orientation);
451 void surface_pixelformat(
452 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
453 int32_t pixelformat) {
454 static_cast<struct surface *>(data)->parent->surface_pixelformat(
455 static_cast<struct surface *>(data)->id, pixelformat);
458 void surface_layer(void *data,
459 struct ivi_controller_surface * /*ivi_controller_surface*/,
460 struct ivi_controller_layer *layer) {
461 static_cast<struct surface *>(data)->parent->surface_layer(
462 static_cast<struct surface *>(data)->id, layer);
465 void surface_stats(void *data,
466 struct ivi_controller_surface * /*ivi_controller_surface*/,
467 uint32_t redraw_count, uint32_t frame_count,
468 uint32_t update_count, uint32_t pid,
469 const char *process_name) {
470 static_cast<struct surface *>(data)->parent->surface_stats(
471 static_cast<struct surface *>(data)->id, redraw_count, frame_count,
472 update_count, pid, process_name);
475 void surface_destroyed(
476 void *data, struct ivi_controller_surface * /*ivi_controller_surface*/) {
477 static_cast<struct surface *>(data)->parent->surface_destroyed(
478 static_cast<struct surface *>(data)->id);
481 void surface_content(void *data,
482 struct ivi_controller_surface * /*ivi_controller_surface*/,
483 int32_t content_state) {
484 static_cast<struct surface *>(data)->parent->surface_content(
485 static_cast<struct surface *>(data)->id, content_state);
488 constexpr struct ivi_controller_surface_listener surface_listener = {
491 surface_source_rectangle,
492 surface_destination_rectangle,
493 surface_configuration,
503 surface::surface(uint32_t i, struct controller *c)
504 : wayland_proxy(ivi_controller_surface_create(c->proxy, i)),
505 controller_child(c, i),
512 this->parent->add_proxy_to_id_mapping(this->proxy, i);
513 ivi_controller_surface_add_listener(this->proxy, &surface_listener, this);
516 surface::~surface() {
517 logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
518 this->parent->remove_proxy_to_id_mapping(this->proxy);
519 ivi_controller_surface_destroy(this->proxy, 1);
520 this->proxy = nullptr;
523 void controller::surface_visibility(uint32_t id, int32_t visibility) {
524 logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
525 this->surfaces[id]->visibility = visibility;
528 void controller::surface_opacity(uint32_t id, float opacity) {
529 logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy, opacity);
530 this->surfaces[id]->opacity = opacity;
533 void controller::surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
534 int32_t width, int32_t height) {
535 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
536 this->proxy, x, y, width, height);
537 this->surfaces[id]->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
540 void controller::surface_destination_rectangle(uint32_t id, int32_t x,
541 int32_t y, int32_t width,
543 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
544 this->proxy, x, y, width, height);
545 this->surfaces[id]->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
548 void controller::surface_configuration(uint32_t id, int32_t width,
550 logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
552 this->surfaces[id]->size = size{uint32_t(width), uint32_t(height)};
555 void controller::surface_orientation(uint32_t id, int32_t orientation) {
556 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
557 this->surfaces[id]->orientation = orientation;
560 void controller::surface_pixelformat(uint32_t /*id*/, int32_t pixelformat) {
561 logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
564 void controller::surface_layer(uint32_t /*id*/,
565 struct ivi_controller_layer *layer) {
566 logdebug("genivi::surface %s @ %p l %u @ %p", __func__, this->proxy,
567 this->layer_proxy_to_id[uintptr_t(layer)], layer);
570 void controller::surface_stats(uint32_t /*id*/, uint32_t redraw_count,
571 uint32_t frame_count, uint32_t update_count,
572 uint32_t pid, const char *process_name) {
573 logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
574 this->proxy, redraw_count, frame_count, update_count, pid,
578 void controller::surface_destroyed(uint32_t id) {
579 logdebug("genivi::surface %s @ %p", __func__, this->proxy);
580 this->surfaces.erase(id);
583 void controller::surface_content(uint32_t id, int32_t content_state) {
584 logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
586 if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
587 add_task("remove surface",
588 [id](struct controller *c) { c->surfaces.erase(id); });
593 // ___ ___ _ __ ___ ___ _ __
594 // / __|/ __| '__/ _ \/ _ \ '_ \
595 // \__ \ (__| | | __/ __/ | | |
596 // |___/\___|_| \___|\___|_| |_|
598 screen::screen(uint32_t i, struct controller *c,
599 struct ivi_controller_screen *p)
600 : wayland_proxy(p), controller_child(c, i) {
601 logdebug("genivi::screen @ %p id %u", p, i);
603 } // namespace genivi