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 **************************************************************************/
32 #define WL_HIDE_DEPRECATED
41 #include "tbm_bufmgr_int.h"
43 #include "wayland-tbm-drm-client-protocol.h"
45 struct wayland_tbm_drm_client {
46 struct wl_display *display;
47 struct wl_tbm_drm *wl_tbm_drm;
50 uint32_t capabilities;
54 handle_tbm_drm_authentication_info(void *data, struct wl_tbm_drm *wl_tbm_drm, const char *device_name, uint32_t capabilities, int32_t auth_fd)
56 struct wayland_tbm_drm_client *tbm_drm_client = (struct wayland_tbm_drm_client *)data;
58 /* client authentication infomation */
59 tbm_drm_client->auth_fd = auth_fd;
60 tbm_drm_client->capabilities = capabilities;
62 tbm_drm_client->device = strndup(device_name, 256);
65 static const struct wl_tbm_drm_listener wl_tbm_drm_client_listener = {
66 handle_tbm_drm_authentication_info
70 _wayland_tbm_drm_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
72 struct wayland_tbm_drm_client *tbm_drm_client = (struct wayland_tbm_drm_client *)data;
74 if (!strcmp(interface, "wl_tbm_drm")) {
75 tbm_drm_client->wl_tbm_drm = wl_registry_bind(registry, name, &wl_tbm_drm_interface, version);
76 TBM_RETURN_IF_FAIL(tbm_drm_client->wl_tbm_drm != NULL);
78 wl_tbm_drm_add_listener(tbm_drm_client->wl_tbm_drm, &wl_tbm_drm_client_listener, tbm_drm_client);
80 wl_tbm_drm_get_authentication_info(tbm_drm_client->wl_tbm_drm);
81 wl_display_roundtrip(tbm_drm_client->display);
85 static const struct wl_registry_listener registry_listener = {
86 _wayland_tbm_drm_client_registry_handle_global,
91 wayland_tbm_drm_client_get_auth_info(int *auth_fd, char **device, uint32_t *capabilities)
93 struct wl_display *display;
94 struct wl_registry *wl_registry;
95 struct wayland_tbm_drm_client *tbm_drm_client;
97 tbm_drm_client = calloc(1, sizeof(struct wayland_tbm_drm_client));
98 TBM_RETURN_VAL_IF_FAIL(tbm_drm_client != NULL, 0);
100 tbm_drm_client->auth_fd = -1;
102 display = wl_display_connect("tbm_drm");
104 TBM_LOG("Failed to connect display\n");
105 free(tbm_drm_client);
110 tbm_drm_client->display = display;
112 wl_registry = wl_display_get_registry(display);
114 TBM_LOG("Failed to connect display\n");
115 wl_display_disconnect(display);
116 free(tbm_drm_client);
121 wl_registry_add_listener(wl_registry, ®istry_listener, &tbm_drm_client);
122 wl_display_roundtrip(display); //For Gloabl registry
124 if (!tbm_drm_client->wl_tbm_drm) {
125 TBM_LOG("Failed to get wl_tbm_drm interface\n");
126 wl_registry_destroy(wl_registry);
127 wl_display_disconnect(display);
128 free(tbm_drm_client);
133 if (tbm_drm_client->auth_fd < 0) {
134 TBM_LOG("Failed to get auth info\n");
135 wl_tbm_drm_set_user_data(tbm_drm_client->wl_tbm_drm, NULL);
136 wl_tbm_drm_destroy(tbm_drm_client->wl_tbm_drm);
137 wl_registry_destroy(wl_registry);
138 wl_display_disconnect(display);
139 free(tbm_drm_client);
145 *auth_fd = tbm_drm_client->auth_fd;
150 *capabilities = tbm_drm_client->capabilities;
152 if (tbm_drm_client->device && device)
153 *device = strdup(tbm_drm_client->device);
157 wl_tbm_drm_set_user_data(tbm_drm_client->wl_tbm_drm, NULL);
158 wl_tbm_drm_destroy(tbm_drm_client->wl_tbm_drm);
160 if (tbm_drm_client->device)
161 free(tbm_drm_client->device);
163 free(tbm_drm_client);
165 wl_registry_destroy(wl_registry);
166 wl_display_disconnect(display);