4 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
5 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
6 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
7 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
12 // __| (_)___ _ __ | | __ _ _ _
13 // / _` | / __| '_ \| |/ _` | | | |
14 // | (_| | \__ \ |_) | | (_| | |_| |
15 // \__,_|_|___/ .__/|_|\__,_|\__, |
18 : d(std::unique_ptr<struct wl_display,
19 std::function<void(struct wl_display *)>>(
20 wl_display_connect(NULL),
21 [](struct wl_display *d) {
22 logdebug("wl::display ~display @ %p", d);
23 wl_display_disconnect(d);
25 r(!d ? nullptr : std::make_unique<struct registry>(d.get())) {}
27 display::~display() {}
29 bool display::ok() const { return d && wl_display_get_error(d.get()) == 0; }
31 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
33 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
35 void display::flush() { wl_display_flush(this->d.get()); }
37 int display::get_fd() const { return wl_display_get_fd(this->d.get()); }
40 // _ __ ___ __ _(_)___| |_ _ __ _ _
41 // | '__/ _ \/ _` | / __| __| '__| | | |
42 // | | | __/ (_| | \__ \ |_| | | |_| |
43 // |_| \___|\__, |_|___/\__|_| \__, |
46 void registry_global(void *data, struct wl_registry *r, uint32_t name,
47 char const *iface, uint32_t v) {
48 static_cast<struct registry *>(data)->global(name, iface, v);
51 void registry_global_remove(void *data, struct wl_registry *r, uint32_t name) {
52 static_cast<struct registry *>(data)->global_remove(name);
55 constexpr struct wl_registry_listener registry_listener = {
56 registry_global, registry_global_remove};
59 registry::registry(struct wl_display *d)
60 : wayland_proxy(!d ? nullptr : wl_display_get_registry(d)) {
62 wl_registry_add_listener(this->proxy, ®istry_listener, this);
65 registry::~registry() {
66 logdebug("wl::registry %s @ %p", __func__, this->proxy);
69 void registry::add_global_handler(char const *iface, binder bind) {
70 this->bindings[iface] = bind;
73 void registry::global(uint32_t name, char const *iface, uint32_t v) {
74 auto b = this->bindings.find(iface);
75 if (b != this->bindings.end())
76 b->second(this->proxy, name, v);
78 logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name,
82 void registry::global_remove(uint32_t name) {}
85 // ___ _ _| |_ _ __ _ _| |_
86 // / _ \| | | | __| '_ \| | | | __|
87 // | (_) | |_| | |_| |_) | |_| | |_
88 // \___/ \__,_|\__| .__/ \__,_|\__|
91 void output_geometry(void *data, struct wl_output *wl_output, int32_t x,
92 int32_t y, int32_t physical_width, int32_t physical_height,
93 int32_t subpixel, const char *make, const char *model,
95 static_cast<struct output *>(data)->geometry(
96 x, y, physical_width, physical_height, subpixel, make, model, transform);
99 void output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
100 int32_t width, int32_t height, int32_t refresh) {
101 static_cast<struct output *>(data)->mode(flags, width, height, refresh);
104 void output_done(void *data, struct wl_output *wl_output) {
105 static_cast<struct output *>(data)->done();
108 void output_scale(void *data, struct wl_output *wl_output, int32_t factor) {
109 static_cast<struct output *>(data)->scale(factor);
112 constexpr struct wl_output_listener output_listener = {
113 output_geometry, output_mode, output_done, output_scale};
116 output::output(struct wl_registry *r, uint32_t name, uint32_t v)
117 : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
118 wl_output_add_listener(this->proxy, &output_listener, this);
121 void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
122 int32_t subpel, char const *make, char const *model,
125 "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
126 __func__, this->proxy, x, y, pw, ph, subpel, make, model, tx);
129 void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
130 logdebug("wl::output %s @ %p f %x w %i h %i r %i", __func__, this->proxy,
132 if (flags & WL_OUTPUT_MODE_CURRENT) {
139 void output::done() {
140 logdebug("wl::output %s @ %p done", __func__, this->proxy);
143 void output::scale(int32_t factor) {
144 logdebug("wl::output %s @ %p f %i", __func__, this->proxy, factor);
148 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
149 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
150 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
151 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
154 // __ _ ___ _ __ (_)_ _(_)
155 // / _` |/ _ \ '_ \| \ \ / / |
156 // | (_| | __/ | | | |\ V /| |
157 // \__, |\___|_| |_|_| \_/ |_|
162 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
163 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
164 // | (_| (_) | | | | |_| | | (_) | | | __/ |
165 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
168 void controller_screen(void *data, struct ivi_controller *ivi_controller,
170 struct ivi_controller_screen *screen) {
171 static_cast<struct controller *>(data)->controller_screen(id_screen, screen);
174 void controller_layer(void *data, struct ivi_controller *ivi_controller,
176 static_cast<struct controller *>(data)->controller_layer(id_layer);
179 void controller_surface(void *data, struct ivi_controller *ivi_controller,
180 uint32_t id_surface) {
181 static_cast<struct controller *>(data)->controller_surface(id_surface);
184 void controller_error(void *data, struct ivi_controller *ivi_controller,
185 int32_t object_id, int32_t object_type,
186 int32_t error_code, const char *error_text) {
187 static_cast<struct controller *>(data)->controller_error(
188 object_id, object_type, error_code, error_text);
191 constexpr struct ivi_controller_listener listener = {
192 controller_screen, controller_layer, controller_surface, controller_error};
195 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
197 wl_registry_bind(r, name, &ivi_controller_interface, version)) {
198 ivi_controller_add_listener(this->proxy, &listener, this);
201 controller::~controller() {}
203 void controller::layer_create(uint32_t id, int32_t w, int32_t h) {
204 this->layers[id] = std::make_unique<layer>(id, w, h, this);
207 void controller::surface_create(uint32_t id) {
208 this->surfaces[id] = std::make_unique<surface>(id, this);
211 void controller::controller_screen(uint32_t id,
212 struct ivi_controller_screen *screen) {
213 logdebug("genivi::controller @ %p screen %u (%x) @ %p", this->proxy, id, id,
215 this->screens[id] = std::make_unique<struct screen>(id, this, screen);
218 void controller::controller_layer(uint32_t id) {
219 logdebug("genivi::controller @ %p layer %u (%x)", this->proxy, id, id);
220 this->layers[id] = std::make_unique<struct layer>(id, this);
223 void controller::controller_surface(uint32_t id) {
224 logdebug("genivi::controller @ %p surface %u (%x)", this->proxy, id, id);
225 this->surfaces[id] = std::make_unique<struct surface>(id, this);
228 void controller::controller_error(int32_t object_id, int32_t object_type,
229 int32_t error_code, const char *error_text) {
230 logdebug("genivi::controller @ %p error o %i t %i c %i text %s", this->proxy,
231 object_id, object_type, error_code, error_text);
235 // | | __ _ _ _ ___ _ __
236 // | |/ _` | | | |/ _ \ '__|
237 // | | (_| | |_| | __/ |
238 // |_|\__,_|\__, |\___|_|
241 void layer_visibility(void *data,
242 struct ivi_controller_layer *ivi_controller_layer,
243 int32_t visibility) {
244 static_cast<struct layer *>(data)->parent->layer_visibility(
245 static_cast<struct layer *>(data)->id, visibility);
248 void layer_opacity(void *data,
249 struct ivi_controller_layer *ivi_controller_layer,
250 wl_fixed_t opacity) {
251 static_cast<struct layer *>(data)->parent->layer_opacity(
252 static_cast<struct layer *>(data)->id, wl_fixed_to_double(opacity));
255 void layer_source_rectangle(void *data,
256 struct ivi_controller_layer *ivi_controller_layer,
257 int32_t x, int32_t y, int32_t width,
259 static_cast<struct layer *>(data)->parent->layer_source_rectangle(
260 static_cast<struct layer *>(data)->id, x, y, width, height);
263 void layer_destination_rectangle(
264 void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
265 int32_t y, int32_t width, int32_t height) {
266 static_cast<struct layer *>(data)->parent->layer_destination_rectangle(
267 static_cast<struct layer *>(data)->id, x, y, width, height);
270 void layer_configuration(void *data,
271 struct ivi_controller_layer *ivi_controller_layer,
272 int32_t width, int32_t height) {
273 static_cast<struct layer *>(data)->parent->layer_configuration(
274 static_cast<struct layer *>(data)->id, width, height);
277 void layer_orientation(void *data,
278 struct ivi_controller_layer *ivi_controller_layer,
279 int32_t orientation) {
280 static_cast<struct layer *>(data)->parent->layer_orientation(
281 static_cast<struct layer *>(data)->id, orientation);
284 void layer_screen(void *data, struct ivi_controller_layer *ivi_controller_layer,
285 struct wl_output *screen) {
286 static_cast<struct layer *>(data)->parent->layer_screen(
287 static_cast<struct layer *>(data)->id, screen);
290 void layer_destroyed(void *data,
291 struct ivi_controller_layer *ivi_controller_layer) {
292 static_cast<struct layer *>(data)->parent->layer_destroyed(
293 static_cast<struct layer *>(data)->id);
296 constexpr struct ivi_controller_layer_listener layer_listener = {
297 layer_visibility, layer_opacity,
298 layer_source_rectangle, layer_destination_rectangle,
299 layer_configuration, layer_orientation,
300 layer_screen, layer_destroyed,
304 layer::layer(uint32_t i, struct controller *c)
305 : layer(i, 0, 0, c) {
308 layer::layer(uint32_t i, int32_t w, int32_t h, struct controller *c)
309 : wayland_proxy(ivi_controller_layer_create(c->proxy, i, w, h)),
310 controlled_entity(c, i) {
311 ivi_controller_layer_add_listener(this->proxy, &layer_listener, this);
315 logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
316 ivi_controller_layer_destroy(this->proxy, 1);
317 this->proxy = nullptr;
320 void controller::layer_visibility(uint32_t id, int32_t visibility) {
321 logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
324 void controller::layer_opacity(uint32_t id, float opacity) {
325 logdebug("genivi::layer %s @ %p o %f", __func__, this->proxy, opacity);
328 void controller::layer_source_rectangle(uint32_t id, int32_t x, int32_t y,
329 int32_t width, int32_t height) {
330 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
331 x, y, width, height);
334 void controller::layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
335 int32_t width, int32_t height) {
336 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
337 x, y, width, height);
340 void controller::layer_configuration(uint32_t id, int32_t width,
342 logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
346 void controller::layer_orientation(uint32_t id, int32_t orientation) {
347 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
350 void controller::layer_screen(uint32_t id, struct wl_output *screen) {
351 logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
354 void controller::layer_destroyed(uint32_t id) {
355 logdebug("genivi::layer %s @ %p", __func__, this->proxy);
359 // ___ _ _ _ __ / _| __ _ ___ ___
360 // / __| | | | '__| |_ / _` |/ __/ _ \
361 // \__ \ |_| | | | _| (_| | (_| __/
362 // |___/\__,_|_| |_| \__,_|\___\___|
366 void surface_visibility(void *data,
367 struct ivi_controller_surface *ivi_controller_surface,
368 int32_t visibility) {
369 static_cast<struct surface *>(data)->parent->surface_visibility(
370 static_cast<struct surface *>(data)->id, visibility);
373 void surface_opacity(void *data,
374 struct ivi_controller_surface *ivi_controller_surface,
375 wl_fixed_t opacity) {
376 static_cast<struct surface *>(data)->parent->surface_opacity(
377 static_cast<struct surface *>(data)->id, wl_fixed_to_double(opacity));
380 void surface_source_rectangle(
381 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
382 int32_t y, int32_t width, int32_t height) {
383 static_cast<struct surface *>(data)->parent->surface_source_rectangle(
384 static_cast<struct surface *>(data)->id, x, y, width, height);
387 void surface_destination_rectangle(
388 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
389 int32_t y, int32_t width, int32_t height) {
390 static_cast<struct surface *>(data)->parent->surface_destination_rectangle(
391 static_cast<struct surface *>(data)->id, x, y, width, height);
394 void surface_configuration(
395 void *data, struct ivi_controller_surface *ivi_controller_surface,
396 int32_t width, int32_t height) {
397 static_cast<struct surface *>(data)->parent->surface_configuration(
398 static_cast<struct surface *>(data)->id, width, height);
401 void surface_orientation(void *data,
402 struct ivi_controller_surface *ivi_controller_surface,
403 int32_t orientation) {
404 static_cast<struct surface *>(data)->parent->surface_orientation(
405 static_cast<struct surface *>(data)->id, orientation);
408 void surface_pixelformat(void *data,
409 struct ivi_controller_surface *ivi_controller_surface,
410 int32_t pixelformat) {
411 static_cast<struct surface *>(data)->parent->surface_pixelformat(
412 static_cast<struct surface *>(data)->id, pixelformat);
415 void surface_layer(void *data,
416 struct ivi_controller_surface *ivi_controller_surface,
417 struct ivi_controller_layer *layer) {
418 static_cast<struct surface *>(data)->parent->surface_layer(
419 static_cast<struct surface *>(data)->id, layer);
422 void surface_stats(void *data,
423 struct ivi_controller_surface *ivi_controller_surface,
424 uint32_t redraw_count, uint32_t frame_count,
425 uint32_t update_count, uint32_t pid,
426 const char *process_name) {
427 static_cast<struct surface *>(data)->parent->surface_stats(
428 static_cast<struct surface *>(data)->id, redraw_count, frame_count,
429 update_count, pid, process_name);
432 void surface_destroyed(void *data,
433 struct ivi_controller_surface *ivi_controller_surface) {
434 static_cast<struct surface *>(data)->parent->surface_destroyed(
435 static_cast<struct surface *>(data)->id);
438 void surface_content(void *data,
439 struct ivi_controller_surface *ivi_controller_surface,
440 int32_t content_state) {
441 static_cast<struct surface *>(data)->parent->surface_content(
442 static_cast<struct surface *>(data)->id, content_state);
445 constexpr struct ivi_controller_surface_listener surface_listener = {
448 surface_source_rectangle,
449 surface_destination_rectangle,
450 surface_configuration,
460 surface::surface(uint32_t i, struct controller *c)
461 : wayland_proxy(ivi_controller_surface_create(c->proxy, i)),
462 controlled_entity(c, i),
469 ivi_controller_surface_add_listener(this->proxy, &surface_listener, this);
472 surface::~surface() {
473 logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
474 ivi_controller_surface_destroy(this->proxy, 1);
475 this->proxy = nullptr;
478 void controller::surface_visibility(uint32_t id, int32_t visibility) {
479 logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
480 struct surface *s = this->surfaces[id].get();
481 s->visibility = visibility;
484 void controller::surface_opacity(uint32_t id, float opacity) {
485 logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy, opacity);
486 struct surface *s = this->surfaces[id].get();
487 s->opacity = opacity;
490 void controller::surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
491 int32_t width, int32_t height) {
492 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
493 this->proxy, x, y, width, height);
494 struct surface *s = this->surfaces[id].get();
495 s->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
498 void controller::surface_destination_rectangle(uint32_t id, int32_t x,
499 int32_t y, int32_t width,
501 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
502 this->proxy, x, y, width, height);
503 struct surface *s = this->surfaces[id].get();
504 s->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
507 void controller::surface_configuration(uint32_t id, int32_t width,
509 logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
511 struct surface *s = this->surfaces[id].get();
512 bool center = s->size.w != width && s->size.h != height;
513 s->size = size{uint32_t(width), uint32_t(height)};
515 auto const s = c->surfaces.find(id);
516 if (s != c->surfaces.end())
517 s->second->set_destination_rectangle(
518 800 / 2 - width / 2, 600 / 2 - height / 2, width, height);
519 add_task("fullscreen surface", [id, width, height](struct controller *c) {
523 void controller::surface_orientation(uint32_t id, int32_t orientation) {
524 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
525 struct surface *s = this->surfaces[id].get();
526 s->orientation = orientation;
529 void controller::surface_pixelformat(uint32_t id, int32_t pixelformat) {
530 logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
533 void controller::surface_layer(uint32_t id,
534 struct ivi_controller_layer *layer) {
535 logdebug("genivi::surface %s @ %p l @ %p", __func__, this->proxy, layer);
538 void controller::surface_stats(uint32_t id, uint32_t redraw_count,
539 uint32_t frame_count, uint32_t update_count,
540 uint32_t pid, const char *process_name) {
541 logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
542 this->proxy, redraw_count, frame_count, update_count, pid,
546 void controller::surface_destroyed(uint32_t id) {
547 logdebug("genivi::surface %s @ %p", __func__, this->proxy);
550 void controller::surface_content(uint32_t id, int32_t content_state) {
551 logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
553 if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
554 add_task("remove surface",
555 [id](struct controller *c) { c->surfaces.erase(id); });
560 // ___ ___ _ __ ___ ___ _ __
561 // / __|/ __| '__/ _ \/ _ \ '_ \
562 // \__ \ (__| | | __/ __/ | | |
563 // |___/\___|_| \___|\___|_| |_|
565 screen::screen(uint32_t i, struct controller *c,
566 struct ivi_controller_screen *p)
567 : wayland_proxy(p), controlled_entity(c, i) {
568 logdebug("genivi::screen @ %p id %u", p, i);