4 #include "ivi-controller-client-protocol.h"
10 #include <unordered_map>
14 // __ ____ _ _ _| | __ _ _ __ __| | _ __ _ __ _____ ___ _
15 // \ \ /\ / / _` | | | | |/ _` | '_ \ / _` | | '_ \| '__/ _ \ \/ / | | |
16 // \ V V / (_| | |_| | | (_| | | | | (_| | | |_) | | | (_) > <| |_| |
17 // \_/\_/ \__,_|\__, |_|\__,_|_| |_|\__,_|____| .__/|_| \___/_/\_\\__, |
18 // |___/ |_____|_| |___/
19 template <typename ProxyT>
20 struct wayland_proxy {
21 std::unique_ptr<ProxyT, std::function<void(ProxyT *)>> proxy;
22 wayland_proxy(wayland_proxy const &) = delete;
23 wayland_proxy &operator=(wayland_proxy const &) = delete;
24 wayland_proxy(void *p)
26 reinterpret_cast<void (*)(ProxyT *)>(wl_proxy_destroy)) {}
27 wayland_proxy(void *p, std::function<void(ProxyT *)> &&p_del)
28 : proxy(std::unique_ptr<ProxyT, std::function<void(ProxyT *)>>(
29 static_cast<ProxyT *>(p), p_del)) {}
33 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___ __ _| |
34 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \ \ \ /\ / / |
35 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/ \ V V /| |
36 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___| \_/\_/ |_|
40 // _ __ ___ __ _(_)___| |_ _ __ _ _
41 // | '__/ _ \/ _` | / __| __| '__| | | |
42 // | | | __/ (_| | \__ \ |_| | | |_| |
43 // |_| \___|\__, |_|___/\__|_| \__, |
45 struct registry : public wayland_proxy<struct wl_registry> {
46 typedef std::function<void(struct wl_registry *, uint32_t, uint32_t)> binder;
47 std::unordered_map<std::string, binder> bindings;
49 registry(registry const &) = delete;
50 registry &operator=(registry const &) = delete;
51 registry(struct wl_display *d);
53 void add_global_handler(char const *iface, binder bind);
56 void global(uint32_t name, char const *iface, uint32_t v);
57 void global_remove(uint32_t name);
61 // __| (_)___ _ __ | | __ _ _ _
62 // / _` | / __| '_ \| |/ _` | | | |
63 // | (_| | \__ \ |_) | | (_| | |_| |
64 // \__,_|_|___/ .__/|_|\__,_|\__, |
67 std::unique_ptr<struct wl_display, void (*)(struct wl_display *)> d;
70 display(display const &) = delete;
71 display &operator=(display const &) = delete;
82 // ___ _ _| |_ _ __ _ _| |_
83 // / _ \| | | | __| '_ \| | | | __|
84 // | (_) | |_| | |_| |_) | |_| | |_
85 // \___/ \__,_|\__| .__/ \__,_|\__|
87 struct output : wayland_proxy<struct wl_output> {
92 output(output const &) = delete;
93 output &operator=(output const &) = delete;
94 output(struct wl_registry *r, uint32_t name, uint32_t v);
97 void geometry(int32_t x, int32_t y, int32_t pw, int32_t ph, int32_t subpel,
98 char const *make, char const *model, int32_t tx);
99 void mode(uint32_t flags, int32_t w, int32_t h, int32_t r);
101 void scale(int32_t factor);
105 // _ __ __ _ _ __ ___ ___ ___ _ __ __ _ ___ ___
106 // | '_ \ / _` | '_ ` _ \ / _ \/ __| '_ \ / _` |/ __/ _ \
107 // | | | | (_| | | | | | | __/\__ \ |_) | (_| | (_| __/
108 // |_| |_|\__,_|_| |_| |_|\___||___/ .__/ \__,_|\___\___|
111 // __ _ ___ _ __ (_)_ _(_)
112 // / _` |/ _ \ '_ \| \ \ / / |
113 // | (_| | __/ | | | |\ V /| |
114 // \__, |\___|_| |_|_| \_/ |_|
129 struct controller_child {
130 struct controller *parent;
133 controller_child(controller_child const &) = delete;
134 controller_child &operator=(controller_child const &) = delete;
135 controller_child(struct controller *c, uint32_t i) : parent(c), id(i) {}
136 virtual ~controller_child() {}
139 struct surface_properties {
140 uint32_t id; // let's just save an ID here too
141 struct rect dst_rect;
142 struct rect src_rect;
150 // ___ _ _ _ __ / _| __ _ ___ ___
151 // / __| | | | '__| |_ / _` |/ __/ _ \
152 // \__ \ |_| | | | _| (_| | (_| __/
153 // |___/\__,_|_| |_| \__,_|\___\___|
155 struct surface : public wayland_proxy<struct ivi_controller_surface>,
157 surface(surface const &) = delete;
158 surface &operator=(surface const &) = delete;
159 surface(uint32_t i, struct controller *c);
162 void set_visibility(uint32_t visibility);
163 void set_opacity(wl_fixed_t opacity);
164 void set_source_rectangle(int32_t x, int32_t y, int32_t width,
166 void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
168 void set_configuration(int32_t width, int32_t height);
169 void set_orientation(int32_t orientation);
170 void screenshot(const char *filename);
172 void destroy(int32_t destroy_scene_object);
176 // | | __ _ _ _ ___ _ __
177 // | |/ _` | | | |/ _ \ '__|
178 // | | (_| | |_| | __/ |
179 // |_|\__,_|\__, |\___|_|
181 struct layer : public wayland_proxy<struct ivi_controller_layer>,
183 layer(layer const &) = delete;
184 layer &operator=(layer const &) = delete;
185 layer(uint32_t i, struct controller *c);
186 layer(uint32_t i, int32_t w, int32_t h, struct controller *c);
189 void set_visibility(uint32_t visibility);
190 void set_opacity(wl_fixed_t opacity);
191 void set_source_rectangle(int32_t x, int32_t y, int32_t width,
193 void set_destination_rectangle(int32_t x, int32_t y, int32_t width,
195 void set_configuration(int32_t width, int32_t height);
196 void set_orientation(int32_t orientation);
197 void screenshot(const char *filename);
198 void clear_surfaces();
199 void add_surface(struct surface *surface);
200 void remove_surface(struct surface *surface);
201 void set_render_order(std::vector<uint32_t> const &ro);
205 // ___ ___ _ __ ___ ___ _ __
206 // / __|/ __| '__/ _ \/ _ \ '_ \
207 // \__ \ (__| | | __/ __/ | | |
208 // |___/\___|_| \___|\___|_| |_|
210 struct screen : public wayland_proxy<struct ivi_controller_screen>,
212 screen(screen const &) = delete;
213 screen &operator=(screen const &) = delete;
214 screen(uint32_t i, struct controller *c, struct ivi_controller_screen *p);
216 void add_layer(layer *l);
217 void set_render_order(std::vector<uint32_t> const &ro);
221 // ___ ___ _ __ | |_ _ __ ___ | | | ___ _ __
222 // / __/ _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|
223 // | (_| (_) | | | | |_| | | (_) | | | __/ |
224 // \___\___/|_| |_|\__|_| \___/|_|_|\___|_|
226 struct controller : public wayland_proxy<struct ivi_controller> {
227 typedef std::unordered_map<uintptr_t, uint32_t> proxy_to_id_map_type;
228 typedef std::unordered_map<uint32_t, std::unique_ptr<struct surface>>
230 typedef std::unordered_map<uint32_t, std::unique_ptr<struct layer>>
232 typedef std::unordered_map<uint32_t, std::unique_ptr<struct screen>>
235 typedef std::unordered_map<uint32_t, struct surface_properties> props_map;
238 // The order of these member is mandatory, as when objects are destroyed
239 // they will call their parent (that's us right here!) and remove their
240 // proxy-to-id mapping. I.e. the *_proxy_to_id members need to be valid
241 // when the surfaces/layers/screens maps are destroyed. This sucks, but
242 // I cannot see a better solution w/o globals or some other horrible
243 // call-our-parent construct.
244 proxy_to_id_map_type surface_proxy_to_id;
245 proxy_to_id_map_type layer_proxy_to_id;
246 proxy_to_id_map_type screen_proxy_to_id;
248 surface_map_type surfaces;
249 layer_map_type layers;
250 screen_map_type screens;
255 typedef std::pair<char const *, std::function<void(struct controller *)>>
257 std::vector<name_task_pair> pending;
261 void add_proxy_to_id_mapping(struct ivi_controller_surface *p, uint32_t id);
262 void remove_proxy_to_id_mapping(struct ivi_controller_surface *p);
263 void add_proxy_to_id_mapping(struct ivi_controller_layer *p, uint32_t id);
264 void remove_proxy_to_id_mapping(struct ivi_controller_layer *p);
265 void add_proxy_to_id_mapping(struct wl_output *p, uint32_t id);
266 void remove_proxy_to_id_mapping(struct wl_output *p);
268 void add_task(char const *name,
269 std::function<void(struct controller *)> &&f);
270 void execute_pending();
272 controller(struct wl_registry *r, uint32_t name, uint32_t version);
275 void commit_changes() const {
276 ivi_controller_commit_changes(this->proxy.get());
278 void layer_create(uint32_t id, int32_t w, int32_t h);
279 void surface_create(uint32_t id);
283 void controller_screen(uint32_t id, struct ivi_controller_screen *screen);
284 void controller_layer(uint32_t id);
285 void controller_surface(uint32_t id);
286 void controller_error(int32_t object_id, int32_t object_type,
287 int32_t error_code, char const *error_text);
290 void surface_visibility(struct surface *s, int32_t visibility);
291 void surface_opacity(struct surface *s, float opacity);
292 void surface_source_rectangle(struct surface *s, int32_t x, int32_t y,
293 int32_t width, int32_t height);
294 void surface_destination_rectangle(struct surface *s, int32_t x, int32_t y,
295 int32_t width, int32_t height);
296 void surface_configuration(struct surface *s, int32_t width, int32_t height);
297 void surface_orientation(struct surface *s, int32_t orientation);
298 void surface_pixelformat(struct surface *s, int32_t pixelformat);
299 void surface_layer(struct surface *s, struct ivi_controller_layer *layer);
300 void surface_stats(struct surface *s, uint32_t redraw_count,
301 uint32_t frame_count, uint32_t update_count, uint32_t pid,
302 const char *process_name);
303 void surface_destroyed(struct surface *s);
304 void surface_content(struct surface *s, int32_t content_state);
307 void layer_visibility(struct layer *l, int32_t visibility);
308 void layer_opacity(struct layer *l, float opacity);
309 void layer_source_rectangle(struct layer *l, int32_t x, int32_t y,
310 int32_t width, int32_t height);
311 void layer_destination_rectangle(struct layer *l, int32_t x, int32_t y,
312 int32_t width, int32_t height);
313 void layer_configuration(struct layer *l, int32_t width, int32_t height);
314 void layer_orientation(struct layer *l, int32_t orientation);
315 void layer_screen(struct layer *l, struct wl_output *screen);
316 void layer_destroyed(struct layer *l);
318 } // namespace genivi
320 #endif // !WM_WAYLAND_HPP