Use tbm 2.0 version 59/65559/1 accepted/tizen/common/20160414.142602 accepted/tizen/ivi/20160415.014811 accepted/tizen/mobile/20160415.014831 accepted/tizen/tv/20160415.014727 accepted/tizen/wearable/20160415.014752 submit/tizen/20160414.040521
authorChangyeon Lee <cyeon.lee@samsung.com>
Mon, 11 Apr 2016 04:09:33 +0000 (13:09 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Mon, 11 Apr 2016 05:51:23 +0000 (14:51 +0900)
Change-Id: I794e5e2ce021bab1f9f297fe0d037ba2d9192aff

configure.ac
packaging/libtbm-dumb.spec
src/Makefile.am
src/tbm_bufmgr_dumb.c
src/tbm_wayland.c [deleted file]
src/tbm_wayland.h [deleted file]

index 15826cf..fc5e7ac 100644 (file)
@@ -39,10 +39,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 PKG_CHECK_MODULES(LIBDRM, libdrm)
 PKG_CHECK_MODULES(LIBTBM, libtbm)
 PKG_CHECK_MODULES(DLOG, dlog)
-PKG_CHECK_MODULES(WAYLAND_CLIENT, wayland-client wayland-server)
-
-WYLAND_PREFIX=`$PKG_CONFIG --variable=prefix wayland-client wayland-server`
-AC_PATH_PROG([WAYLAND_SCANNER], [wayland-scanner],, [${WAYLAND_PREFIX}/bin$PATH_SEPARATOR$PATH])
+PKG_CHECK_MODULES(LIBUDEV, libudev)
 
 AC_ARG_ENABLE(cachectrl,
              AS_HELP_STRING([--enable-cachectrl],
@@ -53,8 +50,9 @@ if test "x$CACHE_CTRL" = xyes; then
     AC_DEFINE(ENABLE_CACHECRTL, 1, [Enable cache control])
 fi
 
-LIBTBM_DUMB_CFLAGS="$LIBDRM_CFLAGS $LIBTBM_CFLAGS $DLOG_CFLAGS $WAYLAND_CLIENT_CLFAGS "
-LIBTBM_DUMB_LIBS="$LIBDRM_LIBS $LIBTBM_LIBS $DLOG_LIBS $WAYLAND_CLIENT_LIBS "
+LIBTBM_DUMB_CFLAGS="$LIBDRM_CFLAGS $LIBTBM_CFLAGS $DLOG_CFLAGS $LIBUDEV_CFLAGS "
+LIBTBM_DUMB_LIBS="$LIBDRM_LIBS $LIBTBM_LIBS $DLOG_LIBS $LIBUDEV_LIBS "
+
 AC_SUBST(LIBTBM_DUMB_CFLAGS)
 AC_SUBST(LIBTBM_DUMB_LIBS)
 
index 0fa0488..a653e39 100644 (file)
@@ -12,7 +12,7 @@ BuildRequires:  pkgconfig(pthread-stubs)
 BuildRequires:  pkgconfig(libdrm)
 BuildRequires:  pkgconfig(libtbm)
 BuildRequires:  pkgconfig(dlog)
-BuildRequires:  pkgconfig(wayland-client)
+BuildRequires:  pkgconfig(libudev)
 
 %description
 descriptionion: Tizen Buffer manager backend module uses drm dumb
index 161a61a..a53d589 100644 (file)
@@ -9,5 +9,4 @@ libtbm_dumb_ladir = /${bufmgr_dir}
 libtbm_dumb_la_LIBADD = @LIBTBM_DUMB_LIBS@
 
 libtbm_dumb_la_SOURCES = \
-       tbm_bufmgr_dumb.c \
-       tbm_wayland.c
+       tbm_bufmgr_dumb.c
index 3436f52..bf0bbae 100755 (executable)
@@ -49,7 +49,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <pthread.h>
 #include <tbm_surface.h>
 #include <tbm_surface_internal.h>
-#include "tbm_wayland.h"
+#include <libudev.h>
+#include <tbm_drm_helper.h>
 
 #define DEBUG
 #define USE_DMAIMPORT
@@ -156,6 +157,7 @@ typedef struct _tbm_bo_dumb *tbm_bo_dumb;
 typedef struct _dumb_private
 {
     int ref_count;
+    struct _tbm_bo_dumb *bo_priv;
 } PrivGem;
 
 /* tbm buffor object for dumb */
@@ -192,7 +194,8 @@ struct _tbm_bufmgr_dumb
 
     int use_dma_fence;
 
-    int fd_owner;
+    char *device_name;
+    void *bind_display;
 };
 
 char *STR_DEVICE[]=
@@ -222,6 +225,86 @@ uint32_t tbm_dumb_color_format_list[TBM_COLOR_FORMAT_COUNT] = {   TBM_FORMAT_RGB
                                                                         TBM_FORMAT_YUV420,
                                                                         TBM_FORMAT_YVU420 };
 
+static int
+_tbm_dumb_open_drm()
+{ 
+    struct udev *udev = NULL;
+    struct udev_enumerate *e = NULL;
+    struct udev_list_entry *entry = NULL;
+    struct udev_device *device = NULL, *drm_device = NULL, *pci = NULL;
+    const char *filepath, *id;
+    struct stat s;
+    int fd = -1;
+    int ret;
+
+    udev = udev_new();
+    if (!udev) {
+        TBM_DUMB_LOG("udev_new() failed.\n");
+        return -1;
+    }
+
+    e = udev_enumerate_new(udev);
+    udev_enumerate_add_match_subsystem(e, "drm");
+    udev_enumerate_add_match_sysname(e, "card[0-9]*");
+    udev_enumerate_scan_devices(e);
+
+    drm_device = NULL;
+    udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
+        filepath = udev_list_entry_get_name(entry);
+        device = udev_device_new_from_syspath(udev, filepath);
+        if (!device)
+            continue;
+        
+        pci = udev_device_get_parent_with_subsystem_devtype(device, "pci", NULL);
+        if (pci) {
+            id = udev_device_get_sysattr_value(pci, "boot_vga");
+            if (id && !strcmp(id, "1")) {
+                if (drm_device)
+                udev_device_unref(drm_device);
+                drm_device = device;
+                break;
+            }
+        }
+        
+        if (!drm_device)
+            drm_device = device;
+        else
+            udev_device_unref(device);
+    }
+    
+    udev_enumerate_unref(e);
+
+    /* Get device file path. */
+    filepath = udev_device_get_devnode(drm_device);
+    if (!filepath) {
+        TBM_DUMB_LOG("udev_device_get_devnode() failed.\n");
+        udev_device_unref(drm_device);
+        udev_unref(udev);
+        return -1;
+    }
+
+    /* Open DRM device file and check validity. */
+    fd = open(filepath, O_RDWR | O_CLOEXEC);
+    if (fd < 0) {
+        TBM_DUMB_LOG("open(%s, O_RDWR | O_CLOEXEC) failed.\n");
+        udev_device_unref(drm_device);
+        udev_unref(udev);
+        return -1;
+    }
+
+    ret = fstat(fd, &s);
+    if (ret) {
+        TBM_DUMB_LOG("fstat() failed %s.\n");
+        udev_device_unref(drm_device);
+        udev_unref(udev);
+        return -1;
+    }
+
+    udev_device_unref(drm_device);
+    udev_unref(udev);
+
+    return fd;
+}
 
 static unsigned int
 _get_dumb_flag_from_tbm (unsigned int ftbm)
@@ -428,6 +511,7 @@ tbm_dumb_bo_alloc (tbm_bo bo, int size, int flags)
     }
 
     privGem->ref_count = 1;
