Add tbm drm helper 26/60726/1
authorChangyeon Lee <cyeon.lee@samsung.com>
Thu, 25 Feb 2016 01:51:09 +0000 (10:51 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Fri, 26 Feb 2016 13:05:26 +0000 (22:05 +0900)
Change-Id: I4dc7aafc1dbda489b34aebe1d57d6e2d98152eb0

configure.ac
packaging/libtbm.spec
protocol/wayland-tbm-drm.xml [new file with mode: 0644]
src/Makefile.am
src/tbm_drm_helper.h [new file with mode: 0644]
src/tbm_drm_helper_client.c [new file with mode: 0644]
src/tbm_drm_helper_server.c [new file with mode: 0644]

index 0144728..43dc446 100644 (file)
@@ -58,6 +58,10 @@ AC_CHECK_FUNCS([clock_gettime], [CLOCK_LIB=],
                              [AC_MSG_ERROR([Couldn't find clock_gettime])])])
 AC_SUBST([CLOCK_LIB])
 
+AC_PATH_PROG([wayland_scanner], [wayland-scanner])
+if test x$wayland_scanner = x; then
+      AC_MSG_ERROR([wayland-scanner is needed to compile wayland-tbm])
+fi
 
 PKG_CHECK_MODULES(CAPI, [capi-base-common >= 0.1.1], [capi_0_1_1=yes], [capi_0_1_1=no])
 if test x"$capi_0_1_1" = xyes; then
@@ -66,9 +70,12 @@ fi
 
 PKG_CHECK_MODULES(LIBDRM, libdrm)
 PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs)
+PKG_CHECK_MODULES(WL_CLIENT, wayland-client)
+PKG_CHECK_MODULES(WL_SERVER, wayland-server)
+PKG_CHECK_MODULES(WL_SCANNER, wayland-scanner)
 
-LIBTBM_CFLAGS+="$LIBTBM_CFALGS $LIBDRM_CFLAGS $PTHREADSTUBS_CFLAGS $CAPI_CFLAGS"
-LIBTBM_LIBS+="$LIBTBM_LIBS $LIBDRM_LIBS $PTHREADSTUBS_LIBS $CAPI_LIBS"
+LIBTBM_CFLAGS+="$LIBTBM_CFALGS $LIBDRM_CFLAGS $PTHREADSTUBS_CFLAGS $CAPI_CFLAGS $WL_CLIENT_CFLAGS $WL_SERVER_CFLAGS"
+LIBTBM_LIBS+="$LIBTBM_LIBS $LIBDRM_LIBS $PTHREADSTUBS_LIBS $CAPI_LIBS $WL_CLIENT_LIBS $WL_SERVER_LIBS"
 AC_SUBST(LIBTBM_CFLAGS)
 AC_SUBST(LIBTBM_LIBS)
 
index 3011d20..35b62c8 100644 (file)
@@ -11,6 +11,8 @@ Source0:        %{name}-%{version}.tar.gz
 Source1001:            %name.manifest
 
 BuildRequires:  pkgconfig(libdrm)
+BuildRequires:  pkgconfig(wayland-server)
+BuildRequires:  pkgconfig(wayland-client)
 BuildRequires:  pkgconfig(pthread-stubs)
 BuildRequires:  pkgconfig(capi-base-common)
 
@@ -74,5 +76,6 @@ rm -rf %{buildroot}
 %{_includedir}/tbm_surface_queue.h
 %{_includedir}/tbm_bufmgr_backend.h
 %{_includedir}/tbm_type.h
+%{_includedir}/tbm_drm_helper.h
 %{_libdir}/libtbm.so
 %{_libdir}/pkgconfig/libtbm.pc
diff --git a/protocol/wayland-tbm-drm.xml b/protocol/wayland-tbm-drm.xml
new file mode 100644 (file)
index 0000000..a097a15
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="tbm_drm">
+
+  <copyright>
+    Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+    Permission to use, copy, modify, distribute, and sell this
+    software and its documentation for any purpose is hereby granted
+    without fee, provided that\n the above copyright notice appear in
+    all copies and that both that copyright notice and this permission
+    notice appear in supporting documentation, and that the name of
+    the copyright holders not be used in advertising or publicity
+    pertaining to distribution of the software without specific,
+    written prior permission.  The copyright holders make no
+    representations about the suitability of this software for any
+    purpose.  It is provided "as is" without express or implied
+    warranty.
+
+    THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+    SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+    FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+    SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+    AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+    THIS SOFTWARE.
+  </copyright>
+
+  <!-- tbm support. This object is created by the server and published
+       using the display's global event. -->
+  <interface name="wl_tbm_drm" version="1">
+    <enum name="error">
+      <entry name="authenticate_fail" value="0"/>
+    </enum>
+
+    <request name="get_authentication_info">
+    </request>
+
+    <event name="authentication_info">
+       <arg name="device_name" type="string"/>
+       <arg name="capabilities" type="uint"/>
+       <arg name="auth_fd" type="fd"/>
+    </event>
+
+  </interface>
+
+</protocol>
index cbe61dc..16aef4b 100644 (file)
@@ -18,8 +18,27 @@ libtbm_la_SOURCES = \
        tbm_surface.c \
        tbm_surface_queue.c \
        tbm_bufmgr_backend.c \
-       tbm_bufmgr.c
+       tbm_bufmgr.c \
+       tbm_drm_helper_server.c \
+       tbm_drm_helper_client.c
+
+nodist_libtbm_la_SOURCES =             \
+       wayland-tbm-drm-server-protocol.h       \
+       wayland-tbm-drm-client-protocol.h       \
+       wayland-tbm-drm-protocol.c
+
+%-protocol.c : $(top_srcdir)/protocol/%.xml
+       $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(wayland_scanner) code < $< > $@
+
+%-server-protocol.h : $(top_srcdir)/protocol/%.xml
+       $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(wayland_scanner) server-header < $< > $@
+
+%-client-protocol.h : $(top_srcdir)/protocol/%.xml
+       $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(wayland_scanner) client-header < $< > $@
+
+BUILT_SOURCES = $(nodist_libtbm_la_SOURCES)
 
 libtbmincludedir=$(includedir)
-libtbminclude_HEADERS = tbm_bufmgr.h tbm_surface.h tbm_bufmgr_backend.h tbm_type.h tbm_surface_internal.h tbm_surface_queue.h
+libtbminclude_HEADERS = tbm_bufmgr.h tbm_surface.h tbm_bufmgr_backend.h tbm_type.h tbm_surface_internal.h tbm_surface_queue.h tbm_drm_helper.h
 
+CLEANFILES = $(BUILT_SOURCES)
diff --git a/src/tbm_drm_helper.h b/src/tbm_drm_helper.h
new file mode 100644 (file)
index 0000000..eebe10f
--- /dev/null
@@ -0,0 +1,42 @@
+/**************************************************************************
+
+libtbm
+
+Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
+Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef _TBM_DRM_HELPER_H_
+#define _TBM_DRM_HELPER_H_
+
+int tbm_drm_helper_wl_server_init(void  *wl_display, int fd, const char *device_name, uint32_t flags);
+void tbm_drm_helper_wl_server_deinit(void);
+int tbm_drm_helper_get_master_fd(void);
+void tbm_drm_helper_set_master_fd(int fd);
+
+int tbm_drm_helper_get_auth_info(int *auth_fd, char **device, uint32_t *capabilities);
+
+#endif                                                 /* _TBM_DRM_HELPER_H_ */
diff --git a/src/tbm_drm_helper_client.c b/src/tbm_drm_helper_client.c
new file mode 100644 (file)
index 0000000..4e2eaf1
--- /dev/null
@@ -0,0 +1,169 @@
+/**************************************************************************
+
+libtbm
+
+Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
+Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#define WL_HIDE_DEPRECATED
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "tbm_bufmgr_int.h"
+
+#include "wayland-tbm-drm-client-protocol.h"
+
+struct wayland_tbm_drm_client {
+       struct wl_display *display;
+       struct wl_tbm_drm *wl_tbm_drm;
+       int auth_fd;
+       char *device;
+       uint32_t capabilities;
+};
+
+static void
+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)
+{
+       struct wayland_tbm_drm_client *tbm_drm_client = (struct wayland_tbm_drm_client *)data;
+
+       /* client authentication infomation */
+       tbm_drm_client->auth_fd = auth_fd;
+       tbm_drm_client->capabilities = capabilities;
+       if (device_name)
+           tbm_drm_client->device = strndup(device_name, 256);
+}
+
+static const struct wl_tbm_drm_listener wl_tbm_drm_client_listener = {
+    handle_tbm_drm_authentication_info
+};
+
+static void
+_wayland_tbm_drm_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
+{
+       struct wayland_tbm_drm_client *tbm_drm_client = (struct wayland_tbm_drm_client *)data;
+
+       if (!strcmp(interface, "wl_tbm_drm")) {
+               tbm_drm_client->wl_tbm_drm = wl_registry_bind(registry, name, &wl_tbm_drm_interface, version);
+               TBM_RETURN_IF_FAIL(tbm_drm_client->wl_tbm_drm != NULL);
+
+               wl_tbm_drm_add_listener(tbm_drm_client->wl_tbm_drm, &wl_tbm_drm_client_listener, tbm_drm_client);
+
+               wl_tbm_drm_get_authentication_info(tbm_drm_client->wl_tbm_drm);
+               wl_display_roundtrip(tbm_drm_client->display);
+       }
+}
+
+static const struct wl_registry_listener registry_listener = {
+    _wayland_tbm_drm_client_registry_handle_global,
+    NULL
+};
+
+int
+wayland_tbm_drm_client_get_auth_info(int *auth_fd, char **device, uint32_t *capabilities)
+{
+       struct wl_display *display;
+       struct wl_registry *wl_registry;
+       struct wayland_tbm_drm_client *tbm_drm_client;
+
+       tbm_drm_client = calloc(1, sizeof(struct wayland_tbm_drm_client));
+       TBM_RETURN_VAL_IF_FAIL(tbm_drm_client != NULL, 0);
+
+       tbm_drm_client->auth_fd = -1;
+
+       display = wl_display_connect("tbm_drm");
+       if (!display) {
+               TBM_LOG("Failed to connect display\n");
+               free(tbm_drm_client);
+
+               return 0;
+       }
+
+       tbm_drm_client->display = display;
+
+       wl_registry = wl_display_get_registry(display);
+       if (!wl_registry) {
+               TBM_LOG("Failed to connect display\n");
+               wl_display_disconnect(display);
+               free(tbm_drm_client);
+
+               return 0;
+       }
+
+       wl_registry_add_listener(wl_registry, &registry_listener, &tbm_drm_client);
+       wl_display_roundtrip(display); //For Gloabl registry
+
+       if (!tbm_drm_client->wl_tbm_drm) {
+               TBM_LOG("Failed to get wl_tbm_drm interface\n");
+               wl_registry_destroy(wl_registry);
+               wl_display_disconnect(display);
+               free(tbm_drm_client);
+
+               return 0;
+       }
+
+       if (tbm_drm_client->auth_fd < 0) {
+               TBM_LOG("Failed to get auth info\n");
+               wl_tbm_drm_set_user_data(tbm_drm_client->wl_tbm_drm, NULL);
+               wl_tbm_drm_destroy(tbm_drm_client->wl_tbm_drm);
+               wl_registry_destroy(wl_registry);
+               wl_display_disconnect(display);
+               free(tbm_drm_client);
+
+               return 0;
+       }
+
+       if (auth_fd)
+               *auth_fd = tbm_drm_client->auth_fd;
+       else
+               close(*auth_fd);
+
+       if (capabilities)
+               *capabilities = tbm_drm_client->capabilities;
+
+       if (tbm_drm_client->device && device)
+               *device = strdup(tbm_drm_client->device);
+       else
+               *device = NULL;
+
+       wl_tbm_drm_set_user_data(tbm_drm_client->wl_tbm_drm, NULL);
+       wl_tbm_drm_destroy(tbm_drm_client->wl_tbm_drm);
+
+       if (tbm_drm_client->device)
+               free(tbm_drm_client->device);
+
+       free(tbm_drm_client);
+
+       wl_registry_destroy(wl_registry);
+       wl_display_disconnect(display);
+
+       return 1;
+}
diff --git a/src/tbm_drm_helper_server.c b/src/tbm_drm_helper_server.c
new file mode 100644 (file)
index 0000000..7dbb7a5
--- /dev/null
@@ -0,0 +1,235 @@
+/**************************************************************************
+
+libtbm
+
+Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
+Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#define WL_HIDE_DEPRECATED
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <xf86drm.h>
+
+#include "tbm_bufmgr_int.h"
+
+#include "wayland-tbm-drm-server-protocol.h"
+
+struct wayland_tbm_drm_server {
+       struct wl_display *display;
+       struct wl_global *wl_tbm_drm_global;
+
+       char *device_name;
+       uint32_t fd;
+       uint32_t flags;
+};
+
+#define MIN(x,y) (((x)<(y))?(x):(y))
+
+struct wayland_tbm_drm_server *tbm_drm_srv;
+
+static void
+_send_server_auth_info(struct wayland_tbm_drm_server *tbm_drm_srv,
+                      struct wl_resource *resource)
+{
+       int fd = -1;
+       uint32_t capabilities;
+       char *device_name = NULL;
+       drm_magic_t magic = 0;
+
+       fd = open(tbm_drm_srv->device_name, O_RDWR | O_CLOEXEC);
+       if (fd == -1 && errno == EINVAL) {
+               fd = open(tbm_drm_srv->device_name, O_RDWR);
+               if (fd != -1)
+                       fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+       }
+
+       if (fd < 0) {
+               TBM_LOG("failed to open drm : device_name, %s\n", tbm_drm_srv->device_name);
+
+               wl_resource_post_error(resource, WL_TBM_DRM_ERROR_AUTHENTICATE_FAIL,
+                                      "authenicate failed::open_drm");
+               goto fini;
+       }
+
+       if (drmGetMagic(fd, &magic) < 0) {
+               if (errno != EACCES) {
+                       TBM_LOG("failed to get magic\n");
+
+                       wl_resource_post_error(resource, WL_TBM_DRM_ERROR_AUTHENTICATE_FAIL,
+                                              "authenicate failed::get_magic");
+                       goto fini;
+               }
+       }
+
+       if (drmAuthMagic(tbm_drm_srv->fd, magic) < 0) {
+               TBM_LOG("failed to authenticate magic\n");
+
+               wl_resource_post_error(resource, WL_TBM_DRM_ERROR_AUTHENTICATE_FAIL,
+                                      "authenicate failed::auth_magic");
+               goto fini;
+       }
+
+       capabilities = tbm_drm_srv->flags;
+       device_name = tbm_drm_srv->device_name;
+
+       /* send */
+       wl_tbm_drm_send_authentication_info(resource, device_name, capabilities, fd);
+
+fini:
+       if (fd >= 0)
+               close(fd);
+
+       if (device_name && device_name != tbm_drm_srv->device_name)
+               free(device_name);
+
+}
+
+static void
+_wayland_tbm_drm_server_impl_get_authentication_info(struct wl_client *client,
+               struct wl_resource *resource)
+{
+       struct wayland_tbm_drm_server *tbm_drm_srv = wl_resource_get_user_data(resource);
+
+       /* if display server is the client of the host display server, for embedded server */
+       _send_server_auth_info(tbm_drm_srv, resource);
+}
+
+
+static const struct wl_tbm_drm_interface _wayland_tbm_drm_server_implementation = {
+       _wayland_tbm_drm_server_impl_get_authentication_info,
+};
+
+static void
+_wayland_tbm_drm_server_bind_cb(struct wl_client *client, void *data,
+                           uint32_t version,
+                           uint32_t id)
+{
+       struct wl_resource *resource;
+
+       resource = wl_resource_create(client, &wl_tbm_drm_interface, MIN(version, 1), id);
+       if (!resource) {
+               wl_client_post_no_memory(client);
+               return;
+       }
+
+       wl_resource_set_implementation(resource,
+                                      &_wayland_tbm_drm_server_implementation,
+                                      data,
+                                      NULL);
+}
+
+int
+tbm_drm_helper_wl_server_init(void *wl_display,   int fd, const char *device_name, uint32_t flags)
+{
+       if (!tbm_drm_srv) {
+               TBM_RETURN_VAL_IF_FAIL(wl_display != NULL, 0);
+
+               tbm_drm_srv = calloc(1, sizeof(struct wayland_tbm_drm_server));
+               TBM_RETURN_VAL_IF_FAIL(tbm_drm_srv != NULL, 0);
+
+               tbm_drm_srv->display = (struct wl_display *)wl_display;
+               tbm_drm_srv->device_name = strdup(device_name);
+               tbm_drm_srv->fd = fd;
+               tbm_drm_srv->flags = flags;
+
+               if(!wl_display_add_socket(tbm_drm_srv->display, "tbm_drm")) {
+                       TBM_LOG("[WL_TBM] fail to add socket");
+
+                       if (tbm_drm_srv->device_name)
+                               free(tbm_drm_srv->device_name);
+
+                       free(tbm_drm_srv);
+                       tbm_drm_srv = NULL;
+
+                       return 0;
+               }
+
+               /* init the client resource list */
+               tbm_drm_srv->wl_tbm_drm_global = wl_global_create(tbm_drm_srv->display, &wl_tbm_drm_interface, 1,
+                                        tbm_drm_srv, _wayland_tbm_drm_server_bind_cb);
+       }
+
+       return 1;
+}
+
+void
+tbm_drm_helper_wl_server_deinit(void)
+{
+       if (tbm_drm_srv) {
+               wl_global_destroy(tbm_drm_srv->wl_tbm_drm_global);
+
+               if (tbm_drm_srv->device_name)
+                       free(tbm_drm_srv->device_name);
+
+               free(tbm_drm_srv);
+               tbm_drm_srv = NULL;
+       }
+}
+
+int
+tbm_drm_helper_get_master_fd(void)
+{
+    const char *value;
+    int ret, fd = -1;
+
+    value = (const char*)getenv("TIZEN_DRM_MASTER_FD");
+    if (!value)
+        return -1;
+
+    ret = sscanf(value, "%d", &fd);
+    if (ret <= 0)
+        return -1;
+
+    TBM_LOG("TIZEN_DRM_MASTER_FD: %d", fd);
+
+    return fd;
+}
+
+void
+tbm_drm_helper_set_master_fd(int fd)
+{
+    char buf[32];
+    int ret;
+
+    snprintf(buf, sizeof(buf), "%d", fd);
+
+    ret = setenv("TIZEN_DRM_MASTER_FD", (const char*)buf, 1);
+    if (ret)
+    {
+        TBM_LOG("failed to set TIZEN_DRM_MASTER_FD to %d", fd);
+        return;
+    }
+
+    TBM_LOG("TIZEN_DRM_MASTER_FD: %d", fd);
+}