wayland: honor output transformations
[staging/windowmanager.git] / src / wayland.cpp
1 /*
2  * Copyright (C) 2017 Mentor Graphics Development (Deutschland) GmbH
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 "wayland.hpp"
20
21 //                                                                  _
22 //  _ __   __ _ _ __ ___   ___  ___ _ __   __ _  ___ ___  __      _| |
23 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
24 // | | | | (_| | | | | | |  __/\__ \ |_) | (_| | (_|  __/  \ V  V /| |
25 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|   \_/\_/ |_|
26 //                                 |_|
27 namespace wl {
28
29 //      _ _           _
30 //   __| (_)___ _ __ | | __ _ _   _
31 //  / _` | / __| '_ \| |/ _` | | | |
32 // | (_| | \__ \ |_) | | (_| | |_| |
33 //  \__,_|_|___/ .__/|_|\__,_|\__, |
34 //             |_|            |___/
35 display::display()
36    : d(std::unique_ptr<struct wl_display, void (*)(struct wl_display *)>(
37         wl_display_connect(nullptr), &wl_display_disconnect)),
38      r(d.get()) {}
39
40 bool display::ok() const { return d && wl_display_get_error(d.get()) == 0; }
41
42 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
43
44 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
45
46 void display::flush() { wl_display_flush(this->d.get()); }
47
48 int display::get_fd() const { return wl_display_get_fd(this->d.get()); }
49
50 int display::get_error() { return wl_display_get_error(this->d.get()); }
51
52 //                 _     _
53 //  _ __ ___  __ _(_)___| |_ _ __ _   _
54 // | '__/ _ \/ _` | / __| __| '__| | | |
55 // | | |  __/ (_| | \__ \ |_| |  | |_| |
56 // |_|  \___|\__, |_|___/\__|_|   \__, |
57 //           |___/                |___/
58 namespace {
59 void registry_global(void *data, struct wl_registry * /*r*/, uint32_t name,
60                      char const *iface, uint32_t v) {
61    static_cast<struct registry *>(data)->global(name, iface, v);
62 }
63
64 void registry_global_remove(void *data, struct wl_registry * /*r*/,
65                             uint32_t name) {
66    static_cast<struct registry *>(data)->global_remove(name);
67 }
68
69 constexpr struct wl_registry_listener registry_listener = {
70    registry_global, registry_global_remove};
71 }  // namespace
72
73 registry::registry(struct wl_display *d)
74    : wayland_proxy(d == nullptr ? nullptr : wl_display_get_registry(d)) {
75    if (this->proxy != nullptr) {
76       wl_registry_add_listener(this->proxy.get(), &registry_listener, this);
77    }
78 }
79
80 void registry::add_global_handler(char const *iface, binder bind) {
81    this->bindings[iface] = std::move(bind);
82 }
83
84 void registry::global(uint32_t name, char const *iface, uint32_t v) {
85    auto b = this->bindings.find(iface);
86    if (b != this->bindings.end()) {
87       b->second(this->proxy.get(), name, v);
88    }
89    logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy.get(), name,
90             iface, v);
91 }
92
93 void registry::global_remove(uint32_t /*name*/) {}
94
95 //              _               _
96 //   ___  _   _| |_ _ __  _   _| |_
97 //  / _ \| | | | __| '_ \| | | | __|
98 // | (_) | |_| | |_| |_) | |_| | |_
99 //  \___/ \__,_|\__| .__/ \__,_|\__|
100 //                 |_|
101 namespace {
102 void output_geometry(void *data, struct wl_output * /*wl_output*/, int32_t x,
103                      int32_t y, int32_t physical_width, int32_t physical_height,
104                      int32_t subpixel, const char *make, const char *model,
105                      int32_t transform) {
106    static_cast<struct output *>(data)->geometry(
107       x, y, physical_width, physical_height, subpixel, make, model, transform);
108 }
109
110 void output_mode(void *data, struct wl_output * /*wl_output*/, uint32_t flags,
111                  int32_t width, int32_t height, int32_t refresh) {
112    static_cast<struct output *>(data)->mode(flags, width, height, refresh);
113 }
114
115 void output_done(void *data, struct wl_output * /*wl_output*/) {
116    static_cast<struct output *>(data)->done();
117 }
118
119 void output_scale(void *data, struct wl_output * /*wl_output*/,
120                   int32_t factor) {
121    static_cast<struct output *>(data)->scale(factor);
122 }
123
124 constexpr struct wl_output_listener output_listener = {
125    output_geometry, output_mode, output_done, output_scale};
126 }  // namespace
127
128 output::output(struct wl_registry *r, uint32_t name, uint32_t v)
129    : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
130    wl_output_add_listener(this->proxy.get(), &output_listener, this);
131 }
132
133 void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
134                       int32_t subpel, char const *make, char const *model,
135                       int32_t tx) {
136    logdebug(
137       "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
138       __func__, this->proxy.get(), x, y, pw, ph, subpel, make, model, tx);
139    this->transform = tx;
140 }
141
142 void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
143    logdebug("wl::output %s @ %p f %x w %i h %i r %i", __func__,
144             this->proxy.get(), flags, w, h, r);
145    if ((flags & WL_OUTPUT_MODE_CURRENT) != 0u) {
146       this->width = w;
147       this->height = h;
148       this->refresh = r;
149    }
150 }
151
152 void output::done() {
153    logdebug("wl::output %s @ %p done", __func__, this->proxy.get());
154    // Let's just disregard the flipped ones...
155    if (this->transform == WL_OUTPUT_TRANSFORM_90 ||
156        this->transform == WL_OUTPUT_TRANSFORM_270) {
157       std::swap(this->width, this->height);
158    }
159 }
160
161 void output::scale(int32_t factor) {
162    logdebug("wl::output %s @ %p f %i", __func__, this->proxy.get(), factor);
163 }
164 }  // namespace wl
165
166 //  _ __   __ _ _ __ ___   ___  ___ _ __   __ _  ___ ___
167 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
168 // | | | | (_| | | | | | |  __/\__ \ |_) | (_| | (_|  __/
169 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
170 //                                 |_|
171 //                   _       _
172 //   __ _  ___ _ __ (_)_   _(_)
173 //  / _` |/ _ \ '_ \| \ \ / / |
174 // | (_| |  __/ | | | |\ V /| |
175 //  \__, |\___|_| |_|_| \_/ |_|
176 //  |___/
177 namespace genivi {
178
179 //                  _             _ _
180 //   ___ ___  _ __ | |_ _ __ ___ | | | ___ _ __
181 //  / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
182 // | (_| (_) | | | | |_| | | (_) | | |  __/ |
183 //  \___\___/|_| |_|\__|_|  \___/|_|_|\___|_|
184 //
185 namespace {
186 void controller_screen(void *data, struct ivi_controller * /*ivi_controller*/,
187                        uint32_t id_screen,
188                        struct ivi_controller_screen *screen) {
189    static_cast<struct controller *>(data)->controller_screen(id_screen, screen);
190 }
191
192 void controller_layer(void *data, struct ivi_controller * /*ivi_controller*/,
193                       uint32_t id_layer) {
194    static_cast<struct controller *>(data)->controller_layer(id_layer);
195 }
196
197 void controller_surface(void *data, struct ivi_controller * /*ivi_controller*/,
198                         uint32_t id_surface) {
199    static_cast<struct controller *>(data)->controller_surface(id_surface);
200 }
201
202 void controller_error(void *data, struct ivi_controller * /*ivi_controller*/,
203                       int32_t object_id, int32_t object_type,
204                       int32_t error_code, const char *error_text) {
205    static_cast<struct controller *>(data)->controller_error(
206       object_id, object_type, error_code, error_text);
207 }
208
209 constexpr struct ivi_controller_listener listener = {
210    controller_screen, controller_layer, controller_surface, controller_error};
211 }  // namespace
212
213 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
214    : wayland_proxy(
215         wl_registry_bind(r, name, &ivi_controller_interface, version)),
216      output_size{} {
217    ivi_controller_add_listener(this->proxy.get(), &listener, this);
218 }
219
220 void controller::layer_create(uint32_t id, int32_t w, int32_t h) {
221    this->layers[id] = std::make_unique<struct layer>(id, w, h, this);
222 }
223
224 void controller::surface_create(uint32_t id) {
225    this->surfaces[id] = std::make_unique<struct 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.get(),
231             id, id, 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.get(), 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.get(), id,
243             id);
244    this->surfaces[id] = std::make_unique<struct surface>(id, this);
245    this->chooks->surface_created(id);
246 }
247
248 void controller::controller_error(int32_t object_id, int32_t object_type,
249                                   int32_t error_code, const char *error_text) {
250    logdebug("genivi::controller @ %p error o %i t %i c %i text %s",
251             this->proxy.get(), object_id, object_type, error_code, error_text);
252 }
253
254 //  _
255 // | | __ _ _   _  ___ _ __
256 // | |/ _` | | | |/ _ \ '__|
257 // | | (_| | |_| |  __/ |
258 // |_|\__,_|\__, |\___|_|
259 //          |___/
260 namespace {
261 void layer_visibility(void *data,
262                       struct ivi_controller_layer * /*ivi_controller_layer*/,
263                       int32_t visibility) {
264    auto l = static_cast<struct layer *>(data);
265    l->parent->layer_visibility(l, visibility);
266 }
267
268 void layer_opacity(void *data,
269                    struct ivi_controller_layer * /*ivi_controller_layer*/,
270                    wl_fixed_t opacity) {
271    auto l = static_cast<struct layer *>(data);
272    l->parent->layer_opacity(l, float(wl_fixed_to_double(opacity)));
273 }
274
275 void layer_source_rectangle(
276    void *data, struct ivi_controller_layer * /*ivi_controller_layer*/,
277    int32_t x, int32_t y, int32_t width, int32_t height) {
278    auto l = static_cast<struct layer *>(data);
279    l->parent->layer_source_rectangle(l, x, y, width, height);
280 }
281
282 void layer_destination_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_destination_rectangle(l, x, y, width, height);
287 }
288
289 void layer_configuration(void *data,
290                          struct ivi_controller_layer * /*ivi_controller_layer*/,
291                          int32_t width, int32_t height) {
292    auto l = static_cast<struct layer *>(data);
293    l->parent->layer_configuration(l, width, height);
294 }
295
296 void layer_orientation(void *data,
297                        struct ivi_controller_layer * /*ivi_controller_layer*/,
298                        int32_t orientation) {
299    auto l = static_cast<struct layer *>(data);
300    l->parent->layer_orientation(l, orientation);
301 }
302
303 void layer_screen(void *data,
304                   struct ivi_controller_layer * /*ivi_controller_layer*/,
305                   struct wl_output *screen) {
306    auto l = static_cast<struct layer *>(data);
307    l->parent->layer_screen(l, screen);
308 }
309
310 void layer_destroyed(void *data,
311                      struct ivi_controller_layer * /*ivi_controller_layer*/) {
312    auto l = static_cast<struct layer *>(data);
313    l->parent->layer_destroyed(l);
314 }
315
316 constexpr struct ivi_controller_layer_listener layer_listener = {
317    layer_visibility,       layer_opacity,
318    layer_source_rectangle, layer_destination_rectangle,
319    layer_configuration,    layer_orientation,
320    layer_screen,           layer_destroyed,
321 };
322 }  // namespace
323
324 layer::layer(uint32_t i, struct controller *c) : layer(i, 0, 0, c) {}
325
326 layer::layer(uint32_t i, int32_t w, int32_t h, struct controller *c)
327    : wayland_proxy(ivi_controller_layer_create(c->proxy.get(), i, w, h),
328                    [c, i](ivi_controller_layer *l) {
329                       logdebug("~layer layer %i @ %p", i, l);
330                       c->remove_proxy_to_id_mapping(l);
331                       ivi_controller_layer_destroy(l, 1);
332                    }),
333      controller_child(c, i) {
334    this->parent->add_proxy_to_id_mapping(this->proxy.get(), i);
335    ivi_controller_layer_add_listener(this->proxy.get(), &layer_listener, this);
336 }
337
338 void layer::set_visibility(uint32_t visibility) {
339    ivi_controller_layer_set_visibility(this->proxy.get(), visibility);
340 }
341
342 void layer::set_opacity(wl_fixed_t opacity) {
343    ivi_controller_layer_set_opacity(this->proxy.get(), opacity);
344 }
345
346 void layer::set_source_rectangle(int32_t x, int32_t y, int32_t width,
347                                  int32_t height) {
348    ivi_controller_layer_set_source_rectangle(this->proxy.get(), x, y, width,
349                                              height);
350 }
351
352 void layer::set_destination_rectangle(int32_t x, int32_t y, int32_t width,
353                                       int32_t height) {
354    ivi_controller_layer_set_destination_rectangle(this->proxy.get(), x, y,
355                                                   width, height);
356 }
357
358 void layer::set_configuration(int32_t width, int32_t height) {
359    ivi_controller_layer_set_configuration(this->proxy.get(), width, height);
360 }
361
362 void layer::set_orientation(int32_t orientation) {
363    ivi_controller_layer_set_orientation(this->proxy.get(), orientation);
364 }
365
366 void layer::screenshot(const char *filename) {
367    ivi_controller_layer_screenshot(this->proxy.get(), filename);
368 }
369
370 void layer::clear_surfaces() {
371    ivi_controller_layer_clear_surfaces(this->proxy.get());
372 }
373
374 void layer::add_surface(struct surface *surface) {
375    ivi_controller_layer_add_surface(this->proxy.get(), surface->proxy.get());
376 }
377
378 void layer::remove_surface(struct surface *surface) {
379    ivi_controller_layer_remove_surface(this->proxy.get(), surface->proxy.get());
380 }
381
382 void layer::set_render_order(std::vector<uint32_t> const &ro) {
383    struct wl_array wlro {
384       .size = ro.size() * sizeof(ro[0]), .alloc = ro.capacity() * sizeof(ro[0]),
385       .data = const_cast<void *>(static_cast<void const *>(ro.data()))
386    };
387    ivi_controller_layer_set_render_order(this->proxy.get(), &wlro);
388 }
389
390 void controller::layer_visibility(struct layer *l, int32_t visibility) {
391    logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy.get(),
392             visibility);
393    this->lprops[l->id].visibility = visibility;
394 }
395
396 void controller::layer_opacity(struct layer *l, float opacity) {
397    logdebug("genivi::layer %s @ %p o %f", __func__, this->proxy.get(), opacity);
398    this->lprops[l->id].opacity = opacity;
399 }
400
401 void controller::layer_source_rectangle(struct layer *l, int32_t x, int32_t y,
402                                         int32_t width, int32_t height) {
403    logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__,
404             this->proxy.get(), x, y, width, height);
405    this->lprops[l->id].src_rect = rect{width, height, x, y};
406 }
407
408 void controller::layer_destination_rectangle(struct layer *l, int32_t x,
409                                              int32_t y, int32_t width,
410                                              int32_t height) {
411    logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__,
412             this->proxy.get(), x, y, width, height);
413    this->lprops[l->id].dst_rect = rect{width, height, x, y};
414 }
415
416 void controller::layer_configuration(struct layer *l, int32_t width,
417                                      int32_t height) {
418    logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy.get(),
419             width, height);
420    this->lprops[l->id].size = size{uint32_t(width), uint32_t(height)};
421 }
422
423 void controller::layer_orientation(struct layer *l, int32_t orientation) {
424    logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy.get(),
425             orientation);
426    this->lprops[l->id].orientation = orientation;
427 }
428
429 void controller::layer_screen(struct layer * /*l*/, struct wl_output *screen) {
430    logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy.get(), screen);
431 }
432
433 void controller::layer_destroyed(struct layer *l) {
434    logdebug("genivi::layer %s @ %p", __func__, this->proxy.get());
435    this->chooks->add_task("remove layer", [l, this] {
436       this->lprops.erase(l->id);
437       this->layers.erase(l->id);
438    });
439 }
440
441 //                  __
442 //  ___ _   _ _ __ / _| __ _  ___ ___
443 // / __| | | | '__| |_ / _` |/ __/ _ \
444 // \__ \ |_| | |  |  _| (_| | (_|  __/
445 // |___/\__,_|_|  |_|  \__,_|\___\___|
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                       logdebug("~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    logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy.get(),
598             visibility);
599    this->sprops[s->id].visibility = visibility;
600 }
601
602 void controller::surface_opacity(struct surface *s, float opacity) {
603    logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy.get(),
604             opacity);
605    this->sprops[s->id].opacity = opacity;
606 }
607
608 void controller::surface_source_rectangle(struct surface *s, int32_t x,
609                                           int32_t y, int32_t width,
610                                           int32_t height) {
611    logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
612             this->proxy.get(), x, y, width, height);
613    this->sprops[s->id].src_rect = rect{width, height, x, y};
614 }
615
616 void controller::surface_destination_rectangle(struct surface *s, int32_t x,
617                                                int32_t y, int32_t width,
618                                                int32_t height) {
619    logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
620             this->proxy.get(), x, y, width, height);
621    this->sprops[s->id].dst_rect = rect{width, height, x, y};
622 }
623
624 void controller::surface_configuration(struct surface *s, int32_t width,
625                                        int32_t height) {
626    logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy.get(),
627             width, height);
628    this->sprops[s->id].size = size{uint32_t(width), uint32_t(height)};
629 }
630
631 void controller::surface_orientation(struct surface *s, int32_t orientation) {
632    logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy.get(),
633             orientation);
634    this->sprops[s->id].orientation = orientation;
635 }
636
637 void controller::surface_pixelformat(struct surface * /*s*/,
638                                      int32_t pixelformat) {
639    logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy.get(),
640             pixelformat);
641 }
642
643 void controller::surface_layer(struct surface * /*s*/,
644                                struct ivi_controller_layer *layer) {
645    logdebug("genivi::surface %s @ %p l %u @ %p", __func__, this->proxy.get(),
646             this->layer_proxy_to_id[uintptr_t(layer)], layer);
647 }
648
649 void controller::surface_stats(struct surface * /*s*/, uint32_t redraw_count,
650                                uint32_t frame_count, uint32_t update_count,
651                                uint32_t pid, const char *process_name) {
652    logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
653             this->proxy.get(), redraw_count, frame_count, update_count, pid,
654             process_name);
655 }
656
657 void controller::surface_destroyed(struct surface *s) {
658    logdebug("genivi::surface %s @ %p", __func__, this->proxy.get());
659    this->chooks->surface_removed(s->id);
660    // XXX: do I need to actually remove the surface late, i.e. using add_task()?
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    logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy.get(),
667             content_state);
668    if (content_state == IVI_CONTROLLER_SURFACE_CONTENT_STATE_CONTENT_REMOVED) {
669       // XXX is this the right thing to do?
670       this->chooks->surface_removed(s->id);
671       this->chooks->add_task("remove surface", [this, s] {
672          this->sprops.erase(s->id);
673          this->surfaces.erase(s->id);
674       });
675    }
676 }
677
678 void controller::add_proxy_to_id_mapping(struct ivi_controller_surface *p,
679                                          uint32_t id) {
680    logdebug("Add surface proxy mapping for %p (%u)", p, id);
681    this->surface_proxy_to_id[uintptr_t(p)] = id;
682    this->sprops[id].id = id;
683 }
684
685 void controller::remove_proxy_to_id_mapping(struct ivi_controller_surface *p) {
686    logdebug("Remove surface proxy mapping for %p", p);
687    this->surface_proxy_to_id.erase(uintptr_t(p));
688 }
689
690 void controller::add_proxy_to_id_mapping(struct ivi_controller_layer *p,
691                                          uint32_t id) {
692    logdebug("Add layer proxy mapping for %p (%u)", p, id);
693    this->layer_proxy_to_id[uintptr_t(p)] = id;
694    this->lprops[id].id = id;
695 }
696
697 void controller::remove_proxy_to_id_mapping(struct ivi_controller_layer *p) {
698    logdebug("Remove layer proxy mapping for %p", p);
699    this->layer_proxy_to_id.erase(uintptr_t(p));
700 }
701
702 void controller::add_proxy_to_id_mapping(struct wl_output *p, uint32_t id) {
703    logdebug("Add screen proxy mapping for %p (%u)", p, id);
704    this->screen_proxy_to_id[uintptr_t(p)] = id;
705 }
706
707 void controller::remove_proxy_to_id_mapping(struct wl_output *p) {
708    logdebug("Remove screen proxy mapping for %p", p);
709    this->screen_proxy_to_id.erase(uintptr_t(p));
710 }
711
712 //
713 //  ___  ___ _ __ ___  ___ _ __
714 // / __|/ __| '__/ _ \/ _ \ '_ \
715 // \__ \ (__| | |  __/  __/ | | |
716 // |___/\___|_|  \___|\___|_| |_|
717 //
718 screen::screen(uint32_t i, struct controller *c,
719                struct ivi_controller_screen *p)
720    : wayland_proxy(p), controller_child(c, i) {
721    logdebug("genivi::screen @ %p id %u", p, i);
722 }
723
724 void screen::clear() { ivi_controller_screen_clear(this->proxy.get()); }
725
726 void screen::add_layer(layer *l) {
727    ivi_controller_screen_add_layer(this->proxy.get(), l->proxy.get());
728 }
729
730 void screen::set_render_order(std::vector<uint32_t> const &ro) {
731    struct wl_array wlro {
732       .size = ro.size() * sizeof(ro[0]), .alloc = ro.capacity() * sizeof(ro[0]),
733       .data = const_cast<void *>(static_cast<void const *>(ro.data()))
734    };
735    ivi_controller_screen_set_render_order(this->proxy.get(), &wlro);
736 }
737
738 }  // namespace genivi