4 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
5 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
6 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
7 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
12 // __| (_)___ _ __ | | __ _ _ _
13 // / _` | / __| '_ \| |/ _` | | | |
14 // | (_| | \__ \ |_) | | (_| | |_| |
15 // \__,_|_|___/ .__/|_|\__,_|\__, |
18 : d(std::unique_ptr<struct wl_display,
19 std::function<void(struct wl_display *)>>(
20 wl_display_connect(NULL),
21 [](struct wl_display *d) {
22 logdebug("wl::display ~display @ %p", d);
23 wl_display_disconnect(d);
25 r(!d ? nullptr : std::make_unique<struct registry>(d.get())) {}
27 display::~display() {}
29 bool display::ok() const { return d && wl_display_get_error(d.get()) == 0; }
31 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
33 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
36 // _ __ ___ __ _(_)___| |_ _ __ _ _
37 // | '__/ _ \/ _` | / __| __| '__| | | |
38 // | | | __/ (_| | \__ \ |_| | | |_| |
39 // |_| \___|\__, |_|___/\__|_| \__, |
42 void registry_global(void *data, struct wl_registry *r, uint32_t name,
43 char const *iface, uint32_t v) {
44 static_cast<struct registry *>(data)->global(name, iface, v);
47 void registry_global_remove(void *data, struct wl_registry *r, uint32_t name) {
48 static_cast<struct registry *>(data)->global_remove(name);
51 constexpr struct wl_registry_listener registry_listener = {
52 registry_global, registry_global_remove};
55 registry::registry(struct wl_display *d)
56 : wayland_proxy(!d ? nullptr : wl_display_get_registry(d)) {
58 wl_registry_add_listener(this->proxy, ®istry_listener, this);
61 registry::~registry() {
62 logdebug("wl::registry %s @ %p", __func__, this->proxy);
65 void registry::add_global_handler(char const *iface, binder bind) {
66 this->bindings[iface] = bind;
69 void registry::global(uint32_t name, char const *iface, uint32_t v) {
70 auto b = this->bindings.find(iface);
71 if (b != this->bindings.end())
72 b->second(this->proxy, name, v);
74 logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name,
78 void registry::global_remove(uint32_t name) {}
81 // ___ _ _| |_ _ __ _ _| |_
82 // / _ \| | | | __| '_ \| | | | __|
83 // | (_) | |_| | |_| |_) | |_| | |_
84 // \___/ \__,_|\__| .__/ \__,_|\__|
87 void output_geometry(void *data, struct wl_output *wl_output, int32_t x,
88 int32_t y, int32_t physical_width, int32_t physical_height,
89 int32_t subpixel, const char *make, const char *model,
91 static_cast<struct output *>(data)->geometry(
92 x, y, physical_width, physical_height, subpixel, make, model, transform);
95 void output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
96 int32_t width, int32_t height, int32_t refresh) {
97 static_cast<struct output *>(data)->mode(flags, width, height, refresh);
100 void output_done(void *data, struct wl_output *wl_output) {
101 static_cast<struct output *>(data)->done();
104 void output_scale(void *data, struct wl_output *wl_output, int32_t factor) {
105 static_cast<struct output *>(data)->scale(factor);
108 constexpr struct wl_output_listener output_listener = {
109 output_geometry, output_mode, output_done, output_scale};
112 output::output(struct wl_registry *r, uint32_t name, uint32_t v)
113 : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
114 wl_output_add_listener(this->proxy, &output_listener, this);
117 void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
118 int32_t subpel, char const *make, char const *model,
121 "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
122 __func__, this->proxy, x, y, pw, ph, subpel, make, model, tx);
125 void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
126 logdebug("wl::output %s @ %p f %x w %i h %i r %i", __func__, this->proxy,
130 void output::done() {
131 logdebug("wl::output %s @ %p done", __func__, this->proxy);
134 void output::scale(int32_t factor) {
135 logdebug("wl::output %s @ %p f %i", __func__, this->proxy, factor);
139 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
140 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
141 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
142 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
145 // __ _ ___ _ __ (_)_ _(_)
146 // / _` |/ _ \ '_ \| \ \ / / |
147 // | (_| | __/ | | | |\ V /| |
148 // \__, |\___|_| |_|_| \_/ |_|
153 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
154 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
155 // | (_| (_) | | | | |_| | | (_) | | | __/ |
156 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
159 void controller_screen(void *data, struct ivi_controller *ivi_controller,
161 struct ivi_controller_screen *screen) {
162 static_cast<struct controller *>(data)->controller_screen(id_screen, screen);
165 void controller_layer(void *data, struct ivi_controller *ivi_controller,
167 static_cast<struct controller *>(data)->controller_layer(id_layer);
170 void controller_surface(void *data, struct ivi_controller *ivi_controller,
171 uint32_t id_surface) {
172 static_cast<struct controller *>(data)->controller_surface(id_surface);
175 void controller_error(void *data, struct ivi_controller *ivi_controller,
176 int32_t object_id, int32_t object_type,
177 int32_t error_code, const char *error_text) {
178 static_cast<struct controller *>(data)->controller_error(
179 object_id, object_type, error_code, error_text);
182 constexpr struct ivi_controller_listener listener = {
183 controller_screen, controller_layer, controller_surface, controller_error};
186 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
188 wl_registry_bind(r, name, &ivi_controller_interface, version)) {
189 ivi_controller_add_listener(this->proxy, &listener, this);
192 controller::~controller() {}
194 void controller::controller_screen(uint32_t id,
195 struct ivi_controller_screen *screen) {
196 logdebug("genivi::controller @ %p screen %u (%x) @ %p", this->proxy, id, id,
198 this->screens[id] = std::make_unique<struct screen>(id, this, screen);
201 void controller::controller_layer(uint32_t id) {
202 logdebug("genivi::controller @ %p layer %u (%x)", this->proxy, id, id);
203 this->layers[id] = std::make_unique<struct layer>(id, this);
206 void controller::controller_surface(uint32_t id) {
207 logdebug("genivi::controller @ %p surface %u (%x)", this->proxy, id, id);
208 this->surfaces[id] = std::make_unique<struct surface>(id, this);
211 void controller::controller_error(int32_t object_id, int32_t object_type,
212 int32_t error_code, const char *error_text) {
213 logdebug("genivi::controller @ %p error o %i t %i c %i text %s", this->proxy,
214 object_id, object_type, error_code, error_text);
218 // | | __ _ _ _ ___ _ __
219 // | |/ _` | | | |/ _ \ '__|
220 // | | (_| | |_| | __/ |
221 // |_|\__,_|\__, |\___|_|
224 void layer_visibility(void *data,
225 struct ivi_controller_layer *ivi_controller_layer,
226 int32_t visibility) {
227 static_cast<struct layer *>(data)->parent->layer_visibility(
228 static_cast<struct layer *>(data)->id, visibility);
231 void layer_opacity(void *data,
232 struct ivi_controller_layer *ivi_controller_layer,
233 wl_fixed_t opacity) {
234 static_cast<struct layer *>(data)->parent->layer_opacity(
235 static_cast<struct layer *>(data)->id, wl_fixed_to_double(opacity));
238 void layer_source_rectangle(void *data,
239 struct ivi_controller_layer *ivi_controller_layer,
240 int32_t x, int32_t y, int32_t width,
242 static_cast<struct layer *>(data)->parent->layer_source_rectangle(
243 static_cast<struct layer *>(data)->id, x, y, width, height);
246 void layer_destination_rectangle(
247 void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
248 int32_t y, int32_t width, int32_t height) {
249 static_cast<struct layer *>(data)->parent->layer_destination_rectangle(
250 static_cast<struct layer *>(data)->id, x, y, width, height);
253 void layer_configuration(void *data,
254 struct ivi_controller_layer *ivi_controller_layer,
255 int32_t width, int32_t height) {
256 static_cast<struct layer *>(data)->parent->layer_configuration(
257 static_cast<struct layer *>(data)->id, width, height);
260 void layer_orientation(void *data,
261 struct ivi_controller_layer *ivi_controller_layer,
262 int32_t orientation) {
263 static_cast<struct layer *>(data)->parent->layer_orientation(
264 static_cast<struct layer *>(data)->id, orientation);
267 void layer_screen(void *data, struct ivi_controller_layer *ivi_controller_layer,
268 struct wl_output *screen) {
269 static_cast<struct layer *>(data)->parent->layer_screen(
270 static_cast<struct layer *>(data)->id, screen);
273 void layer_destroyed(void *data,
274 struct ivi_controller_layer *ivi_controller_layer) {
275 static_cast<struct layer *>(data)->parent->layer_destroyed(
276 static_cast<struct layer *>(data)->id);
279 constexpr struct ivi_controller_layer_listener layer_listener = {
280 layer_visibility, layer_opacity,
281 layer_source_rectangle, layer_destination_rectangle,
282 layer_configuration, layer_orientation,
283 layer_screen, layer_destroyed,
287 layer::layer(uint32_t i, struct controller *c)
288 : wayland_proxy(ivi_controller_layer_create(c->proxy, i, 0, 0)),
289 controlled_entity(c, i) {
290 ivi_controller_layer_add_listener(this->proxy, &layer_listener, this);
294 logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
295 ivi_controller_layer_destroy(this->proxy, 1);
296 this->proxy = nullptr;
299 void controller::layer_visibility(uint32_t id, int32_t visibility) {
300 logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
303 void controller::layer_opacity(uint32_t id, float opacity) {
304 logdebug("genivi::layer %s @ %p o %f", __func__, this->proxy, opacity);
307 void controller::layer_source_rectangle(uint32_t id, int32_t x, int32_t y,
308 int32_t width, int32_t height) {
309 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
310 x, y, width, height);
313 void controller::layer_destination_rectangle(uint32_t id, int32_t x, int32_t y,
314 int32_t width, int32_t height) {
315 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
316 x, y, width, height);
319 void controller::layer_configuration(uint32_t id, int32_t width,
321 logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
325 void controller::layer_orientation(uint32_t id, int32_t orientation) {
326 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
329 void controller::layer_screen(uint32_t id, struct wl_output *screen) {
330 logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
333 void controller::layer_destroyed(uint32_t id) {
334 logdebug("genivi::layer %s @ %p", __func__, this->proxy);
338 // ___ _ _ _ __ / _| __ _ ___ ___
339 // / __| | | | '__| |_ / _` |/ __/ _ \
340 // \__ \ |_| | | | _| (_| | (_| __/
341 // |___/\__,_|_| |_| \__,_|\___\___|
345 void surface_visibility(void *data,
346 struct ivi_controller_surface *ivi_controller_surface,
347 int32_t visibility) {
348 static_cast<struct surface *>(data)->parent->surface_visibility(
349 static_cast<struct surface *>(data)->id, visibility);
352 void surface_opacity(void *data,
353 struct ivi_controller_surface *ivi_controller_surface,
354 wl_fixed_t opacity) {
355 static_cast<struct surface *>(data)->parent->surface_opacity(
356 static_cast<struct surface *>(data)->id, wl_fixed_to_double(opacity));
359 void surface_source_rectangle(
360 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
361 int32_t y, int32_t width, int32_t height) {
362 static_cast<struct surface *>(data)->parent->surface_source_rectangle(
363 static_cast<struct surface *>(data)->id, x, y, width, height);
366 void surface_destination_rectangle(
367 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
368 int32_t y, int32_t width, int32_t height) {
369 static_cast<struct surface *>(data)->parent->surface_destination_rectangle(
370 static_cast<struct surface *>(data)->id, x, y, width, height);
373 void surface_configuration(
374 void *data, struct ivi_controller_surface *ivi_controller_surface,
375 int32_t width, int32_t height) {
376 static_cast<struct surface *>(data)->parent->surface_configuration(
377 static_cast<struct surface *>(data)->id, width, height);
380 void surface_orientation(void *data,
381 struct ivi_controller_surface *ivi_controller_surface,
382 int32_t orientation) {
383 static_cast<struct surface *>(data)->parent->surface_orientation(
384 static_cast<struct surface *>(data)->id, orientation);
387 void surface_pixelformat(void *data,
388 struct ivi_controller_surface *ivi_controller_surface,
389 int32_t pixelformat) {
390 static_cast<struct surface *>(data)->parent->surface_pixelformat(
391 static_cast<struct surface *>(data)->id, pixelformat);
394 void surface_layer(void *data,
395 struct ivi_controller_surface *ivi_controller_surface,
396 struct ivi_controller_layer *layer) {
397 static_cast<struct surface *>(data)->parent->surface_layer(
398 static_cast<struct surface *>(data)->id, layer);
401 void surface_stats(void *data,
402 struct ivi_controller_surface *ivi_controller_surface,
403 uint32_t redraw_count, uint32_t frame_count,
404 uint32_t update_count, uint32_t pid,
405 const char *process_name) {
406 static_cast<struct surface *>(data)->parent->surface_stats(
407 static_cast<struct surface *>(data)->id, redraw_count, frame_count,
408 update_count, pid, process_name);
411 void surface_destroyed(void *data,
412 struct ivi_controller_surface *ivi_controller_surface) {
413 static_cast<struct surface *>(data)->parent->surface_destroyed(
414 static_cast<struct surface *>(data)->id);
417 void surface_content(void *data,
418 struct ivi_controller_surface *ivi_controller_surface,
419 int32_t content_state) {
420 static_cast<struct surface *>(data)->parent->surface_content(
421 static_cast<struct surface *>(data)->id, content_state);
424 constexpr struct ivi_controller_surface_listener surface_listener = {
427 surface_source_rectangle,
428 surface_destination_rectangle,
429 surface_configuration,
439 surface::surface(uint32_t i, struct controller *c)
440 : wayland_proxy(ivi_controller_surface_create(c->proxy, i)),
441 controlled_entity(c, i) {
442 ivi_controller_surface_add_listener(this->proxy, &surface_listener, this);
445 surface::~surface() {
446 logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
447 ivi_controller_surface_destroy(this->proxy, 1);
448 this->proxy = nullptr;
451 void controller::surface_visibility(uint32_t id, int32_t visibility) {
452 logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
455 void controller::surface_opacity(uint32_t id, float opacity) {
456 logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy, opacity);
459 void controller::surface_source_rectangle(uint32_t id, int32_t x, int32_t y,
460 int32_t width, int32_t height) {
461 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
462 this->proxy, x, y, width, height);
465 void controller::surface_destination_rectangle(uint32_t id, int32_t x,
466 int32_t y, int32_t width,
468 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
469 this->proxy, x, y, width, height);
472 void controller::surface_configuration(uint32_t id, int32_t width,
474 logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
478 void controller::surface_orientation(uint32_t id, int32_t orientation) {
479 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
482 void controller::surface_pixelformat(uint32_t id, int32_t pixelformat) {
483 logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
486 void controller::surface_layer(uint32_t id,
487 struct ivi_controller_layer *layer) {
488 logdebug("genivi::surface %s @ %p l @ %p", __func__, this->proxy, layer);
491 void controller::surface_stats(uint32_t id, uint32_t redraw_count,
492 uint32_t frame_count, uint32_t update_count,
493 uint32_t pid, const char *process_name) {
494 logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
495 this->proxy, redraw_count, frame_count, update_count, pid,
499 void controller::surface_destroyed(uint32_t id) {
500 logdebug("genivi::surface %s @ %p", __func__, this->proxy);
503 void controller::surface_content(uint32_t id, int32_t content_state) {
504 logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
509 // ___ ___ _ __ ___ ___ _ __
510 // / __|/ __| '__/ _ \/ _ \ '_ \
511 // \__ \ (__| | | __/ __/ | | |
512 // |___/\___|_| \___|\___|_| |_|
514 screen::screen(uint32_t i, struct controller *c,
515 struct ivi_controller_screen *p)
516 : wayland_proxy(p), controlled_entity(c, i) {}