+    privGem->bo_priv = bo_dumb;
     if (drmHashInsert(bufmgr_dumb->hashBos, bo_dumb->name, (void *)privGem) < 0)
     {
         TBM_DUMB_LOG ("error Cannot insert bo to Hash(%d)\n", bo_dumb->name);
@@ -520,10 +604,17 @@ tbm_dumb_bo_import (tbm_bo bo, unsigned int key)
 
     tbm_bufmgr_dumb bufmgr_dumb;
     tbm_bo_dumb bo_dumb;
+    PrivGem *privGem = NULL;
+    int ret;
 
     bufmgr_dumb = (tbm_bufmgr_dumb)tbm_backend_get_bufmgr_priv(bo);
     DUMB_RETURN_VAL_IF_FAIL (bufmgr_dumb!=NULL, 0);
 
+    ret = drmHashLookup (bufmgr_dumb->hashBos, key, (void **)&privGem);
+    if (ret == 0) {
+        return privGem->bo_priv;
+    }
+
     struct drm_gem_open arg = {0, };
 
     arg.name = key;
@@ -562,32 +653,21 @@ tbm_dumb_bo_import (tbm_bo bo, unsigned int key)
     }
 
     /* add bo to hash */
-    PrivGem *privGem = NULL;
-    int ret;
-
-    ret = drmHashLookup (bufmgr_dumb->hashBos, bo_dumb->name, (void**)&privGem);
-    if (ret == 0)
+    privGem = NULL;
+    privGem = calloc (1, sizeof(PrivGem));
+    if (!privGem)
     {
-        privGem->ref_count++;
+        TBM_DUMB_LOG ("[libtbm-dumb:%d] "
+                "error %s:%d Fail to calloc privGem\n",
+                getpid(), __FUNCTION__, __LINE__);
+        free (bo_dumb);
+        return 0;
     }
