4 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
5 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
6 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
7 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
12 // __| (_)___ _ __ | | __ _ _ _
13 // / _` | / __| '_ \| |/ _` | | | |
14 // | (_| | \__ \ |_) | | (_| | |_| |
15 // \__,_|_|___/ .__/|_|\__,_|\__, |
18 : d(std::unique_ptr<wl_display, void (*)(wl_display *)>(
19 wl_display_connect(NULL), wl_display_disconnect)),
20 r(std::make_unique<registry>(d.get())) {}
22 bool display::ok() const {
23 return d.get() != nullptr && wl_display_get_error(d.get()) == 0;
26 void display::roundtrip() { wl_display_roundtrip(this->d.get()); }
28 int display::dispatch() { return wl_display_dispatch(this->d.get()); }
31 // _ __ ___ __ _(_)___| |_ _ __ _ _
32 // | '__/ _ \/ _` | / __| __| '__| | | |
33 // | | | __/ (_| | \__ \ |_| | | |_| |
34 // |_| \___|\__, |_|___/\__|_| \__, |
37 void registry_global(void *data, struct wl_registry *r, uint32_t name,
38 char const *iface, uint32_t v) {
39 static_cast<registry *>(data)->global(name, iface, v);
42 void registry_global_remove(void *data, struct wl_registry *r, uint32_t name) {
43 static_cast<registry *>(data)->global_remove(name);
46 constexpr wl_registry_listener registry_listener = {registry_global,
47 registry_global_remove};
50 registry::registry(wl_display *d) : wayland_proxy(wl_display_get_registry(d)) {
51 wl_registry_add_listener(this->proxy, ®istry_listener, this);
54 registry::~registry() {
55 wl_registry_destroy(this->proxy);
56 this->proxy = nullptr;
59 void registry::add_global_handler(char const *iface, binder bind) {
60 this->bindings[iface] = bind;
63 void registry::global(uint32_t name, char const *iface, uint32_t v) {
64 auto b = this->bindings.find(iface);
65 if (b != this->bindings.end())
66 b->second(this->proxy, name, v);
68 logdebug("wl::registry @ %p global n %u i %s v %u", this->proxy, name,
72 void registry::global_remove(uint32_t name) {}
75 // ___ _ _| |_ _ __ _ _| |_
76 // / _ \| | | | __| '_ \| | | | __|
77 // | (_) | |_| | |_| |_) | |_| | |_
78 // \___/ \__,_|\__| .__/ \__,_|\__|
81 void output_geometry(void *data, struct wl_output *wl_output, int32_t x,
82 int32_t y, int32_t physical_width, int32_t physical_height,
83 int32_t subpixel, const char *make, const char *model,
85 static_cast<output *>(data)->geometry(x, y, physical_width, physical_height,
86 subpixel, make, model, transform);
89 void output_mode(void *data, struct wl_output *wl_output, uint32_t flags,
90 int32_t width, int32_t height, int32_t refresh) {
91 static_cast<output *>(data)->mode(flags, width, height, refresh);
94 void output_done(void *data, struct wl_output *wl_output) {
95 static_cast<output *>(data)->done();
98 void output_scale(void *data, struct wl_output *wl_output, int32_t factor) {
99 static_cast<output *>(data)->scale(factor);
102 constexpr wl_output_listener output_listener = {output_geometry, output_mode,
103 output_done, output_scale};
106 output::output(wl_registry *r, uint32_t name, uint32_t v)
107 : wayland_proxy(wl_registry_bind(r, name, &wl_output_interface, v)) {
108 wl_output_add_listener(this->proxy, &output_listener, this);
111 void output::geometry(int32_t x, int32_t y, int32_t pw, int32_t ph,
112 int32_t subpel, char const *make, char const *model,
115 "wl::output %s @ %p x %i y %i w %i h %i spel %x make %s model %s tx %i",
116 __func__, this->proxy, x, y, pw, ph, subpel, make, model, tx);
119 void output::mode(uint32_t flags, int32_t w, int32_t h, int32_t r) {
120 logdebug("wl::output %s @ %p f %x w %i h %i r %i", __func__, this->proxy,
124 void output::done() {
125 logdebug("wl::output %s @ %p done", __func__, this->proxy);
128 void output::scale(int32_t factor) {
129 logdebug("wl::output %s @ %p f %i", __func__, this->proxy, factor);
133 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
134 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
135 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
136 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
139 // __ _ ___ _ __ (_)_ _(_)
140 // / _` |/ _ \ '_ \| \ \ / / |
141 // | (_| | __/ | | | |\ V /| |
142 // \__, |\___|_| |_|_| \_/ |_|
147 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
148 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
149 // | (_| (_) | | | | |_| | | (_) | | | __/ |
150 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
153 void controller_screen(void *data, struct ivi_controller *ivi_controller,
155 struct ivi_controller_screen *screen) {
156 static_cast<controller *>(data)->screen(id_screen, screen);
159 void controller_layer(void *data, struct ivi_controller *ivi_controller,
161 static_cast<controller *>(data)->layer(id_layer);
164 void controller_surface(void *data, struct ivi_controller *ivi_controller,
165 uint32_t id_surface) {
166 static_cast<controller *>(data)->surface(id_surface);
169 void controller_error(void *data, struct ivi_controller *ivi_controller,
170 int32_t object_id, int32_t object_type,
171 int32_t error_code, const char *error_text) {
172 static_cast<controller *>(data)->error(object_id, object_type, error_code,
176 constexpr ivi_controller_listener listener = {
177 controller_screen, controller_layer, controller_surface, controller_error};
180 controller::controller(wl_registry *r, uint32_t name, uint32_t version)
182 wl_registry_bind(r, name, &ivi_controller_interface, version)) {
183 ivi_controller_add_listener(this->proxy, &listener, this);
186 controller::~controller() {}
188 void controller::screen(uint32_t id, struct ivi_controller_screen *screen) {
189 logdebug("genivi::controller @ %p screen %u (%x) @ %p", this->proxy, id, id,
191 this->screens[id] = std::make_unique<struct screen>(id, screen);
194 void controller::layer(uint32_t id) {
195 logdebug("genivi::controller @ %p layer %u (%x)", this->proxy, id, id);
196 this->layers[id] = std::make_unique<struct layer>(id, this->proxy);
199 void controller::surface(uint32_t id) {
200 logdebug("genivi::controller @ %p surface %u (%x)", this->proxy, id, id);
201 this->surfaces[id] = std::make_unique<struct surface>(id, this->proxy);
204 void controller::error(int32_t object_id, int32_t object_type,
205 int32_t error_code, const char *error_text) {
206 logdebug("genivi::controller @ %p error o %i t %i c %i text %s", this->proxy,
207 object_id, object_type, error_code, error_text);
211 // | | __ _ _ _ ___ _ __
212 // | |/ _` | | | |/ _ \ '__|
213 // | | (_| | |_| | __/ |
214 // |_|\__,_|\__, |\___|_|
217 void layer_visibility(void *data,
218 struct ivi_controller_layer *ivi_controller_layer,
219 int32_t visibility) {
220 static_cast<layer *>(data)->visibility(visibility);
223 void layer_opacity(void *data,
224 struct ivi_controller_layer *ivi_controller_layer,
225 wl_fixed_t opacity) {
226 static_cast<layer *>(data)->opacity(opacity);
229 void layer_source_rectangle(void *data,
230 struct ivi_controller_layer *ivi_controller_layer,
231 int32_t x, int32_t y, int32_t width,
233 static_cast<layer *>(data)->source_rectangle(x, y, width, height);
236 void layer_destination_rectangle(
237 void *data, struct ivi_controller_layer *ivi_controller_layer, int32_t x,
238 int32_t y, int32_t width, int32_t height) {
239 static_cast<layer *>(data)->destination_rectangle(x, y, width, height);
242 void layer_configuration(void *data,
243 struct ivi_controller_layer *ivi_controller_layer,
244 int32_t width, int32_t height) {
245 static_cast<layer *>(data)->configuration(width, height);
248 void layer_orientation(void *data,
249 struct ivi_controller_layer *ivi_controller_layer,
250 int32_t orientation) {
251 static_cast<layer *>(data)->orientation(orientation);
254 void layer_screen(void *data, struct ivi_controller_layer *ivi_controller_layer,
255 struct wl_output *screen) {
256 static_cast<layer *>(data)->screen(screen);
259 void layer_destroyed(void *data,
260 struct ivi_controller_layer *ivi_controller_layer) {
261 static_cast<layer *>(data)->destroyed();
264 constexpr ivi_controller_layer_listener layer_listener = {
265 layer_visibility, layer_opacity,
266 layer_source_rectangle, layer_destination_rectangle,
267 layer_configuration, layer_orientation,
268 layer_screen, layer_destroyed,
272 layer::layer(uint32_t i, ivi_controller *c)
273 : wayland_proxy(ivi_controller_layer_create(c, i, 0, 0)), id(i) {
274 ivi_controller_layer_add_listener(this->proxy, &layer_listener, this);
278 logdebug("%s layer %i @ %p", __func__, this->id, this->proxy);
279 ivi_controller_layer_destroy(this->proxy, 1);
280 this->proxy = nullptr;
283 void layer::visibility(int32_t visibility) {
284 logdebug("genivi::layer %s @ %p v %i", __func__, this->proxy, visibility);
287 void layer::opacity(wl_fixed_t opacity) {
288 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, opacity);
291 void layer::source_rectangle(int32_t x, int32_t y, int32_t width,
293 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
294 x, y, width, height);
297 void layer::destination_rectangle(int32_t x, int32_t y, int32_t width,
299 logdebug("genivi::layer %s @ %p x %i y %i w %i h %i", __func__, this->proxy,
300 x, y, width, height);
303 void layer::configuration(int32_t width, int32_t height) {
304 logdebug("genivi::layer %s @ %p w %i h %i", __func__, this->proxy, width,
308 void layer::orientation(int32_t orientation) {
309 logdebug("genivi::layer %s @ %p o %i", __func__, this->proxy, orientation);
312 void layer::screen(struct wl_output *screen) {
313 logdebug("genivi::layer %s @ %p s %p", __func__, this->proxy, screen);
316 void layer::destroyed() {
317 logdebug("genivi::layer %s @ %p", __func__, this->proxy);
321 // ___ _ _ _ __ / _| __ _ ___ ___
322 // / __| | | | '__| |_ / _` |/ __/ _ \
323 // \__ \ |_| | | | _| (_| | (_| __/
324 // |___/\__,_|_| |_| \__,_|\___\___|
328 void surface_visibility(void *data,
329 struct ivi_controller_surface *ivi_controller_surface,
330 int32_t visibility) {
331 static_cast<surface *>(data)->visibility(visibility);
334 void surface_opacity(void *data,
335 struct ivi_controller_surface *ivi_controller_surface,
336 wl_fixed_t opacity) {
337 static_cast<surface *>(data)->opacity(opacity);
340 void surface_source_rectangle(
341 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
342 int32_t y, int32_t width, int32_t height) {
343 static_cast<surface *>(data)->source_rectangle(x, y, width, height);
346 void surface_destination_rectangle(
347 void *data, struct ivi_controller_surface *ivi_controller_surface, int32_t x,
348 int32_t y, int32_t width, int32_t height) {
349 static_cast<surface *>(data)->destination_rectangle(x, y, width, height);
352 void surface_configuration(
353 void *data, struct ivi_controller_surface *ivi_controller_surface,
354 int32_t width, int32_t height) {
355 static_cast<surface *>(data)->configuration(width, height);
358 void surface_orientation(void *data,
359 struct ivi_controller_surface *ivi_controller_surface,
360 int32_t orientation) {
361 static_cast<surface *>(data)->orientation(orientation);
364 void surface_pixelformat(void *data,
365 struct ivi_controller_surface *ivi_controller_surface,
366 int32_t pixelformat) {
367 static_cast<surface *>(data)->pixelformat(pixelformat);
370 void surface_layer(void *data,
371 struct ivi_controller_surface *ivi_controller_surface,
372 struct ivi_controller_layer *layer) {
373 static_cast<surface *>(data)->layer(layer);
376 void surface_stats(void *data,
377 struct ivi_controller_surface *ivi_controller_surface,
378 uint32_t redraw_count, uint32_t frame_count,
379 uint32_t update_count, uint32_t pid,
380 const char *process_name) {
381 static_cast<surface *>(data)->stats(redraw_count, frame_count, update_count,
385 void surface_destroyed(void *data,
386 struct ivi_controller_surface *ivi_controller_surface) {
387 static_cast<surface *>(data)->destroyed();
390 void surface_content(void *data,
391 struct ivi_controller_surface *ivi_controller_surface,
392 int32_t content_state) {
393 static_cast<surface *>(data)->content(content_state);
396 static constexpr ivi_controller_surface_listener surface_listener = {
399 surface_source_rectangle,
400 surface_destination_rectangle,
401 surface_configuration,
411 surface::surface(uint32_t i, ivi_controller *c)
412 : wayland_proxy(ivi_controller_surface_create(c, i)), id(i) {
413 ivi_controller_surface_add_listener(this->proxy, &surface_listener, this);
416 surface::~surface() {
417 logdebug("%s surface %i @ %p", __func__, this->id, this->proxy);
418 ivi_controller_surface_destroy(this->proxy, 1);
419 this->proxy = nullptr;
422 void surface::visibility(int32_t visibility) {
423 logdebug("genivi::surface %s @ %p v %i", __func__, this->proxy, visibility);
426 void surface::opacity(wl_fixed_t opacity) {
427 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, opacity);
430 void surface::source_rectangle(int32_t x, int32_t y, int32_t width,
432 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
433 this->proxy, x, y, width, height);
436 void surface::destination_rectangle(int32_t x, int32_t y, int32_t width,
438 logdebug("genivi::surface %s @ %p x %i y %i w %i h %i", __func__,
439 this->proxy, x, y, width, height);
442 void surface::configuration(int32_t width, int32_t height) {
443 logdebug("genivi::surface %s @ %p w %i h %i", __func__, this->proxy, width,
447 void surface::orientation(int32_t orientation) {
448 logdebug("genivi::surface %s @ %p o %i", __func__, this->proxy, orientation);
451 void surface::pixelformat(int32_t pixelformat) {
452 logdebug("genivi::surface %s @ %p f %i", __func__, this->proxy, pixelformat);
455 void surface::layer(struct ivi_controller_layer *layer) {
456 logdebug("genivi::surface %s @ %p l @ %p", __func__, this->proxy, layer);
459 void surface::stats(uint32_t redraw_count, uint32_t frame_count,
460 uint32_t update_count, uint32_t pid,
461 const char *process_name) {
462 logdebug("genivi::surface %s @ %p r %u f %u u %u pid %u p %s", __func__,
463 this->proxy, redraw_count, frame_count, update_count, pid,
467 void surface::destroyed() {
468 logdebug("genivi::surface %s @ %p", __func__, this->proxy);
471 void surface::content(int32_t content_state) {
472 logdebug("genivi::surface %s @ %p s %i", __func__, this->proxy,
477 // ___ ___ _ __ ___ ___ _ __
478 /// __|/ __| '__/ _ \/ _ \ '_ \
479 //\__ \ (__| | | __/ __/ | | |
480 //|___/\___|_| \___|\___|_| |_|
482 screen::screen(uint32_t i, ivi_controller_screen *p)
483 : wayland_proxy(p), id(i) {}