get drm_fd from TDM_DRM_MASTER_FD enviroment variable 40/65540/2
authorBoram Park <boram1288.park@samsung.com>
Fri, 25 Mar 2016 05:55:54 +0000 (14:55 +0900)
committerBoram Park <boram1288.park@samsung.com>
Thu, 14 Apr 2016 02:23:16 +0000 (19:23 -0700)
Change-Id: I4c90f41ab1badf929d32ca89a068447ba2727148

src/lib/ecore_drm/ecore_drm_device.c
src/lib/ecore_drm/ecore_drm_display.c

index 5860ab0..39953cc 100644 (file)
@@ -5,6 +5,10 @@
 #include "ecore_drm_private.h"
 #include <dlfcn.h>
 
+#ifdef HAVE_TDM
+#include <tdm_helper.h>
+#endif
+
 #define INSIDE(x, y, xx, yy, ww, hh) \
    (((x) < ((xx) + (ww))) && ((y) < ((yy) + (hh))) && \
        ((x) >= (xx)) && ((y) >= (yy)))
@@ -334,7 +338,6 @@ ecore_drm_device_open(Ecore_Drm_Device *dev)
 {
 #ifdef HAVE_TDM
    int events = 0;
-   drmVersionPtr ver;
 
    /* check for valid device */
    if ((!dev) || (!dev->drm.name)) return EINA_FALSE;
@@ -348,10 +351,14 @@ ecore_drm_device_open(Ecore_Drm_Device *dev)
         return EINA_FALSE;
      }
 
-   if ((ver = drmGetVersion(ecore_drm_device_fd_get(dev))))
+   /* TDM backend will set a drm master fd to TDM_DRM_MASTER_FD. */
+   dev->drm.fd = tdm_helper_get_fd("TDM_DRM_MASTER_FD");
+   if (dev->drm.fd < 0)
      {
-        drmFreeVersion(ver);
-        dev->drm.fd = ecore_drm_device_fd_get(dev);
+        ERR("failed: no drm master fd");
+
+        /* If not set, use a tdm display fd instead of a drm master fd. */
+        dev->drm.fd = _ecore_drm_display_get_fd(dev);
      }
 
    /* try to create xkb context */
@@ -468,10 +475,6 @@ ecore_drm_device_close(Ecore_Drm_Device *dev)
    if (dev->drm.hdlr) ecore_main_fd_handler_del(dev->drm.hdlr);
    dev->drm.hdlr = NULL;
 
-#ifdef HAVE_TDM
-   /* when we use TDM, dev->drm.fd comes from TDM. It will close in TDM. */
-   dev->drm.fd = -1;
-#endif
    _ecore_drm_launcher_device_close(dev->drm.name, dev->drm.fd);
 
    _ecore_drm_display_destroy(dev);
@@ -553,10 +556,6 @@ ecore_drm_device_fd_get(Ecore_Drm_Device *dev)
 {
    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
 
-#ifdef HAVE_TDM
-   return _ecore_drm_display_get_fd(dev);
-#endif
-
    return dev->drm.fd;
 }
 
index ec7307d..b064e18 100644 (file)
@@ -92,6 +92,7 @@ Eina_Bool
 _ecore_drm_display_init(Ecore_Drm_Device *dev)
 {
    Ecore_Drm_Hal_Display *hal_display;
+   int fd;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
 
@@ -106,10 +107,12 @@ _ecore_drm_display_init(Ecore_Drm_Device *dev)
      goto fail_init;
 
    hal_display->fd = -1;
-   tdm_display_get_fd(hal_display->display, &hal_display->fd);
-   if (hal_display->fd < 0)
+   tdm_display_get_fd(hal_display->display, &fd);
+   if (fd < 0)
      goto fail_fd;
 
+   hal_display->fd = dup(fd);
+
    hal_display->hdlr =
      ecore_main_fd_handler_add(hal_display->fd, ECORE_FD_READ,
                                _ecore_drm_display_cb_event, hal_display, NULL, NULL);
@@ -121,6 +124,10 @@ _ecore_drm_display_init(Ecore_Drm_Device *dev)
    return EINA_TRUE;
 
 fail_hdlr:
+   if (hal_display->fd >= 0)
+     close(hal_display->fd);
+
+   hal_display->fd = -1;
 fail_fd:
    tdm_display_deinit(hal_display->display);
 fail_init:
@@ -138,6 +145,9 @@ _ecore_drm_display_destroy(Ecore_Drm_Device *dev)
    if (hal_display->hdlr) ecore_main_fd_handler_del(hal_display->hdlr);
    tdm_display_deinit(hal_display->display);
 
+   if (hal_display->fd >= 0)
+     close(hal_display->fd);
+
    free(hal_display);
    dev->hal_display = NULL;
 }