-    else if (ret == 1)
-    {
-        privGem = calloc (1, sizeof(PrivGem));
-        if (!privGem)
-        {
-            TBM_DUMB_LOG ("error Fail to calloc privGem\n");
-            free (bo_dumb);
-            return 0;
-        }
 
-        privGem->ref_count = 1;
-        if (drmHashInsert (bufmgr_dumb->hashBos, bo_dumb->name, (void *)privGem) < 0)
-        {
-            TBM_DUMB_LOG ("error Cannot insert bo to Hash(%d)\n", bo_dumb->name);
-        }
-    }
-    else
-    {
+    privGem->ref_count = 1;
+    privGem->bo_priv = bo_dumb;
+
+    if (drmHashInsert (bufmgr_dumb->hashBos, bo_dumb->name, (void *)privGem) < 0) {
         TBM_DUMB_LOG ("error Cannot insert bo to Hash(%d)\n", bo_dumb->name);
     }
 
@@ -612,6 +692,9 @@ tbm_dumb_bo_import_fd (tbm_bo bo, tbm_fd key)
     bufmgr_dumb = (tbm_bufmgr_dumb)tbm_backend_get_bufmgr_priv(bo);
     DUMB_RETURN_VAL_IF_FAIL (bufmgr_dumb!=NULL, 0);
 
+    PrivGem *privGem = NULL;
+    int ret;
+
     unsigned int gem = 0;
     unsigned int name = 0;
     unsigned int real_size = -1;
@@ -643,7 +726,14 @@ tbm_dumb_bo_import_fd (tbm_bo bo, tbm_fd key)
         TBM_DUMB_LOG ("error bo:%p Cannot get name from gem:%d, fd:%d (%s)\n",
             bo, gem, key, strerror(errno));
         return 0;
-    }    
+    }
+
+    ret = drmHashLookup (bufmgr_dumb->hashBos, name, (void **)&privGem);
+    if (ret == 0) {
+        if (gem == privGem->bo_priv->gem) {
+            return privGem->bo_priv;
+        }
+    }
 
     /* Open the same GEM object only for finding out its size */
     gem_open.name = name;
@@ -680,35 +770,22 @@ tbm_dumb_bo_import_fd (tbm_bo bo, tbm_fd key)
     bo_dumb->name = name;
 
     /* add bo to hash */
-    PrivGem *privGem = NULL;
-    int ret;
-
-    ret = drmHashLookup (bufmgr_dumb->hashBos, bo_dumb->name, (void**)&privGem);
-    if (ret == 0)
+    privGem = NULL;
+    privGem = calloc (1, sizeof(PrivGem));
+    if (!privGem)
     {
-        privGem->ref_count++;
+        TBM_DUMB_LOG ("[libtbm-dumb:%d] "
+                "error %s:%d Fail to calloc privGem\n",
+                getpid(), __FUNCTION__, __LINE__);
+        free (bo_dumb);
+        return 0;
     }
-    else if (ret == 1)
-    {
-        privGem = calloc (1, sizeof(PrivGem));
-        if (!privGem)
-        {
-            TBM_DUMB_LOG ("error Fail to calloc privGem\n");
-            free (bo_dumb);
-            return 0;
-        }
 
-        privGem->ref_count = 1;
-        if (drmHashInsert (bufmgr_dumb->hashBos, bo_dumb->name, (void *)privGem) < 0)
-        {
-            TBM_DUMB_LOG ("error bo:%p Cannot insert bo to Hash(%d) from gem:%d, fd:%d\n",
-                bo, bo_dumb->name, gem, key);
-        }
-    }
-    else
-    {
-        TBM_DUMB_LOG ("error bo:%p Cannot insert bo to Hash(%d) from gem:%d, fd:%d\n",
-                bo, bo_dumb->name, gem, key);
+    privGem->ref_count = 1;
+    privGem->bo_priv = bo_dumb;
+
+    if (drmHashInsert (bufmgr_dumb->hashBos, bo_dumb->name, (void *)privGem) < 0) {
+        TBM_DUMB_LOG ("error Cannot insert bo to Hash(%d)\n", bo_dumb->name);
     }
 
     DBG (" [%s] bo:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d(%d), size:%d\n", target_name(),
@@ -878,52 +955,6 @@ tbm_dumb_bo_unmap (tbm_bo bo)
 }
 
 static int
-tbm_dumb_bo_cache_flush (tbm_bo bo, int flags)
-{
-    tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)tbm_backend_get_bufmgr_priv(bo);
-    DUMB_RETURN_VAL_IF_FAIL (bufmgr_dumb!=NULL, 0);
-
-    /* cache flush is managed by kernel side when using dma-fence. */
-    if (bufmgr_dumb->use_dma_fence)
-       return 1;
-
-    DUMB_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
-
-    tbm_bo_dumb bo_dumb;
-
-    bo_dumb = (tbm_bo_dumb)tbm_backend_get_bo_priv(bo);
-    DUMB_RETURN_VAL_IF_FAIL (bo_dumb!=NULL, 0);
-
-#ifdef USE_CACHE
-    if (!_dumb_cache_flush(bo_dumb->fd, bo_dumb, flags))
-        return 0;
-#endif
-
-    return 1;
-}
-
-static int
-tbm_dumb_bo_get_global_key (tbm_bo bo)
-{
-    DUMB_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
-
-    tbm_bo_dumb bo_dumb;
-
-    bo_dumb = (tbm_bo_dumb)tbm_backend_get_bo_priv(bo);
-    DUMB_RETURN_VAL_IF_FAIL (bo_dumb!=NULL, 0);
-
-    if (!bo_dumb->name)
-    {
-        if (!bo_dumb->gem)
-            return 0;
-
-        bo_dumb->name = _get_name(bo_dumb->fd, bo_dumb->gem);
-    }
-
-    return bo_dumb->name;
-}
-
-static int
 tbm_dumb_bo_lock(tbm_bo bo, int device, int opt)
 {
     DUMB_RETURN_VAL_IF_FAIL (bo!=NULL, 0);
@@ -1144,8 +1175,16 @@ tbm_dumb_bufmgr_deinit (void *priv)
         bufmgr_dumb->hashBos = NULL;
     }
 
