Remove and replace the comments
[apps/agl-service-windowmanager-2017.git] / src / wayland.cpp
1 /*
2  * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <utility>
18
19 #include "util.hpp"
20 #include "wayland.hpp"
21 #include "hmi-debug.h"
22
23 /**
24  * namespace wl
25  */
26 namespace wl {
27
28 /**
29  * display
30  */
31 display::display()
32    : d(std::unique_ptr<struct wl_display, void (*)(struct wl_display *)>(
33         wl_display_connect(nullptr), &wl_display_disconnect)),
34      r(d.get()) {}
35
36 bool display::ok() const { return d && wl_display_get_error(d.get()) == 0; }
37
38 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
39
40 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
41
42 int display::dispatch_pending() { return wl_display_dispatch_pending(this->d.get()); }
43
44 int display::read_events() {
45    ST();
46    while (wl_display_prepare_read(this->d.get()) == -1) {
47       STN(pending_events_dispatch);
48       if (wl_display_dispatch_pending(this->d.get()) == -1) {
49          return -1;
50       }
51    }
52
53    if (wl_display_flush(this->d.get()) == -1) {
54       return -1;
55    }
56
57    if (wl_display_read_events(this->d.get()) == -1) {
58       wl_display_cancel_read(this->d.get());
59    }
60
61    return 0;
62 }
63
64 void display::flush() { wl_display_flush(this->d.get()); }
65
66 int display::get_fd() const { return wl_display_get_fd(this->d.get()); }
67
68 int display::get_error() { return wl_display_get_error(this->d.get()); }
69
70 /**
71  * registry
72  */
73 namespace {
74 void registry_global(void *data, struct wl_registry * /*r*/, uint32_t name,
75                      char const *iface, uint32_t v) {
76    static_cast<struct registry *>(data)->global(name, iface, v);
77 }
78
79 void registry_global_remove(void *data, struct wl_registry * /*r*/,
80                             uint32_t name) {
81    static_cast<struct registry *>(data)->global_remove(name);
82 }
83
84 constexpr struct wl_registry_listener registry_listener = {
85    registry_global, registry_global_remove};
86 }  // namespace
87
88 registry::registry(struct wl_display *d)
89    : wayland_proxy(d == nullptr ? nullptr : wl_display_get_registry(d)) {
90    if (this->proxy != nullptr) {
91       wl_registry_add_listener(this->proxy.get(), &registry_listener, this);
92    }
93 }
94
95 void registry::add_global_handler(char const *iface, binder bind) {
96    this->bindings[iface] = std::move(bind);
97 }
98
99 void registry::global(uint32_t name, char const *iface, uint32_t v) {
100    auto b = this->bindings.find(iface);
101    if (b != this->bindings.end()) {
102       b->second(this->proxy.get(), name, v);
103    }
104    HMI_DEBUG("wm", "wl::registry @ %p global n %u i %s v %u", this->proxy.get(), name,
105             iface, v);
106 }
107
108 void registry::global_remove(uint32_t /*name*/) {}
109
110 /**
111  * output
112  */
113 namespace {
114 void output_geometry(void *data, struct wl_output * /*wl_output*/, int32_t x,
115                      int32_t y, int32_t physical_width, int32_t physical_height,
116                      int32_t subpixel, const char *make, const char *model,
117                      int32_t transform) {
118    static_cast<struct output *>(data)->geometry(
119       x, y, physical_width, physical_height, subpixel, make, model, transform);
120 }
121
122 void output_mode(void *data, struct wl_output * /*wl_output*/, uint32_t flags,
123                  int32_t width, int32_t height, int32_t refresh) {
124    static_cast<struct output *>(data)->mode(flags, width, height, refresh);
125 }
126
127 void output_done(void *data, struct wl_output * /*wl_output*/) {
128    static_cast<struct output *>(data)->done();
129 }
130
131 void output_scale(void *data, struct wl_output * /*wl_output*/,
132                   int32_t factor) {
133    static_cast<struct output *>(data)->scale(factor);
134 }
135
136 constexpr struct wl_output_listener output_listener = {
137    output_geometry, output_mode, output_done, output_scale};
138 }  // namespace
139
140 output::output(struct wl_registry *r, uint32_t name, uint32_t v)
141    : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
142    wl_output_add_listener(this->proxy.get(), &output_listener, this);
143 }
144
145 void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
146                       int32_t subpel, char const *make, char const *model,
147                       int32_t tx) {
148    HMI_DEBUG("wm",
149       "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
150       __func__, this->proxy.get(), x, y, pw, ph, subpel, make, model, tx);
151    this->transform = tx;
152 }
153
154 void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
155    HMI_DEBUG("wm", "wl::output %s @ %p f %x w %i h %i r %i", __func__,
156             this->proxy.get(), flags, w, h, r);
157    if ((flags & WL_OUTPUT_MODE_CURRENT) != 0u) {
158       this->width = w;
159       this->height = h;
160       this->refresh = r;
161    }
162 }
163
164 void output::done() {
165    HMI_DEBUG("wm", "wl::output %s @ %p done", __func__, this->proxy.get());
166    // Let's just disregard the flipped ones...
167    if (this->transform == WL_OUTPUT_TRANSFORM_90 ||
168        this->transform == WL_OUTPUT_TRANSFORM_270) {
169       std::swap(this->width, this->height);
170    }
171 }
172
173 void output::scale(int32_t factor) {
174    HMI_DEBUG("wm", "wl::output %s @ %p f %i", __func__, this->proxy.get(), factor);
175 }
176 }  // namespace wl
177
178 /**
179  * namespace compositor
180  */
181 namespace compositor {
182
183 /**
184  * controller
185  */
186 namespace {
187 void controller_screen(void *data, struct ivi_controller * /*ivi_controller*/,
188                        uint32_t id_screen,
189                        struct ivi_controller_screen *screen) {
190    static_cast<struct controller *>(data)->controller_screen(id_screen, screen);
191 }
192
193 void controller_layer(void *data, struct ivi_controller * /*ivi_controller*/,
194                       uint32_t id_layer) {
195    static_cast<struct controller *>(data)->controller_layer(id_layer);
196 }
197
198 void controller_surface(void *data, struct ivi_controller * /*ivi_controller*/,
199                         uint32_t id_surface) {
200    static_cast<struct controller *>(data)->controller_surface(id_surface);
201 }
202
203 void controller_error(void *data, struct ivi_controller * /*ivi_controller*/,
204                       int32_t object_id, int32_t object_type,
205                       int32_t error_code, const char *error_text) {
206    static_cast<struct controller *>(data)->controller_error(
207       object_id, object_type, error_code, error_text);
208 }
209
210 constexpr struct ivi_controller_listener listener = {
211    controller_screen, controller_layer, controller_surface, controller_error};
212 }  // namespace compositor
213
214 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
215    : wayland_proxy(
216         wl_registry_bind(r, name, &ivi_controller_interface, version)),
217      output_size{} {
218    ivi_controller_add_listener(this->proxy.get(), &listener, this);
219 }
220
221 void controller::layer_create(uint32_t id, int32_t w, int32_t h) {
222    this->layers[id] = std::make_unique<struct layer>(id, w, h, this);
223 }
224
225 void controller::surface_create(uint32_t id) {
226    this->surfaces[id] = std::make_unique<struct surface>(id, this);
227 }
228
229 void controller::controller_screen(uint32_t id,
230                                    struct ivi_controller_screen *screen) {
231    HMI_DEBUG("wm", "compositor::controller @ %p screen %u (%x) @ %p", this->proxy.get(),
232             id, id, screen);
233    this->screens[id] = std::make_unique<struct screen>(id, this, screen);
234 }
235
236 void controller::controller_layer(uint32_t id) {
237    HMI_DEBUG("wm", "compositor::controller @ %p layer %u (%x)", this->proxy.get(), id, id);
238    if (this->layers.find(id) != this->layers.end()) {
239       HMI_DEBUG("wm", "WindowManager has created layer %u (%x) already", id, id);
240    } else {
241       auto &l = this->layers[id] = std::make_unique<struct layer>(id, this);
242       l->clear_surfaces();
243    }
244 }
245
246 void controller::controller_surface(uint32_t id) {
247    HMI_DEBUG("wm", "compositor::controller @ %p surface %u (%x)", this->proxy.get(), id,
248             id);
249    if (this->surfaces.find(id) == this->surfaces.end()) {
250       this->surfaces[id] = std::make_unique<struct surface>(id, this);
251       this->chooks->surface_created(id);
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    HMI_DEBUG("wm", "compositor::controller @ %p error o %i t %i c %i text %s",
258             this->proxy.get(), object_id, object_type, error_code, error_text);
259 }
260
261 /**
262  * layer
263  */
264 namespace {
265 void layer_visibility(void *data,
266                       struct ivi_controller_layer * /*ivi_controller_layer*/,
267                       int32_t visibility) {
268    auto l = static_cast<struct layer *>(data);
269    l->parent->layer_visibility(l, visibility);
270 }
271
272 void layer_opacity(void *data,
273                    struct ivi_controller_layer * /*ivi_controller_layer*/,
274                    wl_fixed_t opacity) {
275    auto l = static_cast<struct layer *>(data);
276    l->parent->layer_opacity(l, float(wl_fixed_to_double(opacity)));
277 }
278
279 void layer_source_rectangle(
280    void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
281    int32_t x, int32_t y, int32_t width, int32_t height) {
282    auto l = static_cast<struct layer *>(data);
283    l->parent->layer_source_rectangle(l, x, y, width, height);
284 }
285
286 void layer_destination_rectangle(
287    void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
288    int32_t x, int32_t y, int32_t width, int32_t height) {
289    auto l = static_cast<struct layer *>(data);
290    l->parent->layer_destination_rectangle(l, x, y, width, height);
291 }
292
293 void layer_configuration(void *data,
294                          struct ivi_controller_layer * /*ivi_controller_layer*/,
295                          int32_t width, int32_t height) {
296    auto l = static_cast<struct layer *>(data);
297    l->parent->layer_configuration(l, width, height);
298 }
299
300 void layer_orientation(void *data,
301                        struct ivi_controller_layer * /*ivi_controller_layer*/,
302                        int32_t orientation) {
303    auto l = static_cast<struct layer *>(data);
304    l->parent->layer_orientation(l, orientation);
305 }
306
307 void layer_screen(void *data,
308                   struct ivi_controller_layer * /*ivi_controller_layer*/,
309                   struct wl_output *screen) {
310    auto l = static_cast<struct layer *>(data);
311    l->parent->layer_screen(l, screen);
312 }
313
314 void layer_destroyed(void *data,
315                      struct ivi_controller_layer * /*ivi_controller_layer*/) {
316    auto l = static_cast<struct layer *>(data);
317    l->parent->layer_destroyed(l);
318 }
319
320 constexpr struct ivi_controller_layer_listener layer_listener = {
321    layer_visibility,       layer_opacity,
322    layer_source_rectangle, layer_destination_rectangle,
323    layer_configuration,    layer_orientation,
324    layer_screen,           layer_destroyed,
325 };
326 }  // namespace
327
328 layer::layer(uint32_t i, struct controller *c) : layer(i, 0, 0, c) {}
329
330 layer::layer(uint32_t i, int32_t w, int32_t h, struct controller *c)
331    : wayland_proxy(ivi_controller_layer_create(c->proxy.get(), i, w, h),
332                    [c, i](ivi_controller_layer *l) {
333                       HMI_DEBUG("wm", "~layer layer %i @ %p", i, l);
334                       c->remove_proxy_to_id_mapping(l);
335                       ivi_controller_layer_destroy(l, 1);
336                    }),
337      controller_child(c, i) {
338    this->parent->add_proxy_to_id_mapping(this->proxy.get(), i);
339    ivi_controller_layer_add_listener(this->proxy.get(), &layer_listener, this);
340 }
341
342 void layer::set_visibility(uint32_t visibility) {
343    ivi_controller_layer_set_visibility(this->proxy.get(), visibility);
344 }
345
346 void layer::set_opacity(wl_fixed_t opacity) {
347    ivi_controller_layer_set_opacity(this->proxy.get(), opacity);
348 }
349
350 void layer::set_source_rectangle(int32_t x, int32_t y, int32_t width,
351                                  int32_t height) {
352    ivi_controller_layer_set_source_rectangle(this->proxy.get(), x, y, width,
353                                              height);
354 }
355
356 void layer::set_destination_rectangle(int32_t x, int32_t y, int32_t width,
357                                       int32_t height) {
358    ivi_controller_layer_set_destination_rectangle(this->proxy.get(), x, y,
359                                                   width, height);
360 }
361
362 void layer::set_configuration(int32_t width, int32_t height) {
363    ivi_controller_layer_set_configuration(this->proxy.get(), width, height);
364 }
365
366 void layer::set_orientation(int32_t orientation) {
367    ivi_controller_layer_set_orientation(this->proxy.get(), orientation);
368 }
369
370 void layer::screenshot(const char *filename) {
371    ivi_controller_layer_screenshot(this->proxy.get(), filename);
372 }
373
374 void layer::clear_surfaces() {
375    ivi_controller_layer_clear_surfaces(this->proxy.get());
376 }
377
378 void layer::add_surface(struct surface *surface) {
379    ivi_controller_layer_add_surface(this->proxy.get(), surface->proxy.get());
380 }
381
382 void layer::remove_surface(struct surface *surface) {
383    ivi_controller_layer_remove_surface(this->proxy.get(), surface->proxy.get());
384 }
385
386 void layer::set_render_order(std::vector<uint32_t> const &ro) {
387    struct wl_array wlro {
388       .size = ro.size() * sizeof(ro[0]), .alloc = ro.capacity() * sizeof(ro[0]),
389       .data = const_cast<void *>(static_cast<void const *>(ro.data()))
390    };
391    ivi_controller_layer_set_render_order(this->proxy.get(), &wlro);
392 }
393
394 void controller::layer_visibility(struct layer *l, int32_t visibility) {
395    HMI_DEBUG("wm", "compositor::layer %s @ %d v %i", __func__, l->id, visibility);
396    this->lprops[l->id].visibility = visibility;
397 }
398
399 void controller::layer_opacity(struct layer *l, float opacity) {
400    HMI_DEBUG("wm", "compositor::layer %s @ %d o %f", __func__, l->id, opacity);
401    this->lprops[l->id].opacity = opacity;
402 }
403
404 void controller::layer_source_rectangle(struct layer *l, int32_t x, int32_t y,
405                                         int32_t width, int32_t height) {
406    HMI_DEBUG("wm", "compositor::layer %s @ %d x %i y %i w %i h %i", __func__,
407             l->id, x, y, width, height);
408    this->lprops[l->id].src_rect = rect{width, height, x, y};
409 }
410
411 void controller::layer_destination_rectangle(struct layer *l, int32_t x,
412                                              int32_t y, int32_t width,
413                                              int32_t height) {
414    HMI_DEBUG("wm", "compositor::layer %s @ %d x %i y %i w %i h %i", __func__,
415             l->id, x, y, width, height);
416    this->lprops[l->id].dst_rect = rect{width, height, x, y};
417 }
418
419 void controller::layer_configuration(struct layer *l, int32_t width,
420                                      int32_t height) {
421    HMI_DEBUG("wm", "compositor::layer %s @ %d w %i h %i", __func__, l->id,
422             width, height);
423    this->lprops[l->id].size = size{uint32_t(width), uint32_t(height)};
424 }
425
426 void controller::layer_orientation(struct layer *l, int32_t orientation) {
427    HMI_DEBUG("wm", "compositor::layer %s @ %d o %i", __func__, l->id,
428             orientation);
429    this->lprops[l->id].orientation = orientation;
430 }
431
432 void controller::layer_screen(struct layer *l, struct wl_output *screen) {
433    HMI_DEBUG("wm", "compositor::layer %s @ %d s %p", __func__, l->id, screen);
434 }
435
436 void controller::layer_destroyed(struct layer *l) {
437    HMI_DEBUG("wm", "compositor::layer %s @ %d", __func__, l->id);
438    this->lprops.erase(l->id);
439    this->layers.erase(l->id);
440 }
441
442 /**
443  * surface
444  */
445 namespace {
446
447 void surface_visibility(
448    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
449    int32_t visibility) {
450    auto s = static_cast<struct surface *>(data);
451    s->parent->surface_visibility(s, visibility);
452 }
453
454 void surface_opacity(void *data,
455                      struct ivi_controller_surface * /*ivi_controller_surface*/,
456                      wl_fixed_t opacity) {
457    auto s = static_cast<struct surface *>(data);
458    s->parent->surface_opacity(s, float(wl_fixed_to_double(opacity)));
459 }
460
461 void surface_source_rectangle(
462    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
463    int32_t x, int32_t y, int32_t width, int32_t height) {
464    auto s = static_cast<struct surface *>(data);
465    s->parent->surface_source_rectangle(s, x, y, width, height);
466 }
467
468 void surface_destination_rectangle(
469    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
470    int32_t x, int32_t y, int32_t width, int32_t height) {
471    auto s = static_cast<struct surface *>(data);
472    s->parent->surface_destination_rectangle(s, x, y, width, height);
473 }
474
475 void surface_configuration(
476    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
477    int32_t width, int32_t height) {
478    auto s = static_cast<struct surface *>(data);
479    s->parent->surface_configuration(s, width, height);
480 }
481
482 void surface_orientation(
483    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
484    int32_t orientation) {
485    auto s = static_cast<struct surface *>(data);
486    s->parent->surface_orientation(s, orientation);
487 }
488
489 void surface_pixelformat(
490    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
491    int32_t pixelformat) {
492    auto s = static_cast<struct surface *>(data);
493    s->parent->surface_pixelformat(s, pixelformat);
494 }
495
496 void surface_layer(void *data,
497                    struct ivi_controller_surface * /*ivi_controller_surface*/,
498                    struct ivi_controller_layer *layer) {
499    auto s = static_cast<struct surface *>(data);
500    s->parent->surface_layer(s, layer);
501 }
502
503 void surface_stats(void *data,
504                    struct ivi_controller_surface * /*ivi_controller_surface*/,
505                    uint32_t redraw_count, uint32_t frame_count,
506                    uint32_t update_count, uint32_t pid,
507                    const char *process_name) {
508    auto s = static_cast<struct surface *>(data);
509    s->parent->surface_stats(s, redraw_count, frame_count, update_count, pid,
510                             process_name);
511 }
512
513 void surface_destroyed(
514    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/) {
515    auto s = static_cast<struct surface *>(data);
516    s->parent->surface_destroyed(s);
517 }
518
519 void surface_content(void *data,
520                      struct ivi_controller_surface * /*ivi_controller_surface*/,
521                      int32_t content_state) {
522    auto s = static_cast<struct surface *>(data);
523    s->parent->surface_content(s, content_state);
524 }
525
526 constexpr struct ivi_controller_surface_listener surface_listener = {
527    surface_visibility,
528    surface_opacity,
529    surface_source_rectangle,
530    surface_destination_rectangle,
531    surface_configuration,
532    surface_orientation,
533    surface_pixelformat,
534    surface_layer,
535    surface_stats,
536    surface_destroyed,
537    surface_content,
538 };
539 }  // namespace
540
541 surface::surface(uint32_t i, struct controller *c)
542    : wayland_proxy(ivi_controller_surface_create(c->proxy.get(), i),
543                    [c, i](ivi_controller_surface *s) {
544                       HMI_DEBUG("wm", "~surface surface %i @ %p", i, s);
545                       c->remove_proxy_to_id_mapping(s);
546                       ivi_controller_surface_destroy(s, 1);
547                    }),
548      controller_child(c, i) {
549    this->parent->add_proxy_to_id_mapping(this->proxy.get(), i);
550    ivi_controller_surface_add_listener(this->proxy.get(), &surface_listener,
551                                        this);
552 }
553
554 void surface::set_visibility(uint32_t visibility) {
555    ivi_controller_surface_set_visibility(this->proxy.get(), visibility);
556 }
557
558 void surface::set_opacity(wl_fixed_t opacity) {
559    ivi_controller_surface_set_opacity(this->proxy.get(), opacity);
560 }
561
562 void surface::set_source_rectangle(int32_t x, int32_t y, int32_t width,
563                                    int32_t height) {
564    ivi_controller_surface_set_source_rectangle(this->proxy.get(), x, y, width,
565                                                height);
566 }
567
568 void surface::set_destination_rectangle(int32_t x, int32_t y, int32_t width,
569                                         int32_t height) {
570    ivi_controller_surface_set_destination_rectangle(this->proxy.get(), x, y,
571                                                     width, height);
572 }
573
574 void surface::set_configuration(int32_t width, int32_t height) {
575    ivi_controller_surface_set_configuration(this->proxy.get(), width, height);
576 }
577
578 void surface::set_orientation(int32_t orientation) {
579    ivi_controller_surface_set_orientation(this->proxy.get(), orientation);
580 }
581
582 void surface::screenshot(const char *filename) {
583    ivi_controller_surface_screenshot(this->proxy.get(), filename);
584 }
585
586 void surface::send_stats() {
587    ivi_controller_surface_send_stats(this->proxy.get());
588 }
589
590 void surface::destroy(int32_t destroy_scene_object) {
591    ivi_controller_surface_destroy(this->proxy.get(), destroy_scene_object);
592 }
593
594 void controller::surface_visibility(struct surface *s, int32_t visibility) {
595    HMI_DEBUG("wm", "compositor::surface %s @ %d v %i", __func__, s->id,
596             visibility);
597    this->sprops[s->id].visibility = visibility;
598    this->chooks->surface_visibility(s->id, visibility);
599 }
600
601 void controller::surface_opacity(struct surface *s, float opacity) {
602    HMI_DEBUG("wm", "compositor::surface %s @ %d o %f", __func__, s->id,
603             opacity);
604    this->sprops[s->id].opacity = opacity;
605 }
606
607 void controller::surface_source_rectangle(struct surface *s, int32_t x,
608                                           int32_t y, int32_t width,
609                                           int32_t height) {
610    HMI_DEBUG("wm", "compositor::surface %s @ %d x %i y %i w %i h %i", __func__,
611             s->id, x, y, width, height);
612    this->sprops[s->id].src_rect = rect{width, height, x, y};
613 }
614
615 void controller::surface_destination_rectangle(struct surface *s, int32_t x,
616                                                int32_t y, int32_t width,
617                                                int32_t height) {
618    HMI_DEBUG("wm", "compositor::surface %s @ %d x %i y %i w %i h %i", __func__,
619             s->id, x, y, width, height);
620    this->sprops[s->id].dst_rect = rect{width, height, x, y};
621    this->chooks->surface_destination_rectangle(s->id, x, y, width, height);
622 }
623
624 void controller::surface_configuration(struct surface *s, int32_t width,
625                                        int32_t height) {
626    HMI_DEBUG("wm", "compositor::surface %s @ %d w %i h %i", __func__, s->id,
627             width, height);
628    this->sprops[s->id].size = size{uint32_t(width), uint32_t(height)};
629    is_configured = true;
630 }
631
632 void controller::surface_orientation(struct surface *s, int32_t orientation) {
633    HMI_DEBUG("wm", "compositor::surface %s @ %d o %i", __func__, s->id,
634             orientation);
635    this->sprops[s->id].orientation = orientation;
636 }
637
638 void controller::surface_pixelformat(struct surface * s,
639                                      int32_t pixelformat) {
640    HMI_DEBUG("wm", "compositor::surface %s @ %d f %i", __func__, s->id,
641             pixelformat);
642 }
643
644 void controller::surface_layer(struct surface * s,
645                                struct ivi_controller_layer *layer) {
646    HMI_DEBUG("wm", "compositor::surface %s @ %d l %u @ %p", __func__, s->id,
647             this->layer_proxy_to_id[uintptr_t(layer)], layer);
648 }
649
650 void controller::surface_stats(struct surface *s, uint32_t redraw_count,
651                                uint32_t frame_count, uint32_t update_count,
652                                uint32_t pid, const char *process_name) {
653    HMI_DEBUG("wm", "compositor::surface %s @ %d r %u f %u u %u pid %u p %s", __func__,
654             s->id, redraw_count, frame_count, update_count, pid,
655             process_name);
656 }
657
658 void controller::surface_destroyed(struct surface *s) {
659    HMI_DEBUG("wm", "compositor::surface %s @ %d", __func__, s->id);
660    this->chooks->surface_removed(s->id);
661    this->sprops.erase(s->id);
662    this->surfaces.erase(s->id);
663 }
664
665 void controller::surface_content(struct surface *s, int32_t content_state) {
666    HMI_DEBUG("wm", "compositor::surface %s @ %d s %i", __func__, s->id,
667             content_state);
668    if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
669       this->chooks->surface_removed(s->id);
670       this->sprops.erase(s->id);
671       this->surfaces.erase(s->id);
672    }
673 }
674
675 void controller::add_proxy_to_id_mapping(struct ivi_controller_surface *p,
676                                          uint32_t id) {
677    HMI_DEBUG("wm", "Add surface proxy mapping for %p (%u)", p, id);
678    this->surface_proxy_to_id[uintptr_t(p)] = id;
679    this->sprops[id].id = id;
680 }
681
682 void controller::remove_proxy_to_id_mapping(struct ivi_controller_surface *p) {
683    HMI_DEBUG("wm", "Remove surface proxy mapping for %p", p);
684    this->surface_proxy_to_id.erase(uintptr_t(p));
685 }
686
687 void controller::add_proxy_to_id_mapping(struct ivi_controller_layer *p,
688                                          uint32_t id) {
689    HMI_DEBUG("wm", "Add layer proxy mapping for %p (%u)", p, id);
690    this->layer_proxy_to_id[uintptr_t(p)] = id;
691    this->lprops[id].id = id;
692 }
693
694 void controller::remove_proxy_to_id_mapping(struct ivi_controller_layer *p) {
695    HMI_DEBUG("wm", "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    HMI_DEBUG("wm", "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    HMI_DEBUG("wm", "Remove screen proxy mapping for %p", p);
706    this->screen_proxy_to_id.erase(uintptr_t(p));
707 }
708
709 /**
710  * screen
711  */
712 screen::screen(uint32_t i, struct controller *c,
713                struct ivi_controller_screen *p)
714    : wayland_proxy(p), controller_child(c, i) {
715    HMI_DEBUG("wm", "compositor::screen @ %p id %u", p, i);
716 }
717
718 void screen::clear() { ivi_controller_screen_clear(this->proxy.get()); }
719
720 void screen::add_layer(layer *l) {
721    ivi_controller_screen_add_layer(this->proxy.get(), l->proxy.get());
722 }
723
724 void screen::set_render_order(std::vector<uint32_t> const &ro) {
725    struct wl_array wlro {
726       .size = ro.size() * sizeof(ro[0]), .alloc = ro.capacity() * sizeof(ro[0]),
727       .data = const_cast<void *>(static_cast<void const *>(ro.data()))
728    };
729    ivi_controller_screen_set_render_order(this->proxy.get(), &wlro);
730 }
731
732 }  // namespace compositor