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"
36 #include <wayland-client.h>
37 #include <wayland-drm-client-protocol.h>
40 struct wl_display *display;
41 struct wl_registry *registry;
43 struct wl_drm *wl_drm;
45 char* drm_device_name;
48 /* initialize drm device */
50 _drm_handle_device( void *data, struct wl_drm *drm, const char *device )
52 struct display *d = data;
54 d->drm_device_name = strdup(device);
58 /* handle format of drm device */
60 _drm_handle_format( void *data, struct wl_drm *drm, uint32_t format )
65 /* handle authentication of drm device */
67 _drm_handle_authenticated( void *data, struct wl_drm *drm )
69 struct display *d = data;
71 printf("DRM authenticated: name:%s fd:%d\n", d->drm_device_name, d->drm_fd);
76 _drm_handle_capabilities(void *data, struct wl_drm *drm, uint32_t value)
81 static const struct wl_drm_listener drm_listener = {
84 _drm_handle_authenticated,
85 _drm_handle_capabilities
90 registry_handle_global(void *data, struct wl_registry *registry,
91 uint32_t id, const char *interface, uint32_t version)
93 struct display *d = data;
95 if (strcmp(interface, "wl_drm") == 0) {
97 wl_registry_bind(registry, id, &wl_drm_interface, version);
98 wl_drm_add_listener(d->wl_drm, &drm_listener, d);
103 registry_handle_global_remove(void *data, struct wl_registry *registry,
108 static const struct wl_registry_listener registry_listener = {
109 registry_handle_global,
110 registry_handle_global_remove
113 static struct display *
116 struct display *display;
119 display = calloc(sizeof(struct display), 1);
120 if (display == NULL) {
121 TBM_LOG ("[libtbm:%d] out of memory\n", getpid());
124 display->display = wl_display_connect(NULL);
125 if (display->display == NULL) {
126 TBM_LOG ("[libtbm:%d] fail to wl display\n", getpid());
130 display->registry = wl_display_get_registry(display->display);
131 wl_registry_add_listener(display->registry,
132 ®istry_listener, display);
133 wl_display_roundtrip(display->display);
135 if (display->wl_drm == NULL) {
136 TBM_LOG ("[libtbm:%d] No wl_drm global\n", getpid());
139 wl_display_roundtrip(display->display);
141 if (!display->drm_device_name) {
142 TBM_LOG ("[libtbm:%d] No drm device name\n", getpid());
146 display->drm_fd = open( display->drm_device_name, O_RDWR | O_CLOEXEC );
147 if (display->drm_fd < 0) {
148 TBM_LOG ("[libtbm:%d] Cannot open drm device\n", getpid());
152 drmGetMagic(display->drm_fd, &magic);
153 wl_drm_authenticate(display->wl_drm, magic);
154 wl_display_roundtrip(display->display);
160 destroy_display(struct display *display)
163 wl_drm_destroy(display->wl_drm);
164 wl_registry_destroy(display->registry);
165 wl_display_flush(display->display);
166 wl_display_disconnect(display->display);
167 if (display->drm_device_name)
168 free (display->drm_device_name);
173 tbm_bufmgr_get_drm_fd_wayland()
175 struct display *display = NULL;
178 display = create_display();
179 if (display == NULL) {
180 TBM_LOG ("[libtbm:%d] fail to create display\n", getpid());
184 drm_fd = display->drm_fd;
185 destroy_display(display);