Revert "Add APIs which can get information of display and area"
[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    // Pivot and flipped
167    if (this->transform == WL_OUTPUT_TRANSFORM_90 ||
168        this->transform == WL_OUTPUT_TRANSFORM_270 ||
169        this->transform == WL_OUTPUT_TRANSFORM_FLIPPED_90 ||
170        this->transform == WL_OUTPUT_TRANSFORM_FLIPPED_270) {
171       std::swap(this->width, this->height);
172    }
173 }
174
175 void output::scale(int32_t factor) {
176    HMI_DEBUG("wm", "wl::output %s @ %p f %i", __func__, this->proxy.get(), factor);
177 }
178 }  // namespace wl
179
180 /**
181  * namespace compositor
182  */
183 namespace compositor {
184
185 /**
186  * controller
187  */
188 namespace {
189 void controller_screen(void *data, struct ivi_controller * /*ivi_controller*/,
190                        uint32_t id_screen,
191                        struct ivi_controller_screen *screen) {
192    static_cast<struct controller *>(data)->controller_screen(id_screen, screen);
193 }
194
195 void controller_layer(void *data, struct ivi_controller * /*ivi_controller*/,
196                       uint32_t id_layer) {
197    static_cast<struct controller *>(data)->controller_layer(id_layer);
198 }
199
200 void controller_surface(void *data, struct ivi_controller * /*ivi_controller*/,
201                         uint32_t id_surface) {
202    static_cast<struct controller *>(data)->controller_surface(id_surface);
203 }
204
205 void controller_error(void *data, struct ivi_controller * /*ivi_controller*/,
206                       int32_t object_id, int32_t object_type,
207                       int32_t error_code, const char *error_text) {
208    static_cast<struct controller *>(data)->controller_error(
209       object_id, object_type, error_code, error_text);
210 }
211
212 constexpr struct ivi_controller_listener listener = {
213    controller_screen, controller_layer, controller_surface, controller_error};
214 }  // namespace compositor
215
216 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
217    : wayland_proxy(
218         wl_registry_bind(r, name, &ivi_controller_interface, version)),
219      output_size{} {
220    ivi_controller_add_listener(this->proxy.get(), &listener, this);
221 }
222
223 void controller::layer_create(uint32_t id, int32_t w, int32_t h) {
224    this->layers[id] = std::make_unique<struct layer>(id, w, h, this);
225 }
226
227 void controller::surface_create(uint32_t id) {
228    this->surfaces[id] = std::make_unique<struct surface>(id, this);
229 }
230
231 void controller::controller_screen(uint32_t id,
232                                    struct ivi_controller_screen *screen) {
233    HMI_DEBUG("wm", "compositor::controller @ %p screen %u (%x) @ %p", this->proxy.get(),
234             id, id, screen);
235    this->screens[id] = std::make_unique<struct screen>(id, this, screen);
236 }
237
238 void controller::controller_layer(uint32_t id) {
239    HMI_DEBUG("wm", "compositor::controller @ %p layer %u (%x)", this->proxy.get(), id, id);
240    if (this->layers.find(id) != this->layers.end()) {
241       HMI_DEBUG("wm", "WindowManager has created layer %u (%x) already", id, id);
242    } else {
243       auto &l = this->layers[id] = std::make_unique<struct layer>(id, this);
244       l->clear_surfaces();
245    }
246 }
247
248 void controller::controller_surface(uint32_t id) {
249    HMI_DEBUG("wm", "compositor::controller @ %p surface %u (%x)", this->proxy.get(), id,
250             id);
251    if (this->surfaces.find(id) == this->surfaces.end()) {
252       this->surfaces[id] = std::make_unique<struct surface>(id, this);
253       this->chooks->surface_created(id);
254    }
255 }
256
257 void controller::controller_error(int32_t object_id, int32_t object_type,
258                                   int32_t error_code, const char *error_text) {
259    HMI_DEBUG("wm", "compositor::controller @ %p error o %i t %i c %i text %s",
260             this->proxy.get(), object_id, object_type, error_code, error_text);
261 }
262
263 /**
264  * layer
265  */
266 namespace {
267 void layer_visibility(void *data,
268                       struct ivi_controller_layer * /*ivi_controller_layer*/,
269                       int32_t visibility) {
270    auto l = static_cast<struct layer *>(data);
271    l->parent->layer_visibility(l, visibility);
272 }
273
274 void layer_opacity(void *data,
275                    struct ivi_controller_layer * /*ivi_controller_layer*/,
276                    wl_fixed_t opacity) {
277    auto l = static_cast<struct layer *>(data);
278    l->parent->layer_opacity(l, float(wl_fixed_to_double(opacity)));
279 }
280
281 void layer_source_rectangle(
282    void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
283    int32_t x, int32_t y, int32_t width, int32_t height) {
284    auto l = static_cast<struct layer *>(data);
285    l->parent->layer_source_rectangle(l, x, y, width, height);
286 }
287
288 void layer_destination_rectangle(
289    void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
290    int32_t x, int32_t y, int32_t width, int32_t height) {
291    auto l = static_cast<struct layer *>(data);
292    l->parent->layer_destination_rectangle(l, x, y, width, height);
293 }
294
295 void layer_configuration(void *data,
296                          struct ivi_controller_layer * /*ivi_controller_layer*/,
297                          int32_t width, int32_t height) {
298    auto l = static_cast<struct layer *>(data);
299    l->parent->layer_configuration(l, width, height);
300 }
301
302 void layer_orientation(void *data,
303                        struct ivi_controller_layer * /*ivi_controller_layer*/,
304                        int32_t orientation) {
305    auto l = static_cast<struct layer *>(data);
306    l->parent->layer_orientation(l, orientation);
307 }
308
309 void layer_screen(void *data,
310                   struct ivi_controller_layer * /*ivi_controller_layer*/,
311                   struct wl_output *screen) {
312    auto l = static_cast<struct layer *>(data);
313    l->parent->layer_screen(l, screen);
314 }
315
316 void layer_destroyed(void *data,
317                      struct ivi_controller_layer * /*ivi_controller_layer*/) {
318    auto l = static_cast<struct layer *>(data);
319    l->parent->layer_destroyed(l);
320 }
321
322 constexpr struct ivi_controller_layer_listener layer_listener = {
323    layer_visibility,       layer_opacity,
324    layer_source_rectangle, layer_destination_rectangle,
325    layer_configuration,    layer_orientation,
326    layer_screen,           layer_destroyed,
327 };
328 }  // namespace
329
330 layer::layer(uint32_t i, struct controller *c) : layer(i, 0, 0, c) {}
331
332 layer::layer(uint32_t i, int32_t w, int32_t h, struct controller *c)
333    : wayland_proxy(ivi_controller_layer_create(c->proxy.get(), i, w, h),
334                    [c, i](ivi_controller_layer *l) {
335                       HMI_DEBUG("wm", "~layer layer %i @ %p", i, l);
336                       c->remove_proxy_to_id_mapping(l);
337                       ivi_controller_layer_destroy(l, 1);
338                    }),
339      controller_child(c, i) {
340    this->parent->add_proxy_to_id_mapping(this->proxy.get(), i);
341    ivi_controller_layer_add_listener(this->proxy.get(), &layer_listener, this);
342 }
343
344 void layer::set_visibility(uint32_t visibility) {
345    ivi_controller_layer_set_visibility(this->proxy.get(), visibility);
346 }
347
348 void layer::set_opacity(wl_fixed_t opacity) {
349    ivi_controller_layer_set_opacity(this->proxy.get(), opacity);
350 }
351
352 void layer::set_source_rectangle(int32_t x, int32_t y, int32_t width,
353                                  int32_t height) {
354    ivi_controller_layer_set_source_rectangle(this->proxy.get(), x, y, width,
355                                              height);
356 }
357
358 void layer::set_destination_rectangle(int32_t x, int32_t y, int32_t width,
359                                       int32_t height) {
360    ivi_controller_layer_set_destination_rectangle(this->proxy.get(), x, y,
361                                                   width, height);
362 }
363
364 void layer::set_configuration(int32_t width, int32_t height) {
365    ivi_controller_layer_set_configuration(this->proxy.get(), width, height);
366 }
367
368 void layer::set_orientation(int32_t orientation) {
369    ivi_controller_layer_set_orientation(this->proxy.get(), orientation);
370 }
371
372 void layer::screenshot(const char *filename) {
373    ivi_controller_layer_screenshot(this->proxy.get(), filename);
374 }
375
376 void layer::clear_surfaces() {
377    ivi_controller_layer_clear_surfaces(this->proxy.get());
378 }
379
380 void layer::add_surface(struct surface *surface) {
381    ivi_controller_layer_add_surface(this->proxy.get(), surface->proxy.get());
382 }
383
384 void layer::remove_surface(struct surface *surface) {
385    ivi_controller_layer_remove_surface(this->proxy.get(), surface->proxy.get());
386 }
387
388 void layer::set_render_order(std::vector<uint32_t> const &ro) {
389    struct wl_array wlro {
390       .size = ro.size() * sizeof(ro[0]), .alloc = ro.capacity() * sizeof(ro[0]),
391       .data = const_cast<void *>(static_cast<void const *>(ro.data()))
392    };
393    ivi_controller_layer_set_render_order(this->proxy.get(), &wlro);
394 }
395
396 void controller::layer_visibility(struct layer *l, int32_t visibility) {
397    HMI_DEBUG("wm", "compositor::layer %s @ %d v %i", __func__, l->id, visibility);
398    this->lprops[l->id].visibility = visibility;
399 }
400
401 void controller::layer_opacity(struct layer *l, float opacity) {
402    HMI_DEBUG("wm", "compositor::layer %s @ %d o %f", __func__, l->id, opacity);
403    this->lprops[l->id].opacity = opacity;
404 }
405
406 void controller::layer_source_rectangle(struct layer *l, int32_t x, int32_t y,
407                                         int32_t width, int32_t height) {
408    HMI_DEBUG("wm", "compositor::layer %s @ %d x %i y %i w %i h %i", __func__,
409             l->id, x, y, width, height);
410    this->lprops[l->id].src_rect = rect{width, height, x, y};
411 }
412
413 void controller::layer_destination_rectangle(struct layer *l, int32_t x,
414                                              int32_t y, int32_t width,
415                                              int32_t height) {
416    HMI_DEBUG("wm", "compositor::layer %s @ %d x %i y %i w %i h %i", __func__,
417             l->id, x, y, width, height);
418    this->lprops[l->id].dst_rect = rect{width, height, x, y};
419 }
420
421 void controller::layer_configuration(struct layer *l, int32_t width,
422                                      int32_t height) {
423    HMI_DEBUG("wm", "compositor::layer %s @ %d w %i h %i", __func__, l->id,
424             width, height);
425    this->lprops[l->id].size = size{uint32_t(width), uint32_t(height)};
426 }
427
428 void controller::layer_orientation(struct layer *l, int32_t orientation) {
429    HMI_DEBUG("wm", "compositor::layer %s @ %d o %i", __func__, l->id,
430             orientation);
431    this->lprops[l->id].orientation = orientation;
432 }
433
434 void controller::layer_screen(struct layer *l, struct wl_output *screen) {
435    HMI_DEBUG("wm", "compositor::layer %s @ %d s %p", __func__, l->id, screen);
436 }
437
438 void controller::layer_destroyed(struct layer *l) {
439    HMI_DEBUG("wm", "compositor::layer %s @ %d", __func__, l->id);
440    this->lprops.erase(l->id);
441    this->layers.erase(l->id);
442 }
443
444 /**
445  * surface
446  */
447 namespace {
448
449 void surface_visibility(
450    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
451    int32_t visibility) {
452    auto s = static_cast<struct surface *>(data);
453    s->parent->surface_visibility(s, visibility);
454 }
455
456 void surface_opacity(void *data,
457                      struct ivi_controller_surface * /*ivi_controller_surface*/,
458                      wl_fixed_t opacity) {
459    auto s = static_cast<struct surface *>(data);
460    s->parent->surface_opacity(s, float(wl_fixed_to_double(opacity)));
461 }
462
463 void surface_source_rectangle(
464    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
465    int32_t x, int32_t y, int32_t width, int32_t height) {
466    auto s = static_cast<struct surface *>(data);
467    s->parent->surface_source_rectangle(s, x, y, width, height);
468 }
469
470 void surface_destination_rectangle(
471    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
472    int32_t x, int32_t y, int32_t width, int32_t height) {
473    auto s = static_cast<struct surface *>(data);
474    s->parent->surface_destination_rectangle(s, x, y, width, height);
475 }
476
477 void surface_configuration(
478    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
479    int32_t width, int32_t height) {
480    auto s = static_cast<struct surface *>(data);
481    s->parent->surface_configuration(s, width, height);
482 }
483
484 void surface_orientation(
485    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
486    int32_t orientation) {
487    auto s = static_cast<struct surface *>(data);
488    s->parent->surface_orientation(s, orientation);
489 }
490
491 void surface_pixelformat(
492    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/,
493    int32_t pixelformat) {
494    auto s = static_cast<struct surface *>(data);
495    s->parent->surface_pixelformat(s, pixelformat);
496 }
497
498 void surface_layer(void *data,
499                    struct ivi_controller_surface * /*ivi_controller_surface*/,
500                    struct ivi_controller_layer *layer) {
501    auto s = static_cast<struct surface *>(data);
502    s->parent->surface_layer(s, layer);
503 }
504
505 void surface_stats(void *data,
506                    struct ivi_controller_surface * /*ivi_controller_surface*/,
507                    uint32_t redraw_count, uint32_t frame_count,
508                    uint32_t update_count, uint32_t pid,
509                    const char *process_name) {
510    auto s = static_cast<struct surface *>(data);
511    s->parent->surface_stats(s, redraw_count, frame_count, update_count, pid,
512                             process_name);
513 }
514
515 void surface_destroyed(
516    void *data, struct ivi_controller_surface * /*ivi_controller_surface*/) {
517    auto s = static_cast<struct surface *>(data);
518    s->parent->surface_destroyed(s);
519 }
520
521 void surface_content(void *data,
522                      struct ivi_controller_surface * /*ivi_controller_surface*/,
523                      int32_t content_state) {
524    auto s = static_cast<struct surface *>(data);
525    s->parent->surface_content(s, content_state);
526 }
527
528 constexpr struct ivi_controller_surface_listener surface_listener = {
529    surface_visibility,
530    surface_opacity,
531    surface_source_rectangle,
532    surface_destination_rectangle,
533    surface_configuration,
534    surface_orientation,
535    surface_pixelformat,
536    surface_layer,
537    surface_stats,
538    surface_destroyed,
539    surface_content,
540 };
541 }  // namespace
542
543 surface::surface(uint32_t i, struct controller *c)
544    : wayland_proxy(ivi_controller_surface_create(c->proxy.get(), i),
545                    [c, i](ivi_controller_surface *s) {
546                       HMI_DEBUG("wm", "~surface surface %i @ %p", i, s);
547                       c->remove_proxy_to_id_mapping(s);
548                       ivi_controller_surface_destroy(s, 1);
549                    }),
550      controller_child(c, i) {
551    this->parent->add_proxy_to_id_mapping(this->proxy.get(), i);
552    ivi_controller_surface_add_listener(this->proxy.get(), &surface_listener,
553                                        this);
554 }
555
556 void surface::set_visibility(uint32_t visibility) {
557    ivi_controller_surface_set_visibility(this->proxy.get(), visibility);
558 }
559
560 void surface::set_opacity(wl_fixed_t opacity) {
561    ivi_controller_surface_set_opacity(this->proxy.get(), opacity);
562 }
563
564 void surface::set_source_rectangle(int32_t x, int32_t y, int32_t width,
565                                    int32_t height) {
566    ivi_controller_surface_set_source_rectangle(this->proxy.get(), x, y, width,
567                                                height);
568 }
569
570 void surface::set_destination_rectangle(int32_t x, int32_t y, int32_t width,
571                                         int32_t height) {
572    ivi_controller_surface_set_destination_rectangle(this->proxy.get(), x, y,
573                                                     width, height);
574 }
575
576 void surface::set_configuration(int32_t width, int32_t height) {
577    ivi_controller_surface_set_configuration(this->proxy.get(), width, height);
578 }
579
580 void surface::set_orientation(int32_t orientation) {
581    ivi_controller_surface_set_orientation(this->proxy.get(), orientation);
582 }
583
584 void surface::screenshot(const char *filename) {
585    ivi_controller_surface_screenshot(this->proxy.get(), filename);
586 }
587
588 void surface::send_stats() {
589    ivi_controller_surface_send_stats(this->proxy.get());
590 }
591
592 void surface::destroy(int32_t destroy_scene_object) {
593    ivi_controller_surface_destroy(this->proxy.get(), destroy_scene_object);
594 }
595
596 void controller::surface_visibility(struct surface *s, int32_t visibility) {
597    HMI_DEBUG("wm", "compositor::surface %s @ %d v %i", __func__, s->id,
598             visibility);
599    this->sprops[s->id].visibility = visibility;
600    this->chooks->surface_visibility(s->id, visibility);
601 }
602
603 void controller::surface_opacity(struct surface *s, float opacity) {
604    HMI_DEBUG("wm", "compositor::surface %s @ %d o %f", __func__, s->id,
605             opacity);
606    this->sprops[s->id].opacity = opacity;
607 }
608
609 void controller::surface_source_rectangle(struct surface *s, int32_t x,
610                                           int32_t y, int32_t width,
611                                           int32_t height) {
612    HMI_DEBUG("wm", "compositor::surface %s @ %d x %i y %i w %i h %i", __func__,
613             s->id, x, y, width, height);
614    this->sprops[s->id].src_rect = rect{width, height, x, y};
615 }
616
617 void controller::surface_destination_rectangle(struct surface *s, int32_t x,
618                                                int32_t y, int32_t width,
619                                                int32_t height) {
620    HMI_DEBUG("wm", "compositor::surface %s @ %d x %i y %i w %i h %i", __func__,
621             s->id, x, y, width, height);
622    this->sprops[s->id].dst_rect = rect{width, height, x, y};
623    this->chooks->surface_destination_rectangle(s->id, x, y, width, height);
624 }
625
626 void controller::surface_configuration(struct surface *s, int32_t width,
627                                        int32_t height) {
628    HMI_DEBUG("wm", "compositor::surface %s @ %d w %i h %i", __func__, s->id,
629             width, height);
630    this->sprops[s->id].size = size{uint32_t(width), uint32_t(height)};
631    is_configured = true;
632 }
633
634 void controller::surface_orientation(struct surface *s, int32_t orientation) {
635    HMI_DEBUG("wm", "compositor::surface %s @ %d o %i", __func__, s->id,
636             orientation);
637    this->sprops[s->id].orientation = orientation;
638 }
639
640 void controller::surface_pixelformat(struct surface * s,
641                                      int32_t pixelformat) {
642    HMI_DEBUG("wm", "compositor::surface %s @ %d f %i", __func__, s->id,
643             pixelformat);
644 }
645
646 void controller::surface_layer(struct surface * s,
647                                struct ivi_controller_layer *layer) {
648    HMI_DEBUG("wm", "compositor::surface %s @ %d l %u @ %p", __func__, s->id,
649             this->layer_proxy_to_id[uintptr_t(layer)], layer);
650 }
651
652 void controller::surface_stats(struct surface *s, uint32_t redraw_count,
653                                uint32_t frame_count, uint32_t update_count,
654                                uint32_t pid, const char *process_name) {
655    HMI_DEBUG("wm", "compositor::surface %s @ %d r %u f %u u %u pid %u p %s", __func__,
656             s->id, redraw_count, frame_count, update_count, pid,
657             process_name);
658 }
659
660 void controller::surface_destroyed(struct surface *s) {
661    HMI_DEBUG("wm", "compositor::surface %s @ %d", __func__, s->id);
662    this->chooks->surface_removed(s->id);
663    this->sprops.erase(s->id);
664    this->surfaces.erase(s->id);
665 }
666
667 void controller::surface_content(struct surface *s, int32_t content_state) {
668    HMI_DEBUG("wm", "compositor::surface %s @ %d s %i", __func__, s->id,
669             content_state);
670    if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
671       this->chooks->surface_removed(s->id);
672       this->sprops.erase(s->id);
673       this->surfaces.erase(s->id);
674    }
675 }
676
677 void controller::add_proxy_to_id_mapping(struct ivi_controller_surface *p,
678                                          uint32_t id) {
679    HMI_DEBUG("wm", "Add surface proxy mapping for %p (%u)", p, id);
680    this->surface_proxy_to_id[uintptr_t(p)] = id;
681    this->sprops[id].id = id;
682 }
683
684 void controller::remove_proxy_to_id_mapping(struct ivi_controller_surface *p) {
685    HMI_DEBUG("wm", "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,
690                                          uint32_t id) {
691    HMI_DEBUG("wm", "Add layer proxy mapping for %p (%u)", p, id);
692    this->layer_proxy_to_id[uintptr_t(p)] = id;
693    this->lprops[id].id = id;
694 }
695
696 void controller::remove_proxy_to_id_mapping(struct ivi_controller_layer *p) {
697    HMI_DEBUG("wm", "Remove layer proxy mapping for %p", p);
698    this->layer_proxy_to_id.erase(uintptr_t(p));
699 }
700
701 void controller::add_proxy_to_id_mapping(struct wl_output *p, uint32_t id) {
702    HMI_DEBUG("wm", "Add screen proxy mapping for %p (%u)", p, id);
703    this->screen_proxy_to_id[uintptr_t(p)] = id;
704 }
705
706 void controller::remove_proxy_to_id_mapping(struct wl_output *p) {
707    HMI_DEBUG("wm", "Remove screen proxy mapping for %p", p);
708    this->screen_proxy_to_id.erase(uintptr_t(p));
709 }
710
711 /**
712  * screen
713  */
714 screen::screen(uint32_t i, struct controller *c,
715                struct ivi_controller_screen *p)
716    : wayland_proxy(p), controller_child(c, i) {
717    HMI_DEBUG("wm", "compositor::screen @ %p id %u", p, i);
718 }
719
720 void screen::clear() { ivi_controller_screen_clear(this->proxy.get()); }
721
722 void screen::add_layer(layer *l) {
723    ivi_controller_screen_add_layer(this->proxy.get(), l->proxy.get());
724 }
725
726 void screen::set_render_order(std::vector<uint32_t> const &ro) {
727    struct wl_array wlro {
728       .size = ro.size() * sizeof(ro[0]), .alloc = ro.capacity() * sizeof(ro[0]),
729       .data = const_cast<void *>(static_cast<void const *>(ro.data()))
730    };
731    ivi_controller_screen_set_render_order(this->proxy.get(), &wlro);
732 }
733
734 }  // namespace compositor