-    if (bufmgr_dumb->fd_owner)
-        close (bufmgr_dumb->fd);
+    if (bufmgr_dumb->bind_display)
+        tbm_drm_helper_wl_auth_server_deinit();
+
+    if (bufmgr_dumb->device_name)
+        free(bufmgr_dumb->device_name);
+
+    if (tbm_backend_is_display_server())
+        tbm_drm_helper_unset_tbm_master_fd();
+
+    close(bufmgr_dumb->fd);
 
     free (bufmgr_dumb);
 }
@@ -1173,7 +1212,6 @@ tbm_dumb_surface_supported_format(uint32_t **formats, uint32_t *num)
 
 /**
  * @brief get the plane data of the surface.
- * @param[in] surface : the surface
  * @param[in] width : the width of the surface
  * @param[in] height : the height of the surface
  * @param[in] format : the format of the surface
@@ -1185,7 +1223,7 @@ tbm_dumb_surface_supported_format(uint32_t **formats, uint32_t *num)
  * @return 1 if this function succeeds, otherwise 0.
  */
 int
-tbm_dumb_surface_get_plane_data(tbm_surface_h surface, int width, int height, tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx)
+tbm_dumb_surface_get_plane_data(int width, int height, tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx)
 {
     int ret = 1;
     int bpp;
@@ -1425,326 +1463,6 @@ tbm_dumb_surface_get_plane_data(tbm_surface_h surface, int width, int height, tb
 }
 
 int
-tbm_dumb_surface_get_num_bos(tbm_format format)
-{
-    int num = 0;
-
-    switch(format)
-    {
-        /* 16 bpp RGB */
-        case TBM_FORMAT_XRGB4444:
-        case TBM_FORMAT_XBGR4444:
-        case TBM_FORMAT_RGBX4444:
-        case TBM_FORMAT_BGRX4444:
-        case TBM_FORMAT_ARGB4444:
-        case TBM_FORMAT_ABGR4444:
-        case TBM_FORMAT_RGBA4444:
-        case TBM_FORMAT_BGRA4444:
-        case TBM_FORMAT_XRGB1555:
-        case TBM_FORMAT_XBGR1555:
-        case TBM_FORMAT_RGBX5551:
-        case TBM_FORMAT_BGRX5551:
-        case TBM_FORMAT_ARGB1555:
-        case TBM_FORMAT_ABGR1555:
-        case TBM_FORMAT_RGBA5551:
-        case TBM_FORMAT_BGRA5551:
-        case TBM_FORMAT_RGB565:
-        /* 24 bpp RGB */
-        case TBM_FORMAT_RGB888:
-        case TBM_FORMAT_BGR888:
-        /* 32 bpp RGB */
-        case TBM_FORMAT_XRGB8888:
-        case TBM_FORMAT_XBGR8888:
-        case TBM_FORMAT_RGBX8888:
-        case TBM_FORMAT_BGRX8888:
-        case TBM_FORMAT_ARGB8888:
-        case TBM_FORMAT_ABGR8888:
-        case TBM_FORMAT_RGBA8888:
-        case TBM_FORMAT_BGRA8888:
-        /* packed YCbCr */
-        case TBM_FORMAT_YUYV:
-        case TBM_FORMAT_YVYU:
-        case TBM_FORMAT_UYVY:
-        case TBM_FORMAT_VYUY:
-        case TBM_FORMAT_AYUV:
-        /*
-        * 2 plane YCbCr
-        * index 0 = Y plane, [7:0] Y
-        * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
-        * or
-        * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
-        */
-        case TBM_FORMAT_NV21:
-        case TBM_FORMAT_NV16:
-        case TBM_FORMAT_NV61:
-        /*
-        * 3 plane YCbCr
-        * index 0: Y plane, [7:0] Y
-        * index 1: Cb plane, [7:0] Cb
-        * index 2: Cr plane, [7:0] Cr
-        * or
-        * index 1: Cr plane, [7:0] Cr
-        * index 2: Cb plane, [7:0] Cb
-        */
-        case TBM_FORMAT_YUV410:
-        case TBM_FORMAT_YVU410:
-        case TBM_FORMAT_YUV411:
-        case TBM_FORMAT_YVU411:
-        case TBM_FORMAT_YUV420:
-        case TBM_FORMAT_YVU420:
-        case TBM_FORMAT_YUV422:
-        case TBM_FORMAT_YVU422:
-        case TBM_FORMAT_YUV444:
-        case TBM_FORMAT_YVU444:
-            num = 1;
-            break;
-
-        case TBM_FORMAT_NV12:
-            num = 2;
-            break;
-
-        default:
-            num = 0;
-            break;
-    }
-
-    return num;
-}
-
-/**
-* @brief get the size of the surface with a format.
-* @param[in] surface : the surface
-* @param[in] width : the width of the surface
-* @param[in] height : the height of the surface
-* @param[in] format : the format of the surface
-* @return size of the surface if this function succeeds, otherwise 0.
-*/
-
-int
-tbm_dumb_surface_get_size(tbm_surface_h surface, int width, int height, tbm_format format)
-{
-    int ret = 0;
-    int bpp = 0;
-    int _pitch =0;
-    int _size =0;
-    int align =TBM_SURFACE_ALIGNMENT_PLANE;
-
-    switch(format)
-    {
-        /* 16 bpp RGB */
-        case TBM_FORMAT_XRGB4444:
-        case TBM_FORMAT_XBGR4444:
-        case TBM_FORMAT_RGBX4444:
-        case TBM_FORMAT_BGRX4444:
-        case TBM_FORMAT_ARGB4444:
-        case TBM_FORMAT_ABGR4444:
-        case TBM_FORMAT_RGBA4444:
-        case TBM_FORMAT_BGRA4444:
-        case TBM_FORMAT_XRGB1555:
-        case TBM_FORMAT_XBGR1555:
-        case TBM_FORMAT_RGBX5551:
-        case TBM_FORMAT_BGRX5551:
-        case TBM_FORMAT_ARGB1555:
-        case TBM_FORMAT_ABGR1555:
-        case TBM_FORMAT_RGBA5551:
-        case TBM_FORMAT_BGRA5551:
-        case TBM_FORMAT_RGB565:
-            bpp = 16;
-            _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
-            _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            break;
-        /* 24 bpp RGB */
-        case TBM_FORMAT_RGB888:
-        case TBM_FORMAT_BGR888:
-            bpp = 24;
-            _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
-            _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            break;
-        /* 32 bpp RGB */
-        case TBM_FORMAT_XRGB8888:
-        case TBM_FORMAT_XBGR8888:
-        case TBM_FORMAT_RGBX8888:
-        case TBM_FORMAT_BGRX8888:
-        case TBM_FORMAT_ARGB8888:
-        case TBM_FORMAT_ABGR8888:
-        case TBM_FORMAT_RGBA8888:
-        case TBM_FORMAT_BGRA8888:
-            bpp = 32;
-            _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB);
-            _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            break;
-        /* packed YCbCr */
-        case TBM_FORMAT_YUYV:
-        case TBM_FORMAT_YVYU:
-        case TBM_FORMAT_UYVY:
-        case TBM_FORMAT_VYUY:
-        case TBM_FORMAT_AYUV:
-            bpp = 32;
-            _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
-            _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            break;
-        /*
-        * 2 plane YCbCr
-        * index 0 = Y plane, [7:0] Y
-        * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
-        * or
-        * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
-        */
-        case TBM_FORMAT_NV12:
-        case TBM_FORMAT_NV21:
-            bpp = 12;
-             //plane_idx == 0
-             {
-                 _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
-                 _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-             }
-             //plane_idx ==1
-             {
-                 _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
-                 _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
-             }
-             break;
-
-            break;
-        case TBM_FORMAT_NV16:
-        case TBM_FORMAT_NV61:
-            bpp = 16;
-            //plane_idx == 0
-            {
-                _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
-                _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            }
-            //plane_idx ==1
-            {
-                _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
-                _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            }
-
-            break;
-        /*
-        * 3 plane YCbCr
-        * index 0: Y plane, [7:0] Y
-        * index 1: Cb plane, [7:0] Cb
-        * index 2: Cr plane, [7:0] Cr
-        * or
-        * index 1: Cr plane, [7:0] Cr
-        * index 2: Cb plane, [7:0] Cb
-        */
-        case TBM_FORMAT_YUV410:
-        case TBM_FORMAT_YVU410:
-            bpp = 9;
-        align = TBM_SURFACE_ALIGNMENT_PITCH_YUV;
-            break;
-        case TBM_FORMAT_YUV411:
-        case TBM_FORMAT_YVU411:
-        case TBM_FORMAT_YUV420:
-        case TBM_FORMAT_YVU420:
-            bpp = 12;
-            //plane_idx == 0
-            {
-                _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
-                _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            }
-            //plane_idx == 1
-            {
-                _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
-                _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
-            }
-            //plane_idx == 2
-            {
-                _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
-                _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE);
-            }
-
-            break;
-        case TBM_FORMAT_YUV422:
-        case TBM_FORMAT_YVU422:
-            bpp = 16;
-            //plane_idx == 0
-            {
-                _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV);
-                _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            }
-            //plane_idx == 1
-            {
-                _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
-                _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            }
-            //plane_idx == 2
-            {
-                _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
-                _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE);
-            }
-            break;
-        case TBM_FORMAT_YUV444:
-        case TBM_FORMAT_YVU444:
-            bpp = 24;
-            align = TBM_SURFACE_ALIGNMENT_PITCH_YUV;
-            break;
-
-        default:
-            bpp = 0;
-            break;
-    }
-
-    if(_size > 0)
-        ret = _size;
-    else
-        ret =  SIZE_ALIGN( (width * height * bpp) >> 3, align);
-
-    return ret;
-
-}
-
-tbm_bo_handle
-tbm_dumb_fd_to_handle(tbm_bufmgr bufmgr, tbm_fd fd, int device)
-{
-    DUMB_RETURN_VAL_IF_FAIL (bufmgr!=NULL, (tbm_bo_handle) NULL);
-    DUMB_RETURN_VAL_IF_FAIL (fd > 0, (tbm_bo_handle) NULL);
-
-    tbm_bo_handle bo_handle;
-    memset (&bo_handle, 0x0, sizeof (uint64_t));
-
-    tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)tbm_backend_get_priv_from_bufmgr(bufmgr);
-
-    switch(device)
-    {
-    case TBM_DEVICE_DEFAULT:
-    case TBM_DEVICE_2D:
-    {
-        //getting handle from fd
-        struct drm_prime_handle arg = {0, };
-
-        arg.fd = fd;
-        arg.flags = 0;
-        if (drmIoctl (bufmgr_dumb->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg))
-        {
-            TBM_DUMB_LOG ("error Cannot get gem handle from fd:%d (%s)\n",
-                     arg.fd, strerror(errno));
-            return (tbm_bo_handle) NULL;
-        }
-
-        bo_handle.u32 = (uint32_t)arg.handle;;
-        break;
-    }
-    case TBM_DEVICE_CPU:
-        TBM_DUMB_LOG ("Not supported device:%d\n", device);
-        bo_handle.ptr = (void *) NULL;
-        break;
-    case TBM_DEVICE_3D:
-    case TBM_DEVICE_MM:
-        bo_handle.u32 = (uint32_t)fd;
-        break;
-    default:
-        TBM_DUMB_LOG ("error Not supported device:%d\n", device);
-        bo_handle.ptr = (void *) NULL;
-        break;
-    }
-
-    return bo_handle;
-}
-
-int
 tbm_dumb_bo_get_flags (tbm_bo bo)
 {
     DUMB_RETURN_VAL_IF_FAIL (bo != NULL, 0);
@@ -1757,6 +1475,25 @@ tbm_dumb_bo_get_flags (tbm_bo bo)
     return bo_dumb->flags_tbm;
 }
 
