4 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
5 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
6 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
7 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
12 // __| (_)___ _ __ | | __ _ _ _
13 // / _` | / __| '_ \| |/ _` | | | |
14 // | (_| | \__ \ |_) | | (_| | |_| |
15 // \__,_|_|___/ .__/|_|\__,_|\__, |
18 : d(std::unique_ptr<struct wl_display, void (*)(struct wl_display *)>(
19 wl_display_connect(NULL),
21 [](struct wl_display *d) {
22 logdebug("wl::display ~display @ %p", d);
23 wl_display_disconnect(d);
26 &wl_display_disconnect)),
31 display::~display() {}
33 bool display::ok() const { return d && wl_display_get_error(d.get()) == 0; }
35 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
37 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
39 void display::flush() { wl_display_flush(this->d.get()); }
41 int display::get_fd() const { return wl_display_get_fd(this->d.get()); }
44 // _ __ ___ __ _(_)___| |_ _ __ _ _
45 // | '__/ _ \/ _` | / __| __| '__| | | |
46 // | | | __/ (_| | \__ \ |_| | | |_| |
47 // |_| \___|\__, |_|___/\__|_| \__, |
50 void registry_global(void *data, struct wl_registry *r, uint32_t name,
51 char const *iface, uint32_t v) {
52 static_cast<struct registry *>(data)->global(name, iface, v);
55 void registry_global_remove(void *data, struct wl_registry *r, uint32_t name) {
56 static_cast<struct registry *>(data)->global_remove(name);
59 constexpr struct wl_registry_listener registry_listener = {
60 registry_global, registry_global_remove};
63 registry::registry(struct wl_display *d)
64 : wayland_proxy(!d ? nullptr : wl_display_get_registry(d)) {
66 wl_registry_add_listener(this->proxy, ®istry_listener, this);
69 registry::~registry() {
70 logdebug("wl::registry %s @ %p", __func__, this->proxy);
73 void registry::add_global_handler(char const *iface, binder bind) {
74 this->bindings[iface] = bind;
77 void registry::global(uint32_t name, char const *iface, uint32_t v) {
78 auto b = this->bindings.find(iface);
79 if (b != this->bindings.end())
80 b->second(this->proxy, name, v);
81 logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name, iface,
85 void registry::global_remove(uint32_t name) {}
88 // ___ _ _| |_ _ __ _ _| |_
89 // / _ \| | | | __| '_ \| | | | __|
90 // | (_) | |_| | |_| |_) | |_| | |_
91 // \___/ \__,_|\__| .__/ \__,_|\__|
94 void output_geometry(void *data, struct wl_output *wl_output, int32_t x,
95 int32_t y, int32_t physical_width, int32_t physical_height,
96 int32_t subpixel, const char *make, const char *model,
98 static_cast<struct output *>(data)->geometry(
99 x, y, physical_width, physical_height, subpixel, make, model, transform);
102 void output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
103 int32_t width, int32_t height, int32_t refresh) {
104 static_cast<struct output *>(data)->mode(flags, width, height, refresh);
107 void output_done(void *data, struct wl_output *wl_output) {
108 static_cast<struct output *>(data)->done();
111 void output_scale(void *data, struct wl_output *wl_output, int32_t factor) {
112 static_cast<struct output *>(data)->scale(factor);
115 constexpr struct wl_output_listener output_listener = {
116 output_geometry, output_mode, output_done, output_scale};
119 output::output(struct wl_registry *r, uint32_t name, uint32_t v)
120 : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
121 wl_output_add_listener(this->proxy, &output_listener, this);
124 void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
125 int32_t subpel, char const *make, char const *model,
128 "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
129 __func__, this->proxy, x, y, pw, ph, subpel, make, model, tx);
132 void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
133 logdebug("wl::output %s @ %p f %x w %i h %i r %i", __func__, this->proxy,
135 if (flags & WL_OUTPUT_MODE_CURRENT) {
142 void output::done() {
143 logdebug("wl::output %s @ %p done", __func__, this->proxy);
146 void output::scale(int32_t factor) {
147 logdebug("wl::output %s @ %p f %i", __func__, this->proxy, factor);
151 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
152 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
153 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
154 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
157 // __ _ ___ _ __ (_)_ _(_)
158 // / _` |/ _ \ '_ \| \ \ / / |
159 // | (_| | __/ | | | |\ V /| |
160 // \__, |\___|_| |_|_| \_/ |_|
165 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
166 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
167 // | (_| (_) | | | | |_| | | (_) | | | __/ |
168 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
171 void controller_screen(void *data, struct ivi_controller *ivi_controller,
173 struct ivi_controller_screen *screen) {
174 static_cast<struct controller *>(data)->controller_screen(id_screen, screen);
177 void controller_layer(void *data, struct ivi_controller *ivi_controller,
179 static_cast<struct controller *>(data)->controller_layer(id_layer);
182 void controller_surface(void *data, struct ivi_controller *ivi_controller,
183 uint32_t id_surface) {
184 static_cast<struct controller *>(data)->controller_surface(id_surface);
187 void controller_error(void *data, struct ivi_controller *ivi_controller,
188 int32_t object_id, int32_t object_type,
189 int32_t error_code, const char *error_text) {
190 static_cast<struct controller *>(data)->controller_error(
191 object_id, object_type, error_code, error_text);
194 constexpr struct ivi_controller_listener listener = {
195 controller_screen, controller_layer, controller_surface, controller_error};
198 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
200 wl_registry_bind(r, name, &ivi_controller_interface, version)),
206 ivi_controller_add_listener(this->proxy, &listener, this);
209 controller::~controller() {}
211 void controller::layer_create(uint32_t id, int32_t w, int32_t h) {
212 this->layers[id] = std::make_unique<layer>(id, w, h, this);
215 void controller::surface_create(uint32_t id) {
216 this->surfaces[id] = std::make_unique<surface>(id, this);
219 void controller::controller_screen(uint32_t id,
220 struct ivi_controller_screen *screen) {
221 logdebug("genivi::controller @ %p screen %u (%x) @ %p", this->proxy, id, id,
223 this->screens[id] = std::make_unique<struct screen>(id, this, screen);
226 void controller::controller_layer(uint32_t id) {
227 logdebug("genivi::controller @ %p layer %u (%x)", this->proxy, id, id);
228 this->layers[id] = std::make_unique<struct layer>(id, this);
231 void controller::controller_surface(uint32_t id) {
232 logdebug("genivi::controller @ %p surface %u (%x)", this->proxy, id, id);
233 this->surfaces[id] = std::make_unique<struct surface>(id, this);
235 add_task("fullscreen surface", [id](struct controller *c) {
236 c->surfaces[id]->set_destination_rectangle(0, 0, c->output_size.w,
238 c->surfaces[id]->set_visibility(1);
239 uint32_t lid = id == 0x16180 ? 1000 : 100;
240 c->layers[lid]->add_surface(c->surfaces[id].get());
241 c->layers[lid]->set_visibility(1);
242 logdebug("Surface %u now fullscreen on layer %u", id, lid);
246 void controller::controller_error(int32_t object_id, int32_t object_type,
247 int32_t error_code, const char *error_text) {
248 logdebug("genivi::controller @ %p error o %i t %i c %i text %s", this->proxy,
249 object_id, object_type, error_code, error_text);
253 // | | __ _ _ _ ___ _ __
254 // | |/ _` | | | |/ _ \ '__|
255 // | | (_| | |_| | __/ |
256 // |_|\__,_|\__, |\___|_|
259 void layer_visibility(void *data,
260 struct ivi_controller_layer *ivi_controller_layer,
261 int32_t visibility) {
262 static_cast<struct layer *>(data)->parent->layer_visibility(
263 static_cast<struct layer *>(data)->id, visibility);
266 void layer_opacity(void *data,
267 struct ivi_controller_layer *ivi_controller_layer,
268 wl_fixed_t opacity) {
269 static_cast<struct layer *>(data)->parent->layer_opacity(
270 static_cast<struct layer *>(data)->id,
271 float(wl_fixed_to_double(opacity)));
274 void layer_source_rectangle(void *data,
275 struct ivi_controller_layer *ivi_controller_layer,
276 int32_t x, int32_t y, int32_t width,
278 static_cast<struct layer *>(data)->parent->layer_source_rectangle(
279 static_cast<struct layer *>(data)->id, x, y, width, height);
282 void layer_destination_rectangle(
283 void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
284 int32_t y, int32_t width, int32_t height) {
285 static_cast<struct layer *>(data)->parent->layer_destination_rectangle(
286 static_cast<struct layer *>(data)->id, x, y, width, height);
289 void layer_configuration(void *data,
290 struct ivi_controller_layer *ivi_controller_layer,
291 int32_t width, int32_t height) {
292 static_cast<struct layer *>(data)->parent->layer_configuration(
293 static_cast<struct layer *>(data)->id, width, height);
296 void layer_orientation(void *data,
297 struct ivi_controller_layer *ivi_controller_layer,
298 int32_t orientation) {
299 static_cast<struct layer *>(data)->parent->layer_orientation(
300 static_cast<struct layer *>(data)->id, orientation);
303 void layer_screen(void *data, struct ivi_controller_layer *ivi_controller_layer,
304 struct wl_output *screen) {
305 static_cast<struct layer *>(data)->parent->layer_screen(
306 static_cast<struct layer *>(data)->id, screen);
309 void layer_destroyed(void *data,
310 struct ivi_controller_layer *ivi_controller_layer) {
311 static_cast<struct layer *>(data)->parent->layer_destroyed(
312 static_cast<struct layer *>(data)->id);
315 constexpr struct ivi_controller_layer_listener layer_listener = {
316 layer_visibility, layer_opacity,
317 layer_source_rectangle, layer_destination_rectangle,
318 layer_configuration, layer_orientation,
319 layer_screen, layer_destroyed,
323 layer::layer(uint32_t i, struct controller *c) : layer(i, 0, 0, c) {}
325 layer::layer(uint32_t i, int32_t w, int32_t h, struct controller *c)
326 : wayland_proxy(ivi_controller_layer_create(c->proxy, i, w, h)),
327 controlled_entity(c, i),
334 ivi_controller_layer_add_listener(this->proxy, &layer_listener, this);
338 logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
339 ivi_controller_layer_destroy(this->proxy, 1);
340 this->proxy = nullptr;
343 void controller::layer_visibility(uint32_t id, int32_t visibility) {
344 logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
345 this->layers[id]->visibility = visibility;
348 void controller::layer_opacity(uint32_t id, float opacity) {
349 logdebug("genivi::layer %s @ %p o %f", __func__, this->proxy, opacity);
350 this->layers[id]->opacity = opacity;
353 void controller::layer_source_rectangle(uint32_t id, int32_t x, int32_t y,
354 int32_t width, int32_t height) {
355 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
356 x, y, width, height);
357 this->layers[id]->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
360 void controller::layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
361 int32_t width, int32_t height) {
362 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
363 x, y, width, height);
364 this->layers[id]->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
367 void controller::layer_configuration(uint32_t id, int32_t width,
369 logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
371 this->layers[id]->size = size{uint32_t(width), uint32_t(height)};
374 void controller::layer_orientation(uint32_t id, int32_t orientation) {
375 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
376 this->layers[id]->orientation = orientation;
379 void controller::layer_screen(uint32_t id, struct wl_output *screen) {
380 logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
383 void controller::layer_destroyed(uint32_t id) {
384 logdebug("genivi::layer %s @ %p", __func__, this->proxy);
388 // ___ _ _ _ __ / _| __ _ ___ ___
389 // / __| | | | '__| |_ / _` |/ __/ _ \
390 // \__ \ |_| | | | _| (_| | (_| __/
391 // |___/\__,_|_| |_| \__,_|\___\___|
395 void surface_visibility(void *data,
396 struct ivi_controller_surface *ivi_controller_surface,
397 int32_t visibility) {
398 static_cast<struct surface *>(data)->parent->surface_visibility(
399 static_cast<struct surface *>(data)->id, visibility);
402 void surface_opacity(void *data,
403 struct ivi_controller_surface *ivi_controller_surface,
404 wl_fixed_t opacity) {
405 static_cast<struct surface *>(data)->parent->surface_opacity(
406 static_cast<struct surface *>(data)->id,
407 float(wl_fixed_to_double(opacity)));
410 void surface_source_rectangle(
411 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
412 int32_t y, int32_t width, int32_t height) {
413 static_cast<struct surface *>(data)->parent->surface_source_rectangle(
414 static_cast<struct surface *>(data)->id, x, y, width, height);
417 void surface_destination_rectangle(
418 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
419 int32_t y, int32_t width, int32_t height) {
420 static_cast<struct surface *>(data)->parent->surface_destination_rectangle(
421 static_cast<struct surface *>(data)->id, x, y, width, height);
424 void surface_configuration(
425 void *data, struct ivi_controller_surface *ivi_controller_surface,
426 int32_t width, int32_t height) {
427 static_cast<struct surface *>(data)->parent->surface_configuration(
428 static_cast<struct surface *>(data)->id, width, height);
431 void surface_orientation(void *data,
432 struct ivi_controller_surface *ivi_controller_surface,
433 int32_t orientation) {
434 static_cast<struct surface *>(data)->parent->surface_orientation(
435 static_cast<struct surface *>(data)->id, orientation);
438 void surface_pixelformat(void *data,
439 struct ivi_controller_surface *ivi_controller_surface,
440 int32_t pixelformat) {
441 static_cast<struct surface *>(data)->parent->surface_pixelformat(
442 static_cast<struct surface *>(data)->id, pixelformat);
445 void surface_layer(void *data,
446 struct ivi_controller_surface *ivi_controller_surface,
447 struct ivi_controller_layer *layer) {
448 static_cast<struct surface *>(data)->parent->surface_layer(
449 static_cast<struct surface *>(data)->id, layer);
452 void surface_stats(void *data,
453 struct ivi_controller_surface *ivi_controller_surface,
454 uint32_t redraw_count, uint32_t frame_count,
455 uint32_t update_count, uint32_t pid,
456 const char *process_name) {
457 static_cast<struct surface *>(data)->parent->surface_stats(
458 static_cast<struct surface *>(data)->id, redraw_count, frame_count,
459 update_count, pid, process_name);
462 void surface_destroyed(void *data,
463 struct ivi_controller_surface *ivi_controller_surface) {
464 static_cast<struct surface *>(data)->parent->surface_destroyed(
465 static_cast<struct surface *>(data)->id);
468 void surface_content(void *data,
469 struct ivi_controller_surface *ivi_controller_surface,
470 int32_t content_state) {
471 static_cast<struct surface *>(data)->parent->surface_content(
472 static_cast<struct surface *>(data)->id, content_state);
475 constexpr struct ivi_controller_surface_listener surface_listener = {
478 surface_source_rectangle,
479 surface_destination_rectangle,
480 surface_configuration,
490 surface::surface(uint32_t i, struct controller *c)
491 : wayland_proxy(ivi_controller_surface_create(c->proxy, i)),
492 controlled_entity(c, i),
499 ivi_controller_surface_add_listener(this->proxy, &surface_listener, this);
502 surface::~surface() {
503 logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
504 ivi_controller_surface_destroy(this->proxy, 1);
505 this->proxy = nullptr;
508 void controller::surface_visibility(uint32_t id, int32_t visibility) {
509 logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
510 this->surfaces[id]->visibility = visibility;
513 void controller::surface_opacity(uint32_t id, float opacity) {
514 logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy, opacity);
515 this->surfaces[id]->opacity = opacity;
518 void controller::surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
519 int32_t width, int32_t height) {
520 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
521 this->proxy, x, y, width, height);
522 this->surfaces[id]->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
525 void controller::surface_destination_rectangle(uint32_t id, int32_t x,
526 int32_t y, int32_t width,
528 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
529 this->proxy, x, y, width, height);
530 this->surfaces[id]->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
533 void controller::surface_configuration(uint32_t id, int32_t width,
535 logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
537 this->surfaces[id]->size = size{uint32_t(width), uint32_t(height)};
540 void controller::surface_orientation(uint32_t id, int32_t orientation) {
541 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
542 this->surfaces[id]->orientation = orientation;
545 void controller::surface_pixelformat(uint32_t id, int32_t pixelformat) {
546 logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
549 void controller::surface_layer(uint32_t id,
550 struct ivi_controller_layer *layer) {
551 logdebug("genivi::surface %s @ %p l @ %p", __func__, this->proxy, layer);
554 void controller::surface_stats(uint32_t id, uint32_t redraw_count,
555 uint32_t frame_count, uint32_t update_count,
556 uint32_t pid, const char *process_name) {
557 logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
558 this->proxy, redraw_count, frame_count, update_count, pid,
562 void controller::surface_destroyed(uint32_t id) {
563 logdebug("genivi::surface %s @ %p", __func__, this->proxy);
564 this->surfaces.erase(id);
567 void controller::surface_content(uint32_t id, int32_t content_state) {
568 logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
570 if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
571 add_task("remove surface",
572 [id](struct controller *c) { c->surfaces.erase(id); });
577 // ___ ___ _ __ ___ ___ _ __
578 // / __|/ __| '__/ _ \/ _ \ '_ \
579 // \__ \ (__| | | __/ __/ | | |
580 // |___/\___|_| \___|\___|_| |_|
582 screen::screen(uint32_t i, struct controller *c,
583 struct ivi_controller_screen *p)
584 : wayland_proxy(p), controlled_entity(c, i) {
585 logdebug("genivi::screen @ %p id %u", p, i);