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(std::make_unique<struct registry>(d.get())) {}
27 display::~display() {}
29 bool display::ok() const {
30 return d && wl_display_get_error(d.get()) == 0;
33 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
35 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
38 // _ __ ___ __ _(_)___| |_ _ __ _ _
39 // | '__/ _ \/ _` | / __| __| '__| | | |
40 // | | | __/ (_| | \__ \ |_| | | |_| |
41 // |_| \___|\__, |_|___/\__|_| \__, |
44 void registry_global(void *data, struct wl_registry *r, uint32_t name,
45 char const *iface, uint32_t v) {
46 static_cast<struct registry *>(data)->global(name, iface, v);
49 void registry_global_remove(void *data, struct wl_registry *r, uint32_t name) {
50 static_cast<struct registry *>(data)->global_remove(name);
53 constexpr struct wl_registry_listener registry_listener = {
54 registry_global, registry_global_remove};
57 registry::registry(struct wl_display *d)
58 : wayland_proxy(wl_display_get_registry(d)) {
59 wl_registry_add_listener(this->proxy, ®istry_listener, this);
62 registry::~registry() {
63 logdebug("wl::registry %s @ %p", __func__, this->proxy);
66 void registry::add_global_handler(char const *iface, binder bind) {
67 this->bindings[iface] = bind;
70 void registry::global(uint32_t name, char const *iface, uint32_t v) {
71 auto b = this->bindings.find(iface);
72 if (b != this->bindings.end())
73 b->second(this->proxy, name, v);
75 logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name,
79 void registry::global_remove(uint32_t name) {}
82 // ___ _ _| |_ _ __ _ _| |_
83 // / _ \| | | | __| '_ \| | | | __|
84 // | (_) | |_| | |_| |_) | |_| | |_
85 // \___/ \__,_|\__| .__/ \__,_|\__|
88 void output_geometry(void *data, struct wl_output *wl_output, int32_t x,
89 int32_t y, int32_t physical_width, int32_t physical_height,
90 int32_t subpixel, const char *make, const char *model,
92 static_cast<struct output *>(data)->geometry(
93 x, y, physical_width, physical_height, subpixel, make, model, transform);
96 void output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
97 int32_t width, int32_t height, int32_t refresh) {
98 static_cast<struct output *>(data)->mode(flags, width, height, refresh);
101 void output_done(void *data, struct wl_output *wl_output) {
102 static_cast<struct output *>(data)->done();
105 void output_scale(void *data, struct wl_output *wl_output, int32_t factor) {
106 static_cast<struct output *>(data)->scale(factor);
109 constexpr struct wl_output_listener output_listener = {
110 output_geometry, output_mode, output_done, output_scale};
113 output::output(struct wl_registry *r, uint32_t name, uint32_t v)
114 : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
115 wl_output_add_listener(this->proxy, &output_listener, this);
118 void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
119 int32_t subpel, char const *make, char const *model,
122 "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
123 __func__, this->proxy, x, y, pw, ph, subpel, make, model, tx);
126 void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
127 logdebug("wl::output %s @ %p f %x w %i h %i r %i", __func__, this->proxy,
131 void output::done() {
132 logdebug("wl::output %s @ %p done", __func__, this->proxy);
135 void output::scale(int32_t factor) {
136 logdebug("wl::output %s @ %p f %i", __func__, this->proxy, factor);
140 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
141 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
142 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
143 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
146 // __ _ ___ _ __ (_)_ _(_)
147 // / _` |/ _ \ '_ \| \ \ / / |
148 // | (_| | __/ | | | |\ V /| |
149 // \__, |\___|_| |_|_| \_/ |_|
154 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
155 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
156 // | (_| (_) | | | | |_| | | (_) | | | __/ |
157 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
160 void controller_screen(void *data, struct ivi_controller *ivi_controller,
162 struct ivi_controller_screen *screen) {
163 static_cast<struct controller *>(data)->screen(id_screen, screen);
166 void controller_layer(void *data, struct ivi_controller *ivi_controller,
168 static_cast<struct controller *>(data)->layer(id_layer);
171 void controller_surface(void *data, struct ivi_controller *ivi_controller,
172 uint32_t id_surface) {
173 static_cast<struct controller *>(data)->surface(id_surface);
176 void controller_error(void *data, struct ivi_controller *ivi_controller,
177 int32_t object_id, int32_t object_type,
178 int32_t error_code, const char *error_text) {
179 static_cast<struct controller *>(data)->error(object_id, object_type,
180 error_code, error_text);
183 constexpr struct ivi_controller_listener listener = {
184 controller_screen, controller_layer, controller_surface, controller_error};
187 controller::controller(struct wl_registry *r, uint32_t name, uint32_t version)
189 wl_registry_bind(r, name, &ivi_controller_interface, version)) {
190 ivi_controller_add_listener(this->proxy, &listener, this);
193 controller::~controller() {}
195 void controller::screen(uint32_t id, 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, screen);
201 void 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->proxy);
206 void 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->proxy);
211 void 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)->visibility(visibility);
230 void layer_opacity(void *data,
231 struct ivi_controller_layer *ivi_controller_layer,
232 wl_fixed_t opacity) {
233 static_cast<struct layer *>(data)->opacity(wl_fixed_to_double(opacity));
236 void layer_source_rectangle(void *data,
237 struct ivi_controller_layer *ivi_controller_layer,
238 int32_t x, int32_t y, int32_t width,
240 static_cast<struct layer *>(data)->source_rectangle(x, y, width, height);
243 void layer_destination_rectangle(
244 void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
245 int32_t y, int32_t width, int32_t height) {
246 static_cast<struct layer *>(data)->destination_rectangle(x, y, width,
250 void layer_configuration(void *data,
251 struct ivi_controller_layer *ivi_controller_layer,
252 int32_t width, int32_t height) {
253 static_cast<struct layer *>(data)->configuration(width, height);
256 void layer_orientation(void *data,
257 struct ivi_controller_layer *ivi_controller_layer,
258 int32_t orientation) {
259 static_cast<struct layer *>(data)->orientation(orientation);
262 void layer_screen(void *data, struct ivi_controller_layer *ivi_controller_layer,
263 struct wl_output *screen) {
264 static_cast<struct layer *>(data)->screen(screen);
267 void layer_destroyed(void *data,
268 struct ivi_controller_layer *ivi_controller_layer) {
269 static_cast<struct layer *>(data)->destroyed();
272 constexpr struct ivi_controller_layer_listener layer_listener = {
273 layer_visibility, layer_opacity,
274 layer_source_rectangle, layer_destination_rectangle,
275 layer_configuration, layer_orientation,
276 layer_screen, layer_destroyed,
280 layer::layer(uint32_t i, struct ivi_controller *c)
281 : wayland_proxy(ivi_controller_layer_create(c, i, 0, 0)), id(i) {
282 ivi_controller_layer_add_listener(this->proxy, &layer_listener, this);
286 logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
287 ivi_controller_layer_destroy(this->proxy, 1);
288 this->proxy = nullptr;
291 void layer::visibility(int32_t visibility) {
292 logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
295 void layer::opacity(float opacity) {
296 logdebug("genivi::layer %s @ %p o %f", __func__, this->proxy, opacity);
299 void layer::source_rectangle(int32_t x, int32_t y, int32_t width,
301 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
302 x, y, width, height);
305 void layer::destination_rectangle(int32_t x, int32_t y, int32_t width,
307 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
308 x, y, width, height);
311 void layer::configuration(int32_t width, int32_t height) {
312 logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
316 void layer::orientation(int32_t orientation) {
317 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
320 void layer::screen(struct wl_output *screen) {
321 logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
324 void layer::destroyed() {
325 logdebug("genivi::layer %s @ %p", __func__, this->proxy);
329 // ___ _ _ _ __ / _| __ _ ___ ___
330 // / __| | | | '__| |_ / _` |/ __/ _ \
331 // \__ \ |_| | | | _| (_| | (_| __/
332 // |___/\__,_|_| |_| \__,_|\___\___|
336 void surface_visibility(void *data,
337 struct ivi_controller_surface *ivi_controller_surface,
338 int32_t visibility) {
339 static_cast<struct surface *>(data)->visibility(visibility);
342 void surface_opacity(void *data,
343 struct ivi_controller_surface *ivi_controller_surface,
344 wl_fixed_t opacity) {
345 static_cast<struct surface *>(data)->opacity(wl_fixed_to_double(opacity));
348 void surface_source_rectangle(
349 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
350 int32_t y, int32_t width, int32_t height) {
351 static_cast<struct surface *>(data)->source_rectangle(x, y, width, height);
354 void surface_destination_rectangle(
355 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
356 int32_t y, int32_t width, int32_t height) {
357 static_cast<struct surface *>(data)->destination_rectangle(x, y, width,
361 void surface_configuration(
362 void *data, struct ivi_controller_surface *ivi_controller_surface,
363 int32_t width, int32_t height) {
364 static_cast<struct surface *>(data)->configuration(width, height);
367 void surface_orientation(void *data,
368 struct ivi_controller_surface *ivi_controller_surface,
369 int32_t orientation) {
370 static_cast<struct surface *>(data)->orientation(orientation);
373 void surface_pixelformat(void *data,
374 struct ivi_controller_surface *ivi_controller_surface,
375 int32_t pixelformat) {
376 static_cast<struct surface *>(data)->pixelformat(pixelformat);
379 void surface_layer(void *data,
380 struct ivi_controller_surface *ivi_controller_surface,
381 struct ivi_controller_layer *layer) {
382 static_cast<struct surface *>(data)->layer(layer);
385 void surface_stats(void *data,
386 struct ivi_controller_surface *ivi_controller_surface,
387 uint32_t redraw_count, uint32_t frame_count,
388 uint32_t update_count, uint32_t pid,
389 const char *process_name) {
390 static_cast<struct surface *>(data)->stats(redraw_count, frame_count,
391 update_count, pid, process_name);
394 void surface_destroyed(void *data,
395 struct ivi_controller_surface *ivi_controller_surface) {
396 static_cast<struct surface *>(data)->destroyed();
399 void surface_content(void *data,
400 struct ivi_controller_surface *ivi_controller_surface,
401 int32_t content_state) {
402 static_cast<struct surface *>(data)->content(content_state);
405 constexpr struct ivi_controller_surface_listener surface_listener = {
408 surface_source_rectangle,
409 surface_destination_rectangle,
410 surface_configuration,
420 surface::surface(uint32_t i, struct ivi_controller *c)
421 : wayland_proxy(ivi_controller_surface_create(c, i)), id(i) {
422 ivi_controller_surface_add_listener(this->proxy, &surface_listener, this);
425 surface::~surface() {
426 logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
427 ivi_controller_surface_destroy(this->proxy, 1);
428 this->proxy = nullptr;
431 void surface::visibility(int32_t visibility) {
432 logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
435 void surface::opacity(float opacity) {
436 logdebug("genivi::surface %s @ %p o %f", __func__, this->proxy, opacity);
439 void surface::source_rectangle(int32_t x, int32_t y, int32_t width,
441 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
442 this->proxy, x, y, width, height);
445 void surface::destination_rectangle(int32_t x, int32_t y, int32_t width,
447 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
448 this->proxy, x, y, width, height);
451 void surface::configuration(int32_t width, int32_t height) {
452 logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
456 void surface::orientation(int32_t orientation) {
457 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
460 void surface::pixelformat(int32_t pixelformat) {
461 logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
464 void surface::layer(struct ivi_controller_layer *layer) {
465 logdebug("genivi::surface %s @ %p l @ %p", __func__, this->proxy, layer);
468 void surface::stats(uint32_t redraw_count, uint32_t frame_count,
469 uint32_t update_count, uint32_t pid,
470 const char *process_name) {
471 logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
472 this->proxy, redraw_count, frame_count, update_count, pid,
476 void surface::destroyed() {
477 logdebug("genivi::surface %s @ %p", __func__, this->proxy);
480 void surface::content(int32_t content_state) {
481 logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
486 // ___ ___ _ __ ___ ___ _ __
487 // / __|/ __| '__/ _ \/ _ \ '_ \
488 // \__ \ (__| | | __/ __/ | | |
489 // |___/\___|_| \___|\___|_| |_|
491 screen::screen(uint32_t i, struct ivi_controller_screen *p)
492 : wayland_proxy(p), id(i) {}