diff options
author | SooChan Lim <sc1.lim@samsung.com> | 2016-03-07 19:45:16 +0900 |
---|---|---|
committer | SooChan Lim <sc1.lim@samsung.com> | 2016-03-07 19:45:40 +0900 |
commit | 8c385fb9d3392440cdcfa3793143627d10612678 (patch) | |
tree | 55bc0116fc1dca1cc42aeb641c0afacb458dd449 | |
parent | 05dab108f25123c488899408803ea98e456468ad (diff) | |
download | libtbm-shm-8c385fb9d3392440cdcfa3793143627d10612678.tar.gz libtbm-shm-8c385fb9d3392440cdcfa3793143627d10612678.tar.bz2 libtbm-shm-8c385fb9d3392440cdcfa3793143627d10612678.zip |
add initial codes
Change-Id: Id4d05432764208383f08d299331dbe19f872082e
-rw-r--r-- | AUTHORS | 3 | ||||
-rw-r--r-- | COPYING | 18 | ||||
-rw-r--r-- | ChangeLog | 0 | ||||
-rw-r--r-- | INSTALL | 291 | ||||
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | NEWS | 0 | ||||
-rw-r--r-- | README | 0 | ||||
-rw-r--r-- | autogen.sh | 12 | ||||
-rw-r--r-- | configure.ac | 71 | ||||
-rw-r--r-- | libtbm-shm.manifest | 5 | ||||
-rw-r--r-- | packaging/libtbm-shm.spec | 47 | ||||
-rw-r--r-- | src/Makefile.am | 11 | ||||
-rw-r--r-- | src/tbm_bufmgr_shm.c | 1142 |
13 files changed, 1601 insertions, 0 deletions
@@ -0,0 +1,3 @@ +SooChan Lim <sc1.lim@samsung.com> +SangJin Lee <lsj119@samsung.com> +Boram Park <boram1288.park@samsung.com> @@ -0,0 +1,18 @@ +Copyright (C) 2000 - 2012 Samsung Electronics co., Ltd. All Rights Reserved. + +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 fur- +nished 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, FIT- +NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON- +NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,291 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006, 2007, 2008 Free Software Foundation, Inc. + + This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + + Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + + 6. Often, you can also type `make uninstall' to remove the installed + files again. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. Run `./configure --help' +for details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + + On MacOS X 10.5 and later systems, you can create libraries and +executables that work on multiple system types--known as "fat" or +"universal" binaries--by specifying multiple `-arch' options to the +compiler but only a single `-arch' option to the preprocessor. Like +this: + + ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ + CPP="gcc -E" CXXCPP="g++ -E" + + This is not guaranteed to produce working output in all cases, you +may have to build one architecture at a time and combine the results +using the `lipo' tool if you have problems. + +Installation Names +================== + + By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Particular systems +================== + + On HP-UX, the default C compiler is not ANSI C compatible. If GNU +CC is not installed, it is recommended to use the following options in +order to use an ANSI C compiler: + + ./configure CC="cc -Ae" + +and if that doesn't work, install pre-built binaries of GCC for HP-UX. + + On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot +parse its `<wchar.h>' header file. The option `-nodtk' can be used as +a workaround. If GNU CC is not installed, it is therefore recommended +to try + + ./configure CC="cc" + +and if that doesn't work, try + + ./configure CC="cc -nodtk" + +Specifying the System Type +========================== + + There may be some features `configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, `configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + + Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + + `configure' recognizes the following options to control how it +operates. + +`--help' +`-h' + Print a summary of all of the options to `configure', and exit. + +`--help=short' +`--help=recursive' + Print a summary of the options unique to this package's + `configure', and exit. The `short' variant lists options used + only in the top level, while the `recursive' variant lists options + also present in any nested packages. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`--prefix=DIR' + Use DIR as the installation prefix. *Note Installation Names:: + for more details, including other options available for fine-tuning + the installation locations. + +`--no-create' +`-n' + Run the configure checks, but stop before creating any output + files. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..af437a6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/autogen.sh b/autogen.sh new file mode 100644 index 0000000..904cd67 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,12 @@ +#! /bin/sh + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir + +autoreconf -v --install || exit 1 +cd $ORIGDIR || exit $? + +$srcdir/configure --enable-maintainer-mode "$@" diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..ccb5639 --- /dev/null +++ b/configure.ac @@ -0,0 +1,71 @@ +# +# 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 +# on 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 +# ADAM JACKSON 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. + +AC_PREREQ(2.60) +AC_INIT(libtbm-shm, 1.0.5) +AC_USE_SYSTEM_EXTENSIONS +AC_CONFIG_SRCDIR([Makefile.am]) +AM_INIT_AUTOMAKE([dist-bzip2]) + +AM_CONFIG_HEADER([config.h]) + +AC_DISABLE_STATIC +AC_PROG_LIBTOOL +AC_PROG_CC + +AC_HEADER_STDC +AC_SYS_LARGEFILE +AC_FUNC_ALLOCA + +# Enable quiet compiles on automake 1.11. +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + +PKG_CHECK_MODULES(LIBDRM, libdrm) +PKG_CHECK_MODULES(LIBTBM, libtbm) +PKG_CHECK_MODULES(DLOG, dlog) + +AC_ARG_ENABLE(cachectrl, + AS_HELP_STRING([--enable-cachectrl], + [Enable cache control (default: enable)]), + [CACHE_CTRL=$enableval], [CACHE_CTRL=yes]) + +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) + +AC_OUTPUT([ + 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 "" + diff --git a/libtbm-shm.manifest b/libtbm-shm.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/libtbm-shm.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> diff --git a/packaging/libtbm-shm.spec b/packaging/libtbm-shm.spec new file mode 100644 index 0000000..cd8c0f9 --- /dev/null +++ b/packaging/libtbm-shm.spec @@ -0,0 +1,47 @@ +Name: libtbm-shm +Version: 1.0.9 +Release: 1 +License: MIT +Summary: Tizen Buffer Manager - drm shm backend +Group: System/Libraries +ExcludeArch: i586 +Source0: %{name}-%{version}.tar.gz + +BuildRequires: pkgconfig(pthread-stubs) +BuildRequires: pkgconfig(libdrm) +BuildRequires: pkgconfig(libtbm) +BuildRequires: pkgconfig(dlog) + +%description +descriptionion: Tizen Buffer manager backend module uses drm shm + +%prep +%setup -q + +%build + +%reconfigure --prefix=%{_prefix} --libdir=%{_libdir}/bufmgr --disable-cachectrl \ + CFLAGS="${CFLAGS} -Wall -Werror" LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed" + +make %{?_smp_mflags} + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/usr/share/license +cp -af COPYING %{buildroot}/usr/share/license/%{name} +%make_install + + +%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 + +%files +%manifest libtbm-shm.manifest +%{_libdir}/bufmgr/libtbm_*.so* +/usr/share/license/%{name} + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..05a380b --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,11 @@ +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/tbm_bufmgr_shm.c b/src/tbm_bufmgr_shm.c new file mode 100644 index 0000000..17e86b6 --- /dev/null +++ b/src/tbm_bufmgr_shm.c @@ -0,0 +1,1142 @@ +/************************************************************************** + +libtbm_shm + +Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@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. + +**************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <linux/unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <tbm_bufmgr.h> +#include <tbm_bufmgr_backend.h> +#include <pthread.h> +#include <tbm_surface.h> +#include <tbm_surface_internal.h> + +#define DEBUG +#define USE_DMAIMPORT +#define TBM_COLOR_FORMAT_COUNT 8 + +#ifdef DEBUG +#define LOG_TAG "TBM_BACKEND" +#include <dlog.h> +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 +{ + int shmid; + key_t key; + void * pBase; + + unsigned int size; + + unsigned int flags_shm; + unsigned int flags_tbm; + + pthread_mutex_t mutex; + int device; + int opt; +}; + +/* tbm bufmgr private for shm */ +struct _tbm_bufmgr_shm +{ + int isLocal; + void* hashBos; +}; + +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_RGBA8888, + TBM_FORMAT_BGRA8888, + TBM_FORMAT_RGBX8888, + TBM_FORMAT_RGB888, + TBM_FORMAT_NV12, + TBM_FORMAT_NV21, + TBM_FORMAT_YUV420, + TBM_FORMAT_YVU420 }; + +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->shmid; + 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 *) NULL; + break; + } + + return bo_handle; +} + +static int +tbm_shm_bo_size (tbm_bo bo) +{ + SHM_RETURN_VAL_IF_FAIL (bo!=NULL, 0); + + tbm_bo_shm bo_shm; + + bo_shm = (tbm_bo_shm)tbm_backend_get_bo_priv(bo); + + return bo_shm->size; +} + +static void * +tbm_shm_bo_alloc (tbm_bo bo, int size, int flags) +{ + SHM_RETURN_VAL_IF_FAIL (bo!=NULL, 0); + + tbm_bo_shm bo_shm; + tbm_bufmgr_shm bufmgr_shm; + + static key_t key = 1; + + bufmgr_shm = (tbm_bufmgr_shm)tbm_backend_get_bufmgr_priv(bo); + SHM_RETURN_VAL_IF_FAIL (bufmgr_shm!=NULL, 0); + + if (flags & TBM_BO_SCANOUT) + { + TBM_SHM_LOG ("[libtbm-shm:%d] warning %s:%d TBM_BO_SCANOUT ins't supported\n", + getpid(), __FUNCTION__, __LINE__); + return 0; + } + + 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__); + return 0; + } + + //get next key for a allocated shm segment + key += 1; + + while ((bo_shm->shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0666)) < 0) + { + if ( errno != EEXIST) + { + TBM_SHM_LOG ("[libtbm-shm:%d] error %s:%d Fail to allocate the shared memory segment (%s)\n", + getpid(), __FUNCTION__, __LINE__, strerror(errno)); + free (bo_shm); + return 0; + } + + //try to allocate the segment with next key; + key += 1; + } + + bo_shm->key = key; + + if ((bo_shm->pBase = shmat(bo_shm->shmid, NULL, 0)) == (char *) -1) { + TBM_SHM_LOG ("[libtbm-shm:%d] error %s:%d Fail to attach the shared memory segment (%s)\n", + getpid(), __FUNCTION__, __LINE__, strerror(errno)); + free(bo_shm); + return 0; + } + + bo_shm->size = size; + bo_shm->flags_shm = 0; + bo_shm->flags_tbm = TBM_BO_DEFAULT | TBM_BO_NONCACHABLE; + + DBG (" [%s] bo:%p, shmid:%d(%d), flags:%d(%d), size:%d\n", target_name(), + bo, + bo_shm->shmid, bo_shm->key, + bo_shm->flags_tbm, bo_shm->flags_shm, + bo_shm->size); + + return (void *)bo_shm; +} + +static void +tbm_shm_bo_free(tbm_bo bo) +{ + tbm_bo_shm bo_shm; + tbm_bufmgr_shm bufmgr_shm; + + if (!bo) + return; + + bufmgr_shm = (tbm_bufmgr_shm)tbm_backend_get_bufmgr_priv(bo); + SHM_RETURN_IF_FAIL (bufmgr_shm!=NULL); + + bo_shm = (tbm_bo_shm)tbm_backend_get_bo_priv(bo); + SHM_RETURN_IF_FAIL (bo_shm!=NULL); + + DBG (" [%s] bo:%p, gem:%d(%d), size:%d\n",target_name(), + bo, + bo_shm->shmid, bo_shm->key, + bo_shm->size); + + /* Free shm object*/ + if (shmdt(bo_shm->pBase) == -1) + { + TBM_SHM_LOG ("[libtbm-shm:%d] error %s:%d Fail to detach shared memory segment bo:%p (%s)\n", + getpid(), __FUNCTION__, __LINE__, bo, strerror(errno)); + } + + free (bo_shm); +} + + +static void * +tbm_shm_bo_import (tbm_bo bo, unsigned int key) +{ + SHM_RETURN_VAL_IF_FAIL (bo!=NULL, 0); + + tbm_bo_shm bo_shm; + struct shmid_ds buf; + + 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__); + return 0; + } + + if((bo_shm->shmid = shmget(key, 0, 0666)) < 0) + { + TBM_SHM_LOG ("[libtbm-shm:%d] error %s:%d Fail to import the shared memory segment key=%d (%s)\n", + getpid(), __FUNCTION__, __LINE__, key, strerror(errno)); + free(bo_shm); + return 0; + } + + if ((bo_shm->pBase = shmat(bo_shm->shmid, NULL, 0)) == (char *) -1) { + TBM_SHM_LOG ("[libtbm-shm:%d] error %s:%d Fail to attach the shared memory segment (%s)\n", + getpid(), __FUNCTION__, __LINE__, strerror(errno)); + free(bo_shm); + return 0; + } + + /*Get the original data for this shmid data structure first.*/ + if (shmctl(bo_shm->shmid, IPC_STAT, &buf) < 0) { + TBM_SHM_LOG ("[libtbm-shm:%d] error %s:%d Fail to get IPC_STAT(%s)\n", + getpid(), __FUNCTION__, __LINE__, strerror(errno)); + free(bo_shm); + return 0; + } + + bo_shm->size = buf.shm_segsz; + bo_shm->flags_shm = 0; + bo_shm->key = key; + bo_shm->flags_tbm = TBM_BO_DEFAULT | TBM_BO_NONCACHABLE; + + DBG (" [%s] bo:%p, shm:%d(%d), flags:%d(%d), size:%d\n", target_name(), + bo, + bo_shm->shmid, bo_shm->key, + bo_shm->flags_tbm, bo_shm->flags_shm, + bo_shm->size); + + return (void *)bo_shm; +} + +static unsigned int +tbm_shm_bo_export (tbm_bo bo) +{ + SHM_RETURN_VAL_IF_FAIL (bo!=NULL, 0); + + tbm_bo_shm bo_shm; + + bo_shm = (tbm_bo_shm)tbm_backend_get_bo_priv(bo); + SHM_RETURN_VAL_IF_FAIL (bo_shm!=NULL, 0); + + DBG (" [%s] bo:%p, shm:%d(%d), flags:%d(%d), size:%d\n", target_name(), + bo, + bo_shm->shmid, bo_shm->key, + bo_shm->flags_tbm, bo_shm->flags_shm, + bo_shm->size); + + return (unsigned int)bo_shm->key; +} + +static tbm_bo_handle +tbm_shm_bo_get_handle (tbm_bo bo, int device) +{ + SHM_RETURN_VAL_IF_FAIL (bo!=NULL, (tbm_bo_handle) NULL); + + tbm_bo_handle bo_handle; + tbm_bo_shm bo_shm; + + bo_shm = (tbm_bo_shm)tbm_backend_get_bo_priv(bo); + SHM_RETURN_VAL_IF_FAIL (bo_shm!=NULL, (tbm_bo_handle) NULL); + + DBG ("[%s] bo:%p, shm:%d(%d), flags:%d(%d), size:%d, %s\n", target_name(), + bo, + bo_shm->shmid, bo_shm->key, + bo_shm->flags_tbm, bo_shm->flags_shm, + 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->shmid, device); + return (tbm_bo_handle) NULL; + } + + return bo_handle; +} + +static tbm_bo_handle +tbm_shm_bo_map (tbm_bo bo, int device, int opt) +{ + SHM_RETURN_VAL_IF_FAIL (bo!=NULL, (tbm_bo_handle) NULL); + + tbm_bo_handle bo_handle; + tbm_bo_shm bo_shm; + + bo_shm = (tbm_bo_shm)tbm_backend_get_bo_priv(bo); + SHM_RETURN_VAL_IF_FAIL (bo_shm!=NULL, (tbm_bo_handle) NULL); + + DBG (" [%s] bo:%p, shm:%d(%d), %s, %s\n", target_name(), + bo, + bo_shm->shmid, bo_shm->key, + 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->shmid, device, opt); + return (tbm_bo_handle) NULL; + } + + return bo_handle; +} + +static int +tbm_shm_bo_unmap (tbm_bo bo) +{ + SHM_RETURN_VAL_IF_FAIL (bo!=NULL, 0); + + tbm_bo_shm bo_shm; + + bo_shm = (tbm_bo_shm)tbm_backend_get_bo_priv(bo); + SHM_RETURN_VAL_IF_FAIL (bo_shm!=NULL, 0); + + DBG (" [%s] bo:%p, shm:%d(%d)\n", target_name(), + bo, + bo_shm->shmid, bo_shm->key); + + return 1; +} + +static int +tbm_shm_bo_get_global_key (tbm_bo bo) +{ + SHM_RETURN_VAL_IF_FAIL (bo!=NULL, 0); + + tbm_bo_shm bo_shm; + + bo_shm = (tbm_bo_shm)tbm_backend_get_bo_priv(bo); + SHM_RETURN_VAL_IF_FAIL (bo_shm!=NULL, 0); + + return bo_shm->key; +} + +static void +tbm_shm_bufmgr_deinit (void *priv) +{ + SHM_RETURN_IF_FAIL (priv!=NULL); + + tbm_bufmgr_shm bufmgr_shm; + + bufmgr_shm = (tbm_bufmgr_shm)priv; + + free (bufmgr_shm); +} + +int +tbm_shm_surface_supported_format(uint32_t **formats, uint32_t *num) +{ + uint32_t* color_formats=NULL; + + color_formats = (uint32_t*)calloc (1,sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT); + + if( color_formats == NULL ) + { + return 0; + } + memcpy( color_formats, tbm_shm_color_format_list , sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT ); + + + *formats = color_formats; + *num = TBM_COLOR_FORMAT_COUNT; + + fprintf (stderr, "tbm_shm_surface_supported_format count = %d \n",*num); + + return 1; +} + + +/** + * @brief get the plane data of the surface. + * @param[in] surface : the surface + * @param[in] width : the width of the surface + * @param[in] height : the height of the surface + * @param[in] format : the format of the surface + * @param[in] plane_idx : the format of the surface + * @param[out] size : the size of the plane + * @param[out] offset : the offset of the plane + * @param[out] pitch : the pitch of the plane + * @param[out] padding : the padding of the plane + * @return 1 if this function succeeds, otherwise 0. + */ +int +tbm_shm_surface_get_plane_data(tbm_surface_h surface, int width, int height, tbm_format format, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch, int *bo_idx) +{ + int ret = 1; + 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: + 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; + } + else if( plane_idx ==1 ) + { + _offset = 0; + _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); + _size = SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE); + _bo_idx = 1; + } + break; + 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; + } + else if( plane_idx ==1 ) + { + _offset = width*height; + _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); + _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/2); + _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; +} + +int +tbm_shm_surface_get_num_bos(tbm_format format) +{ + int num = 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: + /* 24 bpp RGB */ + case TBM_FORMAT_RGB888: + case TBM_FORMAT_BGR888: + /* 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: + /* packed YCbCr */ + case TBM_FORMAT_YUYV: + case TBM_FORMAT_YVYU: + case TBM_FORMAT_UYVY: + case TBM_FORMAT_VYUY: + case TBM_FORMAT_AYUV: + /* + * 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_NV21: + case TBM_FORMAT_NV16: + case TBM_FORMAT_NV61: + /* + * 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 + */ + case TBM_FORMAT_YUV410: + case TBM_FORMAT_YVU410: + case TBM_FORMAT_YUV411: + case TBM_FORMAT_YVU411: + case TBM_FORMAT_YUV420: + case TBM_FORMAT_YVU420: + case TBM_FORMAT_YUV422: + case TBM_FORMAT_YVU422: + case TBM_FORMAT_YUV444: + case TBM_FORMAT_YVU444: + num = 1; + break; + + case TBM_FORMAT_NV12: + num = 2; + break; + + default: + num = 0; + break; + } + + return num; +} + +/** +* @brief get the size of the surface with a format. +* @param[in] surface : the surface +* @param[in] width : the width of the surface +* @param[in] height : the height of the surface +* @param[in] format : the format of the surface +* @return size of the surface if this function succeeds, otherwise 0. +*/ + +int +tbm_shm_surface_get_size(tbm_surface_h surface, int width, int height, tbm_format format) +{ + int ret = 0; + int bpp = 0; + int _pitch =0; + int _size =0; + int align =TBM_SURFACE_ALIGNMENT_PLANE; + + 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; + _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + break; + /* 24 bpp RGB */ + case TBM_FORMAT_RGB888: + case TBM_FORMAT_BGR888: + bpp = 24; + _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + 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; + _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_RGB); + _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + 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; + _pitch = SIZE_ALIGN((width*bpp)>>3,TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + 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; + //plane_idx == 0 + { + _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + } + //plane_idx ==1 + { + _pitch = SIZE_ALIGN( width ,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); + _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE); + } + break; + + break; + case TBM_FORMAT_NV16: + case TBM_FORMAT_NV61: + bpp = 16; + //plane_idx == 0 + { + _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + } + //plane_idx ==1 + { + _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); + _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + } + + 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 + */ + case TBM_FORMAT_YUV410: + case TBM_FORMAT_YVU410: + bpp = 9; + align = TBM_SURFACE_ALIGNMENT_PITCH_YUV; + break; + case TBM_FORMAT_YUV411: + case TBM_FORMAT_YVU411: + case TBM_FORMAT_YUV420: + case TBM_FORMAT_YVU420: + bpp = 12; + //plane_idx == 0 + { + _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + } + //plane_idx == 1 + { + _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); + _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE); + } + //plane_idx == 2 + { + _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); + _size += SIZE_ALIGN(_pitch*(height/2),TBM_SURFACE_ALIGNMENT_PLANE); + } + + break; + case TBM_FORMAT_YUV422: + case TBM_FORMAT_YVU422: + bpp = 16; + //plane_idx == 0 + { + _pitch = SIZE_ALIGN(width,TBM_SURFACE_ALIGNMENT_PITCH_YUV); + _size = SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + } + //plane_idx == 1 + { + _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); + _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + } + //plane_idx == 2 + { + _pitch = SIZE_ALIGN(width/2,TBM_SURFACE_ALIGNMENT_PITCH_YUV/2); + _size += SIZE_ALIGN(_pitch*height,TBM_SURFACE_ALIGNMENT_PLANE); + } + break; + case TBM_FORMAT_YUV444: + case TBM_FORMAT_YVU444: + bpp = 24; + align = TBM_SURFACE_ALIGNMENT_PITCH_YUV; + break; + + default: + bpp = 0; + break; + } + + if(_size > 0) + ret = _size; + else + ret = SIZE_ALIGN( (width * height * bpp) >> 3, align); + + return ret; + +} + +MODULEINITPPROTO (init_tbm_bufmgr_priv); + +static TBMModuleVersionInfo DumbVersRec = +{ + "shm", + "Samsung", + TBM_ABI_VERSION, +}; + +TBMModuleData tbmModuleData = { &DumbVersRec, init_tbm_bufmgr_priv}; + +int +init_tbm_bufmgr_priv (tbm_bufmgr bufmgr, int fd) +{ + tbm_bufmgr_shm bufmgr_shm; + tbm_bufmgr_backend bufmgr_backend; + + if (!bufmgr) + return 0; + + bufmgr_shm = calloc (1, sizeof(struct _tbm_bufmgr_shm)); + if (!bufmgr_shm) + { + TBM_SHM_LOG ("error: Fail to alloc bufmgr_shm!\n"); + return 0; + } + + bufmgr_backend = tbm_backend_alloc(); + if (!bufmgr_backend) + { + TBM_SHM_LOG ("error: Fail to create drm!\n"); + free (bufmgr_shm); + return 0; + } + + bufmgr_backend->priv = (void *)bufmgr_shm; + bufmgr_backend->bufmgr_deinit = tbm_shm_bufmgr_deinit, + bufmgr_backend->bo_size = tbm_shm_bo_size, + bufmgr_backend->bo_alloc = tbm_shm_bo_alloc, + bufmgr_backend->bo_free = tbm_shm_bo_free, + bufmgr_backend->bo_import = tbm_shm_bo_import, + bufmgr_backend->bo_import_fd = NULL, + bufmgr_backend->bo_export = tbm_shm_bo_export, + bufmgr_backend->bo_export_fd = NULL, + bufmgr_backend->bo_get_handle = tbm_shm_bo_get_handle, + bufmgr_backend->bo_map = tbm_shm_bo_map, + bufmgr_backend->bo_unmap = tbm_shm_bo_unmap, + bufmgr_backend->bo_cache_flush = NULL, + bufmgr_backend->bo_get_global_key = tbm_shm_bo_get_global_key; + bufmgr_backend->surface_get_plane_data = tbm_shm_surface_get_plane_data; + bufmgr_backend->surface_get_size = tbm_shm_surface_get_size; + bufmgr_backend->surface_supported_format = tbm_shm_surface_supported_format; + bufmgr_backend->fd_to_handle = NULL; + bufmgr_backend->surface_get_num_bos = tbm_shm_surface_get_num_bos; + + bufmgr_backend->flags = 0; + bufmgr_backend->bo_lock = NULL; + bufmgr_backend->bo_unlock = NULL; + + if (!tbm_backend_init (bufmgr, bufmgr_backend)) + { + TBM_SHM_LOG ("error: Fail to init backend!\n"); + tbm_backend_free (bufmgr_backend); + free (bufmgr_shm); + return 0; + } + +#ifdef DEBUG + { + char* env; + env = getenv ("TBM_SHM_DEBUG"); + if (env) + { + bDebug = atoi (env); + TBM_SHM_LOG ("TBM_SHM_DEBUG=%s\n", env); + } + else + { + bDebug = 0; + } + } +#endif + + return 1; +} + + |