From 2a2f523a32947b6f2e6564645e87cc170e6a1218 Mon Sep 17 00:00:00 2001 From: Changyeon Lee Date: Wed, 22 Jun 2022 17:04:50 +0900 Subject: [PATCH] remove legacy libtbm backend Change-Id: Id9b3842a254b72456719f1667f2de2d6c40af254 --- configure.ac | 21 +- libtbm-shm.manifest | 5 - ...m-shm.manifest => hal-backend-tbm-shm.manifest} | 0 .../{libtbm-shm.spec => hal-backend-tbm-shm.spec} | 39 +- packaging/libhal-backend-tbm-shm.manifest | 5 - src/Makefile.am | 13 +- src/libhal-backend-tbm-shm/Makefile.am | 12 - src/libtbm-shm/Makefile.am | 11 - src/libtbm-shm/tbm_bufmgr_shm.c | 970 --------------------- src/{libhal-backend-tbm-shm => }/tbm_backend_log.c | 0 src/{libhal-backend-tbm-shm => }/tbm_backend_log.h | 0 src/{libhal-backend-tbm-shm => }/tbm_backend_shm.c | 0 12 files changed, 21 insertions(+), 1055 deletions(-) delete mode 100644 libtbm-shm.manifest rename packaging/{libtbm-shm.manifest => hal-backend-tbm-shm.manifest} (100%) rename packaging/{libtbm-shm.spec => hal-backend-tbm-shm.spec} (55%) delete mode 100644 packaging/libhal-backend-tbm-shm.manifest delete mode 100644 src/libhal-backend-tbm-shm/Makefile.am delete mode 100644 src/libtbm-shm/Makefile.am delete mode 100644 src/libtbm-shm/tbm_bufmgr_shm.c rename src/{libhal-backend-tbm-shm => }/tbm_backend_log.c (100%) rename src/{libhal-backend-tbm-shm => }/tbm_backend_log.h (100%) rename src/{libhal-backend-tbm-shm => }/tbm_backend_shm.c (100%) diff --git a/configure.ac b/configure.ac index 646bb16..5241e4a 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. AC_PREREQ(2.60) -AC_INIT(libtbm-shm, 2.0.0) +AC_INIT(hal-backend-tbm-shm, 2.0.0) AC_USE_SYSTEM_EXTENSIONS AC_CONFIG_SRCDIR([Makefile.am]) AM_INIT_AUTOMAKE([dist-bzip2]) @@ -36,7 +36,6 @@ AC_FUNC_ALLOCA # Enable quiet compiles on automake 1.11. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) -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) @@ -57,35 +56,21 @@ AC_ARG_ENABLE(cachectrl, if test "x$CACHE_CTRL" = xyes; then AC_DEFINE(ENABLE_CACHECRTL, 1, [Enable cache control]) fi - -LIBTBM_SHM_CFLAGS="$LIBDRM_CFLAGS $LIBTBM_CFLAGS $DLOG_CFLAGS " -LIBTBM_SHM_LIBS="$LIBDRM_LIBS $LIBTBM_LIBS $DLOG_LIBS " -AC_SUBST(LIBTBM_SHM_CFLAGS) -AC_SUBST(LIBTBM_SHM_LIBS) - -bufmgr_dir=${libdir#*/} -AC_SUBST(bufmgr_dir) - -# for libhal-backend-tbm-shm LIBHAL_BACKEND_TBM_SHM_CFLAGS="$HAL_API_COMMON_CFLAGS $HAL_API_TBM_CFLAGS $LIBDRM_CFLAGS $DLOG_CFLAGS" LIBHAL_BACKEND_TBM_SHM_LIBS="$HAL_API_COMMON_LIBS $HAL_API_TBM_LIBS $LIBDRM_LIBS $DLOG_LIBS" + AC_SUBST(LIBHAL_BACKEND_TBM_SHM_CFLAGS) AC_SUBST(LIBHAL_BACKEND_TBM_SHM_LIBS) AC_OUTPUT([ Makefile - src/libtbm-shm/Makefile - src/libhal-backend-tbm-shm/Makefile src/Makefile]) echo "" echo "CFLAGS : $CFLAGS" echo "LDFLAGS : $LDFLAGS" -echo "LIBTBM_SHM_CFLAGS : $LIBTBM_SHM_CFLAGS" -echo "LIBTBM_SHM_LIBS : $LIBTBM_SHM_LIBS" -echo "bufmgr_dir : $bufmgr_dir" echo "LIBHAL_BACKEND_TBM_SHM_CFLAGS : $LIBHAL_BACKEND_TBM_SHM_CFLAGS" echo "LIBHAL_BACKEND_TBM_SHM_LIBS : $LIBHAL_BACKEND_TBM_SHM_LIBS" -echo "hal-libdir : $HAL_LIBDIR" +echo "HAL_LIBDIR : $HAL_LIBDIR" echo "" diff --git a/libtbm-shm.manifest b/libtbm-shm.manifest deleted file mode 100644 index 97e8c31..0000000 --- a/libtbm-shm.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/libtbm-shm.manifest b/packaging/hal-backend-tbm-shm.manifest similarity index 100% rename from packaging/libtbm-shm.manifest rename to packaging/hal-backend-tbm-shm.manifest diff --git a/packaging/libtbm-shm.spec b/packaging/hal-backend-tbm-shm.spec similarity index 55% rename from packaging/libtbm-shm.spec rename to packaging/hal-backend-tbm-shm.spec index 2acd41d..526883a 100644 --- a/packaging/libtbm-shm.spec +++ b/packaging/hal-backend-tbm-shm.spec @@ -1,42 +1,30 @@ -Name: libtbm-shm +Name: hal-backend-tbm-shm Version: 3.0.1 Release: 1 License: MIT -Summary: Tizen Buffer Manager - drm shm backend +Summary: hal-backend-tbm module for shm Group: System/Libraries ExcludeArch: i586 Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest -Source1002: libhal-backend-tbm-shm.manifest BuildRequires: pkgconfig(libdrm) -BuildRequires: pkgconfig(libtbm) BuildRequires: pkgconfig(hal-api-common) BuildRequires: pkgconfig(hal-api-tbm) BuildRequires: pkgconfig(dlog) %description -descriptionion: Tizen Buffer manager backend module uses drm shm - -%package -n hal-backend-tbm-shm -Summary: hal-backend-tbm module for drm shm -Group: System/Libraries -Requires: hal-api-tbm -Requires: hal-api-common - -%description -n hal-backend-tbm-shm -descriptionion: hal tbm backend module for drm shm +description: hal tbm backend module for drm shm %global TZ_SYS_RO_SHARE %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE}%{!?TZ_SYS_RO_SHARE:/usr/share} %prep %setup -q cp %{SOURCE1001} . -cp %{SOURCE1002} . %build -%reconfigure --prefix=%{_prefix} --libdir=%{_libdir}/bufmgr \ +%reconfigure --prefix=%{_prefix} --libdir=%{_libdir} \ --with-hal-libdir=%{_hal_libdir} \ --disable-cachectrl \ FLAGS="${CFLAGS} -Wall -Werror" LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed" @@ -51,31 +39,16 @@ rm -rf %{buildroot} mkdir -p %{buildroot}%{_hal_licensedir}/libhal-backend-tbm-shm cp -af COPYING %{buildroot}%{_hal_licensedir}/libhal-backend-tbm-shm - %post -if [ -f %{_libdir}/bufmgr/libtbm_default.so ]; then - rm -rf %{_libdir}/bufmgr/libtbm_default.so -fi -ln -s libtbm_shm.so %{_libdir}/bufmgr/libtbm_default.so - -%postun -p /sbin/ldconfig - -%post -n hal-backend-tbm-shm if [ -f %{_hal_libdir}/libhal-backend-tbm.so ]; then rm -rf %{_hal_libdir}/libhal-backend-tbm.so fi ln -s libhal-backend-tbm-shm.so %{_hal_libdir}/libhal-backend-tbm.so -%postun -n hal-backend-tbm-shm -p /sbin/ldconfig +%postun -p /sbin/ldconfig %files %defattr(-,root,root,-) -%manifest libtbm-shm.manifest -%license COPYING -%{_libdir}/bufmgr/libtbm_*.so* - -%files -n hal-backend-tbm-shm -%defattr(-,root,root,-) -%manifest libhal-backend-tbm-shm.manifest +%manifest %{name}.manifest %{_hal_licensedir}/libhal-backend-tbm-shm/COPYING %{_hal_libdir}/libhal-backend-*.so* diff --git a/packaging/libhal-backend-tbm-shm.manifest b/packaging/libhal-backend-tbm-shm.manifest deleted file mode 100644 index 75b0fa5..0000000 --- a/packaging/libhal-backend-tbm-shm.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/src/Makefile.am b/src/Makefile.am index 9cbd3b5..3477f41 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1 +1,12 @@ -SUBDIRS = libtbm-shm libhal-backend-tbm-shm +AM_CFLAGS = \ + @LIBHAL_BACKEND_TBM_SHM_CFLAGS@ \ + -I$(top_srcdir) \ + -I$(top_srcdir)/src + +libhal_backend_tbm_shm_la_LTLIBRARIES = libhal-backend-tbm-shm.la +libhal_backend_tbm_shm_ladir = @HAL_LIBDIR@ +libhal_backend_tbm_shm_la_LIBADD = @LIBHAL_BACKEND_TBM_SHM_LIBS@ + +libhal_backend_tbm_shm_la_SOURCES = \ + tbm_backend_log.c \ + tbm_backend_shm.c diff --git a/src/libhal-backend-tbm-shm/Makefile.am b/src/libhal-backend-tbm-shm/Makefile.am deleted file mode 100644 index e2c1f91..0000000 --- a/src/libhal-backend-tbm-shm/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -AM_CFLAGS = \ - @LIBHAL_BACKEND_TBM_SHM_CFLAGS@ \ - -I$(top_srcdir) \ - -I$(top_srcdir)/src/libhal-backend-tbm-shm - -libhal_backend_tbm_shm_la_LTLIBRARIES = libhal-backend-tbm-shm.la -libhal_backend_tbm_shm_ladir = @HAL_LIBDIR@ -libhal_backend_tbm_shm_la_LIBADD = @LIBHAL_BACKEND_TBM_SHM_LIBS@ - -libhal_backend_tbm_shm_la_SOURCES = \ - tbm_backend_log.c \ - tbm_backend_shm.c diff --git a/src/libtbm-shm/Makefile.am b/src/libtbm-shm/Makefile.am deleted file mode 100644 index 05a380b..0000000 --- a/src/libtbm-shm/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -AM_CFLAGS = \ - @LIBTBM_SHM_CFLAGS@ \ - -I$(top_srcdir) \ - -I$(top_srcdir)/src - -libtbm_shm_la_LTLIBRARIES = libtbm_shm.la -libtbm_shm_ladir = /${bufmgr_dir} -libtbm_shm_la_LIBADD = @LIBTBM_SHM_LIBS@ - -libtbm_shm_la_SOURCES = \ - tbm_bufmgr_shm.c diff --git a/src/libtbm-shm/tbm_bufmgr_shm.c b/src/libtbm-shm/tbm_bufmgr_shm.c deleted file mode 100644 index 88c6522..0000000 --- a/src/libtbm-shm/tbm_bufmgr_shm.c +++ /dev/null @@ -1,970 +0,0 @@ -/************************************************************************** - - libtbm_shm - - Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved. - - Contact: SooChan Lim , Sangjin 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, 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. - - **************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -#define DEBUG -#define TBM_COLOR_FORMAT_COUNT 4 -#define STRERR_BUFSIZE 128 - -#ifdef DEBUG -#define LOG_TAG "TBM_BACKEND" -#include -static int bDebug = 0; - -char* -target_name() -{ - FILE *f; - char *slash; - static int initialized = 0; - static char app_name[128]; - - if (initialized) - return app_name; - - /* get the application name */ - f = fopen("/proc/self/cmdline", "r"); - - if (!f) - return 0; - - memset(app_name, 0x00, sizeof(app_name)); - - if (fgets(app_name, 100, f) == NULL) { - fclose(f); - return 0; - } - - fclose(f); - - if ((slash = strrchr(app_name, '/')) != NULL) - memmove(app_name, slash + 1, strlen(slash)); - - initialized = 1; - - return app_name; -} -#define TBM_SHM_LOG(fmt, args...) LOGE("\033[31m" "[%s]" fmt "\033[0m", target_name(), ##args) -#define DBG(fmt, args...) if (bDebug&01) LOGE(fmt, ##args) -#else -#define TBM_SHM_LOG(...) -#define DBG(...) -#endif - -#define SIZE_ALIGN(value, base) (((value) + ((base) - 1)) & ~((base) - 1)) - -#define TBM_SURFACE_ALIGNMENT_PLANE (64) -#define TBM_SURFACE_ALIGNMENT_PITCH_RGB (64) -#define TBM_SURFACE_ALIGNMENT_PITCH_YUV (16) - -/* check condition */ -#define SHM_RETURN_IF_FAIL(cond) {\ - if (!(cond)) {\ - TBM_SHM_LOG("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return;\ - } \ -} -#define SHM_RETURN_VAL_IF_FAIL(cond, val) {\ - if (!(cond)) {\ - TBM_SHM_LOG("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return val;\ - } \ -} - -typedef struct _tbm_bufmgr_shm *tbm_bufmgr_shm; -typedef struct _tbm_bo_shm *tbm_bo_shm; - -/* tbm buffor object for shm */ -struct _tbm_bo_shm { - key_t key; - void * pBase; - - unsigned int size; - - unsigned int flags_tbm; - tbm_fd fd; - - pthread_mutex_t mutex; - int device; - int opt; -}; - -/* tbm bufmgr private for shm */ -struct _tbm_bufmgr_shm { - int isLocal; - void* hashBos; - - tbm_backend_bufmgr_func *bufmgr_func; - tbm_backend_bo_func *bo_func; - - tbm_bufmgr bufmgr; -}; - -char *STR_DEVICE[] = { - "DEF", - "CPU", - "2D", - "3D", - "MM" -}; - -char *STR_OPT[] = { - "NONE", - "RD", - "WR", - "RDWR" -}; - -uint32_t tbm_shm_color_format_list[TBM_COLOR_FORMAT_COUNT] = { - TBM_FORMAT_ARGB8888, - TBM_FORMAT_XRGB8888, - TBM_FORMAT_NV12, - TBM_FORMAT_YUV420 - }; - -static tbm_bo_handle -_shm_bo_handle(tbm_bo_shm bo_shm, int device) -{ - tbm_bo_handle bo_handle; - memset(&bo_handle, 0x0, sizeof(uint64_t)); - - switch (device) { - case TBM_DEVICE_DEFAULT: - case TBM_DEVICE_2D: - bo_handle.u32 = (uint32_t) bo_shm->fd; - break; - case TBM_DEVICE_CPU: - bo_handle.ptr = (void *) bo_shm->pBase; - break; - case TBM_DEVICE_3D: - case TBM_DEVICE_MM: - default: - TBM_SHM_LOG("[libtbm-shm:%d] error %s:%d Not supported device:%d\n", getpid(), __FUNCTION__, __LINE__, device); - bo_handle.ptr = (void *) bo_shm->pBase; - break; - } - - return bo_handle; -} - -static int -_shm_os_fd_set_cloexec(int fd) -{ - long flags; - - if (fd == -1) - return -1; - - flags = fcntl(fd, F_GETFD); - if (flags == -1) - return -1; - - if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) - return -1; - - return 0; -} - -static int -_shm_set_cloexec_or_close(int fd) -{ - if (_shm_os_fd_set_cloexec(fd) != 0) { - close(fd); - return -1; - } - return fd; -} - -static int -_shm_create_tmpfile_cloexec(char *tmpname) -{ - int fd; - -#ifdef HAVE_MKOSTEMP - fd = mkostemp(tmpname, O_CLOEXEC); - if (fd >= 0) - unlink(tmpname); -#else - fd = mkstemp(tmpname); - if (fd >= 0) { - fd = _shm_set_cloexec_or_close(fd); - unlink(tmpname); - } -#endif - - return fd; -} - -static tbm_fd -_shm_create_anonymous_file(off_t size) -{ - static const char template[] = "/tbm-shared-XXXXXX"; - const char *path; - char *name; - int fd; - int ret; - - path = getenv("XDG_RUNTIME_DIR"); - if (!path) { - errno = ENOENT; - return -1; - } - - name = malloc(strlen(path) + sizeof(template)); - if (!name) - return -1; - - snprintf(name, strlen(path) + sizeof(template), "%s%s", path, template); - - fd = _shm_create_tmpfile_cloexec(name); - - free(name); - - if (fd < 0) - return -1; - -#ifdef HAVE_POSIX_FALLOCATE - do { - ret = posix_fallocate(fd, 0, size); - } while (ret == EINTR); - if (ret != 0) { - close(fd); - errno = ret; - return -1; - } -#else - do { - ret = ftruncate(fd, size); - } while (ret < 0 && errno == EINTR); - if (ret < 0) { - close(fd); - return -1; - } -#endif - - return (tbm_fd)fd; -} - -static tbm_bufmgr_capability -tbm_shm_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_FD; - - if (error) - *error = TBM_ERROR_NONE; - - return capabilities; -} - -static tbm_error_e -tbm_shm_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display) -{ - return TBM_ERROR_NONE; -} - -static tbm_error_e -tbm_shm_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data, - uint32_t **formats, uint32_t *num) -{ - tbm_bufmgr_shm bufmgr_shm = (tbm_bufmgr_shm)bufmgr_data; - uint32_t *color_formats; - - TBM_RETURN_VAL_IF_FAIL(bufmgr_shm != NULL, TBM_ERROR_INVALID_PARAMETER); - - color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT); - if (color_formats == NULL) - return TBM_ERROR_OUT_OF_MEMORY; - - memcpy(color_formats, tbm_shm_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); - - *formats = color_formats; - *num = TBM_COLOR_FORMAT_COUNT; - - TBM_DBG("supported format count = %d\n", *num); - - return TBM_ERROR_NONE; -} - -static tbm_error_e -tbm_shm_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) - -{ - int ret = TBM_ERROR_NONE; - int bpp; - int _offset = 0; - int _pitch = 0; - int _size = 0; - int _bo_idx = 0; - - switch (format) { - /* 16 bpp RGB */ - case TBM_FORMAT_XRGB4444: - case TBM_FORMAT_XBGR4444: - case TBM_FORMAT_RGBX4444: - case TBM_FORMAT_BGRX4444: - case TBM_FORMAT_ARGB4444: - case TBM_FORMAT_ABGR4444: - case TBM_FORMAT_RGBA4444: - case TBM_FORMAT_BGRA4444: - case TBM_FORMAT_XRGB1555: - case TBM_FORMAT_XBGR1555: - case TBM_FORMAT_RGBX5551: - case TBM_FORMAT_BGRX5551: - case TBM_FORMAT_ARGB1555: - case TBM_FORMAT_ABGR1555: - case TBM_FORMAT_RGBA5551: - case TBM_FORMAT_BGRA5551: - case TBM_FORMAT_RGB565: - bpp = 16; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - /* 24 bpp RGB */ - case TBM_FORMAT_RGB888: - case TBM_FORMAT_BGR888: - bpp = 24; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - /* 32 bpp RGB */ - case TBM_FORMAT_XRGB8888: - case TBM_FORMAT_XBGR8888: - case TBM_FORMAT_RGBX8888: - case TBM_FORMAT_BGRX8888: - case TBM_FORMAT_ARGB8888: - case TBM_FORMAT_ABGR8888: - case TBM_FORMAT_RGBA8888: - case TBM_FORMAT_BGRA8888: - bpp = 32; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_RGB); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - - /* packed YCbCr */ - case TBM_FORMAT_YUYV: - case TBM_FORMAT_YVYU: - case TBM_FORMAT_UYVY: - case TBM_FORMAT_VYUY: - case TBM_FORMAT_AYUV: - bpp = 32; - _offset = 0; - _pitch = SIZE_ALIGN((width * bpp) >> 3, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - break; - - /* - * 2 plane YCbCr - * index 0 = Y plane, [7:0] Y - * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian - * or - * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian - */ - case TBM_FORMAT_NV12: - case TBM_FORMAT_NV21: - bpp = 12; - //if (plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if (plane_idx == 1) - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - case TBM_FORMAT_NV16: - case TBM_FORMAT_NV61: - bpp = 16; - //if(plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if( plane_idx ==1 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - - /* - * 3 plane YCbCr - * index 0: Y plane, [7:0] Y - * index 1: Cb plane, [7:0] Cb - * index 2: Cr plane, [7:0] Cr - * or - * index 1: Cr plane, [7:0] Cr - * index 2: Cb plane, [7:0] Cb - */ - /* - NATIVE_BUFFER_FORMAT_YV12 - NATIVE_BUFFER_FORMAT_I420 - */ - case TBM_FORMAT_YUV410: - case TBM_FORMAT_YVU410: - bpp = 9; - _bo_idx = 0; - break; - case TBM_FORMAT_YUV411: - case TBM_FORMAT_YVU411: - case TBM_FORMAT_YUV420: - case TBM_FORMAT_YVU420: - bpp = 12; - //if(plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if( plane_idx == 1 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); - _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - //else if (plane_idx == 2 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); - _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - case TBM_FORMAT_YUV422: - case TBM_FORMAT_YVU422: - bpp = 16; - //if(plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if( plane_idx == 1 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); - _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - //else if (plane_idx == 2 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width / 2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); - _size = SIZE_ALIGN(_pitch * (height), TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - case TBM_FORMAT_YUV444: - case TBM_FORMAT_YVU444: - bpp = 24; - //if(plane_idx == 0) - { - _offset = 0; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 0) - break; - } - //else if( plane_idx == 1 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - if (plane_idx == 1) - break; - } - //else if (plane_idx == 2 ) - { - _offset += _size; - _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV); - _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE); - _bo_idx = 0; - } - break; - default: - bpp = 0; - break; - } - - *size = _size; - *offset = _offset; - *pitch = _pitch; - *bo_idx = _bo_idx; - - return ret; -} - -static tbm_backend_bo_data * -tbm_shm_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, unsigned int size, - tbm_bo_memory_type flags, tbm_error_e *error) - -{ - tbm_bufmgr_shm bufmgr_shm = (tbm_bufmgr_shm)bufmgr_data; - tbm_bo_shm bo_shm; - - if (bufmgr_shm == NULL) { - TBM_ERR("bufmgr_data is null\n"); - if (error) *error = TBM_ERROR_INVALID_PARAMETER; - return NULL; - } - - tbm_fd fd = -1; - - if (flags & TBM_BO_SCANOUT) - TBM_SHM_LOG("[libtbm-shm:%d] warning %s:%d TBM_BO_SCANOUT ins't supported\n", getpid(), __FUNCTION__, __LINE__); - - bo_shm = calloc(1, sizeof(struct _tbm_bo_shm)); - if (!bo_shm) { - TBM_SHM_LOG("[libtbm-shm:%d] error %s:%d Fail to allocate the bo private\n", getpid(), __FUNCTION__, __LINE__); - if (error) *error = TBM_ERROR_INVALID_OPERATION; - return 0; - } - - bo_shm->fd = -1; - fd = _shm_create_anonymous_file((off_t)size); - if (fd < 0) { - TBM_SHM_LOG("[libtbm-shm:%d] error %s:%d Fail to create a buffer file(size: %d) %m\n", getpid(), - __FUNCTION__, __LINE__, size); - free(bo_shm); - if (error) *error = TBM_ERROR_INVALID_OPERATION; - return 0; - } - - bo_shm->fd = fd; - bo_shm->pBase = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (bo_shm->pBase == MAP_FAILED) { - TBM_SHM_LOG("[libtbm-shm:%d] error %s:%d Fail to mmap: %m\n", getpid(), - __FUNCTION__, __LINE__); - close(fd); - free(bo_shm); - if (error) *error = TBM_ERROR_INVALID_OPERATION; - return 0; - } - - bo_shm->size = size; - bo_shm->flags_tbm = TBM_BO_DEFAULT | TBM_BO_NONCACHABLE; - - DBG(" [%s] bo:%p, fd:%d, flags:%d, size:%d\n", target_name(), bo_shm, bo_shm->fd, bo_shm->flags_tbm, bo_shm->size); - if (error) *error = TBM_ERROR_NONE; - - return (tbm_backend_bo_data *) bo_shm; -} - -static tbm_backend_bo_data * -tbm_shm_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error) -{ - tbm_bo_shm bo_shm; - int real_size; - char buf[STRERR_BUFSIZE]; - - if (key < 0) { - TBM_ERR("Invalid fd(%d)\n", key); - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return 0; - } - - bo_shm = calloc(1, sizeof(struct _tbm_bo_shm)); - if (!bo_shm) { - TBM_ERR("Fail to allocate the bo private\n"); - if (error) - *error = TBM_ERROR_INVALID_OPERATION; - return 0; - } - - real_size = lseek(key, 0, SEEK_END); - if (real_size < 0) { - TBM_ERR("Fail to lseek(err:%s)\n", - strerror_r(errno, buf, STRERR_BUFSIZE)); - free(bo_shm); - if (error) - *error = TBM_ERROR_INVALID_OPERATION; - return 0; - } - - bo_shm->pBase = mmap(NULL, real_size, - PROT_READ | PROT_WRITE, MAP_SHARED, key, 0); - if (bo_shm->pBase == MAP_FAILED) { - TBM_ERR("Fail to mmap (size:%d, err:%s)\n", - real_size, strerror_r(errno, buf, STRERR_BUFSIZE)); - free(bo_shm); - if (error) - *error = TBM_ERROR_INVALID_OPERATION; - return 0; - } - - bo_shm->size = real_size; - bo_shm->fd = key; - bo_shm->flags_tbm = TBM_BO_DEFAULT | TBM_BO_NONCACHABLE; - - DBG(" [%s] bo:%p, shm:%d, flags:%d, size:%d\n", target_name(), bo_shm, bo_shm->fd, - bo_shm->flags_tbm, bo_shm->size); - if (error) - *error = TBM_ERROR_NONE; - - return (tbm_backend_bo_data *) bo_shm; -} - -static void -tbm_shm_bo_free(tbm_backend_bo_data *bo_data) -{ - tbm_bo_shm bo_shm = (tbm_bo_shm)bo_data; - char buf[STRERR_BUFSIZE]; - - SHM_RETURN_IF_FAIL(bo_shm != NULL); - - DBG(" [%s] bo:%p, shm:%d, size:%d\n", target_name(), bo_shm, bo_shm->fd, bo_shm->size); - - if (bo_shm->pBase) { - if (munmap(bo_shm->pBase, bo_shm->size) == -1) { - TBM_ERR("bo_shm:%p fail to munmap(%s)\n", - bo_shm, strerror_r(errno, buf, STRERR_BUFSIZE)); - } - } - - /* Free shm object*/ - close(bo_shm->fd); - free(bo_shm); -} - -static int -tbm_shm_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error) -{ - tbm_bo_shm bo_shm = (tbm_bo_shm)bo_data; - - if (!bo_shm) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return 0; - } - - if (error) - *error = TBM_ERROR_NONE; - - return bo_shm->size; -} - - -static tbm_bo_memory_type -tbm_shm_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error) -{ - tbm_bo_shm bo_shm = (tbm_bo_shm)bo_data; - - if (!bo_shm) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return TBM_BO_DEFAULT; - } - - if (error) - *error = TBM_ERROR_NONE; - - return bo_shm->flags_tbm; -} - -static tbm_bo_handle -tbm_shm_bo_get_handle(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, tbm_error_e *error) -{ - tbm_bo_handle bo_handle; - tbm_bo_shm bo_shm = (tbm_bo_shm)bo_data;; - - if (!bo_shm) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return (tbm_bo_handle) NULL; - } - - DBG("[%s] bo:%p, shm:%d, flags:%d, size:%d, %s\n", target_name(), bo_shm, bo_shm->fd, - bo_shm->flags_tbm, bo_shm->size, STR_DEVICE[device]); - - /*Get mapped bo_handle*/ - bo_handle = _shm_bo_handle(bo_shm, device); - if (bo_handle.ptr == NULL) { - TBM_SHM_LOG("error Cannot get handle: shm:%d, device:%d\n", bo_shm->fd, device); - - if (error) - *error = TBM_ERROR_INVALID_OPERATION; - return (tbm_bo_handle) NULL; - } - - if (error) - *error = TBM_ERROR_NONE; - - return bo_handle; -} - - -static tbm_bo_handle -tbm_shm_bo_map(tbm_backend_bo_data *bo_data, tbm_bo_device_type device, - tbm_bo_access_option opt, tbm_error_e *error) -{ - tbm_bo_handle bo_handle; - tbm_bo_shm bo_shm = (tbm_bo_shm)bo_data;; - - if (!bo_shm) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return (tbm_bo_handle) NULL; - } - - DBG(" [%s] bo:%p, shm:%d, %s, %s\n", target_name(), bo_shm, bo_shm->fd, STR_DEVICE[device], - STR_OPT[opt]); - - /*Get mapped bo_handle*/ - bo_handle = _shm_bo_handle(bo_shm, device); - if (bo_handle.ptr == NULL) { - TBM_SHM_LOG("error Cannot get handle: shm:%d, device:%d, opt:%d\n", bo_shm->fd, device, opt); - if (error) - *error = TBM_ERROR_INVALID_OPERATION; - return (tbm_bo_handle) NULL; - } - - if (error) - *error = TBM_ERROR_NONE; - - return bo_handle; -} - -static tbm_error_e -tbm_shm_bo_unmap(tbm_backend_bo_data *bo_data) - -{ - tbm_bo_shm bo_shm = (tbm_bo_shm)bo_data;; - if (!bo_shm) - return TBM_ERROR_INVALID_PARAMETER; - - DBG(" [%s] bo:%p, shm:%d\n", target_name(), bo_shm, bo_shm->fd); - - return TBM_ERROR_NONE; -} - -static tbm_fd -tbm_sprd_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error) -{ - tbm_bo_shm bo_shm = (tbm_bo_shm)bo_data;; - - if (!bo_shm) { - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return -1; - } - - DBG(" [%s] bo:%p, shm:%d, flags:%d, size:%d\n", target_name(), bo_shm, bo_shm->fd, - bo_shm->flags_tbm, bo_shm->size); - - if (error) - *error = TBM_ERROR_NONE; - - return bo_shm->fd; -} - -static tbm_backend_bufmgr_data * -tbm_shm_init(tbm_bufmgr bufmgr, tbm_error_e *error) -{ - tbm_bufmgr_shm bufmgr_shm = NULL; - tbm_backend_bufmgr_func *bufmgr_func = NULL; - tbm_backend_bo_func *bo_func = NULL; - tbm_error_e err; - - if (!bufmgr) { - TBM_ERR("bufmgr is null.\n"); - if (error) - *error = TBM_ERROR_INVALID_PARAMETER; - return NULL; - } - - bufmgr_shm = calloc(1, sizeof(struct _tbm_bufmgr_shm)); - if (!bufmgr_shm) { - TBM_ERR("fail to alloc bufmgr_shm!\n"); - if (error) - *error = TBM_ERROR_OUT_OF_MEMORY; - return NULL; - } - - /* 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_shm_bufmgr_get_capabilities; - bufmgr_func->bufmgr_bind_native_display = tbm_shm_bufmgr_bind_native_display; - bufmgr_func->bufmgr_get_supported_formats = tbm_shm_bufmgr_get_supported_formats; - bufmgr_func->bufmgr_get_plane_data = tbm_shm_bufmgr_get_plane_data; - bufmgr_func->bufmgr_alloc_bo = tbm_shm_bufmgr_alloc_bo; - bufmgr_func->bufmgr_alloc_bo_with_format = NULL; - bufmgr_func->bufmgr_import_fd = tbm_shm_bufmgr_import_fd; - bufmgr_func->bufmgr_import_key = NULL; - - 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_shm->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_shm_bo_free; - bo_func->bo_get_size = tbm_shm_bo_get_size; - bo_func->bo_get_memory_types = tbm_shm_bo_get_memory_type; - bo_func->bo_get_handle = tbm_shm_bo_get_handle; - bo_func->bo_map = tbm_shm_bo_map; - bo_func->bo_unmap = tbm_shm_bo_unmap; - bo_func->bo_lock = NULL; - bo_func->bo_unlock = NULL; - bo_func->bo_export_fd = tbm_sprd_bo_export_fd; - bo_func->bo_export_key = NULL; - - 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_shm->bo_func = bo_func; - - TBM_DBG("tbm_shm_init: done\n"); - - if (error) - *error = TBM_ERROR_NONE; - - bufmgr_shm->bufmgr = bufmgr; - - return (tbm_backend_bufmgr_data *)bufmgr_shm; - -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: - free(bufmgr_shm); - return NULL; -} - -static void -tbm_shm_deinit(tbm_backend_bufmgr_data *bufmgr_data) -{ - tbm_bufmgr_shm bufmgr_shm = (tbm_bufmgr_shm)bufmgr_data; - tbm_bufmgr bufmgr; - - TBM_RETURN_IF_FAIL(bufmgr_shm != NULL); - - bufmgr = bufmgr_shm->bufmgr; - - tbm_backend_bufmgr_free_bufmgr_func(bufmgr, bufmgr_shm->bufmgr_func); - tbm_backend_bufmgr_free_bo_func(bufmgr, bufmgr_shm->bo_func); - - free(bufmgr_shm); -} - - -tbm_backend_module tbm_backend_module_data = { - "shm", - "Samsung", - TBM_BACKEND_ABI_VERSION_3_0, - tbm_shm_init, - tbm_shm_deinit -}; - diff --git a/src/libhal-backend-tbm-shm/tbm_backend_log.c b/src/tbm_backend_log.c similarity index 100% rename from src/libhal-backend-tbm-shm/tbm_backend_log.c rename to src/tbm_backend_log.c diff --git a/src/libhal-backend-tbm-shm/tbm_backend_log.h b/src/tbm_backend_log.h similarity index 100% rename from src/libhal-backend-tbm-shm/tbm_backend_log.h rename to src/tbm_backend_log.h diff --git a/src/libhal-backend-tbm-shm/tbm_backend_shm.c b/src/tbm_backend_shm.c similarity index 100% rename from src/libhal-backend-tbm-shm/tbm_backend_shm.c rename to src/tbm_backend_shm.c -- 2.7.4