+int
+tbm_dumb_bufmgr_bind_native_display (tbm_bufmgr bufmgr, void *native_display)
+{
+    tbm_bufmgr_dumb bufmgr_dumb;
+    
+    bufmgr_dumb = tbm_backend_get_priv_from_bufmgr(bufmgr);
+    DUMB_RETURN_VAL_IF_FAIL(bufmgr_dumb != NULL, 0);
+    
+    if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_dumb->fd,
+                                            bufmgr_dumb->device_name, 0)) {
+        TBM_DUMB_LOG("error:Fail to tbm_drm_helper_wl_server_init\n");
+        return 0;
+    }
+    
+    bufmgr_dumb->bind_display = native_display;
+    
+    return 1;
+}
+
 MODULEINITPPROTO (init_tbm_bufmgr_priv);
 
 static TBMModuleVersionInfo DumbVersRec =
@@ -1792,19 +1529,44 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd)
         return 0;
     }
 
-    if (fd < 0)
-    {
-        bufmgr_dumb->fd = tbm_bufmgr_get_drm_fd_wayland();
-        bufmgr_dumb->fd_owner = 1;
-    }
-    else
-        bufmgr_dumb->fd = fd;
+    if (tbm_backend_is_display_server()) {      
 
-    if (bufmgr_dumb->fd  < 0)
-    {
-        TBM_DUMB_LOG ("error: Fail to create drm!\n");
-        free (bufmgr_dumb);
-        return 0;
+        bufmgr_dumb->fd = tbm_drm_helper_get_master_fd();
+        if (bufmgr_dumb->fd < 0) {
+            bufmgr_dumb->fd = _tbm_dumb_open_drm();
+        }
+    
+        if (bufmgr_dumb->fd < 0) {
+            TBM_DUMB_LOG ("error:Fail to create drm!\n");
+            free (bufmgr_dumb);
+            return 0;
+        }
+
+               tbm_drm_helper_set_tbm_master_fd(bufmgr_dumb->fd);
+    
+        bufmgr_dumb->device_name = drmGetDeviceNameFromFd(bufmgr_dumb->fd);
+        
+        if (!bufmgr_dumb->device_name)
+        {
+            TBM_DUMB_LOG ("error:Fail to get device name!\n");
+    
+            tbm_drm_helper_unset_tbm_master_fd();
+
+            close(bufmgr_dumb->fd);
+    
+            free (bufmgr_dumb);
+            return 0;
+        }
+    } else {
+        if (!tbm_drm_helper_get_auth_info(&(bufmgr_dumb->fd), &(bufmgr_dumb->device_name), NULL)) {
+            TBM_DUMB_LOG ("error:Fail to get auth drm info!\n");
+
+            if (bufmgr_dumb->fd >= 0)
+               close(bufmgr_dumb->fd);
+
+            free (bufmgr_dumb);
+            return 0;
+        }
     }
 
     //Create Hash Table
@@ -1831,8 +1593,10 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd)
         if (bufmgr_dumb->hashBos)
             drmHashDestroy (bufmgr_dumb->hashBos);
 
