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 **************************************************************************/
41 #include <wayland-client.h>
43 #include "wayland-util.h"
45 extern const struct wl_interface wl_buffer_interface;
47 static const struct wl_interface *types[] = {
91 static const struct wl_message wl_tbm_requests[] = {
92 {"create_buffer", "niiuiiiiiiiiiiuiuuu", types + 3},
93 {"create_buffer_with_fd", "niiuiiiiiiiiiiuihhh", types + 22},
94 {"get_authentication_info", "", types + 0},
97 static const struct wl_message wl_tbm_events[] = {
98 {"authentication_info", "suh", types + 0},
101 WL_EXPORT const struct wl_interface wl_tbm_interface = {
110 extern const struct wl_interface wl_tbm_interface;
112 #ifndef WL_TBM_ERROR_ENUM
113 #define WL_TBM_ERROR_ENUM
115 WL_TBM_ERROR_AUTHENTICATE_FAIL = 0,
116 WL_TBM_ERROR_INVALID_FORMAT = 1,
117 WL_TBM_ERROR_INVALID_NAME = 2,
119 #endif /* WL_TBM_ERROR_ENUM */
121 struct wl_tbm_listener {
123 * authentication_info - (none)
124 * @device_name: (none)
125 * @capabilities: (none)
128 void (*authentication_info) (void *data, struct wl_tbm * wl_tbm, const char *device_name, uint32_t capabilities, int32_t auth_fd);
131 static inline int wl_tbm_add_listener(struct wl_tbm *wl_tbm, const struct wl_tbm_listener *listener, void *data)
133 return wl_proxy_add_listener((struct wl_proxy *)wl_tbm, (void (**)(void))listener, data);
136 #define WL_TBM_CREATE_BUFFER 0
137 #define WL_TBM_CREATE_BUFFER_WITH_FD 1
138 #define WL_TBM_GET_AUTHENTICATION_INFO 2
140 static inline void wl_tbm_set_user_data(struct wl_tbm *wl_tbm, void *user_data)
142 wl_proxy_set_user_data((struct wl_proxy *)wl_tbm, user_data);
145 static inline void *wl_tbm_get_user_data(struct wl_tbm *wl_tbm)
147 return wl_proxy_get_user_data((struct wl_proxy *)wl_tbm);
150 static inline void wl_tbm_destroy(struct wl_tbm *wl_tbm)
152 wl_proxy_destroy((struct wl_proxy *)wl_tbm);
155 static inline void wl_tbm_get_authentication_info(struct wl_tbm *wl_tbm)
157 wl_proxy_marshal((struct wl_proxy *)wl_tbm, WL_TBM_GET_AUTHENTICATION_INFO);
161 struct wl_display *dpy;
162 struct wl_event_queue *wl_queue;
163 struct wl_tbm *wl_tbm;
165 uint32_t capabilities;
170 static void handle_tbm_authentication_info(void *data, struct wl_tbm *wl_tbm, const char *device_name, uint32_t capabilities, int32_t auth_fd)
172 struct wl_tbm_info *info = (struct wl_tbm_info *)data;
175 info->capabilities = capabilities;
177 info->device = strndup(device_name, 256);
180 static const struct wl_tbm_listener wl_tbm_client_listener = {
181 handle_tbm_authentication_info
184 static void wl_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
186 struct wl_tbm_info *info = (struct wl_tbm_info *)data;
188 if (!strcmp(interface, "wl_tbm")) {
189 info->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version);
191 printf("Failed to bind wl_tbm\n");
195 wl_tbm_add_listener(info->wl_tbm, &wl_tbm_client_listener, info);
196 wl_proxy_set_queue((struct wl_proxy *)info->wl_tbm, info->wl_queue);
200 static int tbm_util_get_drm_fd(void *dpy, int *fd)
202 struct wl_display *disp = NULL;
203 struct wl_registry *wl_registry;
204 struct wl_tbm_info info = {
213 static const struct wl_registry_listener registry_listener = {
214 wl_client_registry_handle_global,
222 disp = wl_display_connect(NULL);
224 printf("Failed to create a new display connection\n");
231 info.wl_queue = wl_display_create_queue(dpy);
232 if (!info.wl_queue) {
233 printf("Failed to create a WL Queue\n");
235 wl_display_disconnect(disp);
240 wl_registry = wl_display_get_registry(dpy);
242 printf("Failed to get registry\n");
243 wl_event_queue_destroy(info.wl_queue);
245 wl_display_disconnect(disp);
249 wl_proxy_set_queue((struct wl_proxy *)wl_registry, info.wl_queue);
250 wl_registry_add_listener(wl_registry, ®istry_listener, &info);
251 wl_display_roundtrip_queue(dpy, info.wl_queue);
253 wl_tbm_get_authentication_info(info.wl_tbm);
254 wl_display_roundtrip_queue(dpy, info.wl_queue);
258 wl_event_queue_destroy(info.wl_queue);
259 wl_registry_destroy(wl_registry);
262 wl_tbm_set_user_data(info.wl_tbm, NULL);
263 wl_tbm_destroy(info.wl_tbm);
266 wl_display_disconnect(disp);
268 return *fd >= 0 ? 0 : -1;
271 int tbm_bufmgr_get_drm_fd_wayland()
275 if (tbm_util_get_drm_fd(NULL, &fd))
276 printf("Failed to get drm_fd\n");