Added initial support for displaying on Wayland compositors.
[vuplus_xbmc] / xbmc / windowing / DllWaylandClient.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://www.xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS)
24   #include "config.h"
25 #endif
26
27 #include <cstdarg>
28
29 #include "utils/log.h"
30 #include "DynamicDll.h"
31
32 struct wl_proxy;
33 struct wl_interface;
34
35 struct wl_display;
36 struct wl_registry;
37 struct wl_callback;
38 struct wl_compositor;
39 struct wl_shell;
40 struct wl_shell_surface;
41 struct wl_surface;
42 struct wl_seat;
43 struct wl_pointer;
44 struct wl_keyboard;
45 struct wl_output;
46 struct wl_region;
47
48 extern const struct wl_interface wl_display_interface;
49 extern const struct wl_interface wl_registry_interface;
50 extern const struct wl_interface wl_callback_interface;
51 extern const struct wl_interface wl_compositor_interface;
52 extern const struct wl_interface wl_shell_interface;
53 extern const struct wl_interface wl_shell_surface_interface;
54 extern const struct wl_interface wl_surface_interface;
55 extern const struct wl_interface wl_seat_interface;
56 extern const struct wl_interface wl_pointer_interface;
57 extern const struct wl_interface wl_keyboard_interface;
58 extern const struct wl_interface wl_output_interface;
59 extern const struct wl_interface wl_region_interface;
60
61 class IDllWaylandClient
62 {
63 public:
64   typedef void(*wl_proxy_marshal_func)(struct wl_proxy *,
65                                        uint32_t,
66                                        ...);
67   typedef void(*wl_proxy_listener_func)(void);
68
69   virtual struct wl_interface ** Get_wl_display_interface() = 0;
70   virtual struct wl_interface ** Get_wl_registry_interface() = 0;
71   virtual struct wl_interface ** Get_wl_callback_interface() = 0;
72   virtual struct wl_interface ** Get_wl_compositor_interface() = 0;
73   virtual struct wl_interface ** Get_wl_shell_interface() = 0;
74   virtual struct wl_interface ** Get_wl_shell_surface_interface() = 0;
75   virtual struct wl_interface ** Get_wl_surface_interface() = 0;
76   virtual struct wl_interface ** Get_wl_seat_interface() = 0;
77   virtual struct wl_interface ** Get_wl_pointer_interface() = 0;
78   virtual struct wl_interface ** Get_wl_keyboard_interface() = 0;
79   virtual struct wl_interface ** Get_wl_output_interface() = 0;
80   virtual struct wl_interface ** Get_wl_region_interface() = 0;
81
82   virtual struct wl_display * wl_display_connect(const char *) = 0;
83   virtual void wl_display_disconnect(struct wl_display *) = 0;
84   virtual int wl_display_get_fd(struct wl_display *) = 0;
85   virtual int wl_display_dispatch(struct wl_display *) = 0;
86   virtual int wl_display_dispatch_pending(struct wl_display *) = 0;
87   virtual int wl_display_flush(struct wl_display *) = 0;
88   
89   virtual wl_proxy_marshal_func wl_proxy_marshaller() = 0;
90
91   virtual struct wl_proxy * wl_proxy_create(struct wl_proxy *,
92                                             const struct wl_interface *) = 0;
93   virtual void wl_proxy_destroy(struct wl_proxy *) = 0;
94   virtual int wl_proxy_add_listener(struct wl_proxy *,
95                                     wl_proxy_listener_func *,
96                                     void *) = 0;
97
98   virtual ~IDllWaylandClient() {}
99 };
100
101 class DllWaylandClient : public DllDynamic, public IDllWaylandClient
102 {
103   DECLARE_DLL_WRAPPER(DllWaylandClient, DLL_PATH_WAYLAND_CLIENT)
104   
105   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_display_interface);
106   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_registry_interface);
107   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_callback_interface);
108   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_compositor_interface);
109   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_shell_interface);
110   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_shell_surface_interface);
111   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_surface_interface);
112   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_seat_interface);
113   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_pointer_interface);
114   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_keyboard_interface);
115   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_output_interface);
116   DEFINE_GLOBAL_PTR(struct wl_interface *, wl_region_interface);
117   
118   DEFINE_METHOD1(struct wl_display *, wl_display_connect, (const char *p1));
119   DEFINE_METHOD1(void, wl_display_disconnect, (struct wl_display *p1));
120   DEFINE_METHOD1(int, wl_display_get_fd, (struct wl_display *p1));
121   DEFINE_METHOD1(int, wl_display_dispatch, (struct wl_display *p1));
122   DEFINE_METHOD1(int, wl_display_dispatch_pending, (struct wl_display *p1));
123   DEFINE_METHOD1(int, wl_display_flush, (struct wl_display *p1));
124   
125   /* We need to resolve wl_proxy_marshal as a function pointer as it
126    * takes varargs */
127   DEFINE_METHOD_FP(void,
128                    wl_proxy_marshal,
129                    (struct wl_proxy *p1, uint32_t p2, ...));
130
131   DEFINE_METHOD2(struct wl_proxy *,
132                  wl_proxy_create,
133                  (struct wl_proxy *p1, const struct wl_interface *p2));
134   DEFINE_METHOD1(void, wl_proxy_destroy, (struct wl_proxy *p1));
135   DEFINE_METHOD3(int,
136                  wl_proxy_add_listener,
137                  (struct wl_proxy *p1,
138                   wl_proxy_listener_func *p2,
139                   void *p3));
140   
141   BEGIN_METHOD_RESOLVE()
142     RESOLVE_METHOD(wl_display_interface)
143     RESOLVE_METHOD(wl_registry_interface)
144     RESOLVE_METHOD(wl_callback_interface)
145     RESOLVE_METHOD(wl_compositor_interface)
146     RESOLVE_METHOD(wl_shell_interface)
147     RESOLVE_METHOD(wl_shell_surface_interface)
148     RESOLVE_METHOD(wl_surface_interface)
149     RESOLVE_METHOD(wl_seat_interface)
150     RESOLVE_METHOD(wl_pointer_interface)
151     RESOLVE_METHOD(wl_keyboard_interface)
152     RESOLVE_METHOD(wl_output_interface)
153     RESOLVE_METHOD(wl_region_interface)
154   
155     RESOLVE_METHOD(wl_display_connect)
156     RESOLVE_METHOD(wl_display_disconnect)
157     RESOLVE_METHOD(wl_display_get_fd)
158     RESOLVE_METHOD(wl_display_dispatch)
159     RESOLVE_METHOD(wl_display_dispatch_pending)
160     RESOLVE_METHOD(wl_display_flush)
161     RESOLVE_METHOD_FP(wl_proxy_marshal)
162     RESOLVE_METHOD(wl_proxy_create)
163     RESOLVE_METHOD(wl_proxy_destroy)
164     RESOLVE_METHOD(wl_proxy_add_listener)
165   END_METHOD_RESOLVE()
166   
167 public:
168
169   /* This overload returns the function pointer to wl_proxy_marshal
170    * so that clients can call it directly */
171   wl_proxy_marshal_func wl_proxy_marshaller()
172   {
173     return DllWaylandClient::wl_proxy_marshal;
174   }
175 };