-        if (bufmgr_dumb->fd_owner)
-            close(bufmgr_dumb->fd);
+        if (tbm_backend_is_display_server())
+            tbm_drm_helper_unset_tbm_master_fd();
+
+        close(bufmgr_dumb->fd);
 
         free (bufmgr_dumb);
         return 0;
@@ -1850,26 +1614,21 @@ init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd)
     bufmgr_backend->bo_get_handle = tbm_dumb_bo_get_handle,
     bufmgr_backend->bo_map = tbm_dumb_bo_map,
     bufmgr_backend->bo_unmap = tbm_dumb_bo_unmap,
-    bufmgr_backend->bo_cache_flush = tbm_dumb_bo_cache_flush,
-    bufmgr_backend->bo_get_global_key = tbm_dumb_bo_get_global_key;
     bufmgr_backend->surface_get_plane_data = tbm_dumb_surface_get_plane_data;
-    bufmgr_backend->surface_get_size = tbm_dumb_surface_get_size;
     bufmgr_backend->surface_supported_format = tbm_dumb_surface_supported_format;
-    bufmgr_backend->fd_to_handle = tbm_dumb_fd_to_handle;
-    bufmgr_backend->surface_get_num_bos = tbm_dumb_surface_get_num_bos;
     bufmgr_backend->bo_get_flags = tbm_dumb_bo_get_flags;
