From: Junkyeong Kim Date: Wed, 10 Feb 2021 09:06:44 +0000 (+0900) Subject: make hal-backend-tbm-vigs package X-Git-Tag: submit/tizen/20210312.004154~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c99ea540b7000e953b84fb490544268a2cbdddda;p=platform%2Fadaptation%2Femulator%2Flibtbm-vigs.git make hal-backend-tbm-vigs package This is the first step for implementing the new hal backend. libhal-backend-tbm-vigs package has a new hal backend module. The new hal architecture will be available for Tizen 6.5. Change-Id: I5ae4fd664b99aba08ed01a68bed4a3360f948484 Signed-off-by: Junkyeong Kim --- diff --git a/Makefile.am b/Makefile.am index 4d3fc73..02d3393 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ SUBDIRS = src pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libtbm-vigs.pc \ No newline at end of file +pkgconfig_DATA = libtbm-vigs.pc hal-backend-tbm-vigs.pc diff --git a/configure.ac b/configure.ac index 8fc38ca..18cb477 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,9 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 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 " @@ -49,11 +52,28 @@ AC_SUBST(LIBTBM_VIGS_LIBS) 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]), + [ HAL_LIBDIR="$withval" ], + [ HAL_LIBDIR="${DEFAULT_HAL_LIBDIR}" ]) +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_SUBST(LIBHAL_BACKEND_TBM_VIGS_CFLAGS) +AC_SUBST(LIBHAL_BACKEND_TBM_VIGS_LIBS) + AC_OUTPUT([ Makefile src/libtbm-vigs/Makefile + src/libhal-backend-tbm-vigs/Makefile src/Makefile - libtbm-vigs.pc]) + libtbm-vigs.pc + hal-backend-tbm-vigs.pc]) echo "" echo "CFLAGS : $CFLAGS" @@ -61,4 +81,7 @@ 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 "" diff --git a/hal-backend-tbm-vigs.pc.in b/hal-backend-tbm-vigs.pc.in new file mode 100644 index 0000000..5f1044a --- /dev/null +++ b/hal-backend-tbm-vigs.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +hal_libdir=@HAL_LIBDIR@ +includedir=@includedir@ + +Name: hal-backend-tbm-vigs +Description: the library for Tizen Buffer Manager vigs backend +Version: @PACKAGE_VERSION@ +Libs: -L${hal_libdir} -lhal-backend-tbm-vigs +Cflags: -I${includedir} -I${includedir}/tbm-vigs diff --git a/packaging/libhal-backend-tbm-vigs.manifest b/packaging/libhal-backend-tbm-vigs.manifest new file mode 100644 index 0000000..017d22d --- /dev/null +++ b/packaging/libhal-backend-tbm-vigs.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/libtbm-vigs.spec b/packaging/libtbm-vigs.spec index 7535c52..32c9341 100644 --- a/packaging/libtbm-vigs.spec +++ b/packaging/libtbm-vigs.spec @@ -6,12 +6,16 @@ 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} @@ -23,13 +27,33 @@ 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} @@ -60,6 +84,11 @@ if [ -f %{_libdir}/libtbm_vigs.so.0.0.0 ]; then fi ln -s %{_libdir}/bufmgr/libtbm_vigs.so.0.0.0 %{_libdir}/libtbm_vigs.so.0.0.0 +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 -p /sbin/ldconfig %files @@ -74,3 +103,15 @@ ln -s %{_libdir}/bufmgr/libtbm_vigs.so.0.0.0 %{_libdir}/libtbm_vigs.so.0.0.0 %{_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 +%license 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 diff --git a/src/Makefile.am b/src/Makefile.am index 05e726e..7244c42 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = libtbm-vigs +SUBDIRS = libtbm-vigs libhal-backend-tbm-vigs diff --git a/src/libhal-backend-tbm-vigs/Makefile.am b/src/libhal-backend-tbm-vigs/Makefile.am new file mode 100644 index 0000000..c857ce1 --- /dev/null +++ b/src/libhal-backend-tbm-vigs/Makefile.am @@ -0,0 +1,15 @@ +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 diff --git a/src/libhal-backend-tbm-vigs/libhal_backend_tbm_vigs.h b/src/libhal-backend-tbm-vigs/libhal_backend_tbm_vigs.h new file mode 100644 index 0000000..9d65686 --- /dev/null +++ b/src/libhal-backend-tbm-vigs/libhal_backend_tbm_vigs.h @@ -0,0 +1,40 @@ +/* + * libhal-backend-tbm-vigs header + * + * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact : + * SooChan Lim + * Junkyeong kim + * + * 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 diff --git a/src/libhal-backend-tbm-vigs/tbm_backend_log.c b/src/libhal-backend-tbm-vigs/tbm_backend_log.c new file mode 100644 index 0000000..cfd8ce9 --- /dev/null +++ b/src/libhal-backend-tbm-vigs/tbm_backend_log.c @@ -0,0 +1,43 @@ +#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 diff --git a/src/libhal-backend-tbm-vigs/tbm_backend_log.h b/src/libhal-backend-tbm-vigs/tbm_backend_log.h new file mode 100644 index 0000000..f530f8b --- /dev/null +++ b/src/libhal-backend-tbm-vigs/tbm_backend_log.h @@ -0,0 +1,105 @@ +/************************************************************************** + +libtbm_vigs + +Copyright 2021 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim + +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 +#include +#include + +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 diff --git a/src/libhal-backend-tbm-vigs/tbm_backend_vigs.c b/src/libhal-backend-tbm-vigs/tbm_backend_vigs.c new file mode 100644 index 0000000..a4466e4 --- /dev/null +++ b/src/libhal-backend-tbm-vigs/tbm_backend_vigs.c @@ -0,0 +1,948 @@ +/* + * buffer manager for libtbm-vigs + * + * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact : + * Stanislav Vorobiov + * Jinhyung Jo + * Sangho Park + * YeongKyoon Lee + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#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; + 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 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; + + 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, 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; + + 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]; + + 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 = 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; + + 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 = 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; + + 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; + struct vigs_drm_surface *sfc; + + if (!bo_data) + return; + + TBM_BACKEND_DBG("bo_data = %p", bo_data); + + sfc = bo_data->sfc; + + vigs_drm_gem_unref(&sfc->gem); +} + +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; + + 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 (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"); +#if 0 + if (!*data) { + TBM_BACKEND_ERR("*data is null.\n"); + return -1; + } +#endif + /* 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"); + } + + /* 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; + bufmgr_funcs->bufmgr_alloc_bo_with_tiled_format = NULL; + + /* 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: + _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; +} diff --git a/src/libhal-backend-tbm-vigs/tbm_vigs.h b/src/libhal-backend-tbm-vigs/tbm_vigs.h new file mode 100644 index 0000000..eefeacb --- /dev/null +++ b/src/libhal-backend-tbm-vigs/tbm_vigs.h @@ -0,0 +1,39 @@ +/* + * libtbm-vigs header + * + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact : + * SooChan Lim + * + * 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