change the pre/postfix emulator to the pre/postfix vigs. 20/173620/1
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 22 Mar 2018 23:19:04 +0000 (08:19 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Thu, 22 Mar 2018 23:25:38 +0000 (08:25 +0900)
Change-Id: I84c50f04d2ad95bf54457551dec47926022cbc16

configure.ac
libtbm-vigs.pc.in
packaging/libtbm-vigs.spec
src/Makefile.am
src/tbm_bufmgr_emulator.c [deleted file]
src/tbm_bufmgr_vigs.c [new file with mode: 0644]
src/tbm_emulator_log.c [deleted file]
src/tbm_emulator_log.h [deleted file]
src/tbm_vigs_log.c [new file with mode: 0644]
src/tbm_vigs_log.h [new file with mode: 0644]

index b05a0becec1242ee22a5db737c224ec9d8d26cd1..f9cfc87e2d792af302c3d408f028c97ccc55715c 100644 (file)
@@ -18,7 +18,7 @@
 #  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 AC_PREREQ(2.60)
-AC_INIT(libtbm-emulator, 1.0.0)
+AC_INIT(libtbm-vigs, 1.0.0)
 AC_USE_SYSTEM_EXTENSIONS
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([dist-bzip2])
@@ -40,10 +40,10 @@ PKG_CHECK_MODULES(LIBDRM, libdrm)
 PKG_CHECK_MODULES(LIBDRM_VIGS, libdrm_vigs)
 PKG_CHECK_MODULES(LIBTBM, libtbm)
 
-LIBTBM_EMULATOR_CFLAGS="$LIBDRM_CFLAGS $LIBDRM_VIGS_CFLAGS $LIBTBM_CFLAGS "
-LIBTBM_EMULATOR_LIBS="$LIBDRM_LIBS $LIBDRM_VIGS_LIBS $LIBTBM_LIBS "
-AC_SUBST(LIBTBM_EMULATOR_CFLAGS)
-AC_SUBST(LIBTBM_EMULATOR_LIBS)
+LIBTBM_VIGS_CFLAGS="$LIBDRM_CFLAGS $LIBDRM_VIGS_CFLAGS $LIBTBM_CFLAGS "
+LIBTBM_VIGS_LIBS="$LIBDRM_LIBS $LIBDRM_VIGS_LIBS $LIBTBM_LIBS "
+AC_SUBST(LIBTBM_VIGS_CFLAGS)
+AC_SUBST(LIBTBM_VIGS_LIBS)
 
 #bufmgr_dir=${libdir#*/}
 bufmgr_dir=${libdir}/bufmgr/
@@ -57,7 +57,7 @@ AC_OUTPUT([
 echo ""
 echo "CFLAGS  : $CFLAGS"
 echo "LDFLAGS : $LDFLAGS"
-echo "LIBTBM_EMULATOR_CFLAGS : $LIBTBM_EMULATOR_CFLAGS"
-echo "LIBTBM_EMULATOR_LIBS   : $LIBTBM_EMULATOR_LIBS"
+echo "LIBTBM_VIGS_CFLAGS : $LIBTBM_VIGS_CFLAGS"
+echo "LIBTBM_VIGS_LIBS   : $LIBTBM_VIGS_LIBS"
 echo "bufmgr_dir : $bufmgr_dir"
 echo ""
index abc8d192230d1a0d3f7042a6624021d0c867589d..98b2e8af001e587c13615b9e65013ca33f5a0c4a 100644 (file)
@@ -6,5 +6,5 @@ includedir=@includedir@
 Name: libtbm-vigs
 Description: the library for Tizen Buffer Manager vigs backend
 Version: @PACKAGE_VERSION@
-Libs: -L${libdir}/bufmgr -ltbm_emulator
+Libs: -L${libdir}/bufmgr -ltbm_vigs
 Cflags: -I${includedir} -I${includedir}/tbm-vigs
index 89cf35f9226cec0b14e909808c321841aaaba090..a303946317b1a817b9a35a5a092d5a9a98d57990 100644 (file)
@@ -2,7 +2,7 @@ Name:           libtbm-vigs
 Version:        0.1.2
 Release:        1
 License:        MIT
-Summary:        Tizen Buffer Manager - emulator backend
+Summary:        Tizen Buffer Manager - vigs backend
 Group:          System/Libraries
 Source0:        %{name}-%{version}.tar.gz
 Source1001:     libtbm-vigs.manifest
@@ -43,7 +43,7 @@ rm -rf %{buildroot}
 if [ -f %{_libdir}/bufmgr/libtbm_default.so ]; then
     rm -rf %{_libdir}/bufmgr/libtbm_default.so
 fi
-ln -s libtbm_emulator.so %{_libdir}/bufmgr/libtbm_default.so
+ln -s libtbm_vigs.so %{_libdir}/bufmgr/libtbm_default.so
 
 %postun -p /sbin/ldconfig
 
index 1a0c23d3be86eadfc90118bdc74c24389bfaf93e..9609c5d8975880a26ec8835c78ccec66ae132086 100644 (file)
@@ -1,15 +1,15 @@
 AM_CFLAGS = \
-       @LIBTBM_EMULATOR_CFLAGS@ \
+       @LIBTBM_VIGS_CFLAGS@ \
        -I$(top_srcdir) \
        -I$(top_srcdir)/src
 
-libtbm_emulator_la_LTLIBRARIES = libtbm_emulator.la
-libtbm_emulator_ladir = /${bufmgr_dir}
-libtbm_emulator_la_LIBADD = @LIBTBM_EMULATOR_LIBS@
+libtbm_vigs_la_LTLIBRARIES = libtbm_vigs.la
+libtbm_vigs_ladir = /${bufmgr_dir}
+libtbm_vigs_la_LIBADD = @LIBTBM_VIGS_LIBS@
 
-libtbm_emulator_la_SOURCES = \
-       tbm_bufmgr_emulator.c \
-       tbm_emulator_log.c
+libtbm_vigs_la_SOURCES = \
+       tbm_bufmgr_vigs.c \
+       tbm_vigs_log.c
 
-libtbm_emulator_includedir=$(includedir)/tbm-vigs
-libtbm_emulator_include_HEADERS = tbm_vigs.h
\ No newline at end of file
+libtbm_vigs_includedir=$(includedir)/tbm-vigs
+libtbm_vigs_include_HEADERS = tbm_vigs.h
\ No newline at end of file
diff --git a/src/tbm_bufmgr_emulator.c b/src/tbm_bufmgr_emulator.c
deleted file mode 100755 (executable)
index 0dba5fe..0000000
+++ /dev/null
@@ -1,608 +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 <tbm_bufmgr.h>
-#include <tbm_bufmgr_backend.h>
-#include <tbm_surface.h>
-#include <tbm_drm_helper.h>
-#include "vigs.h"
-#include "tbm_emulator_log.h"
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <xf86drm.h>
-#include "tbm_vigs.h"
-
-static struct vigs_drm_device *g_drm_dev = NULL;
-
-#define VIGS_DRM_NAME "vigs"
-
-static uint32_t tbm_bufmgr_emulator_color_format_list[] = {
-       TBM_FORMAT_RGB888,
-       TBM_FORMAT_ARGB8888,
-       TBM_FORMAT_RGBA8888,
-       TBM_FORMAT_XRGB8888,
-       TBM_FORMAT_NV21,
-       TBM_FORMAT_NV61,
-       TBM_FORMAT_YUV420,
-};
-
-static int _tbm_vigs_open_drm(void)
-{
-       int fd = -1;
-
-       fd = drmOpen(VIGS_DRM_NAME, NULL);
-       if (fd < 0) {
-               TBM_EMULATOR_LOG_ERROR("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;
-
-       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_EMULATOR_LOG_ERROR("vigs_drm_gem_map failed: %s", strerror(-ret));
-
-               break;
-       case TBM_DEVICE_3D:
-               bo_handle.ptr = (void *)sfc;
-               break;
-       case TBM_DEVICE_MM:
-               TBM_EMULATOR_LOG_ERROR("TBM_DEVICE_MM not supported");
-               break;
-       default:
-               TBM_EMULATOR_LOG_ERROR("%d not supported", device);
-               break;
-       }
-
-       return bo_handle;
-}
-
-static void tbm_bufmgr_emulator_deinit(void *priv)
-{
-       struct vigs_drm_device *drm_dev = priv;
-
-       TBM_EMULATOR_LOG_DEBUG("enter");
-
-       if (tbm_backend_is_display_server()) {
-               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 int tbm_bufmgr_emulator_bo_size(tbm_bo bo)
-{
-       struct vigs_drm_surface *sfc;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-
-       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
-
-       return sfc->gem.size;
-}
-
-static void *tbm_bufmgr_emulator_bo_alloc(tbm_bo bo, int size, int flags)
-{
-       struct vigs_drm_device *drm_dev;
-       struct vigs_drm_surface *sfc;
-       uint32_t width = 2048, height;
-       int ret;
-
-       TBM_EMULATOR_LOG_DEBUG("size = %d, flags = 0x%X", size, flags);
-
-       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
-
-       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_EMULATOR_LOG_ERROR("vigs_drm_suface_create failed: %s", strerror(-ret));
-               return NULL;
-       }
-
-       return sfc;
-}
-
-static void tbm_bufmgr_emulator_bo_free(tbm_bo bo)
-{
-       struct vigs_drm_surface *sfc;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-
-       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
-
-       vigs_drm_gem_unref(&sfc->gem);
-}
-
-static void *tbm_bufmgr_emulator_bo_import(tbm_bo bo, unsigned int key)
-{
-       struct vigs_drm_device *drm_dev;
-       int ret;
-       struct vigs_drm_surface *sfc;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p, key = %u", bo, key);
-
-       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
-
-       ret = vigs_drm_surface_open(drm_dev, key, &sfc);
-
-       if (ret != 0) {
-               TBM_EMULATOR_LOG_ERROR("vigs_drm_surface_open failed for key %u: %s", key, strerror(-ret));
-               return NULL;
-       }
-
-       TBM_EMULATOR_LOG_DEBUG("handle = %u", sfc->gem.handle);
-
-       return sfc;
-}
-
-static void *tbm_bufmgr_emulator_bo_import_fd(tbm_bo bo, tbm_fd key)
-{
-       struct vigs_drm_device *drm_dev;
-       struct vigs_drm_surface *sfc;
-       int ret;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p, key = %d", bo, key);
-
-       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
-
-       ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc);
-
-       if (ret != 0) {
-               TBM_EMULATOR_LOG_ERROR("vigs_drm_prime_import_fd failed for key %d: %s", key, strerror(-ret));
-               return NULL;
-       }
-
-       TBM_EMULATOR_LOG_DEBUG("handle = %u", sfc->gem.handle);
-
-       return sfc;
-}
-
-static unsigned int tbm_bufmgr_emulator_bo_export(tbm_bo bo)
-{
-       struct vigs_drm_surface *sfc;
-       int ret;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-
-       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
-
-       ret = vigs_drm_gem_get_name(&sfc->gem);
-
-       if (ret != 0) {
-               TBM_EMULATOR_LOG_ERROR("vigs_drm_gem_get_name failed: %s", strerror(-ret));
-               return 0;
-       }
-
-       return sfc->gem.name;
-}
-
-tbm_fd tbm_bufmgr_emulator_bo_export_fd(tbm_bo bo)
-{
-       struct vigs_drm_device *drm_dev;
-       struct vigs_drm_surface *sfc;
-       int ret, fd = 0;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-
-       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
-       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);;
-
-       ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd);
-
-       if (ret != 0) {
-               TBM_EMULATOR_LOG_ERROR("vigs_drm_prime_export_fd failed: %s", strerror(-ret));
-               return 0;
-       }
-
-       return fd;
-}
-
-static tbm_bo_handle tbm_bufmgr_emulator_bo_get_handle(tbm_bo bo, int device)
-{
-       struct vigs_drm_surface *sfc;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d", bo, device);
-
-       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
-
-       return get_tbm_bo_handle(sfc, device);
-}
-
-static tbm_bo_handle tbm_bufmgr_emulator_bo_map(tbm_bo bo, int device, int opt)
-{
-       struct vigs_drm_surface *sfc;
-       tbm_bo_handle handle;
-       uint32_t saf = 0;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p, device = %d, opt = %d", bo, device, opt);
-
-       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
-
-       handle = get_tbm_bo_handle(sfc, device);
-
-       if (!handle.ptr)
-               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);
-
-       return handle;
-}
-
-static int tbm_bufmgr_emulator_bo_unmap(tbm_bo bo)
-{
-       struct vigs_drm_surface *sfc;
-
-       TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-
-       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
-
-       vigs_drm_surface_end_access(sfc, 1);
-
-       return 1;
-}
-
-static int tbm_bufmgr_emulator_bo_lock(tbm_bo bo, int device, int opt)
-{
-       TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-       return 1;
-}
-
-static int tbm_bufmgr_emulator_bo_unlock(tbm_bo bo)
-{
-       TBM_EMULATOR_LOG_DEBUG("bo = %p", bo);
-       return 1;
-}
-
-static int tbm_bufmgr_emulator_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)
-{
-       *size = 0;
-       *offset = 0;
-       *pitch = 0;
-       *bo_idx = 0;
-
-       switch (format) {
-       case TBM_FORMAT_RGB888:
-               *size = width * height * 3;
-               *offset = 0;
-               *pitch = width * 3;
-               *bo_idx = 0;
-               return 1;
-       case TBM_FORMAT_XRGB8888:
-       case TBM_FORMAT_ARGB8888:
-       case TBM_FORMAT_RGBA8888:
-               *size = width * height * 4;
-               *offset = 0;
-               *pitch = width * 4;
-               *bo_idx = 0;
-               return 1;
-       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 0;
-               }
-               return 1;
-       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 0;
-               }
-               return 1;
-       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 0;
-               }
-               return 1;
-       default:
-               return 0;
-       }
-}
-
-static int tbm_bufmgr_emulator_surface_supported_format(uint32_t ** formats, uint32_t * num)
-{
-       uint32_t *color_formats;
-
-       color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_emulator_color_format_list));
-
-       if (!color_formats)
-               return 0;
-
-       memcpy(color_formats, tbm_bufmgr_emulator_color_format_list, sizeof(tbm_bufmgr_emulator_color_format_list));
-
-       *formats = color_formats;
-       *num = sizeof(tbm_bufmgr_emulator_color_format_list) / sizeof(tbm_bufmgr_emulator_color_format_list[0]);
-
-       return 1;
-}
-
-static int tbm_bufmgr_emulator_bind_native_display(tbm_bufmgr bufmgr, void *native_display)
-{
-       struct vigs_drm_device *drm_dev;
-       char *device_name;
-       int ret = 0;
-
-       drm_dev = (struct vigs_drm_device *)tbm_backend_get_priv_from_bufmgr(bufmgr);
-
-       device_name = drmGetDeviceNameFromFd(drm_dev->fd);
-
-       if (!device_name) {
-               TBM_EMULATOR_LOG_ERROR("drmGetDeviceNameFromFd failed");
-               return 0;
-       }
-
-       ret = tbm_drm_helper_wl_auth_server_init(native_display, drm_dev->fd, device_name, 0);
-
-       if (!ret) {
-               TBM_EMULATOR_LOG_ERROR("tbm_drm_helper_wl_auth_server_init failed");
-               free(device_name);
-               return 0;
-       }
-
-       free(device_name);
-
-       return 1;
-}
-
-static void *tbm_bufmgr_emulator_surface_bo_alloc(tbm_bo bo, int width, int height, int format, int flags, int bo_idx)
-{
-       struct vigs_drm_device *drm_dev;
-       struct vigs_drm_surface *sfc;
-       int ret;
-
-       TBM_EMULATOR_LOG_DEBUG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d", width, height, format, flags, bo_idx);
-
-       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
-
-       if (bo_idx != 0) {
-               TBM_EMULATOR_LOG_ERROR("Not supported bo idx");
-               return NULL;
-       }
-
-       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:
-               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, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc);
-               break;
-
-       default:
-               TBM_EMULATOR_LOG_ERROR("Not supported format");
-               return NULL;
-       }
-
-       if (ret != 0) {
-               TBM_EMULATOR_LOG_ERROR("vigs_drm_suface_create failed: %s", strerror(-ret));
-               return NULL;
-       }
-
-       return sfc;
-}
-
-MODULEINITPPROTO(tbm_bufmgr_emulator_init);
-
-static TBMModuleVersionInfo EmulatorVersRec = {
-       "emulator",
-       "Samsung",
-       TBM_ABI_VERSION,
-};
-
-TBMModuleData tbmModuleData = { &EmulatorVersRec, tbm_bufmgr_emulator_init };
-
-int tbm_bufmgr_emulator_init(tbm_bufmgr bufmgr, int fd)
-{
-       int ret = 0;
-       struct vigs_drm_device *drm_dev = NULL;
-       tbm_bufmgr_backend backend = NULL;
-       int drm_fd = -1;
-
-       TBM_EMULATOR_LOG_DEBUG("enter");
-
-       if (!bufmgr)
-               return 0;
-
-       if (tbm_backend_is_display_server()) {
-               drm_fd = tbm_drm_helper_get_master_fd();
-
-               if (drm_fd < 0)
-                       drm_fd = _tbm_vigs_open_drm();
-
-               if (drm_fd < 0) {
-                       TBM_EMULATOR_LOG_ERROR("vigs drm device failed");
-                       goto fail;
-               }
-
-               tbm_drm_helper_set_tbm_master_fd(drm_fd);
-
-       } else {
-               if (!tbm_drm_helper_get_auth_info(&drm_fd, NULL, NULL)) {
-                       TBM_EMULATOR_LOG_ERROR("tbm_drm_helper_get_auth_info failed");
-                       goto fail;
-               }
-       }
-
-       ret = vigs_drm_device_create(drm_fd, &drm_dev);
-
-       if (ret != 0) {
-               TBM_EMULATOR_LOG_ERROR("vigs_drm_device_create failed: %s", strerror(-ret));
-               goto fail;
-       }
-       g_drm_dev = drm_dev;
-
-       backend = tbm_backend_alloc();
-
-       if (!backend) {
-               TBM_EMULATOR_LOG_ERROR("tbm_backend_alloc failed");
-               goto fail;
-       }
-
-       backend->priv = (void *)drm_dev;
-       backend->bufmgr_deinit = tbm_bufmgr_emulator_deinit;
-       backend->bo_size = tbm_bufmgr_emulator_bo_size;
-       backend->bo_alloc = tbm_bufmgr_emulator_bo_alloc;
-       backend->bo_free = tbm_bufmgr_emulator_bo_free;
-       backend->bo_import = tbm_bufmgr_emulator_bo_import;
-       backend->bo_import_fd = tbm_bufmgr_emulator_bo_import_fd;
-       backend->bo_export = tbm_bufmgr_emulator_bo_export;
-       backend->bo_export_fd = tbm_bufmgr_emulator_bo_export_fd;
-       backend->bo_get_handle = tbm_bufmgr_emulator_bo_get_handle;
-       backend->bo_map = tbm_bufmgr_emulator_bo_map;
-       backend->bo_unmap = tbm_bufmgr_emulator_bo_unmap;
-       backend->bo_lock = tbm_bufmgr_emulator_bo_lock;
-       backend->bo_unlock = tbm_bufmgr_emulator_bo_unlock;
-       backend->surface_get_plane_data = tbm_bufmgr_emulator_surface_get_plane_data;
-       backend->surface_supported_format = tbm_bufmgr_emulator_surface_supported_format;
-       backend->bufmgr_bind_native_display = tbm_bufmgr_emulator_bind_native_display;
-       backend->surface_bo_alloc = tbm_bufmgr_emulator_surface_bo_alloc;
-
-       if (!tbm_backend_init(bufmgr, backend)) {
-               TBM_EMULATOR_LOG_ERROR("tbm_backend_init failed");
-               goto fail;
-       }
-
-       TBM_EMULATOR_LOG_INFO("initialized");
-
-       return 1;
-
- fail:
-       if (backend)
-               tbm_backend_free(backend);
-
-       if (drm_dev)
-               vigs_drm_device_destroy(drm_dev);
-
-       if (drm_fd >= 0) {
-               if (tbm_backend_is_display_server())
-                       tbm_drm_helper_unset_tbm_master_fd();
-
-               close(drm_fd);
-       }
-
-       g_drm_dev = NULL;
-
-       return 0;
-}
-
-struct vigs_drm_device *
-tbm_vigs_get_drm_dev(void)
-{
-       return g_drm_dev;
-}
diff --git a/src/tbm_bufmgr_vigs.c b/src/tbm_bufmgr_vigs.c
new file mode 100644 (file)
index 0000000..96c796d
--- /dev/null
@@ -0,0 +1,608 @@
+/*
+ * 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 <tbm_bufmgr.h>
+#include <tbm_bufmgr_backend.h>
+#include <tbm_surface.h>
+#include <tbm_drm_helper.h>
+#include "vigs.h"
+#include "tbm_vigs_log.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <xf86drm.h>
+#include "tbm_vigs.h"
+
+static struct vigs_drm_device *g_drm_dev = NULL;
+
+#define VIGS_DRM_NAME "vigs"
+
+static uint32_t tbm_bufmgr_vigs_color_format_list[] = {
+       TBM_FORMAT_RGB888,
+       TBM_FORMAT_ARGB8888,
+       TBM_FORMAT_RGBA8888,
+       TBM_FORMAT_XRGB8888,
+       TBM_FORMAT_NV21,
+       TBM_FORMAT_NV61,
+       TBM_FORMAT_YUV420,
+};
+
+static int _tbm_vigs_open_drm(void)
+{
+       int fd = -1;
+
+       fd = drmOpen(VIGS_DRM_NAME, NULL);
+       if (fd < 0) {
+               TBM_VIGS_LOG_ERROR("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;
+
+       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_VIGS_LOG_ERROR("vigs_drm_gem_map failed: %s", strerror(-ret));
+
+               break;
+       case TBM_DEVICE_3D:
+               bo_handle.ptr = (void *)sfc;
+               break;
+       case TBM_DEVICE_MM:
+               TBM_VIGS_LOG_ERROR("TBM_DEVICE_MM not supported");
+               break;
+       default:
+               TBM_VIGS_LOG_ERROR("%d not supported", device);
+               break;
+       }
+
+       return bo_handle;
+}
+
+static void tbm_bufmgr_vigs_deinit(void *priv)
+{
+       struct vigs_drm_device *drm_dev = priv;
+
+       TBM_VIGS_LOG_DEBUG("enter");
+
+       if (tbm_backend_is_display_server()) {
+               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 int tbm_bufmgr_vigs_bo_size(tbm_bo bo)
+{
+       struct vigs_drm_surface *sfc;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p", bo);
+
+       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
+
+       return sfc->gem.size;
+}
+
+static void *tbm_bufmgr_vigs_bo_alloc(tbm_bo bo, int size, int flags)
+{
+       struct vigs_drm_device *drm_dev;
+       struct vigs_drm_surface *sfc;
+       uint32_t width = 2048, height;
+       int ret;
+
+       TBM_VIGS_LOG_DEBUG("size = %d, flags = 0x%X", size, flags);
+
+       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
+
+       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_VIGS_LOG_ERROR("vigs_drm_suface_create failed: %s", strerror(-ret));
+               return NULL;
+       }
+
+       return sfc;
+}
+
+static void tbm_bufmgr_vigs_bo_free(tbm_bo bo)
+{
+       struct vigs_drm_surface *sfc;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p", bo);
+
+       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
+
+       vigs_drm_gem_unref(&sfc->gem);
+}
+
+static void *tbm_bufmgr_vigs_bo_import(tbm_bo bo, unsigned int key)
+{
+       struct vigs_drm_device *drm_dev;
+       int ret;
+       struct vigs_drm_surface *sfc;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p, key = %u", bo, key);
+
+       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
+
+       ret = vigs_drm_surface_open(drm_dev, key, &sfc);
+
+       if (ret != 0) {
+               TBM_VIGS_LOG_ERROR("vigs_drm_surface_open failed for key %u: %s", key, strerror(-ret));
+               return NULL;
+       }
+
+       TBM_VIGS_LOG_DEBUG("handle = %u", sfc->gem.handle);
+
+       return sfc;
+}
+
+static void *tbm_bufmgr_vigs_bo_import_fd(tbm_bo bo, tbm_fd key)
+{
+       struct vigs_drm_device *drm_dev;
+       struct vigs_drm_surface *sfc;
+       int ret;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p, key = %d", bo, key);
+
+       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
+
+       ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc);
+
+       if (ret != 0) {
+               TBM_VIGS_LOG_ERROR("vigs_drm_prime_import_fd failed for key %d: %s", key, strerror(-ret));
+               return NULL;
+       }
+
+       TBM_VIGS_LOG_DEBUG("handle = %u", sfc->gem.handle);
+
+       return sfc;
+}
+
+static unsigned int tbm_bufmgr_vigs_bo_export(tbm_bo bo)
+{
+       struct vigs_drm_surface *sfc;
+       int ret;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p", bo);
+
+       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
+
+       ret = vigs_drm_gem_get_name(&sfc->gem);
+
+       if (ret != 0) {
+               TBM_VIGS_LOG_ERROR("vigs_drm_gem_get_name failed: %s", strerror(-ret));
+               return 0;
+       }
+
+       return sfc->gem.name;
+}
+
+tbm_fd tbm_bufmgr_vigs_bo_export_fd(tbm_bo bo)
+{
+       struct vigs_drm_device *drm_dev;
+       struct vigs_drm_surface *sfc;
+       int ret, fd = 0;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p", bo);
+
+       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
+       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);;
+
+       ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd);
+
+       if (ret != 0) {
+               TBM_VIGS_LOG_ERROR("vigs_drm_prime_export_fd failed: %s", strerror(-ret));
+               return 0;
+       }
+
+       return fd;
+}
+
+static tbm_bo_handle tbm_bufmgr_vigs_bo_get_handle(tbm_bo bo, int device)
+{
+       struct vigs_drm_surface *sfc;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p, device = %d", bo, device);
+
+       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
+
+       return get_tbm_bo_handle(sfc, device);
+}
+
+static tbm_bo_handle tbm_bufmgr_vigs_bo_map(tbm_bo bo, int device, int opt)
+{
+       struct vigs_drm_surface *sfc;
+       tbm_bo_handle handle;
+       uint32_t saf = 0;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p, device = %d, opt = %d", bo, device, opt);
+
+       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
+
+       handle = get_tbm_bo_handle(sfc, device);
+
+       if (!handle.ptr)
+               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);
+
+       return handle;
+}
+
+static int tbm_bufmgr_vigs_bo_unmap(tbm_bo bo)
+{
+       struct vigs_drm_surface *sfc;
+
+       TBM_VIGS_LOG_DEBUG("bo = %p", bo);
+
+       sfc = (struct vigs_drm_surface *)tbm_backend_get_bo_priv(bo);
+
+       vigs_drm_surface_end_access(sfc, 1);
+
+       return 1;
+}
+
+static int tbm_bufmgr_vigs_bo_lock(tbm_bo bo, int device, int opt)
+{
+       TBM_VIGS_LOG_DEBUG("bo = %p", bo);
+       return 1;
+}
+
+static int tbm_bufmgr_vigs_bo_unlock(tbm_bo bo)
+{
+       TBM_VIGS_LOG_DEBUG("bo = %p", bo);
+       return 1;
+}
+
+static int tbm_bufmgr_vigs_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)
+{
+       *size = 0;
+       *offset = 0;
+       *pitch = 0;
+       *bo_idx = 0;
+
+       switch (format) {
+       case TBM_FORMAT_RGB888:
+               *size = width * height * 3;
+               *offset = 0;
+               *pitch = width * 3;
+               *bo_idx = 0;
+               return 1;
+       case TBM_FORMAT_XRGB8888:
+       case TBM_FORMAT_ARGB8888:
+       case TBM_FORMAT_RGBA8888:
+               *size = width * height * 4;
+               *offset = 0;
+               *pitch = width * 4;
+               *bo_idx = 0;
+               return 1;
+       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 0;
+               }
+               return 1;
+       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 0;
+               }
+               return 1;
+       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 0;
+               }
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+static int tbm_bufmgr_vigs_surface_supported_format(uint32_t ** formats, uint32_t * num)
+{
+       uint32_t *color_formats;
+
+       color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_vigs_color_format_list));
+
+       if (!color_formats)
+               return 0;
+
+       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 1;
+}
+
+static int tbm_bufmgr_vigs_bind_native_display(tbm_bufmgr bufmgr, void *native_display)
+{
+       struct vigs_drm_device *drm_dev;
+       char *device_name;
+       int ret = 0;
+
+       drm_dev = (struct vigs_drm_device *)tbm_backend_get_priv_from_bufmgr(bufmgr);
+
+       device_name = drmGetDeviceNameFromFd(drm_dev->fd);
+
+       if (!device_name) {
+               TBM_VIGS_LOG_ERROR("drmGetDeviceNameFromFd failed");
+               return 0;
+       }
+
+       ret = tbm_drm_helper_wl_auth_server_init(native_display, drm_dev->fd, device_name, 0);
+
+       if (!ret) {
+               TBM_VIGS_LOG_ERROR("tbm_drm_helper_wl_auth_server_init failed");
+               free(device_name);
+               return 0;
+       }
+
+       free(device_name);
+
+       return 1;
+}
+
+static void *tbm_bufmgr_vigs_surface_bo_alloc(tbm_bo bo, int width, int height, int format, int flags, int bo_idx)
+{
+       struct vigs_drm_device *drm_dev;
+       struct vigs_drm_surface *sfc;
+       int ret;
+
+       TBM_VIGS_LOG_DEBUG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d", width, height, format, flags, bo_idx);
+
+       drm_dev = (struct vigs_drm_device *)tbm_backend_get_bufmgr_priv(bo);
+
+       if (bo_idx != 0) {
+               TBM_VIGS_LOG_ERROR("Not supported bo idx");
+               return NULL;
+       }
+
+       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:
+               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, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc);
+               break;
+
+       default:
+               TBM_VIGS_LOG_ERROR("Not supported format");
+               return NULL;
+       }
+
+       if (ret != 0) {
+               TBM_VIGS_LOG_ERROR("vigs_drm_suface_create failed: %s", strerror(-ret));
+               return NULL;
+       }
+
+       return sfc;
+}
+
+MODULEINITPPROTO(tbm_bufmgr_vigs_init);
+
+static TBMModuleVersionInfo EmulatorVersRec = {
+       "vigs",
+       "Samsung",
+       TBM_ABI_VERSION,
+};
+
+TBMModuleData tbmModuleData = { &EmulatorVersRec, tbm_bufmgr_vigs_init };
+
+int tbm_bufmgr_vigs_init(tbm_bufmgr bufmgr, int fd)
+{
+       int ret = 0;
+       struct vigs_drm_device *drm_dev = NULL;
+       tbm_bufmgr_backend backend = NULL;
+       int drm_fd = -1;
+
+       TBM_VIGS_LOG_DEBUG("enter");
+
+       if (!bufmgr)
+               return 0;
+
+       if (tbm_backend_is_display_server()) {
+               drm_fd = tbm_drm_helper_get_master_fd();
+
+               if (drm_fd < 0)
+                       drm_fd = _tbm_vigs_open_drm();
+
+               if (drm_fd < 0) {
+                       TBM_VIGS_LOG_ERROR("vigs drm device failed");
+                       goto fail;
+               }
+
+               tbm_drm_helper_set_tbm_master_fd(drm_fd);
+
+       } else {
+               if (!tbm_drm_helper_get_auth_info(&drm_fd, NULL, NULL)) {
+                       TBM_VIGS_LOG_ERROR("tbm_drm_helper_get_auth_info failed");
+                       goto fail;
+               }
+       }
+
+       ret = vigs_drm_device_create(drm_fd, &drm_dev);
+
+       if (ret != 0) {
+               TBM_VIGS_LOG_ERROR("vigs_drm_device_create failed: %s", strerror(-ret));
+               goto fail;
+       }
+       g_drm_dev = drm_dev;
+
+       backend = tbm_backend_alloc();
+
+       if (!backend) {
+               TBM_VIGS_LOG_ERROR("tbm_backend_alloc failed");
+               goto fail;
+       }
+
+       backend->priv = (void *)drm_dev;
+       backend->bufmgr_deinit = tbm_bufmgr_vigs_deinit;
+       backend->bo_size = tbm_bufmgr_vigs_bo_size;
+       backend->bo_alloc = tbm_bufmgr_vigs_bo_alloc;
+       backend->bo_free = tbm_bufmgr_vigs_bo_free;
+       backend->bo_import = tbm_bufmgr_vigs_bo_import;
+       backend->bo_import_fd = tbm_bufmgr_vigs_bo_import_fd;
+       backend->bo_export = tbm_bufmgr_vigs_bo_export;
+       backend->bo_export_fd = tbm_bufmgr_vigs_bo_export_fd;
+       backend->bo_get_handle = tbm_bufmgr_vigs_bo_get_handle;
+       backend->bo_map = tbm_bufmgr_vigs_bo_map;
+       backend->bo_unmap = tbm_bufmgr_vigs_bo_unmap;
+       backend->bo_lock = tbm_bufmgr_vigs_bo_lock;
+       backend->bo_unlock = tbm_bufmgr_vigs_bo_unlock;
+       backend->surface_get_plane_data = tbm_bufmgr_vigs_surface_get_plane_data;
+       backend->surface_supported_format = tbm_bufmgr_vigs_surface_supported_format;
+       backend->bufmgr_bind_native_display = tbm_bufmgr_vigs_bind_native_display;
+       backend->surface_bo_alloc = tbm_bufmgr_vigs_surface_bo_alloc;
+
+       if (!tbm_backend_init(bufmgr, backend)) {
+               TBM_VIGS_LOG_ERROR("tbm_backend_init failed");
+               goto fail;
+       }
+
+       TBM_VIGS_LOG_INFO("initialized");
+
+       return 1;
+
+ fail:
+       if (backend)
+               tbm_backend_free(backend);
+
+       if (drm_dev)
+               vigs_drm_device_destroy(drm_dev);
+
+       if (drm_fd >= 0) {
+               if (tbm_backend_is_display_server())
+                       tbm_drm_helper_unset_tbm_master_fd();
+
+               close(drm_fd);
+       }
+
+       g_drm_dev = NULL;
+
+       return 0;
+}
+
+struct vigs_drm_device *
+tbm_vigs_get_drm_dev(void)
+{
+       return g_drm_dev;
+}
diff --git a/src/tbm_emulator_log.c b/src/tbm_emulator_log.c
deleted file mode 100644 (file)
index 10ead18..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * libtbm-vigs log
- *
- * 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
- *
- */
-
-#include "tbm_emulator_log.h"
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-static const char *g_log_level_to_str[] = {
-       "OFF",
-       "ERROR",
-       "INFO",
-       "DEBUG"
-};
-
-static pthread_once_t g_log_init = PTHREAD_ONCE_INIT;
-static int g_debug_enabled = 0;
-
-static void tbm_emulator_log_init_once(void)
-{
-       char *debug_enabled_str = getenv("TBM_EMULATOR_DEBUG");
-       g_debug_enabled = debug_enabled_str ? atoi(debug_enabled_str) : 0;
-}
-
-static void tbm_emulator_log_init(void)
-{
-       pthread_once(&g_log_init, tbm_emulator_log_init_once);
-}
-
-static void tbm_emulator_log_print_current_time(void)
-{
-       char buff[128];
-       struct tm tm;
-       struct timeval tv = { 0, 0 };
-       time_t ti;
-
-       gettimeofday(&tv, NULL);
-
-       ti = tv.tv_sec;
-
-       localtime_r(&ti, &tm);
-       strftime(buff, sizeof(buff), "%H:%M:%S", &tm);
-       fprintf(stderr, "%s", buff);
-}
-
-void tbm_emulator_log_event(tbm_emulator_log_level log_level, const char *func, int line, const char *format, ...)
-{
-       va_list args;
-
-       tbm_emulator_log_init();
-
-       tbm_emulator_log_print_current_time();
-       fprintf(stderr, " %-5s [%u] %s:%d", g_log_level_to_str[log_level], getpid(), func, line);
-       if (format) {
-               va_start(args, format);
-               fprintf(stderr, " - ");
-               vfprintf(stderr, format, args);
-               va_end(args);
-       }
-       fprintf(stderr, "\n");
-}
-
-int tbm_emulator_log_is_debug_enabled()
-{
-       tbm_emulator_log_init();
-
-       return g_debug_enabled;
-}
diff --git a/src/tbm_emulator_log.h b/src/tbm_emulator_log.h
deleted file mode 100644 (file)
index 794b26f..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * libtbm-vigs log header
- *
- * 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
- *
- */
-
-#ifndef _TBM_EMULATOR_LOG_H
-#define _TBM_EMULATOR_LOG_H
-
-typedef enum {
-       tbm_emulator_log_level_off = 0,
-       tbm_emulator_log_level_error = 1,
-       tbm_emulator_log_level_info = 2,
-       tbm_emulator_log_level_debug = 3,
-} tbm_emulator_log_level;
-
-void tbm_emulator_log_event(tbm_emulator_log_level log_level, const char *func, int line, const char *format, ...);
-
-int tbm_emulator_log_is_debug_enabled();
-
-#define TBM_EMULATOR_LOG_DEBUG(format, ...) \
-       do { \
-               if (tbm_emulator_log_is_debug_enabled()) { \
-                       tbm_emulator_log_event(tbm_emulator_log_level_debug, __FUNCTION__, __LINE__, format, ##__VA_ARGS__); \
-               } \
-       } while (0)
-
-#define TBM_EMULATOR_LOG_INFO(format, ...) tbm_emulator_log_event(tbm_emulator_log_level_info, __FUNCTION__, __LINE__, format, ##__VA_ARGS__)
-#define TBM_EMULATOR_LOG_ERROR(format, ...) tbm_emulator_log_event(tbm_emulator_log_level_error, __FUNCTION__, __LINE__, format, ##__VA_ARGS__)
-
-#endif
diff --git a/src/tbm_vigs_log.c b/src/tbm_vigs_log.c
new file mode 100644 (file)
index 0000000..d45097d
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * libtbm-vigs log
+ *
+ * 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
+ *
+ */
+
+#include "tbm_vigs_log.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+static const char *g_log_level_to_str[] = {
+       "OFF",
+       "ERROR",
+       "INFO",
+       "DEBUG"
+};
+
+static pthread_once_t g_log_init = PTHREAD_ONCE_INIT;
+static int g_debug_enabled = 0;
+
+static void tbm_vigs_log_init_once(void)
+{
+       char *debug_enabled_str = getenv("TBM_VIGS_DEBUG");
+       g_debug_enabled = debug_enabled_str ? atoi(debug_enabled_str) : 0;
+}
+
+static void tbm_vigs_log_init(void)
+{
+       pthread_once(&g_log_init, tbm_vigs_log_init_once);
+}
+
+static void tbm_vigs_log_print_current_time(void)
+{
+       char buff[128];
+       struct tm tm;
+       struct timeval tv = { 0, 0 };
+       time_t ti;
+
+       gettimeofday(&tv, NULL);
+
+       ti = tv.tv_sec;
+
+       localtime_r(&ti, &tm);
+       strftime(buff, sizeof(buff), "%H:%M:%S", &tm);
+       fprintf(stderr, "%s", buff);
+}
+
+void tbm_vigs_log_event(tbm_vigs_log_level log_level, const char *func, int line, const char *format, ...)
+{
+       va_list args;
+
+       tbm_vigs_log_init();
+
+       tbm_vigs_log_print_current_time();
+       fprintf(stderr, " %-5s [%u] %s:%d", g_log_level_to_str[log_level], getpid(), func, line);
+       if (format) {
+               va_start(args, format);
+               fprintf(stderr, " - ");
+               vfprintf(stderr, format, args);
+               va_end(args);
+       }
+       fprintf(stderr, "\n");
+}
+
+int tbm_vigs_log_is_debug_enabled()
+{
+       tbm_vigs_log_init();
+
+       return g_debug_enabled;
+}
diff --git a/src/tbm_vigs_log.h b/src/tbm_vigs_log.h
new file mode 100644 (file)
index 0000000..a97f57e
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * libtbm-vigs log header
+ *
+ * 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
+ *
+ */
+
+#ifndef _TBM_VIGS_LOG_H
+#define _TBM_VIGS_LOG_H
+
+typedef enum {
+       tbm_vigs_log_level_off = 0,
+       tbm_vigs_log_level_error = 1,
+       tbm_vigs_log_level_info = 2,
+       tbm_vigs_log_level_debug = 3,
+} tbm_vigs_log_level;
+
+void tbm_vigs_log_event(tbm_vigs_log_level log_level, const char *func, int line, const char *format, ...);
+
+int tbm_vigs_log_is_debug_enabled();
+
+#define TBM_VIGS_LOG_DEBUG(format, ...) \
+       do { \
+               if (tbm_vigs_log_is_debug_enabled()) { \
+                       tbm_vigs_log_event(tbm_vigs_log_level_debug, __FUNCTION__, __LINE__, format, ##__VA_ARGS__); \
+               } \
+       } while (0)
+
+#define TBM_VIGS_LOG_INFO(format, ...) tbm_vigs_log_event(tbm_vigs_log_level_info, __FUNCTION__, __LINE__, format, ##__VA_ARGS__)
+#define TBM_VIGS_LOG_ERROR(format, ...) tbm_vigs_log_event(tbm_vigs_log_level_error, __FUNCTION__, __LINE__, format, ##__VA_ARGS__)
+
+#endif