1 /**************************************************************************
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
34 #include "tbm_bufmgr_int.h"
39 #include <wayland-client.h>
41 #include "wayland-util.h"
43 extern const struct wl_interface wl_buffer_interface;
45 static const struct wl_interface *types[] = {
89 static const struct wl_message wl_tbm_requests[] = {
90 { "create_buffer", "niiuiiiiiiiiiiuiuuu", types + 3 },
91 { "create_buffer_with_fd", "niiuiiiiiiiiiiuihhh", types + 22 },
92 { "get_authentication_info", "", types + 0 },
95 static const struct wl_message wl_tbm_events[] = {
96 { "authentication_info", "suh", types + 0 },
99 WL_EXPORT const struct wl_interface wl_tbm_interface = {
108 extern const struct wl_interface wl_tbm_interface;
110 #ifndef WL_TBM_ERROR_ENUM
111 #define WL_TBM_ERROR_ENUM
113 WL_TBM_ERROR_AUTHENTICATE_FAIL = 0,
114 WL_TBM_ERROR_INVALID_FORMAT = 1,
115 WL_TBM_ERROR_INVALID_NAME = 2,
117 #endif /* WL_TBM_ERROR_ENUM */
119 struct wl_tbm_listener {
121 * authentication_info - (none)
122 * @device_name: (none)
123 * @capabilities: (none)
126 void (*authentication_info)(void *data,
127 struct wl_tbm *wl_tbm,
128 const char *device_name,
129 uint32_t capabilities,
134 wl_tbm_add_listener(struct wl_tbm *wl_tbm,
135 const struct wl_tbm_listener *listener, void *data)
137 return wl_proxy_add_listener((struct wl_proxy *) wl_tbm,
138 (void (**)(void)) listener, data);
141 #define WL_TBM_CREATE_BUFFER 0
142 #define WL_TBM_CREATE_BUFFER_WITH_FD 1
143 #define WL_TBM_GET_AUTHENTICATION_INFO 2
146 wl_tbm_set_user_data(struct wl_tbm *wl_tbm, void *user_data)
148 wl_proxy_set_user_data((struct wl_proxy *) wl_tbm, user_data);
152 wl_tbm_get_user_data(struct wl_tbm *wl_tbm)
154 return wl_proxy_get_user_data((struct wl_proxy *) wl_tbm);
158 wl_tbm_destroy(struct wl_tbm *wl_tbm)
160 wl_proxy_destroy((struct wl_proxy *) wl_tbm);
164 wl_tbm_get_authentication_info(struct wl_tbm *wl_tbm)
166 wl_proxy_marshal((struct wl_proxy *) wl_tbm,
167 WL_TBM_GET_AUTHENTICATION_INFO);
172 struct wl_display* dpy;
173 struct wl_event_queue *wl_queue;
174 struct wl_tbm* wl_tbm;
176 uint32_t capabilities;
182 handle_tbm_authentication_info(void *data,
183 struct wl_tbm *wl_tbm,
184 const char *device_name,
185 uint32_t capabilities,
188 struct wl_tbm_info *info = (struct wl_tbm_info *)data;
191 info->capabilities = capabilities;
193 info->device = strndup(device_name, 256);
196 static const struct wl_tbm_listener wl_tbm_client_listener = {
197 handle_tbm_authentication_info
200 static void wl_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
202 struct wl_tbm_info *info = (struct wl_tbm_info *)data;
204 if (!strcmp(interface, "wl_tbm"))
206 info->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version);
209 printf("Failed to bind wl_tbm\n");
213 wl_tbm_add_listener(info->wl_tbm, &wl_tbm_client_listener, info);
214 wl_proxy_set_queue((struct wl_proxy *)info->wl_tbm, info->wl_queue);
218 static int tbm_util_get_drm_fd(void *dpy, int *fd)
220 struct wl_display *disp = NULL;
221 struct wl_registry *wl_registry;
222 struct wl_tbm_info info = {
231 static const struct wl_registry_listener registry_listener = {
232 wl_client_registry_handle_global,
241 disp = wl_display_connect(NULL);
243 printf("Failed to create a new display connection\n");
250 info.wl_queue = wl_display_create_queue(dpy);
251 if (!info.wl_queue) {
252 printf("Failed to create a WL Queue\n");
254 wl_display_disconnect(disp);
259 wl_registry = wl_display_get_registry(dpy);
261 printf("Failed to get registry\n");
262 wl_event_queue_destroy(info.wl_queue);
264 wl_display_disconnect(disp);
268 wl_proxy_set_queue((struct wl_proxy *)wl_registry, info.wl_queue);
269 wl_registry_add_listener(wl_registry, ®istry_listener, &info);
270 wl_display_roundtrip_queue(dpy, info.wl_queue);
272 wl_tbm_get_authentication_info(info.wl_tbm);
273 wl_display_roundtrip_queue(dpy, info.wl_queue);
277 wl_event_queue_destroy(info.wl_queue);
278 wl_registry_destroy(wl_registry);
281 wl_tbm_set_user_data (info.wl_tbm, NULL);
282 wl_tbm_destroy(info.wl_tbm);
285 wl_display_disconnect(disp);
288 return *fd >= 0 ? 0 : -1;
292 tbm_bufmgr_get_drm_fd_wayland()
296 if(tbm_util_get_drm_fd(NULL, &fd))
298 printf("Failed to get drm_fd\n");