wayland: moved inline methods to .cpp
[staging/windowmanager.git] / src / wayland.cpp
1 #include <utility>
2
3 #include "wayland.hpp"
4
5 //                                                                  _
6 //  _ __   __ _ _ __ ___   ___  ___ _ __   __ _  ___ ___  __      _| |
7 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
8 // | | | | (_| | | | | | |  __/\__ \ |_) | (_| | (_|  __/  \ V  V /| |
9 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|   \_/\_/ |_|
10 //                                 |_|
11 namespace wl {
12
13 //      _ _           _
14 //   __| (_)___ _ __ | | __ _ _   _
15 //  / _` | / __| '_ \| |/ _` | | | |
16 // | (_| | \__ \ |_) | | (_| | |_| |
17 //  \__,_|_|___/ .__/|_|\__,_|\__, |
18 //             |_|            |___/
19 display::display()
20    : d(std::unique_ptr<struct wl_display, void (*)(struct wl_display *)>(
21         wl_display_connect(nullptr),
22 #ifdef DEBUG_OUTPUT
23         [](struct wl_display *d) {
24            logdebug("wl::display ~display @ %p", d);
25            wl_display_disconnect(d);
26         })),
27 #else
28         &wl_display_disconnect)),
29 #endif
30      r(d.get()) {
31 }
32
33 display::~display() = default;
34
35 bool display::ok() const { return d && wl_display_get_error(d.get()) == 0; }
36
37 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
38
39 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
40
41 void display::flush() { wl_display_flush(this->d.get()); }
42
43 int display::get_fd() const { return wl_display_get_fd(this->d.get()); }
44
45 //                 _     _
46 //  _ __ ___  __ _(_)___| |_ _ __ _   _
47 // | '__/ _ \/ _` | / __| __| '__| | | |
48 // | | |  __/ (_| | \__ \ |_| |  | |_| |
49 // |_|  \___|\__, |_|___/\__|_|   \__, |
50 //           |___/                |___/
51 namespace {
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);
55 }
56
57 void registry_global_remove(void *data, struct wl_registry * /*r*/,
58                             uint32_t name) {
59    static_cast<struct registry *>(data)->global_remove(name);
60 }
61
62 constexpr struct wl_registry_listener registry_listener = {
63    registry_global, registry_global_remove};
64 }  // namespace
65
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, &registry_listener, this);
70    }
71 }
72
73 registry::~registry() {
74    logdebug("wl::registry %s @ %p", __func__, this->proxy);
75 }
76
77 void registry::add_global_handler(char const *iface, binder bind) {
78    this->bindings[iface] = std::move(bind);
79 }
80
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);
85    }
86    logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name, iface,
87             v);
88 }
89
90 void registry::global_remove(uint32_t /*name*/) {}
91
92 //              _               _
93 //   ___  _   _| |_ _ __  _   _| |_
94 //  / _ \| | | | __| '_ \| | | | __|
95 // | (_) | |_| | |_| |_) | |_| | |_
96 //  \___/ \__,_|\__| .__/ \__,_|\__|
97 //                 |_|
98 namespace {
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,
102                      int32_t transform) {
103    static_cast<struct output *>(data)->geometry(
104       x, y, physical_width, physical_height, subpixel, make, model, transform);
105 }
106
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);
110 }
111
112 void output_done(void *data, struct wl_output * /*wl_output*/) {
113    static_cast<struct output *>(data)->done();
114 }
115
116 void output_scale(void *data, struct wl_output * /*wl_output*/,
117                   int32_t factor) {
118    static_cast<struct output *>(data)->scale(factor);
119 }
120
121 constexpr struct wl_output_listener output_listener = {
122    output_geometry, output_mode, output_done, output_scale};
123 }  // namespace
124
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);
128 }
129
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,
132                       int32_t tx) {
133    logdebug(
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);
136 }
137
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,
140             flags, w, h, r);
141    if ((flags & WL_OUTPUT_MODE_CURRENT) != 0u) {
142       this->width = w;
143       this->height = h;
144       this->refresh = r;
145    }
146 }
147
148 void output::done() {
149    logdebug("wl::output %s @ %p done", __func__, this->proxy);
150 }
151
152 void output::scale(int32_t factor) {
153    logdebug("wl::output %s @ %p f %i", __func__, this->proxy, factor);
154 }
155 }  // namespace wl
156
157 //  _ __   __ _ _ __ ___   ___  ___ _ __   __ _  ___ ___
158 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
159 // | | | | (_| | | | | | |  __/\__ \ |_) | (_| | (_|  __/
160 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
161 //                                 |_|
162 //                   _       _
163 //   __ _  ___ _ __ (_)_   _(_)
164 //  / _` |/ _ \ '_ \| \ \ / / |
165 // | (_| |  __/ | | | |\ V /| |
166 //  \__, |\___|_| |_|_| \_/ |_|
167 //  |___/
168 namespace genivi {
169
170 //                  _             _ _
171 //   ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __
172 //  / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
173 // | (_| (_) | | | | |_| | | (_) | | |  __/ |
174 //  \___\___/|_| |_|\__|_|  \___/|_|_|\___|_|
175 //
176 namespace {
177 void controller_screen(void *data, struct ivi_controller * /*ivi_controller*/,
178                        uint32_t id_screen,
179                        struct ivi_controller_screen *screen) {
180    static_cast<struct controller *>(data)->controller_screen(id_screen, screen);
181 }
182
183 void controller_layer(void *data, struct ivi_controller * /*ivi_controller*/,
184                       uint32_t id_layer) {
185    static_cast<struct controller *>(data)->controller_layer(id_layer);
186 }
187
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);
191 }
192
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);
198 }
199
200 constexpr struct ivi_controller_listener listener = {
201    controller_screen, controller_layer, controller_surface, controller_error};
202 }  // namespace
203
204 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
205    : wayland_proxy(
206         wl_registry_bind(r, name, &ivi_controller_interface, version)),
207      surface_proxy_to_id{},
208      surfaces{},
209      layer_proxy_to_id{},
210      layers{},
211      screen_proxy_to_id{},
212      screens{},
213      pending{},
214      output_size{} {
215    ivi_controller_add_listener(this->proxy, &listener, this);
216 }
217
218 controller::~controller() = default;
219
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);
222 }
223
224 void controller::surface_create(uint32_t id) {
225    this->surfaces[id] = std::make_unique<surface>(id, this);
226 }
227
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,
231             screen);
232    this->screens[id] = std::make_unique<struct screen>(id, this, screen);
233 }
234
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);
238    l->clear_surfaces();
239 }
240
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);
244
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);
252    });
253 }
254
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);
259 }
260
261 //  _
262 // | | __ _ _   _  ___ _ __
263 // | |/ _` | | | |/ _ \ '__|
264 // | | (_| | |_| |  __/ |
265 // |_|\__,_|\__, |\___|_|
266 //          |___/
267 namespace {
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);
273 }
274
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)));
280 }
281
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);
287 }
288
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);
294 }
295
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);
301 }
302
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);
308 }
309
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);
315 }
316
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);
321 }
322
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,
328 };
329 }  // namespace
330
331 layer::layer(uint32_t i, struct controller *c) : layer(i, 0, 0, c) {}
332
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),
336      dst_rect{},
337      src_rect{},
338      size{},
339      orientation{},
340      visibility{},
341      opacity{} {
342    this->parent->add_proxy_to_id_mapping(this->proxy, i);
343    ivi_controller_layer_add_listener(this->proxy, &layer_listener, this);
344 }
345
346 layer::~layer() {
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;
351 }
352
353 void layer::set_visibility(uint32_t visibility) {
354    ivi_controller_layer_set_visibility(this->proxy, visibility);
355 }
356
357 void layer::set_opacity(wl_fixed_t opacity) {
358    ivi_controller_layer_set_opacity(this->proxy, opacity);
359 }
360
361 void layer::set_source_rectangle(int32_t x, int32_t y, int32_t width,
362                                  int32_t height) {
363    ivi_controller_layer_set_source_rectangle(this->proxy, x, y, width, height);
364 }
365
366 void layer::set_destination_rectangle(int32_t x, int32_t y, int32_t width,
367                                       int32_t height) {
368    ivi_controller_layer_set_destination_rectangle(this->proxy, x, y, width,
369                                                   height);
370 }
371
372 void layer::set_configuration(int32_t width, int32_t height) {
373    ivi_controller_layer_set_configuration(this->proxy, width, height);
374 }
375
376 void layer::set_orientation(int32_t orientation) {
377    ivi_controller_layer_set_orientation(this->proxy, orientation);
378 }
379
380 void layer::screenshot(const char *filename) {
381    ivi_controller_layer_screenshot(this->proxy, filename);
382 }
383
384 void layer::clear_surfaces() {
385    ivi_controller_layer_clear_surfaces(this->proxy);
386 }
387
388 void layer::add_surface(struct surface *surface) {
389    ivi_controller_layer_add_surface(this->proxy, surface->proxy);
390 }
391
392 void layer::remove_surface(struct surface *surface) {
393    ivi_controller_layer_remove_surface(this->proxy, surface->proxy);
394 }
395
396 void layer::set_render_order(std::vector<uint32_t> const &ro) {
397    struct wl_array wlro {
398       .size = ro.size() * sizeof(ro[0]), .alloc = ro.capacity() * sizeof(ro[0]),
399       .data = const_cast<void *>(static_cast<void const *>(ro.data()))
400    };
401    ivi_controller_layer_set_render_order(this->proxy, &wlro);
402 }
403
404 void controller::layer_visibility(uint32_t id, int32_t visibility) {
405    logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
406    this->layers[id]->visibility = visibility;
407 }
408
409 void controller::layer_opacity(uint32_t id, float opacity) {
410    logdebug("genivi::layer %s @ %p o %f", __func__, this->proxy, opacity);
411    this->layers[id]->opacity = opacity;
412 }
413
414 void controller::layer_source_rectangle(uint32_t id, int32_t x, int32_t y,
415                                         int32_t width, int32_t height) {
416    logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
417             x, y, width, height);
418    this->layers[id]->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
419 }
420
421 void controller::layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
422                                              int32_t width, int32_t height) {
423    logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
424             x, y, width, height);
425    this->layers[id]->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
426 }
427
428 void controller::layer_configuration(uint32_t id, int32_t width,
429                                      int32_t height) {
430    logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
431             height);
432    this->layers[id]->size = size{uint32_t(width), uint32_t(height)};
433 }
434
435 void controller::layer_orientation(uint32_t id, int32_t orientation) {
436    logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
437    this->layers[id]->orientation = orientation;
438 }
439
440 void controller::layer_screen(uint32_t /*id*/, struct wl_output *screen) {
441    logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
442 }
443
444 void controller::layer_destroyed(uint32_t id) {
445    logdebug("genivi::layer %s @ %p", __func__, this->proxy);
446    add_task("remove layer",
447             [id](struct controller *c) { c->layers.erase(id); });
448 }
449
450 //                  __
451 //  ___ _   _ _ __ / _| __ _  ___ ___
452 // / __| | | | '__| |_ / _` |/ __/ _ \
453 // \__ \ |_| | |  |  _| (_| | (_|  __/
454 // |___/\__,_|_|  |_|  \__,_|\___\___|
455 //
456 namespace {
457
458 void surface_visibility(
459    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
460    int32_t visibility) {
461    auto s = static_cast<struct surface *>(data);
462    s->parent->surface_visibility(s->id, visibility);
463 }
464
465 void surface_opacity(void *data,
466                      struct ivi_controller_surface * /*ivi_controller_surface*/,
467                      wl_fixed_t opacity) {
468    auto s = static_cast<struct surface *>(data);
469    s->parent->surface_opacity(s->id, float(wl_fixed_to_double(opacity)));
470 }
471
472 void surface_source_rectangle(
473    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
474    int32_t x, int32_t y, int32_t width, int32_t height) {
475    auto s = static_cast<struct surface *>(data);
476    s->parent->surface_source_rectangle(s->id, x, y, width, height);
477 }
478
479 void surface_destination_rectangle(
480    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
481    int32_t x, int32_t y, int32_t width, int32_t height) {
482    auto s = static_cast<struct surface *>(data);
483    s->parent->surface_destination_rectangle(s->id, x, y, width, height);
484 }
485
486 void surface_configuration(
487    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
488    int32_t width, int32_t height) {
489    auto s = static_cast<struct surface *>(data);
490    s->parent->surface_configuration(s->id, width, height);
491 }
492
493 void surface_orientation(
494    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
495    int32_t orientation) {
496    auto s = static_cast<struct surface *>(data);
497    s->parent->surface_orientation(s->id, orientation);
498 }
499
500 void surface_pixelformat(
501    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
502    int32_t pixelformat) {
503    auto s = static_cast<struct surface *>(data);
504    s->parent->surface_pixelformat(s->id, pixelformat);
505 }
506
507 void surface_layer(void *data,
508                    struct ivi_controller_surface * /*ivi_controller_surface*/,
509                    struct ivi_controller_layer *layer) {
510    auto s = static_cast<struct surface *>(data);
511    s->parent->surface_layer(s->id, layer);
512 }
513
514 void surface_stats(void *data,
515                    struct ivi_controller_surface * /*ivi_controller_surface*/,
516                    uint32_t redraw_count, uint32_t frame_count,
517                    uint32_t update_count, uint32_t pid,
518                    const char *process_name) {
519    auto s = static_cast<struct surface *>(data);
520    s->parent->surface_stats(s->id, redraw_count, frame_count,
521       update_count, pid, process_name);
522 }
523
524 void surface_destroyed(
525    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/) {
526    auto s = static_cast<struct surface *>(data);
527    s->parent->surface_destroyed(s->id);
528 }
529
530 void surface_content(void *data,
531                      struct ivi_controller_surface * /*ivi_controller_surface*/,
532                      int32_t content_state) {
533    auto s = static_cast<struct surface *>(data);
534    s->parent->surface_content(s->id, content_state);
535 }
536
537 constexpr struct ivi_controller_surface_listener surface_listener = {
538    surface_visibility,
539    surface_opacity,
540    surface_source_rectangle,
541    surface_destination_rectangle,
542    surface_configuration,
543    surface_orientation,
544    surface_pixelformat,
545    surface_layer,
546    surface_stats,
547    surface_destroyed,
548    surface_content,
549 };
550 }  // namespace
551
552 surface::surface(uint32_t i, struct controller *c)
553    : wayland_proxy(ivi_controller_surface_create(c->proxy, i)),
554      controller_child(c, i),
555      dst_rect{},
556      src_rect{},
557      size{},
558      orientation{},
559      visibility{},
560      opacity{1.f} {
561    this->parent->add_proxy_to_id_mapping(this->proxy, i);
562    ivi_controller_surface_add_listener(this->proxy, &surface_listener, this);
563 }
564
565 surface::~surface() {
566    logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
567    this->parent->remove_proxy_to_id_mapping(this->proxy);
568    ivi_controller_surface_destroy(this->proxy, 1);
569    this->proxy = nullptr;
570 }
571
572 void surface::set_visibility(uint32_t visibility) {
573    ivi_controller_surface_set_visibility(this->proxy, visibility);
574 }
575
576 void surface::set_opacity(wl_fixed_t opacity) {
577    ivi_controller_surface_set_opacity(this->proxy, opacity);
578 }
579
580 void surface::set_source_rectangle(int32_t x, int32_t y, int32_t width,
581                                    int32_t height) {
582    ivi_controller_surface_set_source_rectangle(this->proxy, x, y, width,
583                                                height);
584 }
585
586 void surface::set_destination_rectangle(int32_t x, int32_t y, int32_t width,
587                                         int32_t height) {
588    ivi_controller_surface_set_destination_rectangle(this->proxy, x, y, width,
589                                                     height);
590 }
591
592 void surface::set_configuration(int32_t width, int32_t height) {
593    ivi_controller_surface_set_configuration(this->proxy, width, height);
594 }
595
596 void surface::set_orientation(int32_t orientation) {
597    ivi_controller_surface_set_orientation(this->proxy, orientation);
598 }
599
600 void surface::screenshot(const char *filename) {
601    ivi_controller_surface_screenshot(this->proxy, filename);
602 }
603
604 void surface::send_stats() { ivi_controller_surface_send_stats(this->proxy); }
605
606 void surface::destroy(int32_t destroy_scene_object) {
607    ivi_controller_surface_destroy(this->proxy, destroy_scene_object);
608 }
609
610 void controller::surface_visibility(uint32_t id, int32_t visibility) {
611    logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
612    this->surfaces[id]->visibility = visibility;
613 }
614
615 void controller::surface_opacity(uint32_t id, float opacity) {
616    logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy, opacity);
617    this->surfaces[id]->opacity = opacity;
618 }
619
620 void controller::surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
621                                           int32_t width, int32_t height) {
622    logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
623             this->proxy, x, y, width, height);
624    this->surfaces[id]->src_rect = rect{uint32_t(width), uint32_t(height), x, y};
625 }
626
627 void controller::surface_destination_rectangle(uint32_t id, int32_t x,
628                                                int32_t y, int32_t width,
629                                                int32_t height) {
630    logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
631             this->proxy, x, y, width, height);
632    this->surfaces[id]->dst_rect = rect{uint32_t(width), uint32_t(height), x, y};
633 }
634
635 void controller::surface_configuration(uint32_t id, int32_t width,
636                                        int32_t height) {
637    logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
638             height);
639    this->surfaces[id]->size = size{uint32_t(width), uint32_t(height)};
640 }
641
642 void controller::surface_orientation(uint32_t id, int32_t orientation) {
643    logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
644    this->surfaces[id]->orientation = orientation;
645 }
646
647 void controller::surface_pixelformat(uint32_t /*id*/, int32_t pixelformat) {
648    logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
649 }
650
651 void controller::surface_layer(uint32_t /*id*/,
652                                struct ivi_controller_layer *layer) {
653    logdebug("genivi::surface %s @ %p l %u @ %p", __func__, this->proxy,
654             this->layer_proxy_to_id[uintptr_t(layer)], layer);
655 }
656
657 void controller::surface_stats(uint32_t /*id*/, uint32_t redraw_count,
658                                uint32_t frame_count, uint32_t update_count,
659                                uint32_t pid, const char *process_name) {
660    logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
661             this->proxy, redraw_count, frame_count, update_count, pid,
662             process_name);
663 }
664
665 void controller::surface_destroyed(uint32_t id) {
666    logdebug("genivi::surface %s @ %p", __func__, this->proxy);
667    this->surfaces.erase(id);
668 }
669
670 void controller::surface_content(uint32_t id, int32_t content_state) {
671    logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
672             content_state);
673    if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
674       add_task("remove surface",
675                [id](struct controller *c) { c->surfaces.erase(id); });
676    }
677 }
678
679 void controller::add_proxy_to_id_mapping(struct ivi_controller_surface *p, uint32_t id) {
680    this->surface_proxy_to_id[uintptr_t(p)] = id;
681    logdebug("Add surface proxy mapping for %p (%u)", p, id);
682 }
683
684 void controller::remove_proxy_to_id_mapping(struct ivi_controller_surface *p) {
685    logdebug("Remove surface proxy mapping for %p", p);
686    this->surface_proxy_to_id.erase(uintptr_t(p));
687 }
688
689 void controller::add_proxy_to_id_mapping(struct ivi_controller_layer *p, uint32_t id) {
690    logdebug("Add layer proxy mapping for %p (%u)", p, id);
691    this->layer_proxy_to_id[uintptr_t(p)] = id;
692 }
693
694 void controller::remove_proxy_to_id_mapping(struct ivi_controller_layer *p) {
695    logdebug("Remove layer proxy mapping for %p", p);
696    this->layer_proxy_to_id.erase(uintptr_t(p));
697 }
698
699 void controller::add_proxy_to_id_mapping(struct wl_output *p, uint32_t id) {
700    logdebug("Add screen proxy mapping for %p (%u)", p, id);
701    this->screen_proxy_to_id[uintptr_t(p)] = id;
702 }
703
704 void controller::remove_proxy_to_id_mapping(struct wl_output *p) {
705    logdebug("Remove screen proxy mapping for %p", p);
706    this->screen_proxy_to_id.erase(uintptr_t(p));
707 }
708
709 void controller::add_task(char const *name, std::function<void(struct controller *)> &&f) {
710    this->pending.emplace_back(std::make_pair(name, f));
711 }
712
713 void controller::execute_pending() {
714    if (!this->pending.empty()) {
715       for (auto &t : this->pending) {
716          logdebug("executing task '%s'", t.first);
717          t.second(this);
718       }
719       this->pending.clear();
720       ivi_controller_commit_changes(this->proxy);
721       // XXX: No flush here...
722    }
723 }
724 //
725 //  ___  ___ _ __ ___  ___ _ __
726 // / __|/ __| '__/ _ \/ _ \ '_ \
727 // \__ \ (__| | |  __/  __/ | | |
728 // |___/\___|_|  \___|\___|_| |_|
729 //
730 screen::screen(uint32_t i, struct controller *c,
731                struct ivi_controller_screen *p)
732    : wayland_proxy(p), controller_child(c, i) {
733    logdebug("genivi::screen @ %p id %u", p, i);
734 }
735 }  // namespace genivi