-
-    bufmgr_backend->flags = (TBM_LOCK_CTRL_BACKEND | TBM_CACHE_CTRL_BACKEND);
-    bufmgr_backend->bo_lock = NULL;
-    bufmgr_backend->bo_lock2 = tbm_dumb_bo_lock;
+    bufmgr_backend->bo_lock = tbm_dumb_bo_lock;
     bufmgr_backend->bo_unlock = tbm_dumb_bo_unlock;
+    bufmgr_backend->bufmgr_bind_native_display = tbm_dumb_bufmgr_bind_native_display;
 
     if (!tbm_backend_init (bufmgr, bufmgr_backend))
     {
         TBM_DUMB_LOG ("error: Fail to init backend!\n");
 
-        if (bufmgr_dumb->fd_owner)
-            close(bufmgr_dumb->fd);
+        if (tbm_backend_is_display_server())
+            tbm_drm_helper_unset_tbm_master_fd();
+
+        close(bufmgr_dumb->fd);
 
         tbm_backend_free (bufmgr_backend);
         free (bufmgr_dumb);
diff --git a/src/tbm_wayland.c b/src/tbm_wayland.c
deleted file mode 100644 (file)
index 57286ff..0000000
+++ /dev/null
@@ -1,279 +0,0 @@
-/**************************************************************************
-
-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.
-
-**************************************************************************/
-
-#include "config.h"
-
-#include <xf86drm.h>
-
-#include <stdint.h>
-#include <stddef.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <wayland-client.h>
-
-#include "wayland-util.h"
-
-extern const struct wl_interface wl_buffer_interface;
-
-static const struct wl_interface *types[] = {
-       NULL,
-       NULL,
-       NULL,
-       &wl_buffer_interface,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       &wl_buffer_interface,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-       NULL,
-};
-
-static const struct wl_message wl_tbm_requests[] = {
-       {"create_buffer", "niiuiiiiiiiiiiuiuuu", types + 3},
-       {"create_buffer_with_fd", "niiuiiiiiiiiiiuihhh", types + 22},
-       {"get_authentication_info", "", types + 0},
-};
-
-static const struct wl_message wl_tbm_events[] = {
-       {"authentication_info", "suh", types + 0},
-};
-
-WL_EXPORT const struct wl_interface wl_tbm_interface = {
-       "wl_tbm", 1,
-       3, wl_tbm_requests,
-       1, wl_tbm_events,
-};
-
-struct wl_buffer;
-struct wl_tbm;
-
-extern const struct wl_interface wl_tbm_interface;
-
-#ifndef WL_TBM_ERROR_ENUM
-#define WL_TBM_ERROR_ENUM
-enum wl_tbm_error {
-       WL_TBM_ERROR_AUTHENTICATE_FAIL = 0,
-       WL_TBM_ERROR_INVALID_FORMAT = 1,
-       WL_TBM_ERROR_INVALID_NAME = 2,
-};
-#endif                                                 /* WL_TBM_ERROR_ENUM */
-
-struct wl_tbm_listener {
-       /**
-     * authentication_info - (none)
-     * @device_name: (none)
-     * @capabilities: (none)
-     * @auth_fd: (none)
-     */
-       void (*authentication_info) (void *data, struct wl_tbm * wl_tbm, const char *device_name, uint32_t capabilities, int32_t auth_fd);
-};
-
-static inline int wl_tbm_add_listener(struct wl_tbm *wl_tbm, const struct wl_tbm_listener *listener, void *data)
-{
-       return wl_proxy_add_listener((struct wl_proxy *)wl_tbm, (void (**)(void))listener, data);
-}
-
-#define WL_TBM_CREATE_BUFFER    0
-#define WL_TBM_CREATE_BUFFER_WITH_FD    1
-#define WL_TBM_GET_AUTHENTICATION_INFO  2
-
-static inline void wl_tbm_set_user_data(struct wl_tbm *wl_tbm, void *user_data)
-{
-       wl_proxy_set_user_data((struct wl_proxy *)wl_tbm, user_data);
-}
-
-static inline void *wl_tbm_get_user_data(struct wl_tbm *wl_tbm)
-{
-       return wl_proxy_get_user_data((struct wl_proxy *)wl_tbm);
-}
-
-static inline void wl_tbm_destroy(struct wl_tbm *wl_tbm)
-{
-       wl_proxy_destroy((struct wl_proxy *)wl_tbm);
-}
-
-static inline void wl_tbm_get_authentication_info(struct wl_tbm *wl_tbm)
-{
-       wl_proxy_marshal((struct wl_proxy *)wl_tbm, WL_TBM_GET_AUTHENTICATION_INFO);
-}
-
-struct wl_tbm_info {
-       struct wl_display *dpy;
-       struct wl_event_queue *wl_queue;
-       struct wl_tbm *wl_tbm;
-
-       uint32_t capabilities;
-       char *device;
-       int32_t fd;
-};
-
-static void handle_tbm_authentication_info(void *data, struct wl_tbm *wl_tbm, const char *device_name, uint32_t capabilities, int32_t auth_fd)
-{
-       struct wl_tbm_info *info = (struct wl_tbm_info *)data;
-
-       info->fd = auth_fd;
-       info->capabilities = capabilities;
-       if (device_name)
-               info->device = strndup(device_name, 256);
-}
-
-static const struct wl_tbm_listener wl_tbm_client_listener = {
-       handle_tbm_authentication_info
-};
-
-static void wl_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
-{
-       struct wl_tbm_info *info = (struct wl_tbm_info *)data;
-
-       if (!strcmp(interface, "wl_tbm")) {
-               info->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version);
-               if (!info->wl_tbm) {
-                       printf("Failed to bind wl_tbm\n");
-                       return;
-               }
-
-               wl_tbm_add_listener(info->wl_tbm, &wl_tbm_client_listener, info);
-               wl_proxy_set_queue((struct wl_proxy *)info->wl_tbm, info->wl_queue);
-       }
-}
-
-static int tbm_util_get_drm_fd(void *dpy, int *fd)
-{
-       struct wl_display *disp = NULL;
-       struct wl_registry *wl_registry;
-       struct wl_tbm_info info = {
-               .dpy = NULL,
-               .wl_queue = NULL,
-               .wl_tbm = NULL,
-               .capabilities = 0,
-               .device = NULL,
-               .fd = 0,
-       };
-
-       static const struct wl_registry_listener registry_listener = {
-               wl_client_registry_handle_global,
-               NULL
-       };
-
-       if (!fd)
-               return -1;
-
-       if (!dpy) {
-               disp = wl_display_connect(NULL);
-               if (!disp) {
-                       printf("Failed to create a new display connection\n");
-                       return -1;
-               }
-               dpy = disp;
-       }
-
-       info.dpy = dpy;
-       info.wl_queue = wl_display_create_queue(dpy);
-       if (!info.wl_queue) {
-               printf("Failed to create a WL Queue\n");
-               if (disp == dpy)
-                       wl_display_disconnect(disp);
-
-               return -1;
-       }
-
-       wl_registry = wl_display_get_registry(dpy);
-       if (!wl_registry) {
-               printf("Failed to get registry\n");
-               wl_event_queue_destroy(info.wl_queue);
-               if (disp == dpy)
-                       wl_display_disconnect(disp);
-
-               return -1;
-       }
-       wl_proxy_set_queue((struct wl_proxy *)wl_registry, info.wl_queue);
-       wl_registry_add_listener(wl_registry, &registry_listener, &info);
-       wl_display_roundtrip_queue(dpy, info.wl_queue);
-
-       wl_tbm_get_authentication_info(info.wl_tbm);
-       wl_display_roundtrip_queue(dpy, info.wl_queue);
-
-       *fd = info.fd;
-
-       wl_event_queue_destroy(info.wl_queue);
-       wl_registry_destroy(wl_registry);
-
-       free(info.device);
-       wl_tbm_set_user_data(info.wl_tbm, NULL);
-       wl_tbm_destroy(info.wl_tbm);
-
-       if (disp == dpy)
-               wl_display_disconnect(disp);
-
-       return *fd >= 0 ? 0 : -1;
-}
-
-int tbm_bufmgr_get_drm_fd_wayland()
-{
-       int fd = -1;
-
-       if (tbm_util_get_drm_fd(NULL, &fd))
-               printf("Failed to get drm_fd\n");
-
-       return fd;
-}
diff --git a/src/tbm_wayland.h b/src/tbm_wayland.h
deleted file mode 100644 (file)
index 32ba395..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/**************************************************************************
-
-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_UTIL_H_
-#define _TBM_UTIL_H_
-
-int tbm_bufmgr_get_drm_fd_wayland();
-
-#endif /* _TBM_UTIL_H_ */
-