move source files to src/libtbm-vigs/ 45/252845/1
authorSooChan Lim <sc1.lim@samsung.com>
Wed, 3 Feb 2021 00:31:21 +0000 (09:31 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 3 Feb 2021 00:31:21 +0000 (09:31 +0900)
Change-Id: Ic10ecd04a7f6e0da82edb784e2334a661e026441

configure.ac
src/Makefile.am
src/libtbm-vigs/Makefile.am [new file with mode: 0644]
src/libtbm-vigs/tbm_bufmgr_vigs.c [new file with mode: 0755]
src/libtbm-vigs/tbm_vigs.h [new file with mode: 0644]
src/tbm_bufmgr_vigs.c [deleted file]
src/tbm_vigs.h [deleted file]

index f9cfc87e2d792af302c3d408f028c97ccc55715c..8fc38ca831223d97ee3a2ea6f4b7ba617698cc08 100644 (file)
@@ -51,6 +51,7 @@ AC_SUBST(bufmgr_dir)
 
 AC_OUTPUT([
        Makefile
+       src/libtbm-vigs/Makefile
        src/Makefile
        libtbm-vigs.pc])
 
index 7db93575be5e55ea7bf96b18b2c4bfbd79d6c2cc..05e726e570610ea82e507213757c0a6bad7ad5aa 100644 (file)
@@ -1,14 +1,2 @@
-AM_CFLAGS = \
-       @LIBTBM_VIGS_CFLAGS@ \
-       -I$(top_srcdir) \
-       -I$(top_srcdir)/src
+SUBDIRS = libtbm-vigs
 
-libtbm_vigs_la_LTLIBRARIES = libtbm_vigs.la
-libtbm_vigs_ladir = /${bufmgr_dir}
-libtbm_vigs_la_LIBADD = @LIBTBM_VIGS_LIBS@
-
-libtbm_vigs_la_SOURCES = \
-       tbm_bufmgr_vigs.c
-
-libtbm_vigs_includedir=$(includedir)/tbm-vigs
-libtbm_vigs_include_HEADERS = tbm_vigs.h
diff --git a/src/libtbm-vigs/Makefile.am b/src/libtbm-vigs/Makefile.am
new file mode 100644 (file)
index 0000000..7db9357
--- /dev/null
@@ -0,0 +1,14 @@
+AM_CFLAGS = \
+       @LIBTBM_VIGS_CFLAGS@ \
+       -I$(top_srcdir) \
+       -I$(top_srcdir)/src
+
+libtbm_vigs_la_LTLIBRARIES = libtbm_vigs.la
+libtbm_vigs_ladir = /${bufmgr_dir}
+libtbm_vigs_la_LIBADD = @LIBTBM_VIGS_LIBS@
+
+libtbm_vigs_la_SOURCES = \
+       tbm_bufmgr_vigs.c
+
+libtbm_vigs_includedir=$(includedir)/tbm-vigs
+libtbm_vigs_include_HEADERS = tbm_vigs.h
diff --git a/src/libtbm-vigs/tbm_bufmgr_vigs.c b/src/libtbm-vigs/tbm_bufmgr_vigs.c
new file mode 100755 (executable)
index 0000000..d2b6d0b
--- /dev/null
@@ -0,0 +1,962 @@
+/*
+ * buffer manager for libtbm-vigs
+ *
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact :
+ * Stanislav Vorobiov <s.vorobiov@samsung.com>
+ * Jinhyung Jo <jinhyung.jo@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.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, sublicense, 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 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vigs.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <xf86drm.h>
+#include <tbm_backend.h>
+#include <tbm_drm_helper.h>
+#include <tbm_log.h>
+
+#define STRERR_BUFSIZE 128
+
+#define VIGS_DRM_NAME "vigs"
+
+/* global singleton drm_dev. this is shared with yagl. */
+struct vigs_drm_device *g_drm_dev = NULL;
+
+static uint32_t tbm_bufmgr_vigs_color_format_list[] = {
+       TBM_FORMAT_RGB888,
+       TBM_FORMAT_ARGB8888,
+       TBM_FORMAT_RGBA8888,
+       TBM_FORMAT_XRGB8888,
+       TBM_FORMAT_XBGR8888,
+       TBM_FORMAT_NV21,
+       TBM_FORMAT_NV61,
+       TBM_FORMAT_YUV420,
+};
+
+typedef struct _tbm_bufmgr_vigs *tbm_bufmgr_vigs;
+typedef struct _tbm_bo_vigs *tbm_bo_vigs;
+
+/* tbm buffor object for vigs */
+struct _tbm_bo_vigs {
+       struct vigs_drm_surface *sfc;
+
+       tbm_bufmgr_vigs bufmgr_vigs;
+};
+
+/* tbm bufmgr private for vigs */
+struct _tbm_bufmgr_vigs {
+       struct vigs_drm_device *drm_dev;
+
+       tbm_backend_bufmgr_func *bufmgr_func;
+       tbm_backend_bo_func *bo_func;
+
+       tbm_bufmgr bufmgr;
+};
+
+static int _tbm_vigs_open_drm(void)
+{
+       int fd = -1;
+
+       fd = drmOpen(VIGS_DRM_NAME, NULL);
+       if (fd < 0) {
+               TBM_ERR("open vigs drm device failed");
+               return -1;
+       }
+
+       return fd;
+}
+
+static tbm_bo_handle get_tbm_bo_handle(struct vigs_drm_surface *sfc, int device)
+{
+       tbm_bo_handle bo_handle;
+       int ret;
+       struct vigs_drm_gem *gem = &sfc->gem;
+       char buf[STRERR_BUFSIZE];
+
+       memset(&bo_handle, 0, sizeof(bo_handle));
+
+       switch (device) {
+       case TBM_DEVICE_DEFAULT:
+       case TBM_DEVICE_2D:
+               bo_handle.u32 = gem->handle;
+               break;
+       case TBM_DEVICE_CPU:
+               ret = vigs_drm_gem_map(gem, 1);
+
+               if (ret == 0)
+                       bo_handle.ptr = gem->vaddr;
+               else
+                       TBM_ERR("vigs_drm_gem_map failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+
+               break;
+       case TBM_DEVICE_3D:
+               bo_handle.ptr = (void *)sfc;
+               break;
+       case TBM_DEVICE_MM:
+               TBM_ERR("TBM_DEVICE_MM not supported");
+               break;
+       default:
+               TBM_ERR("%d not supported", device);
+               break;
+       }
+
+       return bo_handle;
+}
+
+static tbm_bufmgr_capability
+tbm_vigs_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error)
+{
+       tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE;
+
+       capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD;
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return capabilities;
+}
+
+static tbm_error_e
+tbm_vigs_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
+       struct vigs_drm_device *drm_dev;
+       char *device_name;
+       int ret = 0;
+
+       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
+               TBM_ERR("bufmgr_data is null\n");
+               return TBM_ERROR_INVALID_PARAMETER;
+       }
+
+       drm_dev = bufmgr_vigs->drm_dev;
+
+       device_name = drmGetDeviceNameFromFd(drm_dev->fd);
+       if (!device_name) {
+               TBM_ERR("drmGetDeviceNameFromFd failed");
+               return TBM_ERROR_INVALID_OPERATION;
+       }
+
+       ret = tbm_drm_helper_wl_auth_server_init(native_display, drm_dev->fd, device_name, 0);
+       if (!ret) {
+               TBM_ERR("tbm_drm_helper_wl_auth_server_init failed");
+               free(device_name);
+               return TBM_ERROR_INVALID_OPERATION;
+       }
+
+       free(device_name);
+
+       return TBM_ERROR_NONE;
+}
+
+static tbm_error_e
+tbm_vigs_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data,
+                                                       uint32_t **formats, uint32_t *num)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
+       uint32_t *color_formats;
+
+       if (!bufmgr_vigs)
+               return TBM_ERROR_INVALID_PARAMETER;
+
+       color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_vigs_color_format_list));
+       if (!color_formats)
+               return TBM_ERROR_OUT_OF_MEMORY;
+
+       memcpy(color_formats, tbm_bufmgr_vigs_color_format_list, sizeof(tbm_bufmgr_vigs_color_format_list));
+
+       *formats = color_formats;
+       *num = sizeof(tbm_bufmgr_vigs_color_format_list) / sizeof(tbm_bufmgr_vigs_color_format_list[0]);
+
+       return TBM_ERROR_NONE;
+}
+
+static tbm_error_e
+tbm_vigs_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data,
+                                                        tbm_format format, int plane_idx, int width,
+                                                        int height, uint32_t * size, uint32_t * offset,
+                                                        uint32_t * pitch, int *bo_idx)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
+
+       *size = 0;
+       *offset = 0;
+       *pitch = 0;
+       *bo_idx = 0;
+
+       if (!bufmgr_vigs)
+               return TBM_ERROR_INVALID_PARAMETER;
+
+       switch (format) {
+       case TBM_FORMAT_RGB888:
+               *size = width * height * 3;
+               *offset = 0;
+               *pitch = width * 3;
+               *bo_idx = 0;
+               return TBM_ERROR_NONE;
+       case TBM_FORMAT_XRGB8888:
+       case TBM_FORMAT_XBGR8888:
+       case TBM_FORMAT_ARGB8888:
+       case TBM_FORMAT_RGBA8888:
+               *size = width * height * 4;
+               *offset = 0;
+               *pitch = width * 4;
+               *bo_idx = 0;
+               return TBM_ERROR_NONE;
+       case TBM_FORMAT_NV21:
+               if (plane_idx == 0) {
+                       *size = width * height;
+                       *offset = 0;
+                       *pitch = width;
+                       *bo_idx = 0;
+               } else if (plane_idx == 1) {
+                       *size = width * (height >> 1);
+                       *offset = width * height;
+                       *pitch = width;
+                       *bo_idx = 0;
+               } else {
+                       return TBM_ERROR_INVALID_PARAMETER;
+               }
+               return TBM_ERROR_NONE;
+       case TBM_FORMAT_NV61:
+               if (plane_idx == 0) {
+                       *size = width * height;
+                       *offset = 0;
+                       *pitch = width;
+                       *bo_idx = 0;
+               } else if (plane_idx == 1) {
+                       *size = width * height;
+                       *offset = width * height;
+                       *pitch = width;
+                       *bo_idx = 0;
+               } else {
+                       return TBM_ERROR_INVALID_PARAMETER;
+               }
+               return TBM_ERROR_NONE;
+       case TBM_FORMAT_YUV420:
+               if (plane_idx == 0) {
+                       *size = width * height;
+                       *offset = 0;
+                       *pitch = width;
+                       *bo_idx = 0;
+               } else if (plane_idx == 1) {
+                       *size = (width * height) >> 2;
+                       *offset = width * height;
+                       *pitch = width >> 1;
+                       *bo_idx = 0;
+               } else if (plane_idx == 2) {
+                       *size = (width * height) >> 2;
+                       *offset = (width * height) + (width * height >> 2);
+                       *pitch = width >> 1;
+                       *bo_idx = 0;
+               } else {
+                       return TBM_ERROR_INVALID_PARAMETER;
+               }
+               return TBM_ERROR_NONE;
+       default:
+               return TBM_ERROR_INVALID_PARAMETER;
+       }
+}
+
+static tbm_backend_bo_data *
+tbm_vigs_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size,
+                                       tbm_bo_memory_type flags, tbm_error_e *error)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
+       tbm_bo_vigs bo_vigs;
+       struct vigs_drm_device *drm_dev;
+       struct vigs_drm_surface *sfc;
+       uint32_t width = 2048, height;
+       int ret;
+       char buf[STRERR_BUFSIZE];
+
+       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
+               TBM_ERR("bufmgr_data is null\n");
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       drm_dev = bufmgr_vigs->drm_dev;
+
+       height = ((uint32_t) size + (width * 4) - 1) / (width * 4);
+
+       ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
+       if (ret != 0) {
+               TBM_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs));
+       if (!bo_vigs) {
+               TBM_ERR("fail to allocate the bo_vigs private\n");
+               vigs_drm_gem_unref(&sfc->gem);
+               if (error)
+                       *error = TBM_ERROR_OUT_OF_MEMORY;
+               return NULL;
+       }
+       bo_vigs->bufmgr_vigs = bufmgr_vigs;
+       bo_vigs->sfc = sfc;
+
+       TBM_DBG("size = %d, flags = 0x%X", size, flags);
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return (tbm_backend_bo_data *)bo_vigs;
+}
+
+static tbm_backend_bo_data *
+tbm_bufmgr_vigs_alloc_bo_with_format(tbm_backend_bufmgr_data *bufmgr_data, int format,  int bo_idx,
+                                                               int width, int height, tbm_bo_memory_type flags, tbm_error_e *error)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
+       tbm_bo_vigs bo_vigs;
+       struct vigs_drm_device *drm_dev;
+       struct vigs_drm_surface *sfc;
+       int ret;
+       char buf[STRERR_BUFSIZE];
+
+       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
+               TBM_ERR("bufmgr_data is null\n");
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       if (bo_idx != 0) {
+               TBM_ERR("Not supported bo idx");
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       drm_dev = bufmgr_vigs->drm_dev;
+
+       switch (format) {
+       case TBM_FORMAT_RGB888:
+               ret = vigs_drm_surface_create(drm_dev, width, height, width * 3, vigs_drm_surface_bgra8888, 0, &sfc);
+               break;
+       case TBM_FORMAT_XRGB8888:
+       case TBM_FORMAT_XBGR8888:
+               ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
+               break;
+       case TBM_FORMAT_ARGB8888:
+       case TBM_FORMAT_RGBA8888:
+               ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
+               break;
+       case TBM_FORMAT_NV21:
+               ret = vigs_drm_surface_create(drm_dev, width, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc);
+               break;
+       case TBM_FORMAT_NV61:
+               ret = vigs_drm_surface_create(drm_dev, width, height * 2, width, vigs_drm_surface_bgra8888, 0, &sfc);
+               break;
+       case TBM_FORMAT_YUV420:
+               ret = vigs_drm_surface_create(drm_dev, width >> 2, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc);
+               break;
+       default:
+               TBM_ERR("Not supported format");
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       if (ret != 0) {
+               TBM_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs));
+       if (!bo_vigs) {
+               TBM_ERR("fail to allocate the bo_vigs private\n");
+               vigs_drm_gem_unref(&sfc->gem);
+               if (error)
+                       *error = TBM_ERROR_OUT_OF_MEMORY;
+               return NULL;
+       }
+       bo_vigs->bufmgr_vigs = bufmgr_vigs;
+       bo_vigs->sfc = sfc;
+
+       TBM_DBG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d",
+                       width, height, format, flags, bo_idx);
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return (tbm_backend_bo_data *)bo_vigs;
+}
+
+static tbm_backend_bo_data *
+tbm_vigs_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
+       tbm_bo_vigs bo_vigs;
+       struct vigs_drm_device *drm_dev;
+       struct vigs_drm_surface *sfc;
+       int ret;
+       char buf[STRERR_BUFSIZE];
+
+       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
+               TBM_ERR("bufmgr_data is null\n");
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       drm_dev = bufmgr_vigs->drm_dev;
+
+       ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc);
+       if (ret != 0) {
+               TBM_ERR("vigs_drm_prime_import_fd failed for key %d: %s",
+                       key, strerror_r(errno, buf, STRERR_BUFSIZE));
+               if (error)
+                       *error = TBM_ERROR_INVALID_OPERATION;
+               return NULL;
+       }
+
+       bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs));
+       if (!bo_vigs) {
+               TBM_ERR("fail to allocate the bo_vigs private\n");
+               vigs_drm_gem_unref(&sfc->gem);
+               if (error)
+                       *error = TBM_ERROR_OUT_OF_MEMORY;
+               return NULL;
+       }
+       bo_vigs->bufmgr_vigs = bufmgr_vigs;
+       bo_vigs->sfc = sfc;
+
+       TBM_DBG("bo_vigs = %p, key = %u handle = %u", bo_vigs, key, sfc->gem.handle);
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return (tbm_backend_bo_data *)bo_vigs;
+}
+
+static tbm_backend_bo_data *
+tbm_vigs_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
+       tbm_bo_vigs bo_vigs;
+       struct vigs_drm_device *drm_dev;
+       int ret;
+       struct vigs_drm_surface *sfc;
+       char buf[STRERR_BUFSIZE];
+
+       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
+               TBM_ERR("bufmgr_data is null\n");
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       drm_dev = bufmgr_vigs->drm_dev;
+
+       ret = vigs_drm_surface_open(drm_dev, key, &sfc);
+       if (ret != 0) {
+               TBM_ERR("vigs_drm_surface_open failed for key %u: %s",
+                       key, strerror_r(errno, buf, STRERR_BUFSIZE));
+               if (error)
+                       *error = TBM_ERROR_INVALID_OPERATION;
+               return NULL;
+       }
+
+       bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs));
+       if (!bo_vigs) {
+               TBM_ERR("fail to allocate the bo_vigs private\n");
+               vigs_drm_gem_unref(&sfc->gem);
+               if (error)
+                       *error = TBM_ERROR_OUT_OF_MEMORY;
+               return NULL;
+       }
+       bo_vigs->bufmgr_vigs = bufmgr_vigs;
+       bo_vigs->sfc = sfc;
+
+       TBM_DBG("bo_vigs = %p, key = %u handle = %u", bo_vigs, key, sfc->gem.handle);
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return (tbm_backend_bo_data *)bo_vigs;
+}
+
+static void
+tbm_vigs_bo_free(tbm_backend_bo_data *bo_data)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+       struct vigs_drm_surface *sfc;
+
+       if (!bo_data)
+               return;
+
+       TBM_DBG("bo_vigs = %p", bo_vigs);
+
+       sfc = bo_vigs->sfc;
+
+       vigs_drm_gem_unref(&sfc->gem);
+}
+
+static int
+tbm_vigs_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+       struct vigs_drm_surface *sfc;
+
+       if (!bo_vigs || !bo_vigs->sfc) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return 0;
+       }
+
+       TBM_DBG("bo_vigs = %p", bo_vigs);
+
+       sfc = bo_vigs->sfc;
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return sfc->gem.size;
+}
+
+static tbm_bo_memory_type
+tbm_vigs_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+
+       if (!bo_vigs || !bo_vigs->sfc) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return TBM_BO_DEFAULT;
+       }
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return TBM_BO_DEFAULT;
+}
+
+static tbm_bo_handle
+tbm_vigs_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+       struct vigs_drm_surface *sfc;
+       tbm_bo_handle handle;
+
+       if (!bo_vigs || !bo_vigs->sfc) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return (tbm_bo_handle) NULL;
+       }
+
+       sfc = bo_vigs->sfc;
+
+       TBM_DBG("bo_vigs = %p, device = %d", bo_vigs, device);
+
+       handle = get_tbm_bo_handle(sfc, device);
+       if (!handle.ptr) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return handle;
+       }
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return handle;
+}
+
+static tbm_bo_handle
+tbm_vigs_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device,
+                               tbm_bo_access_option opt, tbm_error_e *error)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+       struct vigs_drm_surface *sfc;
+       tbm_bo_handle handle;
+       uint32_t saf = 0;
+
+       if (!bo_vigs || !bo_vigs->sfc) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return (tbm_bo_handle) NULL;
+       }
+
+       sfc = bo_vigs->sfc;
+
+       TBM_DBG("bo_vigs = %p, device = %d, opt = %d", bo_vigs, device, opt);
+
+       handle = get_tbm_bo_handle(sfc, device);
+       if (!handle.ptr) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return handle;
+       }
+
+       if ((opt & TBM_OPTION_READ) != 0)
+               saf |= VIGS_DRM_SAF_READ;
+
+       if ((opt & TBM_OPTION_WRITE) != 0)
+               saf |= VIGS_DRM_SAF_WRITE;
+
+       vigs_drm_surface_start_access(sfc, saf);
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return handle;
+}
+
+static tbm_error_e
+tbm_vigs_bo_unmap(tbm_backend_bo_data *bo_data)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+       struct vigs_drm_surface *sfc;
+
+       if (!bo_vigs || !bo_vigs->sfc)
+               return TBM_ERROR_INVALID_PARAMETER;
+
+       sfc = bo_vigs->sfc;
+
+       TBM_DBG("bo_vigs = %p", bo_vigs);
+
+       vigs_drm_surface_end_access(sfc, 1);
+
+       return TBM_ERROR_NONE;
+}
+
+static tbm_error_e
+tbm_vigs_bo_lock(tbm_backend_bo_data *bo_data, tbm_bo_device_type device,
+                               tbm_bo_access_option opt)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+
+       if (!bo_vigs || !bo_vigs->sfc)
+               return TBM_ERROR_INVALID_PARAMETER;
+
+       TBM_DBG("bo_vigs = %p", bo_vigs);
+
+       return TBM_ERROR_NONE;
+}
+
+static tbm_error_e
+tbm_vigs_bo_unlock(tbm_backend_bo_data *bo_data)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+
+       if (!bo_vigs || !bo_vigs->sfc)
+               return TBM_ERROR_INVALID_PARAMETER;
+
+       TBM_DBG("bo_vigs = %p", bo_data);
+
+       return TBM_ERROR_NONE;
+}
+
+tbm_fd
+tbm_vigs_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+       tbm_bufmgr_vigs bufmgr_vigs;
+       struct vigs_drm_surface *sfc;
+       struct vigs_drm_device *drm_dev;
+       int ret, fd = 0;
+       char buf[STRERR_BUFSIZE];
+
+       if (!bo_vigs || !bo_vigs->sfc) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return -1;
+       }
+
+       bufmgr_vigs = bo_vigs->bufmgr_vigs;
+       if (!bufmgr_vigs || !bufmgr_vigs->drm_dev) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return -1;
+       }
+
+       drm_dev = bufmgr_vigs->drm_dev;
+       sfc = bo_vigs->sfc;
+
+       ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd);
+       if (ret != 0) {
+               TBM_ERR("vigs_drm_prime_export_fd failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+               if (error)
+                       *error = TBM_ERROR_INVALID_OPERATION;
+               return -1;
+       }
+
+       TBM_DBG("    bo_vigs:%p, gem:%d(%d)\n", bo_vigs, sfc->gem);
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return (tbm_fd)fd;
+}
+
+static tbm_key
+tbm_vigs_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+{
+       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
+       struct vigs_drm_surface *sfc;
+       int ret;
+       char buf[STRERR_BUFSIZE];
+
+       if (!bo_vigs || !bo_vigs->sfc) {
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return 0;
+       }
+
+       sfc = bo_vigs->sfc;
+
+       ret = vigs_drm_gem_get_name(&sfc->gem);
+       if (ret != 0) {
+               TBM_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+               if (error)
+                       *error = TBM_ERROR_INVALID_OPERATION;
+               return 0;
+       }
+
+       TBM_DBG("    bo_vigs:%p, gem:%d(%d)\n", bo_vigs, sfc->gem);
+
+       if (error)
+               *error = TBM_ERROR_NONE;
+
+       return (tbm_key)sfc->gem.name;
+}
+
+static void
+tbm_vigs_deinit(tbm_backend_bufmgr_data *bufmgr_data)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
+       struct vigs_drm_device *drm_dev;
+       tbm_error_e error;
+       tbm_bufmgr bufmgr;
+
+       TBM_DBG("enter");
+
+       if (!bufmgr_vigs)
+               return;
+
+       drm_dev = bufmgr_vigs->drm_dev;
+       if (!drm_dev)
+               return;
+
+       bufmgr = bufmgr_vigs->bufmgr;
+       if (!bufmgr)
+               return;
+
+       if (tbm_backend_bufmgr_query_display_server(bufmgr, &error)) {
+               tbm_drm_helper_wl_auth_server_deinit();
+               tbm_drm_helper_unset_tbm_master_fd();
+       }
+
+       close(drm_dev->fd);
+
+       vigs_drm_device_destroy(drm_dev);
+
+       g_drm_dev = NULL;
+}
+
+static tbm_backend_bufmgr_data *
+tbm_vigs_init(tbm_bufmgr bufmgr, tbm_error_e *error)
+{
+       tbm_bufmgr_vigs bufmgr_vigs = NULL;
+       tbm_backend_bufmgr_func *bufmgr_func = NULL;
+       tbm_backend_bo_func *bo_func = NULL;
+       int ret = 0;
+       struct vigs_drm_device *drm_dev = NULL;
+       int drm_fd = -1;
+       tbm_error_e err;
+       char buf[STRERR_BUFSIZE];
+       int set_master = 0;
+
+       TBM_DBG("enter");
+
+       if (!bufmgr) {
+               TBM_ERR("bufmgr is null.\n");
+               if (error)
+                       *error = TBM_ERROR_INVALID_PARAMETER;
+               return NULL;
+       }
+
+       bufmgr_vigs = calloc(1, sizeof(struct _tbm_bufmgr_vigs));
+       if (!bufmgr_vigs) {
+               TBM_ERR("fail to alloc bufmgr_vigs!\n");
+               if (error)
+                       *error = TBM_ERROR_OUT_OF_MEMORY;
+               return NULL;
+       }
+
+       /* check the master_fd which already had opened */
+       drm_fd = tbm_drm_helper_get_master_fd();
+       if (drm_fd < 0) {
+               drm_fd = _tbm_vigs_open_drm();
+               if (drm_fd < 0) {
+                       TBM_ERR("fail to open drm!\n");
+                       if (error)
+                               *error = TBM_ERROR_INVALID_OPERATION;
+                       goto fail_open_drm;
+               }
+
+               if (drmIsMaster(drm_fd)) {
+                       tbm_drm_helper_set_tbm_master_fd(drm_fd);
+                       set_master = 1;
+                       TBM_INFO("This is Master FD(%d) from open_drm.", drm_fd);
+               } else {
+                       /* close the fd and get the authenticated fd from the master fd */
+                       close(drm_fd);
+                       drm_fd = -1;
+
+                       /* get the authenticated drm fd from the master fd */
+                       if (!tbm_drm_helper_get_auth_info(&(drm_fd), NULL, NULL)) {
+                               TBM_ERR("fail to get auth drm info!\n");
+                               if (error)
+                                       *error = TBM_ERROR_INVALID_OPERATION;
+                               goto fail_get_auth_info;
+                       }
+                       TBM_INFO("This is Authenticated FD(%d)", drm_fd);
+               }
+       } else {
+               TBM_INFO("This is Master FD from tbm_drm_helper_get_master_fd(%d)", drm_fd);
+       }
+       tbm_drm_helper_set_fd(drm_fd);
+
+       ret = vigs_drm_device_create(drm_fd, &drm_dev);
+       if (ret != 0) {
+               TBM_ERR("vigs_drm_device_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+               if (error)
+                       *error = TBM_ERROR_INVALID_OPERATION;
+               goto fail_create_vigs_drm_device;
+       }
+       bufmgr_vigs->drm_dev = drm_dev;
+       g_drm_dev = drm_dev;
+
+       /* alloc and register bufmgr_funcs */
+       bufmgr_func = tbm_backend_bufmgr_alloc_bufmgr_func(bufmgr, &err);
+       if (!bufmgr_func) {
+               TBM_ERR("fail to alloc bufmgr_func! err(%d)\n", err);
+               if (error)
+                       *error = TBM_ERROR_OUT_OF_MEMORY;
+               goto fail_alloc_bufmgr_func;
+       }
+
+       bufmgr_func->bufmgr_get_capabilities = tbm_vigs_bufmgr_get_capabilities;
+       bufmgr_func->bufmgr_bind_native_display = tbm_vigs_bufmgr_bind_native_display;
+       bufmgr_func->bufmgr_get_supported_formats = tbm_vigs_bufmgr_get_supported_formats;
+       bufmgr_func->bufmgr_get_plane_data = tbm_vigs_bufmgr_get_plane_data;
+       bufmgr_func->bufmgr_alloc_bo = tbm_vigs_bufmgr_alloc_bo;
+       bufmgr_func->bufmgr_alloc_bo_with_format = tbm_bufmgr_vigs_alloc_bo_with_format;
+       bufmgr_func->bufmgr_import_fd = tbm_vigs_bufmgr_import_fd;
+       bufmgr_func->bufmgr_import_key = tbm_vigs_bufmgr_import_key;
+
+       err = tbm_backend_bufmgr_register_bufmgr_func(bufmgr, bufmgr_func);
+       if (err != TBM_ERROR_NONE) {
+               TBM_ERR("fail to register bufmgr_func! err(%d)\n", err);
+               if (error)
+                       *error = TBM_ERROR_INVALID_OPERATION;
+               goto fail_register_bufmgr_func;
+       }
+       bufmgr_vigs->bufmgr_func = bufmgr_func;
+
+       /* alloc and register bo_funcs */
+       bo_func = tbm_backend_bufmgr_alloc_bo_func(bufmgr, &err);
+       if (!bo_func) {
+               TBM_ERR("fail to alloc bo_func! err(%d)\n", err);
+               if (error)
+                       *error = TBM_ERROR_OUT_OF_MEMORY;
+               goto fail_alloc_bo_func;
+       }
+
+       bo_func->bo_free = tbm_vigs_bo_free;
+       bo_func->bo_get_size = tbm_vigs_bo_get_size;
+       bo_func->bo_get_memory_types = tbm_vigs_bo_get_memory_type;
+       bo_func->bo_get_handle = tbm_vigs_bo_get_handle;
+       bo_func->bo_map = tbm_vigs_bo_map;
+       bo_func->bo_unmap = tbm_vigs_bo_unmap;
+       bo_func->bo_lock = tbm_vigs_bo_lock;
+       bo_func->bo_unlock = tbm_vigs_bo_unlock;
+       bo_func->bo_export_fd = tbm_vigs_bo_export_fd;
+       bo_func->bo_export_key = tbm_vigs_bo_export_key;
+
+       err = tbm_backend_bufmgr_register_bo_func(bufmgr, bo_func);
+       if (err != TBM_ERROR_NONE) {
+               TBM_ERR("fail to register bo_func! err(%d)\n", err);
+               if (error)
+                       *error = TBM_ERROR_INVALID_OPERATION;
+               goto fail_register_bo_func;
+       }
+       bufmgr_vigs->bo_func = bo_func;
+
+       TBM_INFO("initialized");
+
+       return (tbm_backend_bufmgr_data *)bufmgr_vigs;
+
+fail_register_bo_func:
+       tbm_backend_bufmgr_free_bo_func(bufmgr, bo_func);
+fail_alloc_bo_func:
+fail_register_bufmgr_func:
+       tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_func);
+fail_alloc_bufmgr_func:
+       vigs_drm_device_destroy(drm_dev);
+fail_create_vigs_drm_device:
+       if (set_master)
+               tbm_drm_helper_unset_tbm_master_fd();
+       if (drm_fd >= 0)
+               close(drm_fd);
+fail_get_auth_info:
+fail_open_drm:
+       if (bufmgr_vigs)
+               free(bufmgr_vigs);
+       g_drm_dev = NULL;
+       return NULL;
+}
+
+tbm_backend_module tbm_backend_module_data = {
+       "vigs",
+       "Samsung",
+       TBM_BACKEND_ABI_VERSION_3_0,
+       tbm_vigs_init,
+       tbm_vigs_deinit
+};
+
+struct vigs_drm_device *
+tbm_vigs_get_drm_dev(void)
+{
+       return g_drm_dev;
+}
diff --git a/src/libtbm-vigs/tbm_vigs.h b/src/libtbm-vigs/tbm_vigs.h
new file mode 100644 (file)
index 0000000..eefeacb
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * libtbm-vigs header
+ *
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact :
+ * SooChan Lim <sc1.lim@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, sublicense, 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 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+#ifndef _TBM_VIGS_LOG_H_
+#define _TBM_VIGS_LOG_H_
+
+#include "vigs.h"
+
+struct vigs_drm_device *tbm_vigs_get_drm_dev(void);
+
+#endif
diff --git a/src/tbm_bufmgr_vigs.c b/src/tbm_bufmgr_vigs.c
deleted file mode 100755 (executable)
index d2b6d0b..0000000
+++ /dev/null
@@ -1,962 +0,0 @@
-/*
- * buffer manager for libtbm-vigs
- *
- * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact :
- * Stanislav Vorobiov <s.vorobiov@samsung.com>
- * Jinhyung Jo <jinhyung.jo@samsung.com>
- * Sangho Park <sangho1206.park@samsung.com>
- * YeongKyoon Lee <yeongkyoon.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, sublicense, 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 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS 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.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "vigs.h"
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <xf86drm.h>
-#include <tbm_backend.h>
-#include <tbm_drm_helper.h>
-#include <tbm_log.h>
-
-#define STRERR_BUFSIZE 128
-
-#define VIGS_DRM_NAME "vigs"
-
-/* global singleton drm_dev. this is shared with yagl. */
-struct vigs_drm_device *g_drm_dev = NULL;
-
-static uint32_t tbm_bufmgr_vigs_color_format_list[] = {
-       TBM_FORMAT_RGB888,
-       TBM_FORMAT_ARGB8888,
-       TBM_FORMAT_RGBA8888,
-       TBM_FORMAT_XRGB8888,
-       TBM_FORMAT_XBGR8888,
-       TBM_FORMAT_NV21,
-       TBM_FORMAT_NV61,
-       TBM_FORMAT_YUV420,
-};
-
-typedef struct _tbm_bufmgr_vigs *tbm_bufmgr_vigs;
-typedef struct _tbm_bo_vigs *tbm_bo_vigs;
-
-/* tbm buffor object for vigs */
-struct _tbm_bo_vigs {
-       struct vigs_drm_surface *sfc;
-
-       tbm_bufmgr_vigs bufmgr_vigs;
-};
-
-/* tbm bufmgr private for vigs */
-struct _tbm_bufmgr_vigs {
-       struct vigs_drm_device *drm_dev;
-
-       tbm_backend_bufmgr_func *bufmgr_func;
-       tbm_backend_bo_func *bo_func;
-
-       tbm_bufmgr bufmgr;
-};
-
-static int _tbm_vigs_open_drm(void)
-{
-       int fd = -1;
-
-       fd = drmOpen(VIGS_DRM_NAME, NULL);
-       if (fd < 0) {
-               TBM_ERR("open vigs drm device failed");
-               return -1;
-       }
-
-       return fd;
-}
-
-static tbm_bo_handle get_tbm_bo_handle(struct vigs_drm_surface *sfc, int device)
-{
-       tbm_bo_handle bo_handle;
-       int ret;
-       struct vigs_drm_gem *gem = &sfc->gem;
-       char buf[STRERR_BUFSIZE];
-
-       memset(&bo_handle, 0, sizeof(bo_handle));
-
-       switch (device) {
-       case TBM_DEVICE_DEFAULT:
-       case TBM_DEVICE_2D:
-               bo_handle.u32 = gem->handle;
-               break;
-       case TBM_DEVICE_CPU:
-               ret = vigs_drm_gem_map(gem, 1);
-
-               if (ret == 0)
-                       bo_handle.ptr = gem->vaddr;
-               else
-                       TBM_ERR("vigs_drm_gem_map failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
-
-               break;
-       case TBM_DEVICE_3D:
-               bo_handle.ptr = (void *)sfc;
-               break;
-       case TBM_DEVICE_MM:
-               TBM_ERR("TBM_DEVICE_MM not supported");
-               break;
-       default:
-               TBM_ERR("%d not supported", device);
-               break;
-       }
-
-       return bo_handle;
-}
-
-static tbm_bufmgr_capability
-tbm_vigs_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error)
-{
-       tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE;
-
-       capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD;
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return capabilities;
-}
-
-static tbm_error_e
-tbm_vigs_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
-       struct vigs_drm_device *drm_dev;
-       char *device_name;
-       int ret = 0;
-
-       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
-               TBM_ERR("bufmgr_data is null\n");
-               return TBM_ERROR_INVALID_PARAMETER;
-       }
-
-       drm_dev = bufmgr_vigs->drm_dev;
-
-       device_name = drmGetDeviceNameFromFd(drm_dev->fd);
-       if (!device_name) {
-               TBM_ERR("drmGetDeviceNameFromFd failed");
-               return TBM_ERROR_INVALID_OPERATION;
-       }
-
-       ret = tbm_drm_helper_wl_auth_server_init(native_display, drm_dev->fd, device_name, 0);
-       if (!ret) {
-               TBM_ERR("tbm_drm_helper_wl_auth_server_init failed");
-               free(device_name);
-               return TBM_ERROR_INVALID_OPERATION;
-       }
-
-       free(device_name);
-
-       return TBM_ERROR_NONE;
-}
-
-static tbm_error_e
-tbm_vigs_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data,
-                                                       uint32_t **formats, uint32_t *num)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
-       uint32_t *color_formats;
-
-       if (!bufmgr_vigs)
-               return TBM_ERROR_INVALID_PARAMETER;
-
-       color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_vigs_color_format_list));
-       if (!color_formats)
-               return TBM_ERROR_OUT_OF_MEMORY;
-
-       memcpy(color_formats, tbm_bufmgr_vigs_color_format_list, sizeof(tbm_bufmgr_vigs_color_format_list));
-
-       *formats = color_formats;
-       *num = sizeof(tbm_bufmgr_vigs_color_format_list) / sizeof(tbm_bufmgr_vigs_color_format_list[0]);
-
-       return TBM_ERROR_NONE;
-}
-
-static tbm_error_e
-tbm_vigs_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data,
-                                                        tbm_format format, int plane_idx, int width,
-                                                        int height, uint32_t * size, uint32_t * offset,
-                                                        uint32_t * pitch, int *bo_idx)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
-
-       *size = 0;
-       *offset = 0;
-       *pitch = 0;
-       *bo_idx = 0;
-
-       if (!bufmgr_vigs)
-               return TBM_ERROR_INVALID_PARAMETER;
-
-       switch (format) {
-       case TBM_FORMAT_RGB888:
-               *size = width * height * 3;
-               *offset = 0;
-               *pitch = width * 3;
-               *bo_idx = 0;
-               return TBM_ERROR_NONE;
-       case TBM_FORMAT_XRGB8888:
-       case TBM_FORMAT_XBGR8888:
-       case TBM_FORMAT_ARGB8888:
-       case TBM_FORMAT_RGBA8888:
-               *size = width * height * 4;
-               *offset = 0;
-               *pitch = width * 4;
-               *bo_idx = 0;
-               return TBM_ERROR_NONE;
-       case TBM_FORMAT_NV21:
-               if (plane_idx == 0) {
-                       *size = width * height;
-                       *offset = 0;
-                       *pitch = width;
-                       *bo_idx = 0;
-               } else if (plane_idx == 1) {
-                       *size = width * (height >> 1);
-                       *offset = width * height;
-                       *pitch = width;
-                       *bo_idx = 0;
-               } else {
-                       return TBM_ERROR_INVALID_PARAMETER;
-               }
-               return TBM_ERROR_NONE;
-       case TBM_FORMAT_NV61:
-               if (plane_idx == 0) {
-                       *size = width * height;
-                       *offset = 0;
-                       *pitch = width;
-                       *bo_idx = 0;
-               } else if (plane_idx == 1) {
-                       *size = width * height;
-                       *offset = width * height;
-                       *pitch = width;
-                       *bo_idx = 0;
-               } else {
-                       return TBM_ERROR_INVALID_PARAMETER;
-               }
-               return TBM_ERROR_NONE;
-       case TBM_FORMAT_YUV420:
-               if (plane_idx == 0) {
-                       *size = width * height;
-                       *offset = 0;
-                       *pitch = width;
-                       *bo_idx = 0;
-               } else if (plane_idx == 1) {
-                       *size = (width * height) >> 2;
-                       *offset = width * height;
-                       *pitch = width >> 1;
-                       *bo_idx = 0;
-               } else if (plane_idx == 2) {
-                       *size = (width * height) >> 2;
-                       *offset = (width * height) + (width * height >> 2);
-                       *pitch = width >> 1;
-                       *bo_idx = 0;
-               } else {
-                       return TBM_ERROR_INVALID_PARAMETER;
-               }
-               return TBM_ERROR_NONE;
-       default:
-               return TBM_ERROR_INVALID_PARAMETER;
-       }
-}
-
-static tbm_backend_bo_data *
-tbm_vigs_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size,
-                                       tbm_bo_memory_type flags, tbm_error_e *error)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
-       tbm_bo_vigs bo_vigs;
-       struct vigs_drm_device *drm_dev;
-       struct vigs_drm_surface *sfc;
-       uint32_t width = 2048, height;
-       int ret;
-       char buf[STRERR_BUFSIZE];
-
-       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
-               TBM_ERR("bufmgr_data is null\n");
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       drm_dev = bufmgr_vigs->drm_dev;
-
-       height = ((uint32_t) size + (width * 4) - 1) / (width * 4);
-
-       ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
-       if (ret != 0) {
-               TBM_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs));
-       if (!bo_vigs) {
-               TBM_ERR("fail to allocate the bo_vigs private\n");
-               vigs_drm_gem_unref(&sfc->gem);
-               if (error)
-                       *error = TBM_ERROR_OUT_OF_MEMORY;
-               return NULL;
-       }
-       bo_vigs->bufmgr_vigs = bufmgr_vigs;
-       bo_vigs->sfc = sfc;
-
-       TBM_DBG("size = %d, flags = 0x%X", size, flags);
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return (tbm_backend_bo_data *)bo_vigs;
-}
-
-static tbm_backend_bo_data *
-tbm_bufmgr_vigs_alloc_bo_with_format(tbm_backend_bufmgr_data *bufmgr_data, int format,  int bo_idx,
-                                                               int width, int height, tbm_bo_memory_type flags, tbm_error_e *error)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
-       tbm_bo_vigs bo_vigs;
-       struct vigs_drm_device *drm_dev;
-       struct vigs_drm_surface *sfc;
-       int ret;
-       char buf[STRERR_BUFSIZE];
-
-       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
-               TBM_ERR("bufmgr_data is null\n");
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       if (bo_idx != 0) {
-               TBM_ERR("Not supported bo idx");
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       drm_dev = bufmgr_vigs->drm_dev;
-
-       switch (format) {
-       case TBM_FORMAT_RGB888:
-               ret = vigs_drm_surface_create(drm_dev, width, height, width * 3, vigs_drm_surface_bgra8888, 0, &sfc);
-               break;
-       case TBM_FORMAT_XRGB8888:
-       case TBM_FORMAT_XBGR8888:
-               ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
-               break;
-       case TBM_FORMAT_ARGB8888:
-       case TBM_FORMAT_RGBA8888:
-               ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
-               break;
-       case TBM_FORMAT_NV21:
-               ret = vigs_drm_surface_create(drm_dev, width, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc);
-               break;
-       case TBM_FORMAT_NV61:
-               ret = vigs_drm_surface_create(drm_dev, width, height * 2, width, vigs_drm_surface_bgra8888, 0, &sfc);
-               break;
-       case TBM_FORMAT_YUV420:
-               ret = vigs_drm_surface_create(drm_dev, width >> 2, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc);
-               break;
-       default:
-               TBM_ERR("Not supported format");
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       if (ret != 0) {
-               TBM_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs));
-       if (!bo_vigs) {
-               TBM_ERR("fail to allocate the bo_vigs private\n");
-               vigs_drm_gem_unref(&sfc->gem);
-               if (error)
-                       *error = TBM_ERROR_OUT_OF_MEMORY;
-               return NULL;
-       }
-       bo_vigs->bufmgr_vigs = bufmgr_vigs;
-       bo_vigs->sfc = sfc;
-
-       TBM_DBG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d",
-                       width, height, format, flags, bo_idx);
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return (tbm_backend_bo_data *)bo_vigs;
-}
-
-static tbm_backend_bo_data *
-tbm_vigs_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
-       tbm_bo_vigs bo_vigs;
-       struct vigs_drm_device *drm_dev;
-       struct vigs_drm_surface *sfc;
-       int ret;
-       char buf[STRERR_BUFSIZE];
-
-       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
-               TBM_ERR("bufmgr_data is null\n");
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       drm_dev = bufmgr_vigs->drm_dev;
-
-       ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc);
-       if (ret != 0) {
-               TBM_ERR("vigs_drm_prime_import_fd failed for key %d: %s",
-                       key, strerror_r(errno, buf, STRERR_BUFSIZE));
-               if (error)
-                       *error = TBM_ERROR_INVALID_OPERATION;
-               return NULL;
-       }
-
-       bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs));
-       if (!bo_vigs) {
-               TBM_ERR("fail to allocate the bo_vigs private\n");
-               vigs_drm_gem_unref(&sfc->gem);
-               if (error)
-                       *error = TBM_ERROR_OUT_OF_MEMORY;
-               return NULL;
-       }
-       bo_vigs->bufmgr_vigs = bufmgr_vigs;
-       bo_vigs->sfc = sfc;
-
-       TBM_DBG("bo_vigs = %p, key = %u handle = %u", bo_vigs, key, sfc->gem.handle);
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return (tbm_backend_bo_data *)bo_vigs;
-}
-
-static tbm_backend_bo_data *
-tbm_vigs_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
-       tbm_bo_vigs bo_vigs;
-       struct vigs_drm_device *drm_dev;
-       int ret;
-       struct vigs_drm_surface *sfc;
-       char buf[STRERR_BUFSIZE];
-
-       if (bufmgr_vigs == NULL || bufmgr_vigs->drm_dev ==  NULL) {
-               TBM_ERR("bufmgr_data is null\n");
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       drm_dev = bufmgr_vigs->drm_dev;
-
-       ret = vigs_drm_surface_open(drm_dev, key, &sfc);
-       if (ret != 0) {
-               TBM_ERR("vigs_drm_surface_open failed for key %u: %s",
-                       key, strerror_r(errno, buf, STRERR_BUFSIZE));
-               if (error)
-                       *error = TBM_ERROR_INVALID_OPERATION;
-               return NULL;
-       }
-
-       bo_vigs = calloc(1, sizeof(struct _tbm_bo_vigs));
-       if (!bo_vigs) {
-               TBM_ERR("fail to allocate the bo_vigs private\n");
-               vigs_drm_gem_unref(&sfc->gem);
-               if (error)
-                       *error = TBM_ERROR_OUT_OF_MEMORY;
-               return NULL;
-       }
-       bo_vigs->bufmgr_vigs = bufmgr_vigs;
-       bo_vigs->sfc = sfc;
-
-       TBM_DBG("bo_vigs = %p, key = %u handle = %u", bo_vigs, key, sfc->gem.handle);
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return (tbm_backend_bo_data *)bo_vigs;
-}
-
-static void
-tbm_vigs_bo_free(tbm_backend_bo_data *bo_data)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-       struct vigs_drm_surface *sfc;
-
-       if (!bo_data)
-               return;
-
-       TBM_DBG("bo_vigs = %p", bo_vigs);
-
-       sfc = bo_vigs->sfc;
-
-       vigs_drm_gem_unref(&sfc->gem);
-}
-
-static int
-tbm_vigs_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-       struct vigs_drm_surface *sfc;
-
-       if (!bo_vigs || !bo_vigs->sfc) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return 0;
-       }
-
-       TBM_DBG("bo_vigs = %p", bo_vigs);
-
-       sfc = bo_vigs->sfc;
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return sfc->gem.size;
-}
-
-static tbm_bo_memory_type
-tbm_vigs_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-
-       if (!bo_vigs || !bo_vigs->sfc) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return TBM_BO_DEFAULT;
-       }
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return TBM_BO_DEFAULT;
-}
-
-static tbm_bo_handle
-tbm_vigs_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-       struct vigs_drm_surface *sfc;
-       tbm_bo_handle handle;
-
-       if (!bo_vigs || !bo_vigs->sfc) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return (tbm_bo_handle) NULL;
-       }
-
-       sfc = bo_vigs->sfc;
-
-       TBM_DBG("bo_vigs = %p, device = %d", bo_vigs, device);
-
-       handle = get_tbm_bo_handle(sfc, device);
-       if (!handle.ptr) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return handle;
-       }
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return handle;
-}
-
-static tbm_bo_handle
-tbm_vigs_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device,
-                               tbm_bo_access_option opt, tbm_error_e *error)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-       struct vigs_drm_surface *sfc;
-       tbm_bo_handle handle;
-       uint32_t saf = 0;
-
-       if (!bo_vigs || !bo_vigs->sfc) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return (tbm_bo_handle) NULL;
-       }
-
-       sfc = bo_vigs->sfc;
-
-       TBM_DBG("bo_vigs = %p, device = %d, opt = %d", bo_vigs, device, opt);
-
-       handle = get_tbm_bo_handle(sfc, device);
-       if (!handle.ptr) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return handle;
-       }
-
-       if ((opt & TBM_OPTION_READ) != 0)
-               saf |= VIGS_DRM_SAF_READ;
-
-       if ((opt & TBM_OPTION_WRITE) != 0)
-               saf |= VIGS_DRM_SAF_WRITE;
-
-       vigs_drm_surface_start_access(sfc, saf);
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return handle;
-}
-
-static tbm_error_e
-tbm_vigs_bo_unmap(tbm_backend_bo_data *bo_data)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-       struct vigs_drm_surface *sfc;
-
-       if (!bo_vigs || !bo_vigs->sfc)
-               return TBM_ERROR_INVALID_PARAMETER;
-
-       sfc = bo_vigs->sfc;
-
-       TBM_DBG("bo_vigs = %p", bo_vigs);
-
-       vigs_drm_surface_end_access(sfc, 1);
-
-       return TBM_ERROR_NONE;
-}
-
-static tbm_error_e
-tbm_vigs_bo_lock(tbm_backend_bo_data *bo_data, tbm_bo_device_type device,
-                               tbm_bo_access_option opt)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-
-       if (!bo_vigs || !bo_vigs->sfc)
-               return TBM_ERROR_INVALID_PARAMETER;
-
-       TBM_DBG("bo_vigs = %p", bo_vigs);
-
-       return TBM_ERROR_NONE;
-}
-
-static tbm_error_e
-tbm_vigs_bo_unlock(tbm_backend_bo_data *bo_data)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-
-       if (!bo_vigs || !bo_vigs->sfc)
-               return TBM_ERROR_INVALID_PARAMETER;
-
-       TBM_DBG("bo_vigs = %p", bo_data);
-
-       return TBM_ERROR_NONE;
-}
-
-tbm_fd
-tbm_vigs_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-       tbm_bufmgr_vigs bufmgr_vigs;
-       struct vigs_drm_surface *sfc;
-       struct vigs_drm_device *drm_dev;
-       int ret, fd = 0;
-       char buf[STRERR_BUFSIZE];
-
-       if (!bo_vigs || !bo_vigs->sfc) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return -1;
-       }
-
-       bufmgr_vigs = bo_vigs->bufmgr_vigs;
-       if (!bufmgr_vigs || !bufmgr_vigs->drm_dev) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return -1;
-       }
-
-       drm_dev = bufmgr_vigs->drm_dev;
-       sfc = bo_vigs->sfc;
-
-       ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd);
-       if (ret != 0) {
-               TBM_ERR("vigs_drm_prime_export_fd failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
-               if (error)
-                       *error = TBM_ERROR_INVALID_OPERATION;
-               return -1;
-       }
-
-       TBM_DBG("    bo_vigs:%p, gem:%d(%d)\n", bo_vigs, sfc->gem);
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return (tbm_fd)fd;
-}
-
-static tbm_key
-tbm_vigs_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
-       tbm_bo_vigs bo_vigs = (tbm_bo_vigs)bo_data;
-       struct vigs_drm_surface *sfc;
-       int ret;
-       char buf[STRERR_BUFSIZE];
-
-       if (!bo_vigs || !bo_vigs->sfc) {
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return 0;
-       }
-
-       sfc = bo_vigs->sfc;
-
-       ret = vigs_drm_gem_get_name(&sfc->gem);
-       if (ret != 0) {
-               TBM_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
-               if (error)
-                       *error = TBM_ERROR_INVALID_OPERATION;
-               return 0;
-       }
-
-       TBM_DBG("    bo_vigs:%p, gem:%d(%d)\n", bo_vigs, sfc->gem);
-
-       if (error)
-               *error = TBM_ERROR_NONE;
-
-       return (tbm_key)sfc->gem.name;
-}
-
-static void
-tbm_vigs_deinit(tbm_backend_bufmgr_data *bufmgr_data)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = (tbm_bufmgr_vigs)bufmgr_data;
-       struct vigs_drm_device *drm_dev;
-       tbm_error_e error;
-       tbm_bufmgr bufmgr;
-
-       TBM_DBG("enter");
-
-       if (!bufmgr_vigs)
-               return;
-
-       drm_dev = bufmgr_vigs->drm_dev;
-       if (!drm_dev)
-               return;
-
-       bufmgr = bufmgr_vigs->bufmgr;
-       if (!bufmgr)
-               return;
-
-       if (tbm_backend_bufmgr_query_display_server(bufmgr, &error)) {
-               tbm_drm_helper_wl_auth_server_deinit();
-               tbm_drm_helper_unset_tbm_master_fd();
-       }
-
-       close(drm_dev->fd);
-
-       vigs_drm_device_destroy(drm_dev);
-
-       g_drm_dev = NULL;
-}
-
-static tbm_backend_bufmgr_data *
-tbm_vigs_init(tbm_bufmgr bufmgr, tbm_error_e *error)
-{
-       tbm_bufmgr_vigs bufmgr_vigs = NULL;
-       tbm_backend_bufmgr_func *bufmgr_func = NULL;
-       tbm_backend_bo_func *bo_func = NULL;
-       int ret = 0;
-       struct vigs_drm_device *drm_dev = NULL;
-       int drm_fd = -1;
-       tbm_error_e err;
-       char buf[STRERR_BUFSIZE];
-       int set_master = 0;
-
-       TBM_DBG("enter");
-
-       if (!bufmgr) {
-               TBM_ERR("bufmgr is null.\n");
-               if (error)
-                       *error = TBM_ERROR_INVALID_PARAMETER;
-               return NULL;
-       }
-
-       bufmgr_vigs = calloc(1, sizeof(struct _tbm_bufmgr_vigs));
-       if (!bufmgr_vigs) {
-               TBM_ERR("fail to alloc bufmgr_vigs!\n");
-               if (error)
-                       *error = TBM_ERROR_OUT_OF_MEMORY;
-               return NULL;
-       }
-
-       /* check the master_fd which already had opened */
-       drm_fd = tbm_drm_helper_get_master_fd();
-       if (drm_fd < 0) {
-               drm_fd = _tbm_vigs_open_drm();
-               if (drm_fd < 0) {
-                       TBM_ERR("fail to open drm!\n");
-                       if (error)
-                               *error = TBM_ERROR_INVALID_OPERATION;
-                       goto fail_open_drm;
-               }
-
-               if (drmIsMaster(drm_fd)) {
-                       tbm_drm_helper_set_tbm_master_fd(drm_fd);
-                       set_master = 1;
-                       TBM_INFO("This is Master FD(%d) from open_drm.", drm_fd);
-               } else {
-                       /* close the fd and get the authenticated fd from the master fd */
-                       close(drm_fd);
-                       drm_fd = -1;
-
-                       /* get the authenticated drm fd from the master fd */
-                       if (!tbm_drm_helper_get_auth_info(&(drm_fd), NULL, NULL)) {
-                               TBM_ERR("fail to get auth drm info!\n");
-                               if (error)
-                                       *error = TBM_ERROR_INVALID_OPERATION;
-                               goto fail_get_auth_info;
-                       }
-                       TBM_INFO("This is Authenticated FD(%d)", drm_fd);
-               }
-       } else {
-               TBM_INFO("This is Master FD from tbm_drm_helper_get_master_fd(%d)", drm_fd);
-       }
-       tbm_drm_helper_set_fd(drm_fd);
-
-       ret = vigs_drm_device_create(drm_fd, &drm_dev);
-       if (ret != 0) {
-               TBM_ERR("vigs_drm_device_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
-               if (error)
-                       *error = TBM_ERROR_INVALID_OPERATION;
-               goto fail_create_vigs_drm_device;
-       }
-       bufmgr_vigs->drm_dev = drm_dev;
-       g_drm_dev = drm_dev;
-
-       /* alloc and register bufmgr_funcs */
-       bufmgr_func = tbm_backend_bufmgr_alloc_bufmgr_func(bufmgr, &err);
-       if (!bufmgr_func) {
-               TBM_ERR("fail to alloc bufmgr_func! err(%d)\n", err);
-               if (error)
-                       *error = TBM_ERROR_OUT_OF_MEMORY;
-               goto fail_alloc_bufmgr_func;
-       }
-
-       bufmgr_func->bufmgr_get_capabilities = tbm_vigs_bufmgr_get_capabilities;
-       bufmgr_func->bufmgr_bind_native_display = tbm_vigs_bufmgr_bind_native_display;
-       bufmgr_func->bufmgr_get_supported_formats = tbm_vigs_bufmgr_get_supported_formats;
-       bufmgr_func->bufmgr_get_plane_data = tbm_vigs_bufmgr_get_plane_data;
-       bufmgr_func->bufmgr_alloc_bo = tbm_vigs_bufmgr_alloc_bo;
-       bufmgr_func->bufmgr_alloc_bo_with_format = tbm_bufmgr_vigs_alloc_bo_with_format;
-       bufmgr_func->bufmgr_import_fd = tbm_vigs_bufmgr_import_fd;
-       bufmgr_func->bufmgr_import_key = tbm_vigs_bufmgr_import_key;
-
-       err = tbm_backend_bufmgr_register_bufmgr_func(bufmgr, bufmgr_func);
-       if (err != TBM_ERROR_NONE) {
-               TBM_ERR("fail to register bufmgr_func! err(%d)\n", err);
-               if (error)
-                       *error = TBM_ERROR_INVALID_OPERATION;
-               goto fail_register_bufmgr_func;
-       }
-       bufmgr_vigs->bufmgr_func = bufmgr_func;
-
-       /* alloc and register bo_funcs */
-       bo_func = tbm_backend_bufmgr_alloc_bo_func(bufmgr, &err);
-       if (!bo_func) {
-               TBM_ERR("fail to alloc bo_func! err(%d)\n", err);
-               if (error)
-                       *error = TBM_ERROR_OUT_OF_MEMORY;
-               goto fail_alloc_bo_func;
-       }
-
-       bo_func->bo_free = tbm_vigs_bo_free;
-       bo_func->bo_get_size = tbm_vigs_bo_get_size;
-       bo_func->bo_get_memory_types = tbm_vigs_bo_get_memory_type;
-       bo_func->bo_get_handle = tbm_vigs_bo_get_handle;
-       bo_func->bo_map = tbm_vigs_bo_map;
-       bo_func->bo_unmap = tbm_vigs_bo_unmap;
-       bo_func->bo_lock = tbm_vigs_bo_lock;
-       bo_func->bo_unlock = tbm_vigs_bo_unlock;
-       bo_func->bo_export_fd = tbm_vigs_bo_export_fd;
-       bo_func->bo_export_key = tbm_vigs_bo_export_key;
-
-       err = tbm_backend_bufmgr_register_bo_func(bufmgr, bo_func);
-       if (err != TBM_ERROR_NONE) {
-               TBM_ERR("fail to register bo_func! err(%d)\n", err);
-               if (error)
-                       *error = TBM_ERROR_INVALID_OPERATION;
-               goto fail_register_bo_func;
-       }
-       bufmgr_vigs->bo_func = bo_func;
-
-       TBM_INFO("initialized");
-
-       return (tbm_backend_bufmgr_data *)bufmgr_vigs;
-
-fail_register_bo_func:
-       tbm_backend_bufmgr_free_bo_func(bufmgr, bo_func);
-fail_alloc_bo_func:
-fail_register_bufmgr_func:
-       tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_func);
-fail_alloc_bufmgr_func:
-       vigs_drm_device_destroy(drm_dev);
-fail_create_vigs_drm_device:
-       if (set_master)
-               tbm_drm_helper_unset_tbm_master_fd();
-       if (drm_fd >= 0)
-               close(drm_fd);
-fail_get_auth_info:
-fail_open_drm:
-       if (bufmgr_vigs)
-               free(bufmgr_vigs);
-       g_drm_dev = NULL;
-       return NULL;
-}
-
-tbm_backend_module tbm_backend_module_data = {
-       "vigs",
-       "Samsung",
-       TBM_BACKEND_ABI_VERSION_3_0,
-       tbm_vigs_init,
-       tbm_vigs_deinit
-};
-
-struct vigs_drm_device *
-tbm_vigs_get_drm_dev(void)
-{
-       return g_drm_dev;
-}
diff --git a/src/tbm_vigs.h b/src/tbm_vigs.h
deleted file mode 100644 (file)
index eefeacb..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * libtbm-vigs header
- *
- * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact :
- * SooChan Lim <sc1.lim@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, sublicense, 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 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS 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.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-#ifndef _TBM_VIGS_LOG_H_
-#define _TBM_VIGS_LOG_H_
-
-#include "vigs.h"
-
-struct vigs_drm_device *tbm_vigs_get_drm_dev(void);
-
-#endif