SUBDIRS = src
pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libtbm-vigs.pc hal-backend-tbm-vigs.pc
+pkgconfig_DATA = hal-backend-tbm-vigs.pc
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AC_PREREQ(2.60)
-AC_INIT(libtbm-vigs, 1.0.0)
+AC_INIT(hal-backend-tbm-vigs, 1.0.0)
AC_USE_SYSTEM_EXTENSIONS
AC_CONFIG_SRCDIR([Makefile.am])
AM_INIT_AUTOMAKE([dist-bzip2])
PKG_CHECK_MODULES(LIBDRM, libdrm)
PKG_CHECK_MODULES(LIBDRM_VIGS, libdrm_vigs)
-PKG_CHECK_MODULES(LIBTBM, libtbm)
PKG_CHECK_MODULES(HAL_API_COMMON, hal-api-common)
PKG_CHECK_MODULES(HAL_API_TBM, hal-api-tbm)
PKG_CHECK_MODULES(DLOG, dlog)
-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/
-AC_SUBST(bufmgr_dir)
-
# set the data dir for the tdm config
DEFAULT_HAL_LIBDIR="/hal/lib"
AC_ARG_WITH(hal-libdir, AS_HELP_STRING([--with-hal-libdir=PATH], [hal backend library path]),
AC_DEFINE_UNQUOTED(HAL_LIBDIR, "${HAL_LIBDIR}", [Directory for hal backend library path])
AC_SUBST(HAL_LIBDIR)
-# for libhal-backend-tbm-exynos-tgm
LIBHAL_BACKEND_TBM_VIGS_CFLAGS="$HAL_API_COMMON_CFLAGS $HAL_API_TBM_CFLAGS $LIBDRM_CFLAGS $LIBDRM_VIGS_CFLAGS $CAPI_CFLAGS $DLOG_CFLAGS "
LIBHAL_BACKEND_TBM_VIGS_LIBS="$HAL_API_COMMON_LIBS $HAL_API_TBM_LIBS $LIBDRM_LIBS $LIBDRM_VIGS_LIBS $CAPI_LIBS $DLOG_LIBS "
AC_OUTPUT([
Makefile
- src/libtbm-vigs/Makefile
- src/libhal-backend-tbm-vigs/Makefile
src/Makefile
- libtbm-vigs.pc
hal-backend-tbm-vigs.pc])
echo ""
echo "CFLAGS : $CFLAGS"
echo "LDFLAGS : $LDFLAGS"
-echo "LIBTBM_VIGS_CFLAGS : $LIBTBM_VIGS_CFLAGS"
-echo "LIBTBM_VIGS_LIBS : $LIBTBM_VIGS_LIBS"
-echo "bufmgr_dir : $bufmgr_dir"
echo "LIBHAL_BACKEND_TBM_VIGS_CFLAGS : $LIBHAL_BACKEND_TBM_VIGS_CFLAGS"
echo "LIBHAL_BACKEND_TBM_VIGS_LIBS : $LIBHAL_BACKEND_TBM_VIGS_LIBS"
-echo "hal-libdir : $HAL_LIBDIR"
+echo "HAL_LIBDIR : $HAL_LIBDIR"
echo ""
+++ /dev/null
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: libtbm-vigs
-Description: the library for Tizen Buffer Manager vigs backend
-Version: @PACKAGE_VERSION@
-Libs: -L${libdir}/bufmgr -ltbm_vigs
-Cflags: -I${includedir} -I${includedir}/tbm-vigs
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+Name: hal-backend-tbm-vigs
+Version: 3.0.5
+Release: 1
+License: MIT
+Summary: hal tbm backend module for vigs
+Group: System/Libraries
+Source0: %{name}-%{version}.tar.gz
+Source1001: %{name}.manifest
+
+BuildRequires: pkgconfig(libdrm)
+BuildRequires: pkgconfig(hal-api-common)
+BuildRequires: pkgconfig(hal-api-tbm)
+BuildRequires: pkgconfig(dlog)
+
+%description
+description: hal tbm backend module for vigs
+
+%package devel
+Summary: hal-backend-tbm library for vigs
+Group: System/Libraries
+Requires: hal-backend-tbm-vigs
+
+%description devel
+description: hal tbm backend library headers for vigs
+
+%prep
+%setup -q
+cp %{SOURCE1001} .
+
+%build
+autoreconf -vfi
+./configure --prefix=%{_prefix} --libdir=%{_libdir} \
+ --with-hal-libdir=%{_hal_libdir} \
+ CFLAGS="${CFLAGS} -Wall -Werror" LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed"
+
+make %{?_smp_mflags}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+# make rule and license files
+mkdir -p %{buildroot}%{_hal_licensedir}/libhal-backend-tbm-vigs
+cp -af COPYING %{buildroot}%{_hal_licensedir}/libhal-backend-tbm-vigs
+
+%post
+if [ -f %{_hal_libdir}/libhal-backend-tbm.so ]; then
+ rm -rf %{_hal_libdir}/libhal-backend-tbm.so
+fi
+ln -s libhal-backend-tbm-vigs.so %{_hal_libdir}/libhal-backend-tbm.so
+
+%postun -n hal-backend-tbm-vigs -p /sbin/ldconfig
+
+%files
+%manifest %{name}.manifest
+%{_hal_licensedir}/libhal-backend-tbm-vigs/COPYING
+%{_hal_libdir}/libhal-backend-*.so*
+
+%files devel
+%defattr(-,root,root,-)
+%dir %{_includedir}
+%{_includedir}/tbm-vigs/libhal_backend_tbm_vigs.h
+%{_hal_libdir}/libhal-backend-tbm*.so
+%{_libdir}/pkgconfig/hal-backend-tbm-vigs.pc
+++ /dev/null
-<manifest>
- <request>
- <domain name="_"/>
- </request>
-</manifest>
+++ /dev/null
-<manifest>
- <request>
- <domain name="_"/>
- </request>
-</manifest>
+++ /dev/null
-Name: libtbm-vigs
-Version: 3.0.5
-Release: 1
-License: MIT
-Summary: Tizen Buffer Manager - vigs backend
-Group: System/Libraries
-Source0: %{name}-%{version}.tar.gz
-Source1001: libtbm-vigs.manifest
-Source1002: libhal-backend-tbm-vigs.manifest
-
-BuildRequires: pkgconfig(libdrm)
-BuildRequires: pkgconfig(libtbm)
-
-Requires: libtbm
-Requires: libdrm
-BuildRequires: pkgconfig(hal-api-common)
-BuildRequires: pkgconfig(hal-api-tbm)
-BuildRequires: pkgconfig(dlog)
-
-%description
-description: ${summary}
-
-%package devel
-Summary: Tizen Buffer Manager Library Backend for vigs
-Group: Development/Libraries
-
-%description devel
-TBM vigs backend. Developement Files.
-
-%package -n hal-backend-tbm-vigs
-Summary: hal-backend-tbm module for vigs
-Group: System/Libraries
-Requires: hal-api-tbm
-Requires: hal-api-common
-
-%description -n hal-backend-tbm-vigs
-descriptionion: hal tbm backend module for vigs
-
-%package -n hal-backend-tbm-vigs-devel
-Summary: hal-backend-tbm library for vigs
-Group: System/Libraries
-Requires: hal-backend-tbm-vigs
-
-%description -n hal-backend-tbm-vigs-devel
-descriptionion: hal tbm backend library headers for vigs
-
-
-%prep
-%setup -q
-cp %{SOURCE1001} .
-cp %{SOURCE1002} .
-
-%build
-autoreconf -vfi
-./configure --prefix=%{_prefix} --libdir=%{_libdir} \
- --with-hal-libdir=%{_hal_libdir} \
- CFLAGS="${CFLAGS} -Wall -Werror" LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed"
-
-make %{?_smp_mflags}
-
-%install
-rm -rf %{buildroot}
-%make_install
-
-# make rule and license files
-mkdir -p %{buildroot}%{_hal_licensedir}/libhal-backend-tbm-vigs
-cp -af COPYING %{buildroot}%{_hal_licensedir}/libhal-backend-tbm-vigs
-
-%post
-if [ -f %{_libdir}/bufmgr/libtbm_default.so ]; then
- rm -rf %{_libdir}/bufmgr/libtbm_default.so
-fi
-ln -s libtbm_vigs.so %{_libdir}/bufmgr/libtbm_default.so
-
-if [ -f %{_libdir}/libtbm_vigs.so ]; then
- rm -rf %{_libdir}/libtbm_vigs.so
-fi
-ln -s bufmgr/libtbm_vigs.so %{_libdir}/libtbm_vigs.so
-
-if [ -f %{_libdir}/libtbm_vigs.so.0 ]; then
- rm -rf %{_libdir}/libtbm_vigs.so.0
-fi
-ln -s %{_libdir}/bufmgr/libtbm_vigs.so.0 %{_libdir}/libtbm_vigs.so.0
-
-if [ -f %{_libdir}/libtbm_vigs.so.0.0.0 ]; then
- rm -rf %{_libdir}/libtbm_vigs.so.0.0.0
-fi
-ln -s %{_libdir}/bufmgr/libtbm_vigs.so.0.0.0 %{_libdir}/libtbm_vigs.so.0.0.0
-
-%postun -p /sbin/ldconfig
-
-%post -n hal-backend-tbm-vigs
-if [ -f %{_hal_libdir}/libhal-backend-tbm.so ]; then
- rm -rf %{_hal_libdir}/libhal-backend-tbm.so
-fi
-ln -s libhal-backend-tbm-vigs.so %{_hal_libdir}/libhal-backend-tbm.so
-
-%postun -n hal-backend-tbm-vigs -p /sbin/ldconfig
-
-%files
-%manifest %{name}.manifest
-%defattr(-,root,root,-)
-%license COPYING
-%{_libdir}/bufmgr/libtbm_*.so*
-
-%files devel
-%defattr(-,root,root,-)
-%dir %{_includedir}
-%{_includedir}/tbm-vigs/tbm_vigs.h
-%{_libdir}/bufmgr/libtbm_*.so
-%{_libdir}/pkgconfig/libtbm-vigs.pc
-
-%files -n hal-backend-tbm-vigs
-%manifest libhal-backend-tbm-vigs.manifest
-%{_hal_licensedir}/libhal-backend-tbm-vigs/COPYING
-%{_hal_libdir}/libhal-backend-*.so*
-
-%files -n hal-backend-tbm-vigs-devel
-%defattr(-,root,root,-)
-%dir %{_includedir}
-%{_includedir}/tbm-vigs/libhal_backend_tbm_vigs.h
-%{_hal_libdir}/libhal-backend-tbm*.so
-%{_libdir}/pkgconfig/hal-backend-tbm-vigs.pc
-SUBDIRS = libtbm-vigs libhal-backend-tbm-vigs
+AM_CFLAGS = \
+ @LIBHAL_BACKEND_TBM_VIGS_CFLAGS@ \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src
+libhal_backend_tbm_vigs_la_LTLIBRARIES = libhal-backend-tbm-vigs.la
+libhal_backend_tbm_vigs_ladir = @HAL_LIBDIR@
+libhal_backend_tbm_vigs_la_LIBADD = @LIBHAL_BACKEND_TBM_VIGS_LIBS@
+
+libhal_backend_tbm_vigs_la_SOURCES = \
+ tbm_backend_log.c \
+ tbm_backend_vigs.c
+
+libhal_backend_tbm_vigs_includedir=$(includedir)/tbm-vigs
+libhal_backend_tbm_vigs_include_HEADERS = libhal_backend_tbm_vigs.h
+++ /dev/null
-AM_CFLAGS = \
- @LIBHAL_BACKEND_TBM_VIGS_CFLAGS@ \
- -I$(top_srcdir) \
- -I$(top_srcdir)/src/libhal-backend-tbm-vigs
-
-libhal_backend_tbm_vigs_la_LTLIBRARIES = libhal-backend-tbm-vigs.la
-libhal_backend_tbm_vigs_ladir = @HAL_LIBDIR@
-libhal_backend_tbm_vigs_la_LIBADD = @LIBHAL_BACKEND_TBM_VIGS_LIBS@
-
-libhal_backend_tbm_vigs_la_SOURCES = \
- tbm_backend_log.c \
- tbm_backend_vigs.c
-
-libhal_backend_tbm_vigs_includedir=$(includedir)/tbm-vigs
-libhal_backend_tbm_vigs_include_HEADERS = libhal_backend_tbm_vigs.h
+++ /dev/null
-/*
- * libhal-backend-tbm-vigs header
- *
- * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact :
- * SooChan Lim <sc1.lim@samsung.com>
- * Junkyeong kim <jk0430.kim@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 _LIBHAL_BACKEND_TBM_VIGS_LOG_H_
-#define _LIBHAL_BACKEND_TBM_VIGS_LOG_H_
-
-#include "vigs.h"
-
-struct vigs_drm_device *libhal_backend_tbm_vigs_get_drm_dev(void);
-
-#endif
+++ /dev/null
-/**************************************************************************
-
-libtbm_vigs
-
-Copyright 2021 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, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#include "tbm_backend_log.h"
-
-#undef LOG_TAG
-#define LOG_TAG "TBM_BACKEND"
-
-unsigned int tbm_log_debug_level = TBM_BACKEND_LOG_LEVEL_INFO;
-
-static void
-_tbm_backend_log_dlog_print(int level, const char *fmt, va_list arg)
-{
- log_priority dlog_prio;
-
- switch (level) {
- case TBM_BACKEND_LOG_LEVEL_ERR:
- dlog_prio = DLOG_ERROR;
- break;
- case TBM_BACKEND_LOG_LEVEL_WRN:
- dlog_prio = DLOG_WARN;
- break;
- case TBM_BACKEND_LOG_LEVEL_INFO:
- dlog_prio = DLOG_INFO;
- break;
- case TBM_BACKEND_LOG_LEVEL_DBG:
- dlog_prio = DLOG_DEBUG;
- break;
- default:
- return;
- }
- __dlog_vprint(LOG_ID_SYSTEM, dlog_prio, LOG_TAG, fmt, arg);
-}
-
-void
-tbm_backend_log_print(int level, const char *fmt, ...)
-{
- va_list arg;
-
- if (level > tbm_log_debug_level)
- return;
-
- va_start(arg, fmt);
- _tbm_backend_log_dlog_print(level, fmt, arg);
- va_end(arg);
-}
\ No newline at end of file
+++ /dev/null
-/**************************************************************************
-
-libtbm_vigs
-
-Copyright 2021 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, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifndef __TBM_BACKEND_LOG_H__
-#define __TBM_BACKEND_LOG_H__
-
-#include <sys/syscall.h>
-#include <time.h>
-#include <dlog.h>
-
-enum {
- TBM_BACKEND_LOG_LEVEL_NONE,
- TBM_BACKEND_LOG_LEVEL_ERR,
- TBM_BACKEND_LOG_LEVEL_WRN,
- TBM_BACKEND_LOG_LEVEL_INFO,
- TBM_BACKEND_LOG_LEVEL_DBG,
-};
-
-
-/* log level */
-void tbm_backend_log_print(int level, const char *fmt, ...);
-
-#define TBM_BACKEND_DBG(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt, \
- (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
- (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
- } while (0)
-
-#define TBM_BACKEND_INFO(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt, \
- (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
- (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
- } while (0)
-
-#define TBM_BACKEND_WRN(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt, \
- (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
- (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
- } while (0)
-
-#define TBM_BACKEND_ERR(fmt, args...) \
- do { \
- struct timespec ts; \
- clock_gettime(CLOCK_MONOTONIC, &ts); \
- tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt, \
- (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
- (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
- } while (0)
-
-#define TBM_BACKEND_RETURN_IF_FAIL(cond) {\
- if (!(cond)) {\
- TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
- return;\
- } \
-}
-#define TBM_BACKEND_RETURN_VAL_IF_FAIL(cond, val) {\
- if (!(cond)) {\
- TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
- return val;\
- } \
-}
-#define TBM_BACKEND_GOTO_VAL_IF_FAIL(cond, val) {\
- if (!(cond)) {\
- TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
- goto val;\
- } \
-}
-
-#endif /* __TBM_BACKEND_LOG_H__ */
\ No newline at end of file
+++ /dev/null
-/*
- * 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 <hal-common.h>
-#include <hal-tbm-types.h>
-#include <hal-tbm-interface.h>
-#include "tbm_backend_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[] = {
- HAL_TBM_FORMAT_RGB888,
- HAL_TBM_FORMAT_ARGB8888,
- HAL_TBM_FORMAT_RGBA8888,
- HAL_TBM_FORMAT_XRGB8888,
- HAL_TBM_FORMAT_XBGR8888,
- HAL_TBM_FORMAT_NV21,
- HAL_TBM_FORMAT_NV61,
- HAL_TBM_FORMAT_YUV420,
-};
-
-typedef struct _tbm_vigs_bufmgr tbm_vigs_bufmgr;
-typedef struct _tbm_vigs_bo tbm_vigs_bo;
-
-/* tbm buffor object for vigs */
-struct _tbm_vigs_bo {
- struct vigs_drm_surface *sfc;
-
- tbm_vigs_bufmgr *bufmgr_data;
-};
-
-/* tbm bufmgr private for vigs */
-struct _tbm_vigs_bufmgr {
- int fd;
- void *hash_bos;
-
- struct vigs_drm_device *drm_dev;
-};
-
-static int
-_tbm_vigs_open_drm(void)
-{
- int fd = -1;
-
- fd = drmOpen(VIGS_DRM_NAME, NULL);
- if (fd < 0) {
- TBM_BACKEND_ERR("open vigs drm device failed");
- return -1;
- }
-
- return fd;
-}
-
-static unsigned int
-_get_name(int fd, unsigned int gem)
-{
- struct drm_gem_flink arg = {0,};
-
- arg.handle = gem;
- if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &arg)) {
- TBM_BACKEND_ERR("fail to DRM_IOCTL_GEM_FLINK gem:%d", gem);
- return 0;
- }
-
- return (unsigned int)arg.name;
-}
-
-static hal_tbm_bo_handle
-get_tbm_bo_handle(struct vigs_drm_surface *sfc, int device)
-{
- hal_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 HAL_TBM_DEVICE_DEFAULT:
- case HAL_TBM_DEVICE_2D:
- bo_handle.u32 = gem->handle;
- break;
- case HAL_TBM_DEVICE_CPU:
- ret = vigs_drm_gem_map(gem, 1);
-
- if (ret == 0)
- bo_handle.ptr = gem->vaddr;
- else
- TBM_BACKEND_ERR("vigs_drm_gem_map failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
-
- break;
- case HAL_TBM_DEVICE_3D:
- bo_handle.ptr = (void *)sfc;
- break;
- case HAL_TBM_DEVICE_MM:
- TBM_BACKEND_ERR("HAL_TBM_DEVICE_MM not supported");
- break;
- default:
- TBM_BACKEND_ERR("%d not supported", device);
- break;
- }
-
- return bo_handle;
-}
-
-static hal_tbm_bufmgr_capability
-tbm_vigs_bufmgr_get_capabilities(hal_tbm_bufmgr *bufmgr, hal_tbm_error *error)
-{
- hal_tbm_bufmgr_capability capabilities = HAL_TBM_BUFMGR_CAPABILITY_NONE;
-
- capabilities = HAL_TBM_BUFMGR_CAPABILITY_SHARE_KEY | HAL_TBM_BUFMGR_CAPABILITY_SHARE_FD;
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return capabilities;
-}
-
-static hal_tbm_error
-tbm_vigs_bufmgr_get_supported_formats(hal_tbm_bufmgr *bufmgr,
- uint32_t **formats, uint32_t *num)
-{
- tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
- uint32_t *color_formats;
-
- if (!bufmgr_data)
- return HAL_TBM_ERROR_INVALID_PARAMETER;
-
- color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_vigs_color_format_list));
- if (!color_formats)
- return HAL_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 HAL_TBM_ERROR_NONE;
-}
-
-static hal_tbm_error
-tbm_vigs_bufmgr_get_plane_data(hal_tbm_bufmgr *bufmgr,
- hal_tbm_format format, int plane_idx, int width,
- int height, uint32_t * size, uint32_t * offset,
- uint32_t * pitch, int *bo_idx)
-{
- tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
-
- *size = 0;
- *offset = 0;
- *pitch = 0;
- *bo_idx = 0;
-
- TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, HAL_TBM_ERROR_INVALID_PARAMETER);
-
- switch (format) {
- case HAL_TBM_FORMAT_RGB888:
- *size = width * height * 3;
- *offset = 0;
- *pitch = width * 3;
- *bo_idx = 0;
- return HAL_TBM_ERROR_NONE;
- case HAL_TBM_FORMAT_XRGB8888:
- case HAL_TBM_FORMAT_XBGR8888:
- case HAL_TBM_FORMAT_ARGB8888:
- case HAL_TBM_FORMAT_RGBA8888:
- *size = width * height * 4;
- *offset = 0;
- *pitch = width * 4;
- *bo_idx = 0;
- return HAL_TBM_ERROR_NONE;
- case HAL_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 HAL_TBM_ERROR_INVALID_PARAMETER;
- }
- return HAL_TBM_ERROR_NONE;
- case HAL_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 HAL_TBM_ERROR_INVALID_PARAMETER;
- }
- return HAL_TBM_ERROR_NONE;
- case HAL_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 HAL_TBM_ERROR_INVALID_PARAMETER;
- }
- return HAL_TBM_ERROR_NONE;
- default:
- return HAL_TBM_ERROR_INVALID_PARAMETER;
- }
-}
-
-static hal_tbm_bo *
-tbm_vigs_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size,
- hal_tbm_bo_memory_type flags, hal_tbm_error *error)
-{
- tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
- tbm_vigs_bo *bo_data;
- struct vigs_drm_device *drm_dev;
- struct vigs_drm_surface *sfc;
- uint32_t width = 2048, height;
- int ret;
- char buf[STRERR_BUFSIZE];
-
- if (bufmgr_data == NULL || bufmgr_data->drm_dev == NULL) {
- TBM_BACKEND_ERR("bufmgr_data is null\n");
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- drm_dev = bufmgr_data->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_BACKEND_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- bo_data = calloc(1, sizeof(struct _tbm_vigs_bo));
- if (!bo_data) {
- TBM_BACKEND_ERR("fail to allocate the bo_data private\n");
- vigs_drm_gem_unref(&sfc->gem);
- if (error)
- *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
- bo_data->bufmgr_data = bufmgr_data;
- bo_data->sfc = sfc;
-
- ret = vigs_drm_gem_get_name(&sfc->gem);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- vigs_drm_gem_unref(&sfc->gem);
- free(bo_data);
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- if (drmHashInsert(bufmgr_data->hash_bos, bo_data->sfc->gem.name, (void *)bo_data) < 0)
- TBM_BACKEND_ERR("Cannot insert bo_data to Hash(%d)\n", bo_data->sfc->gem.name);
-
- TBM_BACKEND_DBG("size = %d, flags = 0x%X", size, flags);
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return (hal_tbm_bo *)bo_data;
-}
-
-static hal_tbm_bo *
-tbm_vigs_bufmgr_alloc_bo_with_format(hal_tbm_bufmgr *bufmgr, int format, int bo_idx,
- int width, int height, int cpp, hal_tbm_bo_memory_type flags, hal_tbm_error *error)
-{
- tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
- tbm_vigs_bo *bo_data;
- struct vigs_drm_device *drm_dev;
- struct vigs_drm_surface *sfc;
- int ret;
- char buf[STRERR_BUFSIZE];
-
- if (bufmgr_data == NULL || bufmgr_data->drm_dev == NULL) {
- TBM_BACKEND_ERR("bufmgr_data is null\n");
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- if (bo_idx != 0) {
- TBM_BACKEND_ERR("Not supported bo idx");
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- drm_dev = bufmgr_data->drm_dev;
-
- switch (format) {
- case HAL_TBM_FORMAT_RGB888:
- ret = vigs_drm_surface_create(drm_dev, width, height, width * 3, vigs_drm_surface_bgra8888, 0, &sfc);
- break;
- case HAL_TBM_FORMAT_XRGB8888:
- case HAL_TBM_FORMAT_XBGR8888:
- ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
- break;
- case HAL_TBM_FORMAT_ARGB8888:
- case HAL_TBM_FORMAT_RGBA8888:
- ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
- break;
- case HAL_TBM_FORMAT_NV21:
- ret = vigs_drm_surface_create(drm_dev, width, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc);
- break;
- case HAL_TBM_FORMAT_NV61:
- ret = vigs_drm_surface_create(drm_dev, width, height * 2, width, vigs_drm_surface_bgra8888, 0, &sfc);
- break;
- case HAL_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_BACKEND_ERR("Not supported format");
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- bo_data = calloc(1, sizeof(struct _tbm_vigs_bo));
- if (!bo_data) {
- TBM_BACKEND_ERR("fail to allocate the bo_data private\n");
- vigs_drm_gem_unref(&sfc->gem);
- if (error)
- *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
- bo_data->bufmgr_data = bufmgr_data;
- bo_data->sfc = sfc;
-
- ret = vigs_drm_gem_get_name(&sfc->gem);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- vigs_drm_gem_unref(&sfc->gem);
- free(bo_data);
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- if (drmHashInsert(bufmgr_data->hash_bos, bo_data->sfc->gem.name, (void *)bo_data) < 0)
- TBM_BACKEND_ERR("Cannot insert bo_data to Hash(%d)\n", bo_data->sfc->gem.name);
-
- TBM_BACKEND_DBG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d",
- width, height, format, flags, bo_idx);
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return (hal_tbm_bo *)bo_data;
-}
-
-static hal_tbm_bo *
-tbm_vigs_bufmgr_import_fd(hal_tbm_bufmgr *bufmgr, hal_tbm_fd key, hal_tbm_error *error)
-{
- tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
- tbm_vigs_bo *bo_data;
- struct vigs_drm_device *drm_dev;
- struct vigs_drm_surface *sfc;
- int ret;
- char buf[STRERR_BUFSIZE];
- struct drm_prime_handle arg = {0, };
- unsigned int gem;
- unsigned int name;
-
- if (bufmgr_data == NULL || bufmgr_data->drm_dev == NULL) {
- TBM_BACKEND_ERR("bufmgr_data is null\n");
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- drm_dev = bufmgr_data->drm_dev;
-
- arg.fd = key;
- if (drmIoctl(bufmgr_data->drm_dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) {
- TBM_BACKEND_ERR("Cannot get gem handle from fd:%d (%s)\n",
- arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
- gem = arg.handle;
-
- name = _get_name(bufmgr_data->drm_dev->fd, gem);
- if (!name) {
- TBM_BACKEND_ERR("Cannot get name from gem:%d, fd:%d (%s)\n",
- gem, key, strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- ret = drmHashLookup(bufmgr_data->hash_bos, name, (void **)&bo_data);
- if (ret == 0) {
- if (gem == bo_data->sfc->gem.handle) {
- if (error)
- *error = HAL_TBM_ERROR_NONE;
- return (hal_tbm_bo *)bo_data;
- }
- }
-
- ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_prime_import_fd failed for key %d: %s",
- key, strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- bo_data = calloc(1, sizeof(struct _tbm_vigs_bo));
- if (!bo_data) {
- TBM_BACKEND_ERR("fail to allocate the bo_data private\n");
- vigs_drm_gem_unref(&sfc->gem);
- if (error)
- *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
- bo_data->bufmgr_data = bufmgr_data;
- bo_data->sfc = sfc;
-
- ret = vigs_drm_gem_get_name(&sfc->gem);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- vigs_drm_gem_unref(&sfc->gem);
- free(bo_data);
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- if (drmHashInsert(bufmgr_data->hash_bos, bo_data->sfc->gem.name, (void *)bo_data) < 0)
- TBM_BACKEND_ERR("Cannot insert bo_data to Hash(%d)\n", bo_data->sfc->gem.name);
-
- TBM_BACKEND_DBG("bo_data = %p, key = %u handle = %u", bo_data, key, sfc->gem.handle);
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return (hal_tbm_bo *)bo_data;
-}
-
-static hal_tbm_bo *
-tbm_vigs_bufmgr_import_key(hal_tbm_bufmgr *bufmgr, hal_tbm_key key, hal_tbm_error *error)
-{
- tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
- tbm_vigs_bo *bo_data;
- struct vigs_drm_device *drm_dev;
- int ret;
- struct vigs_drm_surface *sfc;
- char buf[STRERR_BUFSIZE];
-
- if (bufmgr_data == NULL || bufmgr_data->drm_dev == NULL) {
- TBM_BACKEND_ERR("bufmgr_data is null\n");
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- drm_dev = bufmgr_data->drm_dev;
-
- ret = drmHashLookup(bufmgr_data->hash_bos, key, (void **)&bo_data);
- if (ret == 0) {
- if (error)
- *error = HAL_TBM_ERROR_NONE;
- return (hal_tbm_bo *)bo_data;
- }
-
- ret = vigs_drm_surface_open(drm_dev, key, &sfc);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_surface_open failed for key %u: %s",
- key, strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- bo_data = calloc(1, sizeof(struct _tbm_vigs_bo));
- if (!bo_data) {
- TBM_BACKEND_ERR("fail to allocate the bo_data private\n");
- vigs_drm_gem_unref(&sfc->gem);
- if (error)
- *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
- bo_data->bufmgr_data = bufmgr_data;
- bo_data->sfc = sfc;
-
- ret = vigs_drm_gem_get_name(&sfc->gem);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- vigs_drm_gem_unref(&sfc->gem);
- free(bo_data);
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- if (drmHashInsert(bufmgr_data->hash_bos, bo_data->sfc->gem.name, (void *)bo_data) < 0)
- TBM_BACKEND_ERR("Cannot insert bo_data to Hash(%d)\n", bo_data->sfc->gem.name);
-
- TBM_BACKEND_DBG("bo_data = %p, key = %u handle = %u", bo_data, key, sfc->gem.handle);
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return (hal_tbm_bo *)bo_data;
-}
-
-static void
-tbm_vigs_bo_free(hal_tbm_bo *bo)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
- tbm_vigs_bo *temp;
- struct vigs_drm_surface *sfc;
- tbm_vigs_bufmgr *bufmgr_data;
- int ret;
-
- if (!bo_data)
- return;
-
- bufmgr_data = bo_data->bufmgr_data;
- if (!bufmgr_data)
- return;
-
- TBM_BACKEND_DBG("bo_data = %p", bo_data);
-
- sfc = bo_data->sfc;
-
- /* delete bo from hash */
- ret = drmHashLookup(bufmgr_data->hash_bos, bo_data->sfc->gem.name,
- (void **)&temp);
- if (ret == 0)
- drmHashDelete(bufmgr_data->hash_bos, bo_data->sfc->gem.name);
- else
- TBM_BACKEND_ERR("Cannot find bo_data to Hash(%d), ret=%d\n", bo_data->sfc->gem.name, ret);
-
- vigs_drm_gem_unref(&sfc->gem);
-
- free(bo_data);
-}
-
-static int
-tbm_vigs_bo_get_size(hal_tbm_bo *bo, hal_tbm_error *error)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
- struct vigs_drm_surface *sfc;
-
- if (!bo_data || !bo_data->sfc) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return 0;
- }
-
- TBM_BACKEND_DBG("bo_data = %p", bo_data);
-
- sfc = bo_data->sfc;
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return sfc->gem.size;
-}
-
-static hal_tbm_bo_memory_type
-tbm_vigs_bo_get_memory_type(hal_tbm_bo *bo, hal_tbm_error *error)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
-
- if (!bo_data || !bo_data->sfc) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return HAL_TBM_BO_DEFAULT;
- }
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return HAL_TBM_BO_DEFAULT;
-}
-
-static hal_tbm_bo_handle
-tbm_vigs_bo_get_handle(hal_tbm_bo *bo, hal_tbm_bo_device_type device, hal_tbm_error *error)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
- struct vigs_drm_surface *sfc;
- hal_tbm_bo_handle handle;
-
- if (!bo_data || !bo_data->sfc) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return (hal_tbm_bo_handle) NULL;
- }
-
- sfc = bo_data->sfc;
-
- TBM_BACKEND_DBG("bo_data = %p, device = %d", bo_data, device);
-
- handle = get_tbm_bo_handle(sfc, device);
- if (!handle.ptr) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return handle;
- }
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return handle;
-}
-
-static hal_tbm_bo_handle
-tbm_vigs_bo_map(hal_tbm_bo *bo, hal_tbm_bo_device_type device,
- hal_tbm_bo_access_option opt, hal_tbm_error *error)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
- struct vigs_drm_surface *sfc;
- hal_tbm_bo_handle handle;
- uint32_t saf = 0;
-
- if (!bo_data || !bo_data->sfc) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return (hal_tbm_bo_handle) NULL;
- }
-
- sfc = bo_data->sfc;
-
- TBM_BACKEND_DBG("bo_data = %p, device = %d, opt = %d", bo_data, device, opt);
-
- handle = get_tbm_bo_handle(sfc, device);
- if (!handle.ptr) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return handle;
- }
-
- if ((opt & HAL_TBM_OPTION_READ) != 0)
- saf |= VIGS_DRM_SAF_READ;
-
- if ((opt & HAL_TBM_OPTION_WRITE) != 0)
- saf |= VIGS_DRM_SAF_WRITE;
-
- vigs_drm_surface_start_access(sfc, saf);
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return handle;
-}
-
-static hal_tbm_error
-tbm_vigs_bo_unmap(hal_tbm_bo *bo)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
- struct vigs_drm_surface *sfc;
-
- if (!bo_data || !bo_data->sfc)
- return HAL_TBM_ERROR_INVALID_PARAMETER;
-
- sfc = bo_data->sfc;
-
- TBM_BACKEND_DBG("bo_data = %p", bo_data);
-
- vigs_drm_surface_end_access(sfc, 1);
-
- return HAL_TBM_ERROR_NONE;
-}
-
-static hal_tbm_error
-tbm_vigs_bo_lock(hal_tbm_bo *bo, hal_tbm_bo_device_type device,
- hal_tbm_bo_access_option opt)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
-
- if (!bo_data || !bo_data->sfc)
- return HAL_TBM_ERROR_INVALID_PARAMETER;
-
- TBM_BACKEND_DBG("bo_data = %p", bo_data);
-
- return HAL_TBM_ERROR_NONE;
-}
-
-static hal_tbm_error
-tbm_vigs_bo_unlock(hal_tbm_bo *bo)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
-
- if (!bo_data || !bo_data->sfc)
- return HAL_TBM_ERROR_INVALID_PARAMETER;
-
- TBM_BACKEND_DBG("bo_data = %p", bo_data);
-
- return HAL_TBM_ERROR_NONE;
-}
-
-hal_tbm_fd
-tbm_vigs_bo_export_fd(hal_tbm_bo *bo, hal_tbm_error *error)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
- tbm_vigs_bufmgr *bufmgr_data;
- struct vigs_drm_surface *sfc;
- struct vigs_drm_device *drm_dev;
- int ret, fd = 0;
- char buf[STRERR_BUFSIZE];
-
- if (!bo_data || !bo_data->sfc) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return -1;
- }
-
- bufmgr_data = bo_data->bufmgr_data;
- if (!bufmgr_data || !bufmgr_data->drm_dev) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return -1;
- }
-
- drm_dev = bufmgr_data->drm_dev;
- sfc = bo_data->sfc;
-
- ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_prime_export_fd failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return -1;
- }
-
- TBM_BACKEND_DBG(" bo_data:%p, gem:%d(%d)\n", bo_data, sfc->gem);
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return (hal_tbm_fd)fd;
-}
-
-static hal_tbm_key
-tbm_vigs_bo_export_key(hal_tbm_bo *bo, hal_tbm_error *error)
-{
- tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
- struct vigs_drm_surface *sfc;
- int ret;
- char buf[STRERR_BUFSIZE];
-
- if (!bo_data || !bo_data->sfc) {
- if (error)
- *error = HAL_TBM_ERROR_INVALID_PARAMETER;
- return 0;
- }
-
- sfc = bo_data->sfc;
-
- ret = vigs_drm_gem_get_name(&sfc->gem);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = HAL_TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- TBM_BACKEND_DBG(" bo_data:%p, gem:%d(%d)\n", bo_data, sfc->gem);
-
- if (error)
- *error = HAL_TBM_ERROR_NONE;
-
- return (hal_tbm_key)sfc->gem.name;
-}
-static void
-_tbm_vigs_bufmgr_deinitialize(tbm_vigs_bufmgr *bufmgr_data)
-{
- if (bufmgr_data->drm_dev)
- vigs_drm_device_destroy(bufmgr_data->drm_dev);
-
- g_drm_dev = NULL;
-}
-
-static hal_tbm_error
-_tbm_vigs_bufmgr_initailize(tbm_vigs_bufmgr *bufmgr_data)
-{
- struct vigs_drm_device *drm_dev = NULL;
- char buf[STRERR_BUFSIZE];
- int ret = 0;
-
- ret = vigs_drm_device_create(bufmgr_data->fd, &drm_dev);
- if (ret != 0) {
- TBM_BACKEND_ERR("vigs_drm_device_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
- vigs_drm_device_destroy(drm_dev);
- g_drm_dev = NULL;
- return HAL_TBM_ERROR_INVALID_OPERATION;
- }
-
- bufmgr_data->drm_dev = drm_dev;
- g_drm_dev = drm_dev;
-
- return HAL_TBM_ERROR_NONE;
-}
-
-static hal_tbm_error
-_tbm_vigs_authenticated_drm_fd_handler(hal_tbm_fd auth_fd, void *user_data)
-{
- tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *) user_data;
- int ret = 0;
-
- TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, HAL_TBM_ERROR_INVALID_PARAMETER);
-
- bufmgr_data->fd = auth_fd;
- TBM_BACKEND_INFO("Get the authenticated drm_fd(%d)!\n", bufmgr_data->fd);
-
- ret = _tbm_vigs_bufmgr_initailize(bufmgr_data);
- if (ret != HAL_TBM_ERROR_NONE) {
- TBM_BACKEND_ERR("_tbm_vigs_bufmgr_initailize failed.");
- return ret;
- }
-
- return HAL_TBM_ERROR_NONE;
-}
-
-static int
-hal_backend_tbm_vigs_exit(void *data)
-{
- hal_tbm_backend_data *backend_data = (hal_tbm_backend_data *)data;
- tbm_vigs_bufmgr *bufmgr_data;
- unsigned long key;
- void *value;
-
- TBM_BACKEND_DBG("enter");
-
- TBM_BACKEND_RETURN_VAL_IF_FAIL(backend_data != NULL, -1);
-
- bufmgr_data = (tbm_vigs_bufmgr *)backend_data->bufmgr;
- TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, -1);
-
- if (bufmgr_data->hash_bos) {
- while (drmHashFirst(bufmgr_data->hash_bos, &key, &value) > 0) {
- free(value);
- drmHashDelete(bufmgr_data->hash_bos, key);
- }
-
- drmHashDestroy(bufmgr_data->hash_bos);
- bufmgr_data->hash_bos = NULL;
- }
-
- if (backend_data->bufmgr_funcs)
- free(backend_data->bufmgr_funcs);
- if (backend_data->bo_funcs)
- free(backend_data->bo_funcs);
-
- _tbm_vigs_bufmgr_deinitialize(bufmgr_data);
-
- if (bufmgr_data->fd >= 0)
- close(bufmgr_data->fd);
-
- free(backend_data->bufmgr);
- free(backend_data);
-
- return HAL_TBM_ERROR_NONE;
-}
-
-static int
-hal_backend_tbm_vigs_init(void **data)
-{
- hal_tbm_backend_data *backend_data = NULL;
- hal_tbm_bufmgr_funcs *bufmgr_funcs = NULL;
- hal_tbm_bo_funcs *bo_funcs = NULL;
- tbm_vigs_bufmgr *bufmgr_data = NULL;
- int drm_fd = -1;
- int ret = 0;
-
- TBM_BACKEND_DBG("enter");
-
- /* allocate a hal_tbm_backend_data */
- backend_data = calloc(1, sizeof(struct _hal_tbm_backend_data));
- if (!backend_data) {
- TBM_BACKEND_ERR("fail to alloc backend_data!\n");
- *data = NULL;
- return -1;
- }
- *data = backend_data;
-
- /* allocate a hal_tbm_bufmgr */
- bufmgr_data = calloc(1, sizeof(struct _tbm_vigs_bufmgr));
- if (!bufmgr_data) {
- TBM_BACKEND_ERR("fail to alloc bufmgr_data!\n");
- goto fail_alloc_bufmgr_data;
- }
- backend_data->bufmgr = (hal_tbm_bufmgr *)bufmgr_data;
-
- bufmgr_data->fd = -1;
-
- // open drm_fd
- drm_fd = _tbm_vigs_open_drm();
- if (drm_fd < 0) {
- TBM_BACKEND_ERR("fail to open drm!\n");
- goto fail_open_drm;
- }
-
- // set true when backend has a drm_device.
- backend_data->has_drm_device = 1;
-
- // check if drm_fd is master_drm_fd.
- if (drmIsMaster(drm_fd)) {
- // drm_fd is a master_drm_fd.
- backend_data->drm_info.drm_fd = drm_fd;
- backend_data->drm_info.is_master = 1;
-
- bufmgr_data->fd = drm_fd;
- TBM_BACKEND_INFO("Get the master drm_fd(%d)!\n", bufmgr_data->fd);
-
- ret = _tbm_vigs_bufmgr_initailize(bufmgr_data);
- if (ret != HAL_TBM_ERROR_NONE) {
- TBM_BACKEND_ERR("_tbm_vigs_bufmgr_initailize failed.");
- goto fail_create_vigs_drm_device;
- }
- } else {
- // drm_fd is not a master_drm_fd.
- // request authenticated fd
- close(drm_fd);
- backend_data->drm_info.drm_fd = -1;
- backend_data->drm_info.is_master = 0;
- backend_data->drm_info.auth_drm_fd_func = _tbm_vigs_authenticated_drm_fd_handler;
- backend_data->drm_info.user_data = bufmgr_data;
-
- TBM_BACKEND_INFO("A backend requests an authenticated drm_fd.\n");
- }
-
- bufmgr_data->hash_bos = drmHashCreate();
-
- /* alloc and register bufmgr_funcs */
- bufmgr_funcs = calloc(1, sizeof(struct _hal_tbm_bufmgr_funcs));
- if (!bufmgr_funcs) {
- TBM_BACKEND_ERR("fail to alloc bufmgr_funcs!\n");
- goto fail_alloc_bufmgr_funcs;
- }
- backend_data->bufmgr_funcs = bufmgr_funcs;
-
- bufmgr_funcs->bufmgr_get_capabilities = tbm_vigs_bufmgr_get_capabilities;
- bufmgr_funcs->bufmgr_get_supported_formats = tbm_vigs_bufmgr_get_supported_formats;
- bufmgr_funcs->bufmgr_get_plane_data = tbm_vigs_bufmgr_get_plane_data;
- bufmgr_funcs->bufmgr_alloc_bo = tbm_vigs_bufmgr_alloc_bo;
- bufmgr_funcs->bufmgr_alloc_bo_with_format = tbm_vigs_bufmgr_alloc_bo_with_format;
- bufmgr_funcs->bufmgr_import_fd = tbm_vigs_bufmgr_import_fd;
- bufmgr_funcs->bufmgr_import_key = tbm_vigs_bufmgr_import_key;
-
- /* alloc and register bo_funcs */
- bo_funcs = calloc(1, sizeof(struct _hal_tbm_bo_funcs));
- if (!bo_funcs) {
- TBM_BACKEND_ERR("fail to alloc bo_funcs!\n");
- goto fail_alloc_bo_funcs;
- }
- backend_data->bo_funcs = bo_funcs;
-
- bo_funcs->bo_free = tbm_vigs_bo_free;
- bo_funcs->bo_get_size = tbm_vigs_bo_get_size;
- bo_funcs->bo_get_memory_types = tbm_vigs_bo_get_memory_type;
- bo_funcs->bo_get_handle = tbm_vigs_bo_get_handle;
- bo_funcs->bo_map = tbm_vigs_bo_map;
- bo_funcs->bo_unmap = tbm_vigs_bo_unmap;
- bo_funcs->bo_lock = tbm_vigs_bo_lock;
- bo_funcs->bo_unlock = tbm_vigs_bo_unlock;
- bo_funcs->bo_export_fd = tbm_vigs_bo_export_fd;
- bo_funcs->bo_export_key = tbm_vigs_bo_export_key;
-
- TBM_BACKEND_DBG("drm_fd:%d\n", bufmgr_data->fd);
-
- return HAL_TBM_ERROR_NONE;
-
-fail_alloc_bo_funcs:
- free(bufmgr_funcs);
-fail_alloc_bufmgr_funcs:
- drmHashDestroy(bufmgr_data->hash_bos);
- _tbm_vigs_bufmgr_deinitialize(bufmgr_data);
-fail_create_vigs_drm_device:
- if (bufmgr_data->fd >= 0)
- close(bufmgr_data->fd);
-fail_open_drm:
- free(bufmgr_data);
-fail_alloc_bufmgr_data:
- free(backend_data);
-
- g_drm_dev = NULL;
- *data = NULL;
-
- return -1;
-}
-
-hal_backend hal_backend_tbm_data = {
- "vigs",
- "Samsung",
- HAL_ABI_VERSION_TIZEN_6_5,
- hal_backend_tbm_vigs_init,
- hal_backend_tbm_vigs_exit
-};
-
-struct vigs_drm_device *
-libhal_backend_tbm_vigs_get_drm_dev(void)
-{
- return g_drm_dev;
-}
+++ /dev/null
-/*
- * 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
--- /dev/null
+/*
+ * libhal-backend-tbm-vigs header
+ *
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact :
+ * SooChan Lim <sc1.lim@samsung.com>
+ * Junkyeong kim <jk0430.kim@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 _LIBHAL_BACKEND_TBM_VIGS_LOG_H_
+#define _LIBHAL_BACKEND_TBM_VIGS_LOG_H_
+
+#include "vigs.h"
+
+struct vigs_drm_device *libhal_backend_tbm_vigs_get_drm_dev(void);
+
+#endif
+++ /dev/null
-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
+++ /dev/null
-/*
- * 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;
- void *hash_bos;
-
- 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 unsigned int
-_get_name(int fd, unsigned int gem)
-{
- struct drm_gem_flink arg = {0,};
-
- arg.handle = gem;
- if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &arg)) {
- TBM_ERR("fail to DRM_IOCTL_GEM_FLINK gem:%d", gem);
- return 0;
- }
-
- return (unsigned int)arg.name;
-}
-
-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;
-
- 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));
- vigs_drm_gem_unref(&sfc->gem);
- free(bo_vigs);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- if (drmHashInsert(bufmgr_vigs->hash_bos, bo_vigs->sfc->gem.name, (void *)bo_vigs) < 0)
- TBM_ERR("Cannot insert bo_vigs to Hash(%d)\n", bo_vigs->sfc->gem.name);
-
- 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;
-
- 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));
- vigs_drm_gem_unref(&sfc->gem);
- free(bo_vigs);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- if (drmHashInsert(bufmgr_vigs->hash_bos, bo_vigs->sfc->gem.name, (void *)bo_vigs) < 0)
- TBM_ERR("Cannot insert bo_vigs to Hash(%d)\n", bo_vigs->sfc->gem.name);
-
- 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];
- struct drm_prime_handle arg = {0, };
- unsigned int gem;
- unsigned int name;
-
- 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;
-
- arg.fd = key;
- if (drmIoctl(bufmgr_vigs->drm_dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) {
- TBM_ERR("Cannot get gem handle from fd:%d (%s)\n",
- arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
- gem = arg.handle;
-
- name = _get_name(bufmgr_vigs->drm_dev->fd, gem);
- if (!name) {
- TBM_ERR("Cannot get name from gem:%d, fd:%d (%s)\n",
- gem, key, strerror_r(errno, buf, STRERR_BUFSIZE));
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return NULL;
- }
-
- ret = drmHashLookup(bufmgr_vigs->hash_bos, name, (void **)&bo_vigs);
- if (ret == 0) {
- if (gem == bo_vigs->sfc->gem.handle) {
- if (error)
- *error = TBM_ERROR_NONE;
- return (tbm_backend_bo_data *)bo_vigs;
- }
- }
-
- 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;
-
- 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));
- vigs_drm_gem_unref(&sfc->gem);
- free(bo_vigs);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- if (drmHashInsert(bufmgr_vigs->hash_bos, bo_vigs->sfc->gem.name, (void *)bo_vigs) < 0)
- TBM_ERR("Cannot insert bo_vigs to Hash(%d)\n", bo_vigs->sfc->gem.name);
-
- 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 = drmHashLookup(bufmgr_vigs->hash_bos, key, (void **)&bo_vigs);
- if (ret == 0) {
- if (error)
- *error = TBM_ERROR_NONE;
- return (tbm_backend_bo_data *)bo_vigs;
- }
-
- 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;
-
- 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));
- vigs_drm_gem_unref(&sfc->gem);
- free(bo_vigs);
- if (error)
- *error = TBM_ERROR_INVALID_OPERATION;
- return 0;
- }
-
- if (drmHashInsert(bufmgr_vigs->hash_bos, bo_vigs->sfc->gem.name, (void *)bo_vigs) < 0)
- TBM_ERR("Cannot insert bo_vigs to Hash(%d)\n", bo_vigs->sfc->gem.name);
-
- 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;
- tbm_bo_vigs temp;
- struct vigs_drm_surface *sfc;
- tbm_bufmgr_vigs bufmgr_vigs;
- int ret;
-
- if (!bo_data)
- return;
-
- bufmgr_vigs = bo_vigs->bufmgr_vigs;
- if (!bufmgr_vigs)
- return;
-
- TBM_DBG("bo_vigs = %p", bo_vigs);
-
- sfc = bo_vigs->sfc;
-
- /* delete bo from hash */
- ret = drmHashLookup(bufmgr_vigs->hash_bos, sfc->gem.name,
- (void **)&temp);
- if (ret == 0)
- drmHashDelete(bufmgr_vigs->hash_bos, sfc->gem.name);
- else
- TBM_ERR("Cannot find bo_vigs to Hash(%d), ret=%d\n", sfc->gem.name, ret);
-
- vigs_drm_gem_unref(&sfc->gem);
-
- free(bo_vigs);
-}
-
-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;
- unsigned long key;
- void *value;
-
- 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 (bufmgr_vigs->hash_bos) {
- while (drmHashFirst(bufmgr_vigs->hash_bos, &key, &value) > 0) {
- free(value);
- drmHashDelete(bufmgr_vigs->hash_bos, key);
- }
-
- drmHashDestroy(bufmgr_vigs->hash_bos);
- bufmgr_vigs->hash_bos = NULL;
- }
-
- 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;
-
- bufmgr_vigs->hash_bos = drmHashCreate();
-
- /* 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:
- drmHashDestroy(bufmgr_vigs->hash_bos);
- 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;
-}
+++ /dev/null
-/*
- * 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
--- /dev/null
+/**************************************************************************
+
+libtbm_vigs
+
+Copyright 2021 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, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include "tbm_backend_log.h"
+
+#undef LOG_TAG
+#define LOG_TAG "TBM_BACKEND"
+
+unsigned int tbm_log_debug_level = TBM_BACKEND_LOG_LEVEL_INFO;
+
+static void
+_tbm_backend_log_dlog_print(int level, const char *fmt, va_list arg)
+{
+ log_priority dlog_prio;
+
+ switch (level) {
+ case TBM_BACKEND_LOG_LEVEL_ERR:
+ dlog_prio = DLOG_ERROR;
+ break;
+ case TBM_BACKEND_LOG_LEVEL_WRN:
+ dlog_prio = DLOG_WARN;
+ break;
+ case TBM_BACKEND_LOG_LEVEL_INFO:
+ dlog_prio = DLOG_INFO;
+ break;
+ case TBM_BACKEND_LOG_LEVEL_DBG:
+ dlog_prio = DLOG_DEBUG;
+ break;
+ default:
+ return;
+ }
+ __dlog_vprint(LOG_ID_SYSTEM, dlog_prio, LOG_TAG, fmt, arg);
+}
+
+void
+tbm_backend_log_print(int level, const char *fmt, ...)
+{
+ va_list arg;
+
+ if (level > tbm_log_debug_level)
+ return;
+
+ va_start(arg, fmt);
+ _tbm_backend_log_dlog_print(level, fmt, arg);
+ va_end(arg);
+}
\ No newline at end of file
--- /dev/null
+/**************************************************************************
+
+libtbm_vigs
+
+Copyright 2021 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, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifndef __TBM_BACKEND_LOG_H__
+#define __TBM_BACKEND_LOG_H__
+
+#include <sys/syscall.h>
+#include <time.h>
+#include <dlog.h>
+
+enum {
+ TBM_BACKEND_LOG_LEVEL_NONE,
+ TBM_BACKEND_LOG_LEVEL_ERR,
+ TBM_BACKEND_LOG_LEVEL_WRN,
+ TBM_BACKEND_LOG_LEVEL_INFO,
+ TBM_BACKEND_LOG_LEVEL_DBG,
+};
+
+
+/* log level */
+void tbm_backend_log_print(int level, const char *fmt, ...);
+
+#define TBM_BACKEND_DBG(fmt, args...) \
+ do { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_DBG, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } while (0)
+
+#define TBM_BACKEND_INFO(fmt, args...) \
+ do { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_INFO, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } while (0)
+
+#define TBM_BACKEND_WRN(fmt, args...) \
+ do { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_WRN, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } while (0)
+
+#define TBM_BACKEND_ERR(fmt, args...) \
+ do { \
+ struct timespec ts; \
+ clock_gettime(CLOCK_MONOTONIC, &ts); \
+ tbm_backend_log_print(TBM_BACKEND_LOG_LEVEL_ERR, "[%5d.%06d][%d][%s %d]"fmt, \
+ (int)ts.tv_sec, (int)ts.tv_nsec / 1000, \
+ (int)syscall(SYS_gettid), __FUNCTION__, __LINE__, ##args); \
+ } while (0)
+
+#define TBM_BACKEND_RETURN_IF_FAIL(cond) {\
+ if (!(cond)) {\
+ TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
+ return;\
+ } \
+}
+#define TBM_BACKEND_RETURN_VAL_IF_FAIL(cond, val) {\
+ if (!(cond)) {\
+ TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
+ return val;\
+ } \
+}
+#define TBM_BACKEND_GOTO_VAL_IF_FAIL(cond, val) {\
+ if (!(cond)) {\
+ TBM_BACKEND_ERR("'%s' failed.\n", #cond);\
+ goto val;\
+ } \
+}
+
+#endif /* __TBM_BACKEND_LOG_H__ */
\ No newline at end of file
--- /dev/null
+/*
+ * 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 <hal-common.h>
+#include <hal-tbm-types.h>
+#include <hal-tbm-interface.h>
+#include "tbm_backend_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[] = {
+ HAL_TBM_FORMAT_RGB888,
+ HAL_TBM_FORMAT_ARGB8888,
+ HAL_TBM_FORMAT_RGBA8888,
+ HAL_TBM_FORMAT_XRGB8888,
+ HAL_TBM_FORMAT_XBGR8888,
+ HAL_TBM_FORMAT_NV21,
+ HAL_TBM_FORMAT_NV61,
+ HAL_TBM_FORMAT_YUV420,
+};
+
+typedef struct _tbm_vigs_bufmgr tbm_vigs_bufmgr;
+typedef struct _tbm_vigs_bo tbm_vigs_bo;
+
+/* tbm buffor object for vigs */
+struct _tbm_vigs_bo {
+ struct vigs_drm_surface *sfc;
+
+ tbm_vigs_bufmgr *bufmgr_data;
+};
+
+/* tbm bufmgr private for vigs */
+struct _tbm_vigs_bufmgr {
+ int fd;
+ void *hash_bos;
+
+ struct vigs_drm_device *drm_dev;
+};
+
+static int
+_tbm_vigs_open_drm(void)
+{
+ int fd = -1;
+
+ fd = drmOpen(VIGS_DRM_NAME, NULL);
+ if (fd < 0) {
+ TBM_BACKEND_ERR("open vigs drm device failed");
+ return -1;
+ }
+
+ return fd;
+}
+
+static unsigned int
+_get_name(int fd, unsigned int gem)
+{
+ struct drm_gem_flink arg = {0,};
+
+ arg.handle = gem;
+ if (drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &arg)) {
+ TBM_BACKEND_ERR("fail to DRM_IOCTL_GEM_FLINK gem:%d", gem);
+ return 0;
+ }
+
+ return (unsigned int)arg.name;
+}
+
+static hal_tbm_bo_handle
+get_tbm_bo_handle(struct vigs_drm_surface *sfc, int device)
+{
+ hal_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 HAL_TBM_DEVICE_DEFAULT:
+ case HAL_TBM_DEVICE_2D:
+ bo_handle.u32 = gem->handle;
+ break;
+ case HAL_TBM_DEVICE_CPU:
+ ret = vigs_drm_gem_map(gem, 1);
+
+ if (ret == 0)
+ bo_handle.ptr = gem->vaddr;
+ else
+ TBM_BACKEND_ERR("vigs_drm_gem_map failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+
+ break;
+ case HAL_TBM_DEVICE_3D:
+ bo_handle.ptr = (void *)sfc;
+ break;
+ case HAL_TBM_DEVICE_MM:
+ TBM_BACKEND_ERR("HAL_TBM_DEVICE_MM not supported");
+ break;
+ default:
+ TBM_BACKEND_ERR("%d not supported", device);
+ break;
+ }
+
+ return bo_handle;
+}
+
+static hal_tbm_bufmgr_capability
+tbm_vigs_bufmgr_get_capabilities(hal_tbm_bufmgr *bufmgr, hal_tbm_error *error)
+{
+ hal_tbm_bufmgr_capability capabilities = HAL_TBM_BUFMGR_CAPABILITY_NONE;
+
+ capabilities = HAL_TBM_BUFMGR_CAPABILITY_SHARE_KEY | HAL_TBM_BUFMGR_CAPABILITY_SHARE_FD;
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return capabilities;
+}
+
+static hal_tbm_error
+tbm_vigs_bufmgr_get_supported_formats(hal_tbm_bufmgr *bufmgr,
+ uint32_t **formats, uint32_t *num)
+{
+ tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
+ uint32_t *color_formats;
+
+ if (!bufmgr_data)
+ return HAL_TBM_ERROR_INVALID_PARAMETER;
+
+ color_formats = (uint32_t *) calloc(1, sizeof(tbm_bufmgr_vigs_color_format_list));
+ if (!color_formats)
+ return HAL_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 HAL_TBM_ERROR_NONE;
+}
+
+static hal_tbm_error
+tbm_vigs_bufmgr_get_plane_data(hal_tbm_bufmgr *bufmgr,
+ hal_tbm_format format, int plane_idx, int width,
+ int height, uint32_t * size, uint32_t * offset,
+ uint32_t * pitch, int *bo_idx)
+{
+ tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
+
+ *size = 0;
+ *offset = 0;
+ *pitch = 0;
+ *bo_idx = 0;
+
+ TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, HAL_TBM_ERROR_INVALID_PARAMETER);
+
+ switch (format) {
+ case HAL_TBM_FORMAT_RGB888:
+ *size = width * height * 3;
+ *offset = 0;
+ *pitch = width * 3;
+ *bo_idx = 0;
+ return HAL_TBM_ERROR_NONE;
+ case HAL_TBM_FORMAT_XRGB8888:
+ case HAL_TBM_FORMAT_XBGR8888:
+ case HAL_TBM_FORMAT_ARGB8888:
+ case HAL_TBM_FORMAT_RGBA8888:
+ *size = width * height * 4;
+ *offset = 0;
+ *pitch = width * 4;
+ *bo_idx = 0;
+ return HAL_TBM_ERROR_NONE;
+ case HAL_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 HAL_TBM_ERROR_INVALID_PARAMETER;
+ }
+ return HAL_TBM_ERROR_NONE;
+ case HAL_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 HAL_TBM_ERROR_INVALID_PARAMETER;
+ }
+ return HAL_TBM_ERROR_NONE;
+ case HAL_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 HAL_TBM_ERROR_INVALID_PARAMETER;
+ }
+ return HAL_TBM_ERROR_NONE;
+ default:
+ return HAL_TBM_ERROR_INVALID_PARAMETER;
+ }
+}
+
+static hal_tbm_bo *
+tbm_vigs_bufmgr_alloc_bo(hal_tbm_bufmgr *bufmgr, unsigned int size,
+ hal_tbm_bo_memory_type flags, hal_tbm_error *error)
+{
+ tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
+ tbm_vigs_bo *bo_data;
+ struct vigs_drm_device *drm_dev;
+ struct vigs_drm_surface *sfc;
+ uint32_t width = 2048, height;
+ int ret;
+ char buf[STRERR_BUFSIZE];
+
+ if (bufmgr_data == NULL || bufmgr_data->drm_dev == NULL) {
+ TBM_BACKEND_ERR("bufmgr_data is null\n");
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return NULL;
+ }
+
+ drm_dev = bufmgr_data->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_BACKEND_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return NULL;
+ }
+
+ bo_data = calloc(1, sizeof(struct _tbm_vigs_bo));
+ if (!bo_data) {
+ TBM_BACKEND_ERR("fail to allocate the bo_data private\n");
+ vigs_drm_gem_unref(&sfc->gem);
+ if (error)
+ *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ bo_data->bufmgr_data = bufmgr_data;
+ bo_data->sfc = sfc;
+
+ ret = vigs_drm_gem_get_name(&sfc->gem);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ vigs_drm_gem_unref(&sfc->gem);
+ free(bo_data);
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return 0;
+ }
+
+ if (drmHashInsert(bufmgr_data->hash_bos, bo_data->sfc->gem.name, (void *)bo_data) < 0)
+ TBM_BACKEND_ERR("Cannot insert bo_data to Hash(%d)\n", bo_data->sfc->gem.name);
+
+ TBM_BACKEND_DBG("size = %d, flags = 0x%X", size, flags);
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return (hal_tbm_bo *)bo_data;
+}
+
+static hal_tbm_bo *
+tbm_vigs_bufmgr_alloc_bo_with_format(hal_tbm_bufmgr *bufmgr, int format, int bo_idx,
+ int width, int height, int cpp, hal_tbm_bo_memory_type flags, hal_tbm_error *error)
+{
+ tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
+ tbm_vigs_bo *bo_data;
+ struct vigs_drm_device *drm_dev;
+ struct vigs_drm_surface *sfc;
+ int ret;
+ char buf[STRERR_BUFSIZE];
+
+ if (bufmgr_data == NULL || bufmgr_data->drm_dev == NULL) {
+ TBM_BACKEND_ERR("bufmgr_data is null\n");
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return NULL;
+ }
+
+ if (bo_idx != 0) {
+ TBM_BACKEND_ERR("Not supported bo idx");
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return NULL;
+ }
+
+ drm_dev = bufmgr_data->drm_dev;
+
+ switch (format) {
+ case HAL_TBM_FORMAT_RGB888:
+ ret = vigs_drm_surface_create(drm_dev, width, height, width * 3, vigs_drm_surface_bgra8888, 0, &sfc);
+ break;
+ case HAL_TBM_FORMAT_XRGB8888:
+ case HAL_TBM_FORMAT_XBGR8888:
+ ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
+ break;
+ case HAL_TBM_FORMAT_ARGB8888:
+ case HAL_TBM_FORMAT_RGBA8888:
+ ret = vigs_drm_surface_create(drm_dev, width, height, width * 4, vigs_drm_surface_bgra8888, 0, &sfc);
+ break;
+ case HAL_TBM_FORMAT_NV21:
+ ret = vigs_drm_surface_create(drm_dev, width, height * 3 >> 1, width, vigs_drm_surface_bgra8888, 0, &sfc);
+ break;
+ case HAL_TBM_FORMAT_NV61:
+ ret = vigs_drm_surface_create(drm_dev, width, height * 2, width, vigs_drm_surface_bgra8888, 0, &sfc);
+ break;
+ case HAL_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_BACKEND_ERR("Not supported format");
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return NULL;
+ }
+
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_suface_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return NULL;
+ }
+
+ bo_data = calloc(1, sizeof(struct _tbm_vigs_bo));
+ if (!bo_data) {
+ TBM_BACKEND_ERR("fail to allocate the bo_data private\n");
+ vigs_drm_gem_unref(&sfc->gem);
+ if (error)
+ *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ bo_data->bufmgr_data = bufmgr_data;
+ bo_data->sfc = sfc;
+
+ ret = vigs_drm_gem_get_name(&sfc->gem);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ vigs_drm_gem_unref(&sfc->gem);
+ free(bo_data);
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return 0;
+ }
+
+ if (drmHashInsert(bufmgr_data->hash_bos, bo_data->sfc->gem.name, (void *)bo_data) < 0)
+ TBM_BACKEND_ERR("Cannot insert bo_data to Hash(%d)\n", bo_data->sfc->gem.name);
+
+ TBM_BACKEND_DBG("width = %d, height = %d, format = %x, flags = 0x%X bo_idx = %d",
+ width, height, format, flags, bo_idx);
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return (hal_tbm_bo *)bo_data;
+}
+
+static hal_tbm_bo *
+tbm_vigs_bufmgr_import_fd(hal_tbm_bufmgr *bufmgr, hal_tbm_fd key, hal_tbm_error *error)
+{
+ tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
+ tbm_vigs_bo *bo_data;
+ struct vigs_drm_device *drm_dev;
+ struct vigs_drm_surface *sfc;
+ int ret;
+ char buf[STRERR_BUFSIZE];
+ struct drm_prime_handle arg = {0, };
+ unsigned int gem;
+ unsigned int name;
+
+ if (bufmgr_data == NULL || bufmgr_data->drm_dev == NULL) {
+ TBM_BACKEND_ERR("bufmgr_data is null\n");
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return NULL;
+ }
+
+ drm_dev = bufmgr_data->drm_dev;
+
+ arg.fd = key;
+ if (drmIoctl(bufmgr_data->drm_dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &arg)) {
+ TBM_BACKEND_ERR("Cannot get gem handle from fd:%d (%s)\n",
+ arg.fd, strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return NULL;
+ }
+ gem = arg.handle;
+
+ name = _get_name(bufmgr_data->drm_dev->fd, gem);
+ if (!name) {
+ TBM_BACKEND_ERR("Cannot get name from gem:%d, fd:%d (%s)\n",
+ gem, key, strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return NULL;
+ }
+
+ ret = drmHashLookup(bufmgr_data->hash_bos, name, (void **)&bo_data);
+ if (ret == 0) {
+ if (gem == bo_data->sfc->gem.handle) {
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+ return (hal_tbm_bo *)bo_data;
+ }
+ }
+
+ ret = vigs_drm_prime_import_fd(drm_dev, key, &sfc);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_prime_import_fd failed for key %d: %s",
+ key, strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return NULL;
+ }
+
+ bo_data = calloc(1, sizeof(struct _tbm_vigs_bo));
+ if (!bo_data) {
+ TBM_BACKEND_ERR("fail to allocate the bo_data private\n");
+ vigs_drm_gem_unref(&sfc->gem);
+ if (error)
+ *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ bo_data->bufmgr_data = bufmgr_data;
+ bo_data->sfc = sfc;
+
+ ret = vigs_drm_gem_get_name(&sfc->gem);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ vigs_drm_gem_unref(&sfc->gem);
+ free(bo_data);
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return 0;
+ }
+
+ if (drmHashInsert(bufmgr_data->hash_bos, bo_data->sfc->gem.name, (void *)bo_data) < 0)
+ TBM_BACKEND_ERR("Cannot insert bo_data to Hash(%d)\n", bo_data->sfc->gem.name);
+
+ TBM_BACKEND_DBG("bo_data = %p, key = %u handle = %u", bo_data, key, sfc->gem.handle);
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return (hal_tbm_bo *)bo_data;
+}
+
+static hal_tbm_bo *
+tbm_vigs_bufmgr_import_key(hal_tbm_bufmgr *bufmgr, hal_tbm_key key, hal_tbm_error *error)
+{
+ tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *)bufmgr;
+ tbm_vigs_bo *bo_data;
+ struct vigs_drm_device *drm_dev;
+ int ret;
+ struct vigs_drm_surface *sfc;
+ char buf[STRERR_BUFSIZE];
+
+ if (bufmgr_data == NULL || bufmgr_data->drm_dev == NULL) {
+ TBM_BACKEND_ERR("bufmgr_data is null\n");
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return NULL;
+ }
+
+ drm_dev = bufmgr_data->drm_dev;
+
+ ret = drmHashLookup(bufmgr_data->hash_bos, key, (void **)&bo_data);
+ if (ret == 0) {
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+ return (hal_tbm_bo *)bo_data;
+ }
+
+ ret = vigs_drm_surface_open(drm_dev, key, &sfc);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_surface_open failed for key %u: %s",
+ key, strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return NULL;
+ }
+
+ bo_data = calloc(1, sizeof(struct _tbm_vigs_bo));
+ if (!bo_data) {
+ TBM_BACKEND_ERR("fail to allocate the bo_data private\n");
+ vigs_drm_gem_unref(&sfc->gem);
+ if (error)
+ *error = HAL_TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+ bo_data->bufmgr_data = bufmgr_data;
+ bo_data->sfc = sfc;
+
+ ret = vigs_drm_gem_get_name(&sfc->gem);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ vigs_drm_gem_unref(&sfc->gem);
+ free(bo_data);
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return 0;
+ }
+
+ if (drmHashInsert(bufmgr_data->hash_bos, bo_data->sfc->gem.name, (void *)bo_data) < 0)
+ TBM_BACKEND_ERR("Cannot insert bo_data to Hash(%d)\n", bo_data->sfc->gem.name);
+
+ TBM_BACKEND_DBG("bo_data = %p, key = %u handle = %u", bo_data, key, sfc->gem.handle);
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return (hal_tbm_bo *)bo_data;
+}
+
+static void
+tbm_vigs_bo_free(hal_tbm_bo *bo)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+ tbm_vigs_bo *temp;
+ struct vigs_drm_surface *sfc;
+ tbm_vigs_bufmgr *bufmgr_data;
+ int ret;
+
+ if (!bo_data)
+ return;
+
+ bufmgr_data = bo_data->bufmgr_data;
+ if (!bufmgr_data)
+ return;
+
+ TBM_BACKEND_DBG("bo_data = %p", bo_data);
+
+ sfc = bo_data->sfc;
+
+ /* delete bo from hash */
+ ret = drmHashLookup(bufmgr_data->hash_bos, bo_data->sfc->gem.name,
+ (void **)&temp);
+ if (ret == 0)
+ drmHashDelete(bufmgr_data->hash_bos, bo_data->sfc->gem.name);
+ else
+ TBM_BACKEND_ERR("Cannot find bo_data to Hash(%d), ret=%d\n", bo_data->sfc->gem.name, ret);
+
+ vigs_drm_gem_unref(&sfc->gem);
+
+ free(bo_data);
+}
+
+static int
+tbm_vigs_bo_get_size(hal_tbm_bo *bo, hal_tbm_error *error)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+ struct vigs_drm_surface *sfc;
+
+ if (!bo_data || !bo_data->sfc) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return 0;
+ }
+
+ TBM_BACKEND_DBG("bo_data = %p", bo_data);
+
+ sfc = bo_data->sfc;
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return sfc->gem.size;
+}
+
+static hal_tbm_bo_memory_type
+tbm_vigs_bo_get_memory_type(hal_tbm_bo *bo, hal_tbm_error *error)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+
+ if (!bo_data || !bo_data->sfc) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return HAL_TBM_BO_DEFAULT;
+ }
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return HAL_TBM_BO_DEFAULT;
+}
+
+static hal_tbm_bo_handle
+tbm_vigs_bo_get_handle(hal_tbm_bo *bo, hal_tbm_bo_device_type device, hal_tbm_error *error)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+ struct vigs_drm_surface *sfc;
+ hal_tbm_bo_handle handle;
+
+ if (!bo_data || !bo_data->sfc) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return (hal_tbm_bo_handle) NULL;
+ }
+
+ sfc = bo_data->sfc;
+
+ TBM_BACKEND_DBG("bo_data = %p, device = %d", bo_data, device);
+
+ handle = get_tbm_bo_handle(sfc, device);
+ if (!handle.ptr) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return handle;
+ }
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return handle;
+}
+
+static hal_tbm_bo_handle
+tbm_vigs_bo_map(hal_tbm_bo *bo, hal_tbm_bo_device_type device,
+ hal_tbm_bo_access_option opt, hal_tbm_error *error)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+ struct vigs_drm_surface *sfc;
+ hal_tbm_bo_handle handle;
+ uint32_t saf = 0;
+
+ if (!bo_data || !bo_data->sfc) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return (hal_tbm_bo_handle) NULL;
+ }
+
+ sfc = bo_data->sfc;
+
+ TBM_BACKEND_DBG("bo_data = %p, device = %d, opt = %d", bo_data, device, opt);
+
+ handle = get_tbm_bo_handle(sfc, device);
+ if (!handle.ptr) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return handle;
+ }
+
+ if ((opt & HAL_TBM_OPTION_READ) != 0)
+ saf |= VIGS_DRM_SAF_READ;
+
+ if ((opt & HAL_TBM_OPTION_WRITE) != 0)
+ saf |= VIGS_DRM_SAF_WRITE;
+
+ vigs_drm_surface_start_access(sfc, saf);
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return handle;
+}
+
+static hal_tbm_error
+tbm_vigs_bo_unmap(hal_tbm_bo *bo)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+ struct vigs_drm_surface *sfc;
+
+ if (!bo_data || !bo_data->sfc)
+ return HAL_TBM_ERROR_INVALID_PARAMETER;
+
+ sfc = bo_data->sfc;
+
+ TBM_BACKEND_DBG("bo_data = %p", bo_data);
+
+ vigs_drm_surface_end_access(sfc, 1);
+
+ return HAL_TBM_ERROR_NONE;
+}
+
+static hal_tbm_error
+tbm_vigs_bo_lock(hal_tbm_bo *bo, hal_tbm_bo_device_type device,
+ hal_tbm_bo_access_option opt)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+
+ if (!bo_data || !bo_data->sfc)
+ return HAL_TBM_ERROR_INVALID_PARAMETER;
+
+ TBM_BACKEND_DBG("bo_data = %p", bo_data);
+
+ return HAL_TBM_ERROR_NONE;
+}
+
+static hal_tbm_error
+tbm_vigs_bo_unlock(hal_tbm_bo *bo)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+
+ if (!bo_data || !bo_data->sfc)
+ return HAL_TBM_ERROR_INVALID_PARAMETER;
+
+ TBM_BACKEND_DBG("bo_data = %p", bo_data);
+
+ return HAL_TBM_ERROR_NONE;
+}
+
+hal_tbm_fd
+tbm_vigs_bo_export_fd(hal_tbm_bo *bo, hal_tbm_error *error)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+ tbm_vigs_bufmgr *bufmgr_data;
+ struct vigs_drm_surface *sfc;
+ struct vigs_drm_device *drm_dev;
+ int ret, fd = 0;
+ char buf[STRERR_BUFSIZE];
+
+ if (!bo_data || !bo_data->sfc) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return -1;
+ }
+
+ bufmgr_data = bo_data->bufmgr_data;
+ if (!bufmgr_data || !bufmgr_data->drm_dev) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return -1;
+ }
+
+ drm_dev = bufmgr_data->drm_dev;
+ sfc = bo_data->sfc;
+
+ ret = vigs_drm_prime_export_fd(drm_dev, sfc, &fd);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_prime_export_fd failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return -1;
+ }
+
+ TBM_BACKEND_DBG(" bo_data:%p, gem:%d(%d)\n", bo_data, sfc->gem);
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return (hal_tbm_fd)fd;
+}
+
+static hal_tbm_key
+tbm_vigs_bo_export_key(hal_tbm_bo *bo, hal_tbm_error *error)
+{
+ tbm_vigs_bo *bo_data = (tbm_vigs_bo *)bo;
+ struct vigs_drm_surface *sfc;
+ int ret;
+ char buf[STRERR_BUFSIZE];
+
+ if (!bo_data || !bo_data->sfc) {
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_PARAMETER;
+ return 0;
+ }
+
+ sfc = bo_data->sfc;
+
+ ret = vigs_drm_gem_get_name(&sfc->gem);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_gem_get_name failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = HAL_TBM_ERROR_INVALID_OPERATION;
+ return 0;
+ }
+
+ TBM_BACKEND_DBG(" bo_data:%p, gem:%d(%d)\n", bo_data, sfc->gem);
+
+ if (error)
+ *error = HAL_TBM_ERROR_NONE;
+
+ return (hal_tbm_key)sfc->gem.name;
+}
+static void
+_tbm_vigs_bufmgr_deinitialize(tbm_vigs_bufmgr *bufmgr_data)
+{
+ if (bufmgr_data->drm_dev)
+ vigs_drm_device_destroy(bufmgr_data->drm_dev);
+
+ g_drm_dev = NULL;
+}
+
+static hal_tbm_error
+_tbm_vigs_bufmgr_initailize(tbm_vigs_bufmgr *bufmgr_data)
+{
+ struct vigs_drm_device *drm_dev = NULL;
+ char buf[STRERR_BUFSIZE];
+ int ret = 0;
+
+ ret = vigs_drm_device_create(bufmgr_data->fd, &drm_dev);
+ if (ret != 0) {
+ TBM_BACKEND_ERR("vigs_drm_device_create failed: %s", strerror_r(errno, buf, STRERR_BUFSIZE));
+ vigs_drm_device_destroy(drm_dev);
+ g_drm_dev = NULL;
+ return HAL_TBM_ERROR_INVALID_OPERATION;
+ }
+
+ bufmgr_data->drm_dev = drm_dev;
+ g_drm_dev = drm_dev;
+
+ return HAL_TBM_ERROR_NONE;
+}
+
+static hal_tbm_error
+_tbm_vigs_authenticated_drm_fd_handler(hal_tbm_fd auth_fd, void *user_data)
+{
+ tbm_vigs_bufmgr *bufmgr_data = (tbm_vigs_bufmgr *) user_data;
+ int ret = 0;
+
+ TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, HAL_TBM_ERROR_INVALID_PARAMETER);
+
+ bufmgr_data->fd = auth_fd;
+ TBM_BACKEND_INFO("Get the authenticated drm_fd(%d)!\n", bufmgr_data->fd);
+
+ ret = _tbm_vigs_bufmgr_initailize(bufmgr_data);
+ if (ret != HAL_TBM_ERROR_NONE) {
+ TBM_BACKEND_ERR("_tbm_vigs_bufmgr_initailize failed.");
+ return ret;
+ }
+
+ return HAL_TBM_ERROR_NONE;
+}
+
+static int
+hal_backend_tbm_vigs_exit(void *data)
+{
+ hal_tbm_backend_data *backend_data = (hal_tbm_backend_data *)data;
+ tbm_vigs_bufmgr *bufmgr_data;
+ unsigned long key;
+ void *value;
+
+ TBM_BACKEND_DBG("enter");
+
+ TBM_BACKEND_RETURN_VAL_IF_FAIL(backend_data != NULL, -1);
+
+ bufmgr_data = (tbm_vigs_bufmgr *)backend_data->bufmgr;
+ TBM_BACKEND_RETURN_VAL_IF_FAIL(bufmgr_data != NULL, -1);
+
+ if (bufmgr_data->hash_bos) {
+ while (drmHashFirst(bufmgr_data->hash_bos, &key, &value) > 0) {
+ free(value);
+ drmHashDelete(bufmgr_data->hash_bos, key);
+ }
+
+ drmHashDestroy(bufmgr_data->hash_bos);
+ bufmgr_data->hash_bos = NULL;
+ }
+
+ if (backend_data->bufmgr_funcs)
+ free(backend_data->bufmgr_funcs);
+ if (backend_data->bo_funcs)
+ free(backend_data->bo_funcs);
+
+ _tbm_vigs_bufmgr_deinitialize(bufmgr_data);
+
+ if (bufmgr_data->fd >= 0)
+ close(bufmgr_data->fd);
+
+ free(backend_data->bufmgr);
+ free(backend_data);
+
+ return HAL_TBM_ERROR_NONE;
+}
+
+static int
+hal_backend_tbm_vigs_init(void **data)
+{
+ hal_tbm_backend_data *backend_data = NULL;
+ hal_tbm_bufmgr_funcs *bufmgr_funcs = NULL;
+ hal_tbm_bo_funcs *bo_funcs = NULL;
+ tbm_vigs_bufmgr *bufmgr_data = NULL;
+ int drm_fd = -1;
+ int ret = 0;
+
+ TBM_BACKEND_DBG("enter");
+
+ /* allocate a hal_tbm_backend_data */
+ backend_data = calloc(1, sizeof(struct _hal_tbm_backend_data));
+ if (!backend_data) {
+ TBM_BACKEND_ERR("fail to alloc backend_data!\n");
+ *data = NULL;
+ return -1;
+ }
+ *data = backend_data;
+
+ /* allocate a hal_tbm_bufmgr */
+ bufmgr_data = calloc(1, sizeof(struct _tbm_vigs_bufmgr));
+ if (!bufmgr_data) {
+ TBM_BACKEND_ERR("fail to alloc bufmgr_data!\n");
+ goto fail_alloc_bufmgr_data;
+ }
+ backend_data->bufmgr = (hal_tbm_bufmgr *)bufmgr_data;
+
+ bufmgr_data->fd = -1;
+
+ // open drm_fd
+ drm_fd = _tbm_vigs_open_drm();
+ if (drm_fd < 0) {
+ TBM_BACKEND_ERR("fail to open drm!\n");
+ goto fail_open_drm;
+ }
+
+ // set true when backend has a drm_device.
+ backend_data->has_drm_device = 1;
+
+ // check if drm_fd is master_drm_fd.
+ if (drmIsMaster(drm_fd)) {
+ // drm_fd is a master_drm_fd.
+ backend_data->drm_info.drm_fd = drm_fd;
+ backend_data->drm_info.is_master = 1;
+
+ bufmgr_data->fd = drm_fd;
+ TBM_BACKEND_INFO("Get the master drm_fd(%d)!\n", bufmgr_data->fd);
+
+ ret = _tbm_vigs_bufmgr_initailize(bufmgr_data);
+ if (ret != HAL_TBM_ERROR_NONE) {
+ TBM_BACKEND_ERR("_tbm_vigs_bufmgr_initailize failed.");
+ goto fail_create_vigs_drm_device;
+ }
+ } else {
+ // drm_fd is not a master_drm_fd.
+ // request authenticated fd
+ close(drm_fd);
+ backend_data->drm_info.drm_fd = -1;
+ backend_data->drm_info.is_master = 0;
+ backend_data->drm_info.auth_drm_fd_func = _tbm_vigs_authenticated_drm_fd_handler;
+ backend_data->drm_info.user_data = bufmgr_data;
+
+ TBM_BACKEND_INFO("A backend requests an authenticated drm_fd.\n");
+ }
+
+ bufmgr_data->hash_bos = drmHashCreate();
+
+ /* alloc and register bufmgr_funcs */
+ bufmgr_funcs = calloc(1, sizeof(struct _hal_tbm_bufmgr_funcs));
+ if (!bufmgr_funcs) {
+ TBM_BACKEND_ERR("fail to alloc bufmgr_funcs!\n");
+ goto fail_alloc_bufmgr_funcs;
+ }
+ backend_data->bufmgr_funcs = bufmgr_funcs;
+
+ bufmgr_funcs->bufmgr_get_capabilities = tbm_vigs_bufmgr_get_capabilities;
+ bufmgr_funcs->bufmgr_get_supported_formats = tbm_vigs_bufmgr_get_supported_formats;
+ bufmgr_funcs->bufmgr_get_plane_data = tbm_vigs_bufmgr_get_plane_data;
+ bufmgr_funcs->bufmgr_alloc_bo = tbm_vigs_bufmgr_alloc_bo;
+ bufmgr_funcs->bufmgr_alloc_bo_with_format = tbm_vigs_bufmgr_alloc_bo_with_format;
+ bufmgr_funcs->bufmgr_import_fd = tbm_vigs_bufmgr_import_fd;
+ bufmgr_funcs->bufmgr_import_key = tbm_vigs_bufmgr_import_key;
+
+ /* alloc and register bo_funcs */
+ bo_funcs = calloc(1, sizeof(struct _hal_tbm_bo_funcs));
+ if (!bo_funcs) {
+ TBM_BACKEND_ERR("fail to alloc bo_funcs!\n");
+ goto fail_alloc_bo_funcs;
+ }
+ backend_data->bo_funcs = bo_funcs;
+
+ bo_funcs->bo_free = tbm_vigs_bo_free;
+ bo_funcs->bo_get_size = tbm_vigs_bo_get_size;
+ bo_funcs->bo_get_memory_types = tbm_vigs_bo_get_memory_type;
+ bo_funcs->bo_get_handle = tbm_vigs_bo_get_handle;
+ bo_funcs->bo_map = tbm_vigs_bo_map;
+ bo_funcs->bo_unmap = tbm_vigs_bo_unmap;
+ bo_funcs->bo_lock = tbm_vigs_bo_lock;
+ bo_funcs->bo_unlock = tbm_vigs_bo_unlock;
+ bo_funcs->bo_export_fd = tbm_vigs_bo_export_fd;
+ bo_funcs->bo_export_key = tbm_vigs_bo_export_key;
+
+ TBM_BACKEND_DBG("drm_fd:%d\n", bufmgr_data->fd);
+
+ return HAL_TBM_ERROR_NONE;
+
+fail_alloc_bo_funcs:
+ free(bufmgr_funcs);
+fail_alloc_bufmgr_funcs:
+ drmHashDestroy(bufmgr_data->hash_bos);
+ _tbm_vigs_bufmgr_deinitialize(bufmgr_data);
+fail_create_vigs_drm_device:
+ if (bufmgr_data->fd >= 0)
+ close(bufmgr_data->fd);
+fail_open_drm:
+ free(bufmgr_data);
+fail_alloc_bufmgr_data:
+ free(backend_data);
+
+ g_drm_dev = NULL;
+ *data = NULL;
+
+ return -1;
+}
+
+hal_backend hal_backend_tbm_data = {
+ "vigs",
+ "Samsung",
+ HAL_ABI_VERSION_TIZEN_6_5,
+ hal_backend_tbm_vigs_init,
+ hal_backend_tbm_vigs_exit
+};
+
+struct vigs_drm_device *
+libhal_backend_tbm_vigs_get_drm_dev(void)
+{
+ return g_drm_dev;
+}