diff options
author | SooChan Lim <sc1.lim@samsung.com> | 2014-08-04 17:16:56 +0900 |
---|---|---|
committer | SooChan Lim <sc1.lim@samsung.com> | 2014-08-04 17:18:17 +0900 |
commit | 3f35393b2de0026c376cf48737cf5cfd0cdf5694 (patch) | |
tree | c91c0b776180fd2045e85708a36f282e86010b64 | |
parent | ae239898e9e011b8893c739e850c3ba3f1b76815 (diff) | |
download | libtbm-3f35393b2de0026c376cf48737cf5cfd0cdf5694.tar.gz libtbm-3f35393b2de0026c376cf48737cf5cfd0cdf5694.tar.bz2 libtbm-3f35393b2de0026c376cf48737cf5cfd0cdf5694.zip |
add tbm surface as the Core api
Change-Id: I756c57edd80ac6ef9ae3aa7318c41b530bc7d09f
-rw-r--r-- | configure.ac | 8 | ||||
-rwxr-xr-x | doc/ui_tbm_bufmgr_doc.h | 31 | ||||
-rwxr-xr-x | doc/ui_tbm_doc.h | 17 | ||||
-rwxr-xr-x | doc/ui_tbm_surface_doc.h | 28 | ||||
-rwxr-xr-x | drm_slp/drm_slp_bufmgr.c | 6 | ||||
-rw-r--r-- | libtbm.pc.in | 7 | ||||
-rw-r--r-- | packaging/libtbm.spec | 15 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rwxr-xr-x | src/tbm_bufmgr.c | 370 | ||||
-rwxr-xr-x | src/tbm_bufmgr.h | 719 | ||||
-rwxr-xr-x | src/tbm_bufmgr_backend.c | 1 | ||||
-rwxr-xr-x | src/tbm_bufmgr_backend.h | 516 | ||||
-rwxr-xr-x | src/tbm_bufmgr_int.h | 304 | ||||
-rwxr-xr-x | src/tbm_surface.c | 228 | ||||
-rwxr-xr-x | src/tbm_surface.h | 708 | ||||
-rwxr-xr-x | src/tbm_surface_internal.c | 357 | ||||
-rwxr-xr-x | src/tbm_surface_internal.h | 262 | ||||
-rwxr-xr-x | src/tbm_type.h | 57 |
18 files changed, 3117 insertions, 521 deletions
diff --git a/configure.ac b/configure.ac index c05ad14..de98d92 100644 --- a/configure.ac +++ b/configure.ac @@ -51,9 +51,13 @@ AC_SUBST([CLOCK_LIB]) PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs) PKG_CHECK_MODULES(LIBDRM, libdrm) +PKG_CHECK_MODULES(LIBDRI2, libdri2) +PKG_CHECK_MODULES(X11, x11) +PKG_CHECK_MODULES(CAPI, capi-base-common) +# PKG_CHECK_MODULES(CAPI, capi-base-common >= 0.1.1) -LIBTBM_CFLAGS="$PTHREADSTUBS_CFLAGS $LIBDRM_CFLAGS " -LIBTBM_LIBS="$PTHREADSTUBS_LIBS $LIBDRM_LIBS " +LIBTBM_CFLAGS="$PTHREADSTUBS_CFLAGS $LIBDRM_CFLAGS $LIBDRI2_CFLAGS $X11_CFLAGS $CAPI_CFLAGS" +LIBTBM_LIBS="$PTHREADSTUBS_LIBS $LIBDRM_LIBS $LIBDRI2_LIBS $X11_LIBS $CAPI_LIBS" AC_SUBST(LIBTBM_CFLAGS) AC_SUBST(LIBTBM_LIBS) diff --git a/doc/ui_tbm_bufmgr_doc.h b/doc/ui_tbm_bufmgr_doc.h new file mode 100755 index 0000000..e5d9d8e --- /dev/null +++ b/doc/ui_tbm_bufmgr_doc.h @@ -0,0 +1,31 @@ + +#ifndef __SAMSUNG_UI_TBM_BUFMGR_DOC_H__ +#define __SAMSUNG_UI_TBM_BUFMGR_DOC_H__ + +/** + * @internal + * @defgroup CAPI_UI_TBM_BUFMGR_MODULE TBM Buffer Object + * @brief The tbm_bo stands for the buffer object in the tizen buffer manager + * @ingroup CAPI_UI_TBM_MODULE + * + * @section CAPI_UI_TBM_BUFMGR_MODULE_HEADER Required Header + * \#include <tbm_bufmgr.h> + * + * @section CAPI_UI_TBM_BUFMGR_MODULE_OVERVIEW Overview + * TBM Bufmgr API provides user interface for the TBM Bufmgr, The TBM bo.\n + * The tbm_bufmgr type stands for the tizen buffer manager.\n + * TBM provide the general lock mechanism for the graphic buffer.\n + * The cache flushing in TBM is executed automatically according to the access type and the device type when buffer is mapped.\n + * The user to use the TBM does not need to take care of the cache flushing of the buffer.\n\n + * Features :\n + * - Allocate the buffer object with the memory types.\n + * - Manage the reference count of the buffer object.\n + * - Shared the buffer object among processes.\n + * - Access the buffer object with the device type and the access type.\n + * - Get the information of the buffer object.\n + * - Swap the contents of two buffer objects.\n + * - Set the user data in the buffer object. + */ + +#endif /* __SAMSUNG_UI_TBM_BUFMGR_DOC_H__ */ + diff --git a/doc/ui_tbm_doc.h b/doc/ui_tbm_doc.h new file mode 100755 index 0000000..a3931d2 --- /dev/null +++ b/doc/ui_tbm_doc.h @@ -0,0 +1,17 @@ + +#ifndef __SAMSUNG_UI_TBM_DOC_H__ +#define __SAMSUNG_UI_TBM_DOC_H__ + +/** + * @defgroup CAPI_UI_TBM_MODULE TBM + * @brief TBM stands for the Tizen Buffer Manager. + * @ingroup CAPI_UI_FRAMEWORK + * + * @section CAPI_UI_TBM_MODULE_OVERVIEW Overview + * TBM API provides functions for graphic buffer in tizen\n + * It provides the abstraction interface for the graphic buffer in Tizen.\n + * It provides the user interface for the graphic buffer.\n + */ + +#endif /* __SAMSUNG_IU_TBM_DOC_H__ */ + diff --git a/doc/ui_tbm_surface_doc.h b/doc/ui_tbm_surface_doc.h new file mode 100755 index 0000000..a9dafce --- /dev/null +++ b/doc/ui_tbm_surface_doc.h @@ -0,0 +1,28 @@ + +#ifndef __SAMSUNG_UI_TBM_SURFACE_DOC_H__ +#define __SAMSUNG_UI_TBM_SURFACE_DOC_H__ + +/** + * @defgroup CAPI_UI_TBM_SURFACE_MODULE TBM Surface + * @brief The tbm_surface stands for the surface in the tizen. + * @ingroup CAPI_UI_TBM_MODULE + * + * @section CAPI_UI_TBM_SURFACE_MODULE_HEADER Required Header + * \#include <tbm_surface.h> + * @internal + * \#include <tbm_surface_internal.h> + * @endinternal + * @section CAPI_UI_TBM_SURFACE_MODULE_OVERVIEW Overview + * TBM Surface API provides user interface for The TBM Surface.\n + * The user can get pointer of plane in the surface.\n + * The user can store data to low level graphic buffer by using pointer of each plane.\n\n + * Features :\n + * - Support formats RGB format and YUV format.\n + * - Get format list supported by the system.\n + * - Access the surface with the access type.\n + * - Support the multiple plane graphic buffer.\n + * - Get the information of surface and planes. + */ + +#endif /* __SAMSUNG_UI_TBM_SURFACE_DOC_H__ */ + diff --git a/drm_slp/drm_slp_bufmgr.c b/drm_slp/drm_slp_bufmgr.c index c24b430..b5ae07d 100755 --- a/drm_slp/drm_slp_bufmgr.c +++ b/drm_slp/drm_slp_bufmgr.c @@ -83,7 +83,7 @@ unsigned int drm_slp_bo_map(drm_slp_bo bo, int device, int opt) { tbm_bo_handle bo_handle; - unsigned long ret = 0; + unsigned int ret = 0; bo_handle = tbm_bo_map ((tbm_bo)bo, device, opt); if (bo_handle.ptr == NULL) @@ -98,10 +98,10 @@ drm_slp_bo_map(drm_slp_bo bo, int device, int opt) case TBM_DEVICE_2D: case TBM_DEVICE_3D: case TBM_DEVICE_MM: - ret = (unsigned long)bo_handle.u32; + ret = (unsigned int)bo_handle.u32; break; case TBM_DEVICE_CPU: - ret = (unsigned long)bo_handle.ptr; + ret = (unsigned int)bo_handle.ptr; break; default: TBM_LOG ("[libdrm_slp:%d]: error wrong device type\n", getpid()); diff --git a/libtbm.pc.in b/libtbm.pc.in index ca8f058..166ee6c 100644 --- a/libtbm.pc.in +++ b/libtbm.pc.in @@ -6,6 +6,7 @@ includedir=@includedir@ Name: libtbm Description: the library for Tizen Buffer Manager Version: @PACKAGE_VERSION@ -Requires: libdrm -Libs: -L${libdir} -ltbm @LIBTBM_LIBS@ -Cflags: -I${includedir} @LIBTBM_CFLAGS@ +Requires: libdrm, capi-base-common +Libs: -L${libdir} -ltbm +Cflags: -I${includedir} + diff --git a/packaging/libtbm.spec b/packaging/libtbm.spec index 7567a07..0dcc48b 100644 --- a/packaging/libtbm.spec +++ b/packaging/libtbm.spec @@ -1,23 +1,27 @@ Name: libtbm -Version: 1.0.6 -Release: 5 +Version: 1.1.0 +Release: 2 License: MIT -Summary: Tizen Buffer Manager Library +Summary: The library for Tizen Buffer Manager Group: System/Libraries Source0: %{name}-%{version}.tar.gz Source1001: libtbm.manifest BuildRequires: pkgconfig(pthread-stubs) BuildRequires: pkgconfig(libdrm) +BuildRequires: pkgconfig(x11) +BuildRequires: pkgconfig(libdri2) +BuildRequires: pkgconfig(capi-base-common) %description -The library for Tizen Buffer Manager. +Description: %{summary} %package devel Summary: Tizen Buffer Manager Library - Development Group: Development/Libraries Requires: libtbm = %{version} Requires: pkgconfig(libdrm) +Requires: pkgconfig(capi-base-common) %description devel The library for Tizen Buffer Manager. @@ -61,7 +65,10 @@ rm -rf %{buildroot} %defattr(-,root,root,-) %dir %{_includedir} %{_includedir}/tbm_bufmgr.h +%{_includedir}/tbm_surface.h +%{_includedir}/tbm_surface_internal.h %{_includedir}/tbm_bufmgr_backend.h +%{_includedir}/tbm_type.h %{_libdir}/libtbm.so %{_libdir}/libdrm_slp.so %{_libdir}/pkgconfig/libtbm.pc diff --git a/src/Makefile.am b/src/Makefile.am index feacb17..2e4ce26 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,9 +13,11 @@ libtbm_la_LDFLAGS = -version-number 1:0:0 -no-undefined libtbm_la_LIBADD = @LIBTBM_LIBS@ @PTHREADSTUBS_LIBS@ @CLOCK_LIB@ -ldl libtbm_la_SOURCES = \ + tbm_surface_internal.c \ + tbm_surface.c \ tbm_bufmgr_backend.c \ tbm_bufmgr.c libtbmincludedir=$(includedir) -libtbminclude_HEADERS = tbm_bufmgr.h tbm_bufmgr_backend.h +libtbminclude_HEADERS = tbm_bufmgr.h tbm_surface.h tbm_bufmgr_backend.h tbm_type.h tbm_surface_internal.h diff --git a/src/tbm_bufmgr.c b/src/tbm_bufmgr.c index 3e7c3b8..cc7d797 100755 --- a/src/tbm_bufmgr.c +++ b/src/tbm_bufmgr.c @@ -5,6 +5,7 @@ libtbm Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved. Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -30,28 +31,18 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "config.h" -#include <unistd.h> -#include <limits.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/ioctl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <dlfcn.h> -#include <dirent.h> -#include <string.h> -#include <errno.h> -#include <pthread.h> #include "tbm_bufmgr.h" -#include "tbm_bufmgr_tgl.h" -#include "tbm_bufmgr_backend.h" #include "tbm_bufmgr_int.h" +#include "tbm_bufmgr_backend.h" +#include "tbm_bufmgr_tgl.h" #include "list.h" +#include <X11/Xmd.h> +#include <dri2.h> +#include <xf86drm.h> #define DEBUG #ifdef DEBUG -static int bDebug = 0; +int bDebug = 0; #define DBG(...) if(bDebug&0x1) TBM_LOG (__VA_ARGS__) #define DBG_LOCK(...) if(bDebug&0x2) TBM_LOG (__VA_ARGS__) #else @@ -59,50 +50,6 @@ static int bDebug = 0; #define DBG_LOCK(...) #endif -/* check condition */ -#define TBM_RETURN_IF_FAIL(cond) {\ - if (!(cond)) {\ - TBM_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return;\ - }\ -} -#define TBM_RETURN_VAL_IF_FAIL(cond, val) {\ - if (!(cond)) {\ - TBM_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ - return val;\ - }\ -} - -/* check flags */ -#define RETURN_CHECK_FLAG(cond) {\ - if ((cond)) {\ - return;\ - }\ -} -#define RETURN_VAL_CHECK_FLAG(cond, val) {\ - if ((cond)) {\ - return val;\ - }\ -} - - -/* check validation */ -#define TBM_BUFMGR_IS_VALID(mgr) (mgr && \ - mgr->link.next &&\ - mgr->link.next->prev == &mgr->link) -#define TBM_BO_IS_VALID(bo) (bo && \ - TBM_BUFMGR_IS_VALID(bo->bufmgr) && \ - bo->item_link.next && \ - bo->item_link.next->prev == &bo->item_link) - -#define TBM_ALL_CTRL_BACKEND_VALID(flags) \ - ((flags&TBM_CACHE_CTRL_BACKEND) &&\ - (flags&TBM_LOCK_CTRL_BACKEND)) -#define TBM_CACHE_CTRL_BACKEND_VALID(flags) \ - (flags&TBM_CACHE_CTRL_BACKEND) -#define TBM_LOCK_CTRL_BACKEND_VALID(flags) \ - (flags&TBM_LOCK_CTRL_BACKEND) - #define PREFIX_LIB "libtbm_" #define SUFFIX_LIB ".so" #define DEFAULT_LIB PREFIX_LIB"default"SUFFIX_LIB @@ -152,9 +99,8 @@ typedef struct struct list_head item_link; } tbm_user_data; -/* list of bufmgr */ -static struct list_head *gBufMgrs = NULL; - +pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER; +tbm_bufmgr gBufMgr = NULL; static inline int _tgl_init (int fd, unsigned int key) @@ -449,7 +395,10 @@ _tbm_bo_set_state (tbm_bo bo, int device, int opt) if (opt & TBM_OPTION_WRITE) bo->cache_state.data.isDirtied = DEVICE_CA; else - bo->cache_state.data.isDirtied = DEVICE_NONE; + { + if( bo->cache_state.data.isDirtied != DEVICE_CA ) + bo->cache_state.data.isDirtied = DEVICE_NONE; + } } else { @@ -463,18 +412,21 @@ _tbm_bo_set_state (tbm_bo bo, int device, int opt) if (opt & TBM_OPTION_WRITE) bo->cache_state.data.isDirtied = DEVICE_CO; else - bo->cache_state.data.isDirtied = DEVICE_NONE; + { + if( bo->cache_state.data.isDirtied != DEVICE_CO ) + bo->cache_state.data.isDirtied = DEVICE_NONE; + } } if (need_flush) { - /* call backend cache flush */ - bufmgr->backend->bo_cache_flush (bo, need_flush); - /* set global cache flush count */ if (need_flush & TBM_CACHE_ALL) _tgl_set_data (bufmgr->lock_fd, GLOBAL_KEY, (unsigned int)(++cntFlush)); + /* call backend cache flush */ + bufmgr->backend->bo_cache_flush (bo, need_flush); + DBG ("[libtbm:%d] \tcache(%d,%d,%d)....flush:0x%x, cntFlush(%d)\n", getpid(), bo->cache_state.data.isCacheable, bo->cache_state.data.isCached, @@ -783,6 +735,15 @@ _tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file) dlclose (module_data); return 0; } + + if (!bufmgr->backend || !bufmgr->backend->priv) + { + TBM_LOG ("[libtbm:%d] " + "Error: module(%s) wrong operation. Check backend or backend's priv.\n", + getpid(), file); + dlclose (module_data); + return 0; + } } else { @@ -846,11 +807,100 @@ static int _tbm_load_module (tbm_bufmgr bufmgr, int fd) return ret; } +static int +_tbm_bufmgr_get_drm_fd() +{ + int screen; + Display *display; + int dri2Major, dri2Minor; + int eventBase, errorBase; + drm_magic_t magic; + char *driver_name, *device_name; + int fd; + + display = XOpenDisplay(NULL); + if (!display) + { + TBM_LOG ("[libtbm:%d] Fail XOpenDisplay\n", getpid()); + return -1; + } + + screen = DefaultScreen(display); + + if (!DRI2QueryExtension (display, &eventBase, &errorBase)) + { + TBM_LOG ("[libtbm:%d] Fail DRI2QueryExtention\n", getpid()); + XCloseDisplay(display); + return -1; + } + + if (!DRI2QueryVersion (display, &dri2Major, &dri2Minor)) + { + TBM_LOG ("[libtbm:%d] Fail DRI2QueryVersion\n", getpid()); + XCloseDisplay(display); + return -1; + } + + if (!DRI2Connect (display, RootWindow(display, screen), &driver_name, &device_name)) + { + TBM_LOG ("[libtbm:%d] Fail DRI2Connect\n", getpid()); + XCloseDisplay(display); + return -1; + } + + fd = open (device_name, O_RDWR); + if (fd < 0) + { + TBM_LOG ("[libtbm:%d] cannot open drm device (%s)\n", getpid(), device_name); + free (driver_name); + free (device_name); + XCloseDisplay(display); + return -1; + } + + if (drmGetMagic (fd, &magic)) + { + TBM_LOG ("[libtbm:%d] Fail drmGetMagic\n", getpid()); + free (driver_name); + free (device_name); + close(fd); + XCloseDisplay(display); + return -1; + } + + if (!DRI2Authenticate(display, RootWindow(display, screen), magic)) + { + TBM_LOG ("[libtbm:%d] Fail DRI2Authenticate\n", getpid()); + free (driver_name); + free (device_name); + close(fd); + XCloseDisplay(display); + return -1; + } + + if(!drmAuthMagic(fd, magic)) + { + TBM_LOG ("[libtbm:%d] Fail drmAuthMagic\n", getpid()); + free (driver_name); + free (device_name); + close(fd); + XCloseDisplay(display); + return -1; + } + + free (driver_name); + free (device_name); + XCloseDisplay(display); + return fd; +} + tbm_bufmgr tbm_bufmgr_init (int fd) { char *env; - tbm_bufmgr bufmgr = NULL; + int fd_flag = 0; + + pthread_mutex_lock (&gLock); #ifdef DEBUG env = getenv("GEM_DEBUG"); @@ -864,97 +914,112 @@ tbm_bufmgr_init (int fd) #endif /* initialize buffer manager */ - if (fd < 0) - return NULL; - - if(gBufMgrs == NULL) + if (gBufMgr) { - gBufMgrs = malloc(sizeof(struct list_head)); - LIST_INITHEAD(gBufMgrs); + TBM_LOG ("[libtbm:%d] use previous gBufMgr\n", getpid()); + gBufMgr->ref_count++; + TBM_LOG ("[libtbm:%d] bufmgr ref: fd=%d, ref_count:%d\n", + getpid(), gBufMgr->fd, gBufMgr->ref_count); + pthread_mutex_unlock (&gLock); + return gBufMgr; } - else + + if (fd < 0) { - LIST_FOR_EACH_ENTRY(bufmgr, gBufMgrs, link) + fd = _tbm_bufmgr_get_drm_fd(); + if (fd < 0) { - if(bufmgr->fd == fd) - { - bufmgr->ref_count++; - TBM_LOG ("[libtbm:%d] bufmgr ref: fd=%d, ref_count:%d\n", - getpid(), fd, bufmgr->ref_count); - return bufmgr; - } + TBM_LOG ("[libtbm:%d] Fail get drm fd\n", getpid()); + pthread_mutex_unlock (&gLock); + return NULL; } - bufmgr = NULL; + fd_flag = 1; } + TBM_LOG ("[libtbm:%d] bufmgr init: fd=%d\n", getpid(), fd); /* allocate bufmgr */ - bufmgr = calloc (1, sizeof(struct _tbm_bufmgr)); - if (!bufmgr) + gBufMgr = calloc (1, sizeof(struct _tbm_bufmgr)); + if (!gBufMgr) + { + pthread_mutex_unlock (&gLock); return NULL; + } /* load bufmgr priv from env */ - if (!_tbm_load_module(bufmgr, fd)) + if (!_tbm_load_module(gBufMgr, fd)) { TBM_LOG ("[libtbm:%d] " "error : Fail to load bufmgr backend\n", getpid()); - free (bufmgr); - bufmgr = NULL; + free (gBufMgr); + gBufMgr = NULL; + pthread_mutex_unlock (&gLock); return NULL; } - bufmgr->ref_count = 1; - bufmgr->fd = fd; + gBufMgr->fd_flag = fd_flag; + gBufMgr->fd = fd; + gBufMgr->ref_count = 1; - TBM_LOG ("[libtbm:%d] create tizen bufmgr: ref_count:%d\n", - getpid(), bufmgr->ref_count); + TBM_LOG ("[libtbm:%d] create tizen bufmgr: ref_count:%d\n", getpid(), gBufMgr->ref_count); - if (pthread_mutex_init (&bufmgr->lock, NULL) != 0) + if (pthread_mutex_init (&gBufMgr->lock, NULL) != 0) { - bufmgr->backend->bufmgr_deinit (bufmgr); - free (bufmgr); - bufmgr = NULL; + gBufMgr->backend->bufmgr_deinit (gBufMgr->backend->priv); + tbm_backend_free (gBufMgr->backend); + dlclose (gBufMgr->module_data); + free (gBufMgr); + gBufMgr = NULL; + pthread_mutex_unlock (&gLock); return NULL; } /* intialize the tizen global status */ - if (!_tbm_bufmgr_init_state (bufmgr)) + if (!_tbm_bufmgr_init_state (gBufMgr)) { TBM_LOG ("[libtbm:%d] " "error: Fail to init state\n", getpid()); - bufmgr->backend->bufmgr_deinit (bufmgr); - free (bufmgr); - bufmgr = NULL; + gBufMgr->backend->bufmgr_deinit (gBufMgr->backend->priv); + tbm_backend_free (gBufMgr->backend); + pthread_mutex_destroy (&gBufMgr->lock); + dlclose (gBufMgr->module_data); + free (gBufMgr); + gBufMgr = NULL; + pthread_mutex_unlock (&gLock); return NULL; } /* setup the lock_type */ env = getenv ("BUFMGR_LOCK_TYPE"); if (env && !strcmp (env, "always")) - bufmgr->lock_type = LOCK_TRY_ALWAYS; + gBufMgr->lock_type = LOCK_TRY_ALWAYS; else if(env && !strcmp(env, "none")) - bufmgr->lock_type = LOCK_TRY_NEVER; + gBufMgr->lock_type = LOCK_TRY_NEVER; + else if(env && !strcmp(env, "once")) + gBufMgr->lock_type = LOCK_TRY_ONCE; else - bufmgr->lock_type = LOCK_TRY_ONCE; + gBufMgr->lock_type = LOCK_TRY_ALWAYS; + DBG ("[libtbm:%d] BUFMGR_LOCK_TYPE=%s\n", getpid(), env?env:"default:once"); /* setup the map_cache */ env = getenv ("BUFMGR_MAP_CACHE"); if (env && !strcmp (env, "false")) - bufmgr->use_map_cache = 0; + gBufMgr->use_map_cache = 0; else - bufmgr->use_map_cache = 1; + gBufMgr->use_map_cache = 1; DBG ("[libtbm:%d] BUFMGR_MAP_CACHE=%s\n", getpid(), env?env:"default:true"); /* intialize bo_list */ - LIST_INITHEAD (&bufmgr->bo_list); + LIST_INITHEAD (&gBufMgr->bo_list); - /* add bufmgr to the gBufMgrs */ - LIST_ADD(&bufmgr->link, gBufMgrs); + /* intialize surf_list */ + LIST_INITHEAD (&gBufMgr->surf_list); - return bufmgr; + pthread_mutex_unlock (&gLock); + return gBufMgr; } void @@ -965,12 +1030,18 @@ tbm_bufmgr_deinit (tbm_bufmgr bufmgr) tbm_bo bo = NULL; tbm_bo tmp = NULL; + tbm_surface_h surf = NULL; + tbm_surface_h tmp_surf = NULL; + + pthread_mutex_lock (&gLock); + bufmgr->ref_count--; if (bufmgr->ref_count > 0) { TBM_LOG ("[libtbm:%d] " - "tizen bufmgr destroy: bufmgr:%p, ref_cnt:%d\n", + "tizen bufmgr destroy: bufmgr:%p, ref_count:%d\n", getpid(), bufmgr, bufmgr->ref_count); + pthread_mutex_unlock (&gLock); return; } @@ -987,6 +1058,18 @@ tbm_bufmgr_deinit (tbm_bufmgr bufmgr) } } + /* destroy surf_list */ + if(!LIST_IS_EMPTY (&bufmgr->surf_list)) + { + LIST_FOR_EACH_ENTRY_SAFE (surf, tmp_surf, &bufmgr->surf_list, item_link) + { + TBM_LOG ("[libtbm:%d] " + "Destroy surf(%p) \n", + getpid(), surf); + tbm_surface_destroy(surf); + } + } + /* destroy the tizen global status */ _tbm_bufmgr_destroy_state (bufmgr); @@ -999,17 +1082,19 @@ tbm_bufmgr_deinit (tbm_bufmgr bufmgr) pthread_mutex_destroy (&bufmgr->lock); TBM_LOG ("[libtbm:%d] " - "tizen bufmgr destroy: bufmgr:%p, ref_cnt:%d\n", - getpid(), bufmgr, bufmgr->ref_count); + "tizen bufmgr destroy: bufmgr:%p\n", + getpid(), bufmgr); dlclose (bufmgr->module_data); - LIST_DEL (&bufmgr->link); + if(bufmgr->fd_flag) + close(bufmgr->fd); free (bufmgr); bufmgr = NULL; -} + pthread_mutex_unlock (&gLock); +} int tbm_bo_size (tbm_bo bo) @@ -1020,7 +1105,9 @@ tbm_bo_size (tbm_bo bo) int size; pthread_mutex_lock(&bufmgr->lock); + size = bufmgr->backend->bo_size(bo); + pthread_mutex_unlock(&bufmgr->lock); return size; @@ -1147,6 +1234,14 @@ tbm_bo_import (tbm_bufmgr bufmgr, unsigned int key) return bo; } +tbm_bo +tbm_bo_import_fd (tbm_bufmgr bufmgr, tbm_fd fd) +{ + tbm_bo bo = NULL; + + return bo; +} + unsigned int tbm_bo_export (tbm_bo bo) { @@ -1164,6 +1259,15 @@ tbm_bo_export (tbm_bo bo) return ret; } +tbm_fd +tbm_bo_export_fd (tbm_bo bo) +{ + tbm_fd fd = 0; + + return fd; +} + + tbm_bo_handle tbm_bo_get_handle (tbm_bo bo, int device) { @@ -1380,4 +1484,38 @@ tbm_bo_delete_user_data (tbm_bo bo, unsigned long key) return 1; } +int +tbm_bo_cache_flush(tbm_bo bo, int flags) +{ + tbm_bufmgr bufmgr = bo->bufmgr; + + bufmgr->backend->bo_cache_flush (bo, flags); + + RETURN_VAL_CHECK_FLAG (TBM_CACHE_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1); + + unsigned short cntFlush = 0; + unsigned int is_locked; + /* get cache state of a bo */ + bo->cache_state.val = _tgl_get_data (bufmgr->lock_fd, bo->tgl_key, &is_locked); + + if (!bo->cache_state.data.isCacheable) + return 1; + + /* get global cache flush count */ + cntFlush = (unsigned short)_tgl_get_data (bufmgr->lock_fd, GLOBAL_KEY, NULL); + + bo->cache_state.data.isDirtied = DEVICE_NONE; + bo->cache_state.data.isCached = 0; + + /* set global cache flush count */ + _tgl_set_data (bufmgr->lock_fd, GLOBAL_KEY, (unsigned int)(++cntFlush)); + + DBG ("[libtbm:%d] \tcache(%d,%d,%d).... cntFlush(%d)\n", getpid(), + bo->cache_state.data.isCacheable, + bo->cache_state.data.isCached, + bo->cache_state.data.isDirtied, + cntFlush); + + return 1; +} diff --git a/src/tbm_bufmgr.h b/src/tbm_bufmgr.h index 7bf2597..7a3c481 100755 --- a/src/tbm_bufmgr.h +++ b/src/tbm_bufmgr.h @@ -5,6 +5,7 @@ libtbm Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved. Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -31,6 +32,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifndef _TBM_BUFMGR_H_ #define _TBM_BUFMGR_H_ +/** + * @internal + * @addtogroup CAPI_UI_TBM_BUFMGR_MODULE + * @{ + */ + +#include <tbm_type.h> #include <stdint.h> /** @@ -38,24 +46,89 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * \brief Tizen Buffer Manager */ -typedef struct _tbm_bufmgr *tbm_bufmgr; +/** + * @brief Definition for the tizen buffer manager + * @since_tizen 2.3 + */ +typedef struct _tbm_bufmgr * tbm_bufmgr; + +/** + * @brief Definition for the tizen buffer object + * @since_tizen 2.3 + */ typedef struct _tbm_bo *tbm_bo; +/** + * @brief Definition for the key associated with the buffer object + * @since_tizen 2.3 + */ +typedef uint32_t tbm_key; +/** + * @brief Definition for the file descripter of the system buffer manager + * @since_tizen 2.3 + */ +typedef int32_t tbm_fd; + /* TBM_DEVICE_TYPE */ -#define TBM_DEVICE_DEFAULT 0 /**< device type to get the default handle */ -#define TBM_DEVICE_CPU 1 /**< device type to get the virtual memory */ -#define TBM_DEVICE_2D 2 /**< device type to get the 2D memory handle */ -#define TBM_DEVICE_3D 3 /**< device type to get the 3D memory handle */ -#define TBM_DEVICE_MM 4 /**< device type to get the multimedia handle */ + +/** + * @brief Definition for the device type to get the default handle + * @since_tizen 2.3 + */ +#define TBM_DEVICE_DEFAULT 0 +/** + * @brief Definition for the device type to get the virtual memory + * @since_tizen 2.3 + */ +#define TBM_DEVICE_CPU 1 +/** + * @brief Definition for the device type to get the 2D memory handle + * @since_tizen 2.3 + */ +#define TBM_DEVICE_2D 2 +/** + * @brief Definition for the device type to get the 3D memory handle + * @since_tizen 2.3 + */ +#define TBM_DEVICE_3D 3 +/** + * @brief Definition for the device type to get the multimedia handle + * @since_tizen 2.3 + */ +#define TBM_DEVICE_MM 4 + +/** + * @brief Definition for the cache invalidate + * @since_tizen 2.3 + */ +#define TBM_CACHE_INV 0x01 +/** + * @brief Definition for the cache clean + * @since_tizen 2.3 + */ +#define TBM_CACHE_CLN 0x02 /* TBM_OPTION */ -#define TBM_OPTION_READ (1 << 0) /**< access option to read */ -#define TBM_OPTION_WRITE (1 << 1) /**< access option to write */ -#define TBM_OPTION_VENDOR (0xffff0000) /**< vendor specific option: it depends on the backend */ /** - * @brief tbm_bo_handle - * abstraction of the memory handle by TBM_DEVICE_TYPE + * @brief Definition for the access option to read + * @since_tizen 2.3 + */ +#define TBM_OPTION_READ (1 << 0) +/** + * @brief Definition for the access option to write + * @since_tizen 2.3 + */ +#define TBM_OPTION_WRITE (1 << 1) +/** + * @brief Definition for the vendor specific option that depends on the backend + * @since_tizen 2.3 + */ +#define TBM_OPTION_VENDOR (0xffff0000) + +/** + * @brief tbm_bo_handle abstraction of the memory handle by TBM_DEVICE_TYPE + * @since_tizen 2.3 */ typedef union _tbm_bo_handle { @@ -68,6 +141,7 @@ typedef union _tbm_bo_handle /** * @brief Enumeration of bo memory type + * @since_tizen 2.3 */ enum TBM_BO_FLAGS { @@ -85,145 +159,710 @@ extern "C" { /* Functions for buffer manager */ /** - * @brief initialize the buffer manager. + * @brief Initializes the buffer manager. + * @details If fd is lower than zero, fd is get drm fd in tbm_bufmgr_init function\n + * The user can decide the lock type and cache flush type with the environment variables, which are BUFMGR_LOCK_TYPE and BUFMGR_MAP_CACHE.\n + * \n + * BUFMGR_LOCK default is once\n + * once : The previous bo which is locked is unlock when the new bo is trying to be locked\n + * always : The new bo is locked until the previous bo which is locked is unlocked\n + * never : Every bo is never locked.\n + * \n + * BUFMGR_MAP_CACHE default is true\n + * true : use map cache flushing\n + * false : to use map cache flushing + * @since_tizen 2.3 * @param[in] fd : file descripter of the system buffer manager * @return a buffer manager + * @retval #tbm_bufmgr + * @see tbm_bufmgr_deinit(); + * @par Example + @code + #include <tbm_bufmgr.h> + int bufmgr_fd; + + + setenv("BUFMGR_LOCK_TYPE", "once", 1); + setenv("BUFMGR_MAP_CACHE", "true", 1); + + tbm_bufmgr bufmgr; + bufmgr = tbm_bufmgr_init (bufmgr_fd); + + .... + + tbm_bufmgr_deinit (bufmgr); + @endcode */ tbm_bufmgr tbm_bufmgr_init (int fd); /** - * @brief deinitialize the buffer manager. + * @brief Deinitializes the buffer manager. + * @since_tizen 2.3 * @param[in] bufmgr : the buffer manager + * @see tbm_bufmgr_init() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + bufmgr = tbm_bufmgr_init (bufmgr_fd); + + .... + + tbm_bufmgr_deinit (bufmgr); + @endcode */ void tbm_bufmgr_deinit (tbm_bufmgr bufmgr); /* Functions for bo */ /** - * @brief allocate the buffer object + * @brief Allocates the buffer object. + * @details This function create tbm_bo and set reference count to 1.\n + * The user can craete tbm_bo with memory type flag #TBM_BO_FLAGS\n\n + * #TBM_BO_DEFAULT indecates default memory: it depends on the backend\n + * #TBM_BO_SCANOUT indecates scanout memory\n + * #TBM_BO_NONCACHABLE indecates non-cachable memory\n + * #TBM_BO_WC indecates write-combine memory\n + * #TBM_BO_VENDOR indecates vendor specific memory: it depends on the tbm backend + * @since_tizen 2.3 * @param[in] bufmgr : the buffer manager * @param[in] size : the size of buffer object * @param[in] flags : the flags of memory type * @return a buffer object + * @retval #tbm_bo + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + + .... + + tbm_bufmgr_deinit (bufmgr); + @endcode */ tbm_bo tbm_bo_alloc (tbm_bufmgr bufmgr, int size, int flags); /** - * @brief increase the reference count of bo. + * @brief Increases the reference count of bo. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @return a buffer object + * @retval #tbm_bo + * @see tbm_bo_unref() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + + ... + + bo = tbm_bo_ref (bo); + + .... + + tbm_bufmgr_deinit (bufmgr); + @endcode */ tbm_bo tbm_bo_ref (tbm_bo bo); /** - * @brief increase the reference count of bo. + * @brief Decreases the reference count of bo + * @since_tizen 2.3 * @param[in] bo : the buffer object + * @see tbm_bo_ref() + * @see tbm_bo_alloc() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode */ void tbm_bo_unref (tbm_bo bo); /** - * @brief map the buffer object according to the device type and the option. + * @brief Maps the buffer object according to the device type and the option. + * @details Cache flushing and Locking is executed, while tbm_bo is mapping in the proper condition according to the device type and the access option.\n + * If the cache flush type of bufmgr set true, the map cache flushing is executed + * If the lock type of bufmgr set once, the previous bo which is locked is unlock when the new bo is trying to be locked.\n + * If the lock type of bufmgr set always, the new bo is locked until the previous bo which is locked is unlocked.\n + * If the lock type of bufmgr set never, Every bo is never locked.\n\n + * #TBM_DEVICE_DEFAULT indecates the default handle.\n + * #TBM_DEVICE_2D indecates the 2D memory handle.\n + * #TBM_DEVICE_3D indecates the 3D memory handle.\n + * #TBM_DEVICE_CPU indecates the virtual memory handle.\n + * #TBM_DEVICE_MM indecates the multimedia handle.\n\n + * #TBM_OPTION_READ indecates the accss option to read.\n + * #TBM_OPTION_WRITE indecates the access option to write.\n + * #TBM_OPTION_VENDOR indecates the vendor specific option that depends on the backend. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @param[in] device : the device type to get a handle - * @param[in] option : the option to access the buffer object + * @param[in] opt : the option to access the buffer object * @return the handle of the buffer object + * @retval #tbm_bo + * @see tbm_bo_unmap() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + tbm_bo_handle handle; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + + ... + + handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE); + + ... + + tbm_bo_unmap (bo); + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode */ tbm_bo_handle tbm_bo_map (tbm_bo bo, int device, int opt); /** - * @brief unmap the buffer object. + * @brief Unmaps the buffer object. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @return 1 if this function succeeds, otherwise 0. + * @see tbm_bo_map() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo + tbm_bo_handle handle; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + + ... + + handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE); + + ... + + tbm_bo_unmap (bo); + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode */ int tbm_bo_unmap (tbm_bo bo); /** - * @brief get the tbm_bo_handle according to the device type. + * @brief Gets the tbm_bo_handle according to the device type. + * @details The tbm_bo_handle can be get without the map of the tbm_bo.\n + * In this case, TBM does not guarantee the lock and the cache flush of the tbm_bo.\n\n + * #TBM_DEVICE_DEFAULT indecates the default handle.\n + * #TBM_DEVICE_2D indecates the 2D memory handle.\n + * #TBM_DEVICE_3D indecates the 3D memory handle.\n + * #TBM_DEVICE_CPU indecates the virtual memory handle.\n + * #TBM_DEVICE_MM indecates the multimedia handle. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @param[in] device : the device type to get a handle * @return the handle of the buffer object - */ + * @retval #tbm_bo_handle + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + tbm_bo_handle handle; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + + ... + + handle = tbm_bo_get_handle (bo, TBM_DEVICE_2D); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode + */ tbm_bo_handle tbm_bo_get_handle (tbm_bo bo, int device); /** - * @brief export the buffer object + * @brief Exports the buffer object by key. + * @details The tbm_bo can be exported to the anther process with the unique key associated with the the tbm_bo. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @return key associated with the buffer object - */ -unsigned int tbm_bo_export (tbm_bo bo); + * @retval #tbm_key + * @see tbm_bo_import() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo; + tbm_key key; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + key = tbm_bo_export (bo); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode + */ +tbm_key tbm_bo_export (tbm_bo bo); /** - * @brief import the buffer object associated with the key. + * @brief Exports the buffer object by fd. + * @details The tbm_bo can be exported to the anther process with the unique fd associated with the the tbm_bo. + * @since_tizen 2.3 + * @param[in] bo : the buffer object + * @return fd associated with the buffer object + * @retval #tbm_fd + * @see tbm_bo_import_fd() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_fd bo_fd; + tbm_bufmgr bufmgr; + tbm_bo; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + bo_fd = tbm_bo_export (bo); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode + */ +tbm_fd tbm_bo_export_fd (tbm_bo bo); + +/** + * @brief Imports the buffer object associated with the key. + * @details The reference count of the tbm_bo is 1. + * @since_tizen 2.3 * @param[in] bufmgr : the buffer manager * @param[in] key : the key associated with the buffer object * @return a buffer object - */ -tbm_bo tbm_bo_import (tbm_bufmgr bufmgr, unsigned int key); + * @retval #tbm_bo + * @see tbm_bo_export() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + int bo_key; + tbm_bufmgr bufmgr; + tbm_bo; + + ... + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_import (key); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode + */ +tbm_bo tbm_bo_import (tbm_bufmgr bufmgr, tbm_key key); /** - * @brief get the size of a bo. + * @brief Imports the buffer object associated with the fd. + * @details The reference count of the tbm_bo is 1. + * @since_tizen 2.3 + * @param[in] bufmgr : the buffer manager + * @param[in] fd : the fd associated with the buffer object + * @return a buffer object + * @retval #tbm_bo + * @see tbm_bo_export_fd() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_fd bo_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + + ... + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_import (bo_fd); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode + */ +tbm_bo tbm_bo_import_fd (tbm_bufmgr bufmgr, tbm_fd fd); + +/** + * @brief Gets the size of a bo. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @return 1 if this function succeeds, otherwise 0. - */ + * @see tbm_bo_alloc() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo; + int size; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + size = tbm_bo_size (bo); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode + */ int tbm_bo_size (tbm_bo bo); /** - * @brief get the state where the buffer object is locked. + * @brief Gets the state where the buffer object is locked. + * @since_tizen 2.3 * @param[in] bo : the buffer object - * @return 1 if this function succeeds, otherwise 0. - */ + * @return 1 if this bo is locked, otherwise 0. + * @see tbm_bo_map() + * @see tbm_bo_unmap() + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + + ... + + if (tbm_bo_locked (bo)) + { + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + @endcode +*/ int tbm_bo_locked (tbm_bo bo); /** - * @brief swap the buffer object. + * @brief Swaps the buffer object. + * @since_tizen 2.3 * @param[in] bo1 : the buffer object * @param[in] bo2 : the buffer object * @return 1 if this function succeeds, otherwise 0. + * @par Example + @code + #include <tbm_bufmgr.h> + + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo1; + tbm_bo bo2; + int ret; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo1 = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + bo2 = tbm_bo_alloc (bufmgr, 256 * 256, TBM_BO_DEFAULT); + + ... + + ret = tbm_bo_swap (bo1, bo2); + + ... + + tbm_bo_unref (bo1); + tbm_bo_unref (bo2); + tbm_bufmgr_deinit (bufmgr); + @endcode */ int tbm_bo_swap (tbm_bo bo1, tbm_bo bo2); -/* Functions for userdata of bo */ -typedef void (*tbm_data_free)(void *); +/** + * @brief Called when the user data is deleted in buffer object. + * @since_tizen 2.3 + * @param[in] user_data User_data to be passed to callback function + * @pre The callback must be registered using tbm_bo_add_user_data().\n + * tbm_bo_delete_user_data() must be called to invoke this callback. + * @see tbm_bo_add_user_data() + * @see tbm_bo_delete_user_data() + */ +typedef void (*tbm_data_free)(void *user_data); /** - * @brief add a user_data to the buffer object + * @brief Adds a user_data to the buffer object. + * @since_tizen 2.3 * @param[in] bo : the buffer object - * @param[in] key : the key associated with the user_date + * @param[in] key : the key associated with the user_data * @param[in] data_free_func : the function pointer to free the user_data * @return 1 if this function succeeds, otherwise 0. + * @post tbm_data_free() will be called under certain conditions, after calling tbm_bo_delete_user_data(). + * @see tbm_data_free() + * @see tbm_bo_set_user_data() + * @see tbm_bo_get_user_data() + * @see tbm_bo_delete_user_data() + * @par Example + @code + #include <tbm_bufmgr.h> + + void example_data_free (void *user_data) + { + char *data = (char*) user_data; + free(data); + } + + int main() + { + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + char *user_data; + char *get_data; + int ret; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + user_data = (char*) malloc (sizeof(char) * 128); + + ... + + tbm_bo_add_user_data (bo, 1, example_data_free); + tbm_bo_set_user_data (bo, 1, user_data); + + ... + + ret = tbm_bo_get_user_data (bo, 1, &get_data); + tbm_bo_delete_user_data (bo, 1); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + } + @endcode */ + int tbm_bo_add_user_data (tbm_bo bo, unsigned long key, tbm_data_free data_free_func); /** - * @brief delete the user_data in the buffer object. + * @brief Deletes the user_data in the buffer object. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @param[in] key : the key associated with the user_date * @return 1 if this function succeeds, otherwise 0. + * @see tbm_bo_add_user_data() + * @see tbm_bo_get_user_data() + * @see tbm_bo_delete_user_data() + * @par Example + @code + #include <tbm_bufmgr.h> + + void example_data_free (void *user_data) + { + char *data = (char*) user_data; + free(data); + } + + int main() + { + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + char *user_data; + char *get_data; + int ret; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + user_data = (char*) malloc (sizeof(char) * 128); + + ... + + tbm_bo_add_user_data (bo, 1, example_data_free); + tbm_bo_set_user_data (bo, 1, user_data); + + ... + + ret = tbm_bo_get_user_data (bo, 1, &get_data); + tbm_bo_delete_user_data (bo, 1); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + } + @endcode */ int tbm_bo_delete_user_data (tbm_bo bo, unsigned long key); /** - * @brief set a user_date to the buffer object. + * @brief Sets a user_date to the buffer object. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @param[in] key : the key associated with the user_date * @param[in] data : a pointer of the user_data * @return 1 if this function succeeds, otherwise 0. + * @see tbm_bo_add_user_data() + * @see tbm_bo_set_user_data() + * @see tbm_bo_delete_user_data() + * @par Example + @code + #include <tbm_bufmgr.h> + + void example_data_free (void *user_data) + { + char *data = (char*) user_data; + free(data); + } + + int main() + { + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + char *user_data; + char *get_data; + int ret; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + user_data = (char*) malloc (sizeof(char) * 128); + + ... + + tbm_bo_add_user_data (bo, 1, example_data_free); + tbm_bo_set_user_data (bo, 1, user_data); + + ... + + ret = tbm_bo_get_user_data (bo, 1, &get_data); + tbm_bo_delete_user_data (bo, 1); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + } + @endcode */ int tbm_bo_set_user_data (tbm_bo bo, unsigned long key, void* data); /** - * @brief get a user_date from the buffer object with the key. + * @brief Gets a user_data from the buffer object with the key. + * @since_tizen 2.3 * @param[in] bo : the buffer object * @param[in] key : the key associated with the user_date * @param[out] data : to get the user data * @return 1 if this function succeeds, otherwise 0. + * @see tbm_bo_add_user_data() + * @see tbm_bo_set_user_data() + * @see tbm_bo_get_user_data() + * @par Example + @code + #include <tbm_bufmgr.h> + + void example_data_free (void *user_data) + { + char *data = (char*) user_data; + free(data); + } + + int main() + { + int bufmgr_fd; + tbm_bufmgr bufmgr; + tbm_bo bo; + char *user_data; + char *get_data; + int ret; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + user_data = (char*) malloc (sizeof(char) * 128); + + ... + + tbm_bo_add_user_data (bo, 1, example_data_free); + tbm_bo_set_user_data (bo, 1, user_data); + + ... + + ret = tbm_bo_get_user_data (bo, 1, &get_data); + tbm_bo_delete_user_data (bo, 1); + + ... + + tbm_bo_unref (bo); + tbm_bufmgr_deinit (bufmgr); + } + @endcode */ int tbm_bo_get_user_data (tbm_bo bo, unsigned long key, void** data); +int tbm_bo_cache_flush (tbm_bo bo, int flags); + + #ifdef __cplusplus } #endif +/** +* @} +*/ + #endif /* _TBM_BUFMGR_H_ */ diff --git a/src/tbm_bufmgr_backend.c b/src/tbm_bufmgr_backend.c index dd82402..462103b 100755 --- a/src/tbm_bufmgr_backend.c +++ b/src/tbm_bufmgr_backend.c @@ -5,6 +5,7 @@ libtbm Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved. Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/src/tbm_bufmgr_backend.h b/src/tbm_bufmgr_backend.h index b0b3501..c9bd0a7 100755 --- a/src/tbm_bufmgr_backend.h +++ b/src/tbm_bufmgr_backend.h @@ -1,243 +1,281 @@ -/**************************************************************************
-
-libtbm
-
-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.
-
-**************************************************************************/
-
-/*
- * This file is referenced by the xf86Module.h in xorg server.
- */
-
-#ifndef _TBM_BUFMGR_BACKEND_H_
-#define _TBM_BUFMGR_BACKEND_H_
-
-#include <tbm_bufmgr.h>
-#include <pthread.h>
-
-/**
- * \file tbm_bufmgr_backend.h
- * \brief backend header for Tizen Buffer Manager
- * This header is for the implementation of the TBM backend module.
- */
-
-
-#define ABI_MINOR_MASK 0x0000FFFF
-#define ABI_MAJOR_MASK 0xFFFF0000
-#define GET_ABI_MINOR(v) ((v) & ABI_MINOR_MASK)
-#define GET_ABI_MAJOR(v) (((v) & ABI_MAJOR_MASK) >> 16)
-
-/*
- * ABI versions. Each version has a major and minor revision. Modules
- * using lower minor revisions must work with servers of a higher minor
- * revision. There is no compatibility between different major revisions.
- * Whenever the ABI_ANSIC_VERSION is changed, the others must also be
- * changed. The minor revision mask is 0x0000FFFF and the major revision
- * mask is 0xFFFF0000.
- */
-#define SET_ABI_VERSION(maj, min) \
- ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK))
-
-#define TBM_ABI_VERSION SET_ABI_VERSION(1, 0) /**< current abi vertion */
-
-/* TBM_CACHE */
-#define TBM_CACHE_INV 0x01 /**< cache invalidate */
-#define TBM_CACHE_CLN 0x02 /**< cache clean */
-#define TBM_CACHE_ALL 0x10 /**< cache all */
-#define TBM_CACHE_FLUSH (TBM_CACHE_INV|TBM_CACHE_CLN) /**< cache flush */
-#define TBM_CACHE_FLUSH_ALL (TBM_CACHE_FLUSH|TBM_CACHE_ALL) /**< cache flush all */
-
-/* TBM flag for cache control and lock control */
-/**
- * TBM_CACHE_CTRL_BACKEND indicates that the backend control the cache coherency.
+/************************************************************************** + +libtbm + +Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, 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. + +**************************************************************************/ + +/* + * This file is referenced by the xf86Module.h in xorg server. + */ + +#ifndef _TBM_BUFMGR_BACKEND_H_ +#define _TBM_BUFMGR_BACKEND_H_ + +#include <tbm_bufmgr.h> +#include <pthread.h> + +/** + * \file tbm_bufmgr_backend.h + * \brief backend header for Tizen Buffer Manager + * This header is for the implementation of the TBM backend module. + */ + + +#define ABI_MINOR_MASK 0x0000FFFF +#define ABI_MAJOR_MASK 0xFFFF0000 +#define GET_ABI_MINOR(v) ((v) & ABI_MINOR_MASK) +#define GET_ABI_MAJOR(v) (((v) & ABI_MAJOR_MASK) >> 16) + +/* + * ABI versions. Each version has a major and minor revision. Modules + * using lower minor revisions must work with servers of a higher minor + * revision. There is no compatibility between different major revisions. + * Whenever the ABI_ANSIC_VERSION is changed, the others must also be + * changed. The minor revision mask is 0x0000FFFF and the major revision + * mask is 0xFFFF0000. + */ +#define SET_ABI_VERSION(maj, min) \ + ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK)) + +#define TBM_ABI_VERSION SET_ABI_VERSION(1, 0) /**< current abi vertion */ + +/* TBM_CACHE */ +#define TBM_CACHE_INV 0x01 /**< cache invalidate */ +#define TBM_CACHE_CLN 0x02 /**< cache clean */ +#define TBM_CACHE_ALL 0x10 /**< cache all */ +#define TBM_CACHE_FLUSH (TBM_CACHE_INV|TBM_CACHE_CLN) /**< cache flush */ +#define TBM_CACHE_FLUSH_ALL (TBM_CACHE_FLUSH|TBM_CACHE_ALL) /**< cache flush all */ + +/* TBM flag for cache control and lock control */ +/** + * TBM_CACHE_CTRL_BACKEND indicates that the backend control the cache coherency. + */ +#define TBM_CACHE_CTRL_BACKEND (1 << 0) + +/** + * TBM_LOCK_CTRL_BACKEND indicates that the backend control the lock of bos. + */ +#define TBM_LOCK_CTRL_BACKEND (1 << 1) + +typedef struct _tbm_bufmgr_backend *tbm_bufmgr_backend; + +/** + * @brief TBM backend functions + * the set of function pointers for the backend module of TBM. + */ +struct _tbm_bufmgr_backend +{ + int flags; + + void *priv; /**< bufmgr private */ + + /** + * @brief deinitialize the bufmgr private. + * @param[in] bufmgr : the private of the bufmgr + * @return 1 if this function succeeds, otherwise 0. + */ + void (*bufmgr_deinit) (void *priv); + + /** + * @brief get the size of a bo. + * @param[in] bo : the buffer object + * @return 1 if this function succeeds, otherwise 0. + */ + int (*bo_size) (tbm_bo bo); + + /** + * @brief allocate the buffer object + * @param[in] bo : the buffer object + * @param[in] size : the size of buffer object + * @param[in] flags : the flags of memory type + * @return pointer of the bo private. + */ + void * (*bo_alloc) (tbm_bo bo, int size, int flags); + + /** + * @brief free the buffer object. + * @param[in] bo : the buffer object + */ + void (*bo_free) (tbm_bo bo); + + /** + * @brief import the buffer object associated with the key. + * @param[in] bo : the buffer object + * @param[in] key : the key associated with the buffer object + * @return pointer of the bo private. + */ + void * (*bo_import) (tbm_bo bo, unsigned int key); + + /** + * @brief export the buffer object + * @param[in] bo : the buffer object + * @return key associated with the buffer object + */ + unsigned int (*bo_export) (tbm_bo bo); + + /** + * @brief get the tbm_bo_handle according to the device type. + * @param[in] bo : the buffer object + * @param[in] device : the device type to get a handle + * @return the handle of the buffer object + */ + tbm_bo_handle (*bo_get_handle) (tbm_bo bo, int device); + + /** + * @brief map the buffer object according to the device type and the option. + * @param[in] bo : the buffer object + * @param[in] device : the device type to get a handle + * @param[in] option : the option to access the buffer object + * @return the handle of the buffer object + */ + tbm_bo_handle (*bo_map) (tbm_bo bo, int device, int opt); + + /** + * @brief unmap the buffer object. + * @param[in] bo : the buffer object + * @return 1 if this function succeeds, otherwise 0. + */ + int (*bo_unmap) (tbm_bo bo); + + /** + * @brief flush the cache of the buffer object. + * @param[in] bo : the buffer object + * @param[in] flags : the flags of cache flush type + * @return 1 if this function succeeds, otherwise 0. + */ + int (*bo_cache_flush) (tbm_bo bo, int flags); + + /** + * @brief get the global key associated with the buffer object. + * @param[in] bo : the buffer object + * @return global key associated with the buffer object. + */ + int (*bo_get_global_key) (tbm_bo bo); + + /** + * @brief lock the buffer object. + * @param[in] bo : the buffer object + * @return 1 if this function succeeds, otherwise 0. + * @remark This function pointer could be null. (default: use the tizen global lock) + */ + int (*bo_lock) (tbm_bo bo); + + /** + * @brief unlock the buffer object. + * @param[in] bo : the buffer object + * @return 1 if this function succeeds, otherwise 0. + * @remark This function pointer could be null. (default: use the tizen global lock) + */ + int (*bo_unlock) (tbm_bo bo); + + /** + * @brief lock the buffer object with a device and an opt. + * @param[in] bo : the buffer object + * @param[in] device : the device type to get a handle + * @param[in] option : the option to access the buffer object + * @return 1 if this function succeeds, otherwise 0. + * @remark This function pointer could be null. (default: use the tizen global lock) + */ + int (*bo_lock2) (tbm_bo bo, int device, int opt); + + /** + * @brief query the formats list and the num to be supported by backend. + * @param[out] *formats : format array list. this array has to be allocated by backend funtion + * @param[out] *num : the number of the formats to be supported by backend + * @return 1 if this function succeeds, otherwise 0. + */ + int (*surface_supported_format) (uint32_t **formats, uint32_t *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 (*surface_get_size) (tbm_surface_h surface, int width, int height, tbm_format format); + + /** + * @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 + * @return 1 if this function succeeds, otherwise 0. + */ + int (*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); + + /* Padding for future extension */ + void (*reserved1) (void); + void (*reserved2) (void); + void (*reserved3) (void); + void (*reserved4) (void); + void (*reserved5) (void); + void (*reserved6) (void); + void (*reserved7) (void); + void (*reserved8) (void); +}; + +/** + * @brief tbm module information + * data type for the module information */ -#define TBM_CACHE_CTRL_BACKEND (1 << 0)
+typedef struct +{ + const char *modname; /**< name of module, e.g. "foo" */ + const char *vendor; /**< vendor specific string */ + unsigned long abiversion; /**< ABI version */ +} TBMModuleVersionInfo; + +typedef int (*ModuleInitProc) (tbm_bufmgr, int); + +#define MODULEINITPPROTO(func) int func(tbm_bufmgr, int) /**< prototype for init symbol of bakcend module */ /** - * TBM_LOCK_CTRL_BACKEND indicates that the backend control the lock of bos.
+ * @brief tbm module data + * data type for the entry point of the backend module */ -#define TBM_LOCK_CTRL_BACKEND (1 << 1)
-
-typedef struct _tbm_bufmgr_backend *tbm_bufmgr_backend;
-
-/**
- * @brief TBM backend functions
- * the set of function pointers for the backend module of TBM.
- */
-struct _tbm_bufmgr_backend
-{
- int flags;
-
- void *priv; /**< bufmgr private */
-
- /**
- * @brief deinitialize the bufmgr private.
- * @param[in] bufmgr : the private of the bufmgr
- * @return 1 if this function succeeds, otherwise 0.
- */
- void (*bufmgr_deinit) (void *priv);
-
- /**
- * @brief get the size of a bo.
- * @param[in] bo : the buffer object
- * @return 1 if this function succeeds, otherwise 0.
- */
- int (*bo_size) (tbm_bo bo);
-
- /**
- * @brief allocate the buffer object
- * @param[in] bo : the buffer object
- * @param[in] size : the size of buffer object
- * @param[in] flags : the flags of memory type
- * @return pointer of the bo private.
- */
- void * (*bo_alloc) (tbm_bo bo, int size, int flags);
-
- /**
- * @brief free the buffer object.
- * @param[in] bo : the buffer object
- */
- void (*bo_free) (tbm_bo bo);
-
- /**
- * @brief import the buffer object associated with the key.
- * @param[in] bo : the buffer object
- * @param[in] key : the key associated with the buffer object
- * @return pointer of the bo private.
- */
- void * (*bo_import) (tbm_bo bo, unsigned int key);
-
- /**
- * @brief export the buffer object
- * @param[in] bo : the buffer object
- * @return key associated with the buffer object
- */
- unsigned int (*bo_export) (tbm_bo bo);
-
- /**
- * @brief get the tbm_bo_handle according to the device type.
- * @param[in] bo : the buffer object
- * @param[in] device : the device type to get a handle
- * @return the handle of the buffer object
- */
- tbm_bo_handle (*bo_get_handle) (tbm_bo bo, int device);
-
- /**
- * @brief map the buffer object according to the device type and the option.
- * @param[in] bo : the buffer object
- * @param[in] device : the device type to get a handle
- * @param[in] option : the option to access the buffer object
- * @return the handle of the buffer object
- */
- tbm_bo_handle (*bo_map) (tbm_bo bo, int device, int opt);
-
- /**
- * @brief unmap the buffer object.
- * @param[in] bo : the buffer object
- * @return 1 if this function succeeds, otherwise 0.
- */
- int (*bo_unmap) (tbm_bo bo);
-
- /**
- * @brief flush the cache of the buffer object.
- * @param[in] bo : the buffer object
- * @param[in] flags : the flags of cache flush type
- * @return 1 if this function succeeds, otherwise 0.
- */
- int (*bo_cache_flush) (tbm_bo bo, int flags);
-
- /**
- * @brief get the global key associated with the buffer object.
- * @param[in] bo : the buffer object
- * @return global key associated with the buffer object.
- */
- int (*bo_get_global_key) (tbm_bo bo);
-
- /**
- * @brief lock the buffer object.
- * @param[in] bo : the buffer object
- * @return 1 if this function succeeds, otherwise 0.
- * @remark This function pointer could be null. (default: use the tizen global lock)
- */
- int (*bo_lock) (tbm_bo bo);
-
- /**
- * @brief unlock the buffer object.
- * @param[in] bo : the buffer object
- * @return 1 if this function succeeds, otherwise 0.
- * @remark This function pointer could be null. (default: use the tizen global lock)
- */
- int (*bo_unlock) (tbm_bo bo);
-
- /**
- * @brief lock the buffer object with a device and an opt.
- * @param[in] bo : the buffer object
- * @param[in] device : the device type to get a handle
- * @param[in] option : the option to access the buffer object
- * @return 1 if this function succeeds, otherwise 0.
- * @remark This function pointer could be null. (default: use the tizen global lock)
- */
- int (*bo_lock2) (tbm_bo bo, int device, int opt);
-
- /* Padding for future extension */
- void (*reserved1) (void);
- void (*reserved2) (void);
- void (*reserved3) (void);
-};
-
-/**
- * @brief tbm module information
- * data type for the module information
- */
-typedef struct
-{
- const char *modname; /**< name of module, e.g. "foo" */
- const char *vendor; /**< vendor specific string */
- unsigned long abiversion; /**< ABI version */
-} TBMModuleVersionInfo;
-
-typedef int (*ModuleInitProc) (tbm_bufmgr, int);
-
-#define MODULEINITPPROTO(func) int func(tbm_bufmgr, int) /**< prototype for init symbol of bakcend module */
-
-/**
- * @brief tbm module data
- * data type for the entry point of the backend module
- */
-typedef struct
-{
- TBMModuleVersionInfo *vers; /**< tbm module informtaion */
- ModuleInitProc init; /**< init function of a backend module */
-} TBMModuleData;
-
-tbm_bufmgr_backend tbm_backend_alloc (void);
-void tbm_backend_free (tbm_bufmgr_backend backend);
-int tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend);
-
-void *tbm_backend_get_bufmgr_priv (tbm_bo bo);
-void *tbm_backend_get_bo_priv (tbm_bo bo);
-
-#endif /* _TBM_BUFMGR_BACKEND_H_ */
+typedef struct +{ + TBMModuleVersionInfo *vers; /**< tbm module informtaion */ + ModuleInitProc init; /**< init function of a backend module */ +} TBMModuleData; + +tbm_bufmgr_backend tbm_backend_alloc (void); +void tbm_backend_free (tbm_bufmgr_backend backend); +int tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend); + +void *tbm_backend_get_bufmgr_priv (tbm_bo bo); +void *tbm_backend_get_bo_priv (tbm_bo bo); + +#endif /* _TBM_BUFMGR_BACKEND_H_ */ diff --git a/src/tbm_bufmgr_int.h b/src/tbm_bufmgr_int.h index e13535a..ca0e8f9 100755 --- a/src/tbm_bufmgr_int.h +++ b/src/tbm_bufmgr_int.h @@ -1,113 +1,191 @@ -/**************************************************************************
-
-libtbm
-
-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.
-
-**************************************************************************/
-
-#ifndef _TBM_BUFMGR_INT_H_
-#define _TBM_BUFMGR_INT_H_
-
-#include <tbm_bufmgr.h>
-#include <pthread.h>
-#include "tbm_bufmgr_backend.h"
-
-#define TBM_LOG(...) fprintf (stderr, __VA_ARGS__)
-
-typedef union _tbm_bo_cache_state tbm_bo_cache_state;
-
-struct list_head
-{
- struct list_head *prev;
- struct list_head *next;
-};
-
-union _tbm_bo_cache_state
-{
- unsigned int val;
- struct {
- unsigned int cntFlush:16; /*Flush all index for sync*/
- unsigned int isCacheable:1;
- unsigned int isCached:1;
- unsigned int isDirtied:2;
- } data;
-};
-
-/**
- * @brief tbm buffer object
- * buffer object of Tizen Buffer Manager
- */
-struct _tbm_bo
-{
- tbm_bufmgr bufmgr; /**< tbm buffer manager */
-
- int ref_cnt; /**< ref count of bo */
-
- int flags; /**< TBM_BO_FLAGS :bo memory type */
-
- unsigned int tgl_key; /**< global key for tizen global lock */
-
- /* for cache control */
- unsigned int map_cnt; /**< device map count */
- tbm_bo_cache_state cache_state; /**< cache state */
-
- int lock_cnt; /**< lock count of bo */
-
- struct list_head user_data_list; /**< list of the user_date in bo */
-
- void *priv; /**< bo private */
-
- struct list_head item_link; /**< link of bo */
-};
-
-/**
- * @brief tbm_bufmgr : structure for tizen buffer manager
- *
- */
-struct _tbm_bufmgr
-{
- int ref_count; /**< ref count of bufmgr */
-
- pthread_mutex_t lock; /**< mutex lock */
-
- int fd; /**< bufmgr fd */
-
- int lock_fd; /**< fd of tizen global lock */
-
- int lock_type; /**< lock_type of bufmgr */
-
- int use_map_cache; /**< flag to use the map_cahce */
-
- struct list_head bo_list; /**< list of bos belonging to bufmgr */
-
- void *module_data;
-
- tbm_bufmgr_backend backend; /**< bufmgr backend */
-
- struct list_head link; /**< link of bufmgr */
-};
-
-#endif /* _TBM_BUFMGR_INT_H_ */
+/************************************************************************** + +libtbm + +Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, 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_BUFMGR_INT_H_ +#define _TBM_BUFMGR_INT_H_ + +#include <unistd.h> +#include <limits.h> +#include <stdlib.h> +#include <stdio.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <dlfcn.h> +#include <dirent.h> +#include <string.h> +#include <errno.h> +#include <pthread.h> +#include <tbm_bufmgr.h> +#include <tbm_surface.h> +#include <tbm_bufmgr_backend.h> + +/* check condition */ +#define TBM_RETURN_IF_FAIL(cond) {\ + if (!(cond)) {\ + TBM_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + return;\ + }\ +} +#define TBM_RETURN_VAL_IF_FAIL(cond, val) {\ + if (!(cond)) {\ + TBM_LOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\ + return val;\ + }\ +} + +/* check flags */ +#define RETURN_CHECK_FLAG(cond) {\ + if ((cond)) {\ + return;\ + }\ +} +#define RETURN_VAL_CHECK_FLAG(cond, val) {\ + if ((cond)) {\ + return val;\ + }\ +} + + +/* check validation */ +#define TBM_BUFMGR_IS_VALID(mgr) (mgr) +#define TBM_BO_IS_VALID(bo) (bo && \ + TBM_BUFMGR_IS_VALID(bo->bufmgr) && \ + bo->item_link.next && \ + bo->item_link.next->prev == &bo->item_link) +#define TBM_SURFACE_IS_VALID(surf) (surf && \ + TBM_BUFMGR_IS_VALID(surf->bufmgr) && \ + surf->item_link.next && \ + surf->item_link.next->prev == &surf->item_link) + +#define TBM_ALL_CTRL_BACKEND_VALID(flags) \ + ((flags&TBM_CACHE_CTRL_BACKEND) &&\ + (flags&TBM_LOCK_CTRL_BACKEND)) +#define TBM_CACHE_CTRL_BACKEND_VALID(flags) \ + (flags&TBM_CACHE_CTRL_BACKEND) +#define TBM_LOCK_CTRL_BACKEND_VALID(flags) \ + (flags&TBM_LOCK_CTRL_BACKEND) + +#define TBM_LOG(...) fprintf (stderr, __VA_ARGS__) + +typedef union _tbm_bo_cache_state tbm_bo_cache_state; + +struct list_head +{ + struct list_head *prev; + struct list_head *next; +}; + +union _tbm_bo_cache_state +{ + unsigned int val; + struct { + unsigned int cntFlush:16; /*Flush all index for sync*/ + unsigned int isCacheable:1; + unsigned int isCached:1; + unsigned int isDirtied:2; + } data; +}; + +/** + * @brief tbm_bo : buffer object of Tizen Buffer Manager + */ +struct _tbm_bo +{ + tbm_bufmgr bufmgr; /* tbm buffer manager */ + + int ref_cnt; /* ref count of bo */ + + int flags; /* TBM_BO_FLAGS :bo memory type */ + + unsigned int tgl_key; /*global key for tizen global lock */ + + /* for cache control */ + unsigned int map_cnt; /* device map count */ + tbm_bo_cache_state cache_state; /*cache state */ + + int lock_cnt; /* lock count of bo */ + + struct list_head user_data_list; /* list of the user_date in bo */ + + void *priv; /* bo private */ + + struct list_head item_link; /* link of bo */ +}; + +/** + * @brief tbm_bufmgr : structure for tizen buffer manager + * + */ +struct _tbm_bufmgr +{ + pthread_mutex_t lock; /* mutex lock */ + + int ref_count; /*reference count */ + + int fd; /* bufmgr fd */ + + int fd_flag; /* flag set 1 when bufmgr fd open in tbm_bufmgr_init*/ + + int lock_fd; /* fd of tizen global lock */ + + int lock_type; /* lock_type of bufmgr */ + + int use_map_cache; /* flag to use the map_cahce */ + + struct list_head bo_list; /* list of bos belonging to bufmgr */ + + struct list_head surf_list; /* list of surfaces belonging to bufmgr */ + + void *module_data; + + tbm_bufmgr_backend backend; /* bufmgr backend */ +}; + +/** + * @brief tbm_surface : structure for tizen buffer surface + * + */ +struct _tbm_surface { + tbm_bufmgr bufmgr; /* tbm buffer manager */ + + tbm_surface_info_s info; /* tbm surface information */ + + int flags; + + int num_bos; /* the number of buffer objects */ + tbm_bo bos[4]; /* the array of buffer objects */ + + struct list_head item_link; /* link of surface */ +}; + +#endif /* _TBM_BUFMGR_INT_H_ */ diff --git a/src/tbm_surface.c b/src/tbm_surface.c new file mode 100755 index 0000000..19d6f2c --- /dev/null +++ b/src/tbm_surface.c @@ -0,0 +1,228 @@ +/************************************************************************** + +libtbm + +Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +#include "config.h" +#include "tbm_bufmgr.h" +#include "tbm_bufmgr_int.h" +#include "tbm_surface_internal.h" + +extern tbm_bufmgr gBufMgr; + +static int +_tbm_surface_get_info (struct _tbm_surface *surf, int opt, tbm_surface_info_s *info, int map) +{ + tbm_bo_handle bo_handles[4]; + int i; + + info->width = surf->info.width; + info->height = surf->info.height; + info->format = surf->info.format; + info->bpp = surf->info.bpp; + info->size = surf->info.size; + info->num_planes = surf->info.num_planes; + + if (surf->num_bos == 1) + { + if (map == 1) + { + bo_handles[0] = tbm_bo_map (surf->bos[0], TBM_DEVICE_CPU, opt); + if (bo_handles[0].ptr == NULL) + return 0; + } + else + { + bo_handles[0] = tbm_bo_get_handle (surf->bos[0], TBM_DEVICE_CPU); + if (bo_handles[0].ptr == NULL) + return 0; + } + + for (i = 0; i < surf->info.num_planes; i++) + { + info->planes[i].size = surf->info.planes[i].size; + info->planes[i].offset = surf->info.planes[i].offset; + info->planes[i].stride = surf->info.planes[i].stride; + info->planes[i].ptr = bo_handles[0].ptr + surf->info.planes[i].offset; + } + } + else + { + /* TODO: calculate the virtaul address when num_bos is over 1 */ + } + + return 1; +} + +int +tbm_surface_query_formats (uint32_t **formats, uint32_t *num) +{ + if (!gBufMgr) + { + gBufMgr = tbm_bufmgr_init (-1); + } + + if (!tbm_surface_internal_query_supported_formats (gBufMgr, formats, num)) + return TBM_SURFACE_ERROR_INVALID_OPERATION; + + return TBM_SURFACE_ERROR_NONE; +} + +tbm_surface_h +tbm_surface_create (int width, int height, tbm_format format) +{ + if (!(width > 0) || !(height > 0)) + { + //set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER); + return NULL; + } + + struct _tbm_surface *surf = NULL; + + if (!gBufMgr) + { + gBufMgr = tbm_bufmgr_init (-1); + } + + surf = tbm_surface_internal_create_with_flags (gBufMgr, width, height, format, TBM_BO_DEFAULT); + if (!surf) + { + //set_last_result (TBM_SURFACE_ERROR_INVALID_OPERATION); + return NULL; + } + + //set_last_result (TBM_SURFACE_ERROR_NONE); + return surf; +} + + +int +tbm_surface_destroy (tbm_surface_h surface) +{ + struct _tbm_surface *surf = NULL; + int i; + + if (!surface) + return TBM_SURFACE_ERROR_INVALID_PARAMETER; + + surf = (struct _tbm_surface *)surface; + + for (i = 0; i < surf->num_bos; i++) + { + tbm_bo_unref (surf->bos[i]); + surf->bos[i] = NULL; + } + + free (surf); + surf = NULL; + + return TBM_SURFACE_ERROR_NONE; +} + +int +tbm_surface_map (tbm_surface_h surface, int opt, tbm_surface_info_s *info) +{ + TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL (info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + + struct _tbm_surface *surf = (struct _tbm_surface *)surface; + int ret = 0; + + ret = _tbm_surface_get_info (surf, opt, info, 1); + if (ret == 0) + return TBM_SURFACE_ERROR_INVALID_OPERATION; + + return TBM_SURFACE_ERROR_NONE; +} + +int +tbm_surface_unmap (tbm_surface_h surface) +{ + TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + + struct _tbm_surface *surf = (struct _tbm_surface *)surface; + int i; + + for (i = 0; i < surf->num_bos; i++) + tbm_bo_unmap (surf->bos[i]); + + return TBM_SURFACE_ERROR_NONE; +} + +int +tbm_surface_get_info (tbm_surface_h surface, tbm_surface_info_s *info) +{ + TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + TBM_RETURN_VAL_IF_FAIL (info != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + + struct _tbm_surface *surf = (struct _tbm_surface *)surface; + int ret = 0; + + ret = _tbm_surface_get_info (surf, 0, info, 0); + if (ret == 0) + return TBM_SURFACE_ERROR_INVALID_OPERATION; + + return TBM_SURFACE_ERROR_NONE; +} + +int +tbm_surface_get_width (tbm_surface_h surface) +{ + TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + + struct _tbm_surface *surf = (struct _tbm_surface *)surface; + + return surf->info.width; +} + +int +tbm_surface_get_height (tbm_surface_h surface) +{ + TBM_RETURN_VAL_IF_FAIL (surface != NULL, TBM_SURFACE_ERROR_INVALID_PARAMETER); + + struct _tbm_surface *surf = (struct _tbm_surface *)surface; + + return surf->info.height; +} + +tbm_format +tbm_surface_get_format (tbm_surface_h surface) +{ + if (surface) + { + //set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER); + return 0; + } + + struct _tbm_surface *surf = (struct _tbm_surface *)surface; + + //set_last_result (TBM_SURFACE_ERROR_NONE); + return surf->info.format; +} + diff --git a/src/tbm_surface.h b/src/tbm_surface.h new file mode 100755 index 0000000..f51c6ec --- /dev/null +++ b/src/tbm_surface.h @@ -0,0 +1,708 @@ +/************************************************************************** + +libtbm + +Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Inpyo Kang <mantiger@samsung.com>, Dongyeon Kim <dy5.kim@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, 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_SURFACE_H_ +#define _TBM_SURFACE_H_ + +/** + * @addtogroup CAPI_UI_TBM_SURFACE_MODULE + * @{ + */ + +#include <tbm_type.h> +#include <tizen.h> + +/** + * \file tbm_surface.h + * \brief TBM Surface + */ + +/** + * @brief Enumeration of tbm_surface error type + * @since_tizen 2.3 + */ +typedef enum +{ + TBM_SURFACE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + TBM_SURFACE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + TBM_SURFACE_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid Operation */ +} tbm_surface_error_e; + +/** + * @brief Definition for the max number of tbm surface plane. + * @since_tizen 2.3 + */ +#define TBM_SURF_PLANE_MAX 4 + +/* option to map the tbm_surface */ +/** + * @brief Definition for the access option to read. + * @since_tizen 2.3 + */ +#define TBM_SURF_OPTION_READ (1 << 0) +/** + * @brief Definition for the access option to write. + * @since_tizen 2.3 + */ +#define TBM_SURF_OPTION_WRITE (1 << 1) + +/** + * @brief Definition for the tbm surface infomation struct. + * @since_tizen 2.3 + */ +typedef struct _tbm_surface_info +{ + uint32_t width; /**< tbm surface width */ + uint32_t height; /**< tbm surface height */ + tbm_format format; /**< tbm surface foramt*/ + uint32_t bpp; /**< tbm surface bbp */ + uint32_t size; /**< tbm surface size */ + + uint32_t num_planes; /**< the number of planes */ + + struct { + unsigned char *ptr; /**< plane pointer */ + uint32_t size; /**< plane size */ + uint32_t offset; /**< plane offset */ + uint32_t stride; /**< plane stride */ + + void *reserved1; + void *reserved2; + void *reserved3; + } planes[TBM_SURF_PLANE_MAX]; /**< array of planes */ + + void *reserved4; + void *reserved5; + void *reserved6; +} tbm_surface_info_s; + +#define __tbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \ + ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24)) + +/* color index */ +/** + * @brief Definition for the tbm surface foramt C8 ([7:0] C) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_C8 __tbm_fourcc_code('C', '8', ' ', ' ') + +/* 8 bpp RGB */ +/** + * @brief Definition for the tbm surface foramt RGB322 ([7:0] R:G:B 3:3:2) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGB332 __tbm_fourcc_code('R', 'G', 'B', '8') +/** + * @brief Definition for the tbm surface foramt RGB233 ([7:0] B:G:R 2:3:3) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGR233 __tbm_fourcc_code('B', 'G', 'R', '8') + +/* 16 bpp RGB */ +/** + * @brief Definition for the tbm surface foramt XRGB4444 ([15:0] x:R:G:B 4:4:4:4 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_XRGB4444 __tbm_fourcc_code('X', 'R', '1', '2') +/** + * @brief Definition for the tbm surface foramt XBRG4444 ([15:0] x:B:G:R 4:4:4:4 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_XBGR4444 __tbm_fourcc_code('X', 'B', '1', '2') +/** + * @brief Definition for the tbm surface foramt RGBX4444 ([15:0] R:G:B:x 4:4:4:4 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGBX4444 __tbm_fourcc_code('R', 'X', '1', '2') +/** + * @brief Definition for the tbm surface foramt BGRX4444 ([15:0] B:G:R:x 4:4:4:4 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGRX4444 __tbm_fourcc_code('B', 'X', '1', '2') + +/** + * @brief Definition for the tbm surface foramt ARGB4444 ([15:0] A:R:G:B 4:4:4:4 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_ARGB4444 __tbm_fourcc_code('A', 'R', '1', '2') +/** + * @brief Definition for the tbm surface foramt ABGR4444 ([15:0] A:B:G:R 4:4:4:4 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_ABGR4444 __tbm_fourcc_code('A', 'B', '1', '2') +/** + * @brief Definition for the tbm surface foramt RGBA4444 ([15:0] R:G:B:A 4:4:4:4 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGBA4444 __tbm_fourcc_code('R', 'A', '1', '2') +/** + * @brief Definition for the tbm surface foramt BGRA4444 ([15:0] B:G:R:A 4:4:4:4 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGRA4444 __tbm_fourcc_code('B', 'A', '1', '2') + +/** + * @brief Definition for the tbm surface foramt XRGB1555 ([15:0] x:R:G:B 1:5:5:5 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_XRGB1555 __tbm_fourcc_code('X', 'R', '1', '5') +/** + * @brief Definition for the tbm surface foramt XBGR1555 ([15:0] x:B:G:R 1:5:5:5 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_XBGR1555 __tbm_fourcc_code('X', 'B', '1', '5') +/** + * @brief Definition for the tbm surface foramt RGBX5551 ([15:0] R:G:B:x 5:5:5:1 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGBX5551 __tbm_fourcc_code('R', 'X', '1', '5') +/** + * @brief Definition for the tbm surface foramt BGRX5551 ([15:0] B:G:R:x 5:5:5:1 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGRX5551 __tbm_fourcc_code('B', 'X', '1', '5') + +/** + * @brief Definition for the tbm surface foramt ARGB1555 ([15:0] A:R:G:B 1:5:5:5 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_ARGB1555 __tbm_fourcc_code('A', 'R', '1', '5') +/** + * @brief Definition for the tbm surface foramt ABGR1555 ([15:0] A:B:G:R 1:5:5:5 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_ABGR1555 __tbm_fourcc_code('A', 'B', '1', '5') +/** + * @brief Definition for the tbm surface foramt RGBA5551 ([15:0] R:G:B:A 5:5:5:1 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGBA5551 __tbm_fourcc_code('R', 'A', '1', '5') +/** + * @brief Definition for the tbm surface foramt BGRA5551 ([15:0] B:G:R:A 5:5:5:1 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGRA5551 __tbm_fourcc_code('B', 'A', '1', '5') + +/** + * @brief Definition for the tbm surface foramt RGB565 ([15:0] R:G:B 5:6:5 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGB565 __tbm_fourcc_code('R', 'G', '1', '6') +/** + * @brief Definition for the tbm surface foramt BGR565 ([15:0] B:G:R 5:6:5 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGR565 __tbm_fourcc_code('B', 'G', '1', '6') + +/* 24 bpp RGB */ +/** + * @brief Definition for the tbm surface foramt RGB888 ([23:0] R:G:B little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGB888 __tbm_fourcc_code('R', 'G', '2', '4') +/** + * @brief Definition for the tbm surface foramt BGR888 ([23:0] B:G:R little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGR888 __tbm_fourcc_code('B', 'G', '2', '4') + +/* 32 bpp RGB */ +/** + * @brief Definition for the tbm surface foramt XRGB8888 ([31:0] x:R:G:B 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_XRGB8888 __tbm_fourcc_code('X', 'R', '2', '4') +/** + * @brief Definition for the tbm surface foramt XBGR8888 ([31:0] x:B:G:R 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_XBGR8888 __tbm_fourcc_code('X', 'B', '2', '4') +/** + * @brief Definition for the tbm surface foramt RGBX8888 ([31:0] R:G:B:x 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGBX8888 __tbm_fourcc_code('R', 'X', '2', '4') +/** + * @brief Definition for the tbm surface foramt BGRX8888 ([31:0] B:G:R:x 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGRX8888 __tbm_fourcc_code('B', 'X', '2', '4') + +/** + * @brief Definition for the tbm surface foramt ARGB8888 ([31:0] A:R:G:B 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_ARGB8888 __tbm_fourcc_code('A', 'R', '2', '4') +/** + * @brief Definition for the tbm surface foramt ABGR8888 ([31:0] [31:0] A:B:G:R 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_ABGR8888 __tbm_fourcc_code('A', 'B', '2', '4') +/** + * @brief Definition for the tbm surface foramt RGBA8888 ([31:0] R:G:B:A 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGBA8888 __tbm_fourcc_code('R', 'A', '2', '4') +/** + * @brief Definition for the tbm surface foramt BGRA8888 ([31:0] B:G:R:A 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGRA8888 __tbm_fourcc_code('B', 'A', '2', '4') + +/** + * @brief Definition for the tbm surface foramt XRGB2101010 ([31:0] x:R:G:B 2:10:10:10 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_XRGB2101010 __tbm_fourcc_code('X', 'R', '3', '0') +/** + * @brief Definition for the tbm surface foramt XBGR2101010 ([31:0] x:B:G:R 2:10:10:10 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_XBGR2101010 __tbm_fourcc_code('X', 'B', '3', '0') +/** + * @brief Definition for the tbm surface foramt RGBX1010102 ([31:0] R:G:B:x 10:10:10:2 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGBX1010102 __tbm_fourcc_code('R', 'X', '3', '0') +/** + * @brief Definition for the tbm surface foramt BGRX1010102 ([31:0] B:G:R:x 10:10:10:2 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGRX1010102 __tbm_fourcc_code('B', 'X', '3', '0') + +/** + * @brief Definition for the tbm surface foramt ARGB2101010 ([31:0] A:R:G:B 2:10:10:10 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_ARGB2101010 __tbm_fourcc_code('A', 'R', '3', '0') +/** + * @brief Definition for the tbm surface foramt ABGR2101010 ([31:0] A:B:G:R 2:10:10:10 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_ABGR2101010 __tbm_fourcc_code('A', 'B', '3', '0') +/** + * @brief Definition for the tbm surface foramt RGBA1010102 ([31:0] R:G:B:A 10:10:10:2 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_RGBA1010102 __tbm_fourcc_code('R', 'A', '3', '0') +/** + * @brief Definition for the tbm surface foramt BGRA1010102 ([31:0] B:G:R:A 10:10:10:2 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_BGRA1010102 __tbm_fourcc_code('B', 'A', '3', '0') /* */ + +/* packed YCbCr */ +/** + * @brief Definition for the tbm surface foramt YUYV ([31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YUYV __tbm_fourcc_code('Y', 'U', 'Y', 'V') +/** + * @brief Definition for the tbm surface foramt YVYU ([31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YVYU __tbm_fourcc_code('Y', 'V', 'Y', 'U') /* */ +/** + * @brief Definition for the tbm surface foramt UYVY ([31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian ) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_UYVY __tbm_fourcc_code('U', 'Y', 'V', 'Y') +/** + * @brief Definition for the tbm surface foramt VYUY ([31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_VYUY __tbm_fourcc_code('V', 'Y', 'U', 'Y') + +/** + * @brief Definition for the tbm surface foramt AYUV ([31:0] A:Y:Cb:Cr 8:8:8:8 little endian) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_AYUV __tbm_fourcc_code('A', 'Y', 'U', 'V') + +/* + * 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 + */ +/** + * @brief Definition for the tbm surface foramt NV12 (2x2 subsampled Cr:Cb plane) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_NV12 __tbm_fourcc_code('N', 'V', '1', '2') +/** + * @brief Definition for the tbm surface foramt NV21 (2x2 subsampled Cb:Cr plane) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_NV21 __tbm_fourcc_code('N', 'V', '2', '1') /* */ +/** + * @brief Definition for the tbm surface foramt NV16 (2x1 subsampled Cr:Cb plane) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_NV16 __tbm_fourcc_code('N', 'V', '1', '6') +/** + * @brief Definition for the tbm surface foramt NV61 (2x1 subsampled Cb:Cr plane) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_NV61 __tbm_fourcc_code('N', 'V', '6', '1') + +/* + * 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 + */ +/** + * @brief Definition for the tbm surface foramt YUV410 (4x4 subsampled Cb (1) and Cr (2) planes) + */ +#define TBM_FORMAT_YUV410 __tbm_fourcc_code('Y', 'U', 'V', '9') +/** + * @brief Definition for the tbm surface foramt YVU410 (4x4 subsampled Cr (1) and Cb (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YVU410 __tbm_fourcc_code('Y', 'V', 'U', '9') +/** + * @brief Definition for the tbm surface foramt YUV411 (4x1 subsampled Cb (1) and Cr (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YUV411 __tbm_fourcc_code('Y', 'U', '1', '1') +/** + * @brief Definition for the tbm surface foramt YVU411 (4x1 subsampled Cr (1) and Cb (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YVU411 __tbm_fourcc_code('Y', 'V', '1', '1') +/** + * @brief Definition for the tbm surface foramt YUV420 (2x2 subsampled Cb (1) and Cr (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YUV420 __tbm_fourcc_code('Y', 'U', '1', '2') +/** + * @brief Definition for the tbm surface foramt YVU420 (2x2 subsampled Cr (1) and Cb (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YVU420 __tbm_fourcc_code('Y', 'V', '1', '2') +/** + * @brief Definition for the tbm surface foramt YUV422 (2x1 subsampled Cb (1) and Cr (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YUV422 __tbm_fourcc_code('Y', 'U', '1', '6') +/** + * @brief Definition for the tbm surface foramt YVU422 (2x1 subsampled Cr (1) and Cb (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YVU422 __tbm_fourcc_code('Y', 'V', '1', '6') +/** + * @brief Definition for the tbm surface foramt YUV444 (non-subsampled Cb (1) and Cr (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YUV444 __tbm_fourcc_code('Y', 'U', '2', '4') +/** + * @brief Definition for the tbm surface foramt YVU444 (non-subsampled Cr (1) and Cb (2) planes) + * @since_tizen 2.3 + */ +#define TBM_FORMAT_YVU444 __tbm_fourcc_code('Y', 'V', '2', '4') + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Queries surface format list and number of format supported by the system. + * @since_tizen 2.3 + * @remarks The formats must be released using free(). + * @param[out] **formats : format array which the system can support. This pointer has to be freed by user. + * @param[out] num : the number of formats. + * @return #TBM_SURFACE_ERROR_NONE if this function succeeds, otherwise error status value + * @retval #TBM_SURFACE_ERROR_NONE + * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION + * @par Example + @code + #include <tbm_surface.h> + + uint32_t *formats; + uint32_t format_num; + int ret, i; + + if (tbm_surface_query_formats (&formats, &format_num)) + { + for( i = 0 ; i < format_num ; i++) + { + if (formats[i] == TBM_FORMAT_RGB332) + { + + .... + + free (formats); + @endcode + */ +int tbm_surface_query_formats (uint32_t **formats, uint32_t *num); + +/** + * @brief Creates the tbm_surface. + * @details This function create the tbm_surface with width, height, format. + * @since_tizen 2.3 + * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. + * @param[in] width : the width of surface + * @param[in] height : the height of surface + * @param[in] format : the format of surface + * @return a tbm_surface_h if this function succeeds, otherwise NULL + * @retval #tbm_surface_h + * @exception #TBM_SURFACE_ERROR_NONE Success + * @exception #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #TBM_SURFACE_ERROR_INVALID_OPERATION Invalid operation + * @see tbm_surface_destroy() + * @par Example + @code + #include <tbm_surface.h> + + tbm_surface_h surface; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +tbm_surface_h tbm_surface_create (int width, int height, tbm_format format); + +/** + * @brief Destroies the tbm_surface. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @return #TBM_SURFACE_ERROR_NONE if this function succeeds, otherwise error status value + * @retval #TBM_SURFACE_ERROR_NONE + * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER + * @see tbm_surface_create() + * @par Example + @code + #include <tbm_surface.h> + + tbm_surface_h surface; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_destroy (tbm_surface_h surface); + +/** + * @brief Maps the tbm_surface according to the access option. + * @details After mapping tbm_surface, the information of tbm_surface is assigned in #tbm_surface_info_s struct.\n + * The information of tbm_surface has width, height, format, bpp, size, number of planes and information of planes.\n + * The information of planes has stride, offset, size and pointer of plane\n + * #TBM_SURF_OPTION_READ indecates access option to read.\n + * #TBM_SURF_OPTION_WRITE indecates access option to write. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @param[in] opt : the option to access the tbm_surface + * @param[out] *info : the infomation of the tbm_surface + * @return #TBM_SURFACE_ERROR_NONE if this function succeeds, otherwise error status value + * @retval #TBM_SURFACE_ERROR_NONE + * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER + * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION + * @see tbm_surface_unmap(); + * @par Example + @code + #include <tbm_surface.h> + + tbm_surface_h surface; + tbm_surface_info_s info; + int ret; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); + ret = tbm_surface_map (surface, TBM_SURF_OPTION_WRITE|TBM_SURF_OPTION_READ, &info); + + ... + + tbm_surface_unmap (surface); + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_map (tbm_surface_h surface, int opt, tbm_surface_info_s *info); + +/** + * @brief Unmaps the tbm_surface. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @return #TBM_SURFACE_ERROR_NONE if this function succeeds, otherwise error status value + * @retval #TBM_SURFACE_ERROR_NONE + * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER + * @see tbm_surface_map() + * @par Example + @code + #include <tbm_surface.h> + + tbm_surface_h surface; + tbm_surface_info_s info; + int ret; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); + ret = tbm_surface_map (surface, TBM_SURF_OPTION_WRITE|TBM_SURF_OPTION_READ, &info); + + ... + + tbm_surface_unmap (surface); + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_unmap (tbm_surface_h surface); + +/** + * @brief Gets the information of the tbm_surface. + * @details The information of tbm_surface is assigned in #tbm_surface_info_s struct.\n + * The information of tbm_surface has width, height, format, bpp, size, number of planes and information of planes.\n + * The information of planes has stride, offset, size and pointer of plane. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @param[out] *info : the infomation of the tbm_surface + * @return #TBM_SURFACE_ERROR_NONE if this function succeeds, otherwise error status value + * @retval #TBM_SURFACE_ERROR_NONE + * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER + * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION + * @see tbm_surface_map() + * @par Example + @code + #include <tbm_surface.h> + + tbm_surface_h surface; + tbm_surface_info_s info; + int ret; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); + ret = tbm_surface_get_info (surface, &info); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_get_info (tbm_surface_h surface, tbm_surface_info_s *info); + +/** + * @brief Gets the width of the tbm_surface. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @return the width of the tbm_surface if this function succeeds, otherwise error status value + * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER + * @par Example + @code + #include <tbm_surface.h> + + tbm_surface_h surface; + int width; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); + + ... + + width = tbm_surface_get_width (surface); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_get_width (tbm_surface_h surface); + +/** + * @brief Gets the height of the tbm_surface. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @return the height of the tbm_surface if this function succeeds, otherwise error status value + * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER + * @par Example + @code + #include <tbm_surface.h> + + tbm_surface_h surface; + int height; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); + + ... + + height = tbm_surface_get_height (surface); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_get_height (tbm_surface_h surface); + +/** + * @brief Gets the format of the tbm_surface. + * @since_tizen 2.3 + * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. + * @param[in] surface : the tbm_surface_h + * @return the format of the tbm_surface if this function succeeds, otherwise 0 + * @retval #tbm_format + * @exception #TBM_SURFACE_ERROR_NONE Success + * @exception #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter + * @par Example + @code + #include <tbm_surface.h> + + tbm_surface_s surface; + tbm_format format; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_RGB332); + + ... + + format = tbm_surface_get_format (surface); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +tbm_format tbm_surface_get_format (tbm_surface_h surface); + +#ifdef __cplusplus +} +#endif + +/** +* @} +*/ + +#endif /* _TBM_SURFACE_H_ */ + diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c new file mode 100755 index 0000000..299be2c --- /dev/null +++ b/src/tbm_surface_internal.c @@ -0,0 +1,357 @@ +/************************************************************************** + +libtbm + +Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sub license, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice (including the +next paragraph) shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +#include "config.h" +#include "tbm_bufmgr.h" +#include "tbm_bufmgr_int.h" +#include "tbm_surface_internal.h" + +static int _tbm_surface_internal_get_num_planes (tbm_format format) +{ + int num_planes = 0; + + switch (format) + { + case TBM_FORMAT_C8: + case TBM_FORMAT_RGB332: + case TBM_FORMAT_BGR233: + 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: + case TBM_FORMAT_BGR565: + case TBM_FORMAT_RGB888: + case TBM_FORMAT_BGR888: + 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: + case TBM_FORMAT_XRGB2101010: + case TBM_FORMAT_XBGR2101010: + case TBM_FORMAT_RGBX1010102: + case TBM_FORMAT_BGRX1010102: + case TBM_FORMAT_ARGB2101010: + case TBM_FORMAT_ABGR2101010: + case TBM_FORMAT_RGBA1010102: + case TBM_FORMAT_BGRA1010102: + case TBM_FORMAT_YUYV: + case TBM_FORMAT_YVYU: + case TBM_FORMAT_UYVY: + case TBM_FORMAT_VYUY: + case TBM_FORMAT_AYUV: + num_planes = 1; + break; + case TBM_FORMAT_NV12: + case TBM_FORMAT_NV21: + case TBM_FORMAT_NV16: + case TBM_FORMAT_NV61: + num_planes = 2; + break; + 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_planes = 3; + break; + + default : + break; + } + + return num_planes; +} + + +static int _tbm_surface_internal_get_bpp (tbm_format format) +{ + int bpp = 0; + + switch (format) + { + case TBM_FORMAT_C8: + case TBM_FORMAT_RGB332: + case TBM_FORMAT_BGR233: + bpp = 8; + break; + 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: + case TBM_FORMAT_BGR565: + bpp = 16; + break; + case TBM_FORMAT_RGB888: + case TBM_FORMAT_BGR888: + bpp = 24; + break; + 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: + case TBM_FORMAT_XRGB2101010: + case TBM_FORMAT_XBGR2101010: + case TBM_FORMAT_RGBX1010102: + case TBM_FORMAT_BGRX1010102: + case TBM_FORMAT_ARGB2101010: + case TBM_FORMAT_ABGR2101010: + case TBM_FORMAT_RGBA1010102: + case TBM_FORMAT_BGRA1010102: + case TBM_FORMAT_YUYV: + case TBM_FORMAT_YVYU: + case TBM_FORMAT_UYVY: + case TBM_FORMAT_VYUY: + case TBM_FORMAT_AYUV: + bpp = 32; + break; + case TBM_FORMAT_NV12: + case TBM_FORMAT_NV21: + bpp = 12; + break; + case TBM_FORMAT_NV16: + case TBM_FORMAT_NV61: + bpp = 16; + break; + case TBM_FORMAT_YUV410: + case TBM_FORMAT_YVU410: + bpp = 9; + break; + case TBM_FORMAT_YUV411: + case TBM_FORMAT_YVU411: + case TBM_FORMAT_YUV420: + case TBM_FORMAT_YVU420: + bpp = 12; + break; + case TBM_FORMAT_YUV422: + case TBM_FORMAT_YVU422: + bpp = 16; + break; + case TBM_FORMAT_YUV444: + case TBM_FORMAT_YVU444: + bpp = 24; + break; + default : + break; + } + + return bpp; +} + + +int +tbm_surface_internal_query_supported_formats (tbm_bufmgr bufmgr, uint32_t **formats, uint32_t *num) +{ + TBM_RETURN_VAL_IF_FAIL (bufmgr, 0); + + struct _tbm_bufmgr *mgr = (struct _tbm_bufmgr*)bufmgr; + int ret = 0; + + pthread_mutex_lock (&mgr->lock); + + ret = mgr->backend->surface_supported_format (formats, num); + + pthread_mutex_unlock (&mgr->lock); + + return ret; +} + +tbm_surface_h +tbm_surface_internal_create_with_flags (tbm_bufmgr bufmgr, int width, int height, int format, int flags) +{ + TBM_RETURN_VAL_IF_FAIL (bufmgr, NULL); + TBM_RETURN_VAL_IF_FAIL (width > 0, NULL); + TBM_RETURN_VAL_IF_FAIL (height > 0, NULL); + + struct _tbm_bufmgr *mgr = (struct _tbm_bufmgr*)bufmgr; + + TBM_RETURN_VAL_IF_FAIL (TBM_BUFMGR_IS_VALID(mgr), NULL); + + struct _tbm_surface *surf = NULL; + uint32_t size = 0; + uint32_t offset = 0; + uint32_t stride = 0; + int i; + + surf = calloc (1, sizeof(struct _tbm_surface)); + if (!surf) + return NULL; + + surf->bufmgr = bufmgr; + surf->info.width = width; + surf->info.height = height; + surf->info.format = format; + surf->info.bpp = _tbm_surface_internal_get_bpp (format); + surf->info.size = tbm_surface_internal_get_size (surf); + surf->info.num_planes = _tbm_surface_internal_get_num_planes(format); + + /* get size, stride and offset */ + for (i = 0; i < surf->info.num_planes; i++) + { + tbm_surface_internal_get_plane_data (surf, i, &size, &offset, &stride); + surf->info.planes[i].size = size; + surf->info.planes[i].offset = offset; + surf->info.planes[i].stride = stride; + } + + surf->flags = flags; + + /* create only one bo */ + surf->num_bos = 1; + surf->bos[0] = tbm_bo_alloc (mgr, surf->info.size, flags); + if (!surf->bos[0]) + { + free (surf); + surf = NULL; + } + +// LIST_ADD (&surf->item_link, &mgr->surf_list); + + return surf; +} + +tbm_surface_h +tbm_surface_internal_create_with_bos (tbm_bufmgr bufmgr, int width, int height, int format, tbm_bo *bos, int num) +{ + tbm_surface_h surf = NULL; + + return surf; +} + + +int +tbm_surface_internal_get_num_bos (tbm_surface_h surface) +{ + TBM_RETURN_VAL_IF_FAIL (surface, 0); + + struct _tbm_surface *surf = (struct _tbm_surface *) surface; + + return surf->num_bos; +} + +tbm_bo +tbm_surface_internal_get_bo (tbm_surface_h surface, int bo_idx) +{ + TBM_RETURN_VAL_IF_FAIL (surface, NULL); + TBM_RETURN_VAL_IF_FAIL (bo_idx > -1, NULL); + + struct _tbm_surface *surf = (struct _tbm_surface *) surface; + + return surf->bos[bo_idx]; +} + +int +tbm_surface_internal_get_size (tbm_surface_h surface) +{ + TBM_RETURN_VAL_IF_FAIL (surface, 0); + + struct _tbm_surface *surf = (struct _tbm_surface *) surface; + struct _tbm_bufmgr *mgr = surf->bufmgr; + int size = 0; + + TBM_RETURN_VAL_IF_FAIL (surf->info.width > 0, 0); + TBM_RETURN_VAL_IF_FAIL (surf->info.height > 0, 0); + TBM_RETURN_VAL_IF_FAIL (surf->info.format > 0, 0); + + pthread_mutex_lock (&mgr->lock); + + size = mgr->backend->surface_get_size (surf, surf->info.width, surf->info.height, surf->info.format); + + pthread_mutex_unlock (&mgr->lock); + + return size; +} + +int +tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch) +{ + TBM_RETURN_VAL_IF_FAIL (surface, 0); + TBM_RETURN_VAL_IF_FAIL (plane_idx > -1, 0); + + struct _tbm_surface *surf = (struct _tbm_surface *) surface; + struct _tbm_bufmgr *mgr = surf->bufmgr; + int ret = 0; + + TBM_RETURN_VAL_IF_FAIL (surf->info.width > 0, 0); + TBM_RETURN_VAL_IF_FAIL (surf->info.height > 0, 0); + TBM_RETURN_VAL_IF_FAIL (surf->info.format > 0, 0); + + pthread_mutex_lock (&mgr->lock); + + ret = mgr->backend->surface_get_plane_data (surf, surf->info.width, surf->info.height, surf->info.format, plane_idx, size, offset, pitch); + if (!ret) + return 0; + + pthread_mutex_unlock (&mgr->lock); + + return 1; +} + + + diff --git a/src/tbm_surface_internal.h b/src/tbm_surface_internal.h new file mode 100755 index 0000000..5df478a --- /dev/null +++ b/src/tbm_surface_internal.h @@ -0,0 +1,262 @@ +/************************************************************************** + +libtbm + +Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Inpyo Kang <mantiger@samsung.com>, Dongyeon Kim <dy5.kim@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, 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_SURFACE_INTERNAL_H_ +#define _TBM_SURFACE_INTERNAL_H_ + +/** + * @internal + * @addtogroup CAPI_UI_TBM_SURFACE_MODULE + * @{ + */ + +#include <tbm_bufmgr.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Queries formats which the system can support. + * @since_tizen 2.3 + * @remarks The formats must be released using free(). + * @param[in] bufmgr : the buffer manager + * @param[out] *formats : format array which the system can support. This pointer has to be freed by user. + * @param[out] num : the number of formats. + * @return a tbm_surface_h if this function succeeds, otherwise NULL + * @par Example + @code + #include <tbm_surface.h> + #include <tbm_surface_internal.h> + + tbm_bufmgr bufmgr; + uint32_t *formats; + uint32_t format_num; + + bufmgr = tbm_bufmgr_create (-1); + ret = tbm_surface_internal_query_surpported_foramts (bufmgr, &formats, &format_num); + + ... + + free (foramts); + tbm_surface_bufmgr_deinit (bufmgr); + @endcode + */ +int tbm_surface_internal_query_supported_formats (tbm_bufmgr bufmgr, uint32_t **formats, uint32_t *num); + +/** + * @brief Creates the tbm_surface with memory type. + * @since_tizen 2.3 + * @details + * #TBM_BO_DEFAULT is default memory: it depends on the backend\n + * #TBM_BO_SCANOUT is scanout memory\n + * #TBM_BO_NONCACHABLE is non-cachable memory\n + * #TBM_BO_WC is write-combine memory\n + * #TBM_BO_VENDOR vendor specific memory: it depends on the tbm backend\n + * @param[in] bufmgr : the buffer manager + * @param[in] width : the width of surface + * @param[in] height : the height of surface + * @param[in] format : the format of surface + * @param[in] flags : the flags of memory type + * @return a tbm_surface_h if this function succeeds, otherwise NULL + * @retval #tbm_surface_h + * @par Example + @code + #include <tbm_surface.h> + #include <tbm_surface_internal.h> + + int bufmgr_fd + tbm_bufmgr bufmgr; + tbm_surface_h surface; + uint32_t *format; + uint32_t format_num; + + bufmgr = tbm_bufmgr_create (bufmgr_fd); + surface = tbm_surface_internal_create_with_flags (bufmgr, 128, 128, TBM_FORMAT_YUV420, TBM_BO_DEFAULT); + + ... + + tbm_surface_destroy (surface); + tbm_surface_bufmgr_deinit (bufmgr); + @endcode + */ +tbm_surface_h tbm_surface_internal_create_with_flags (tbm_bufmgr bufmgr, int width, int height, int format, int flags); + +/** + * @brief Creates the tbm_surface with buffer objects. + * @since_tizen 2.3 + * @param[in] bufmgr : the buffer manager + * @param[in] width : the width of surface + * @param[in] height : the height of surface + * @param[in] format : the format of surface + * @param[in] *bos : the array pointer of buffer objects + * @param[in] num : the number of buffer objects + * @return a tbm_surface_h if this function succeeds, otherwise NULL + * @retval #tbm_surface_h + * @par Example + @code + #include <tbm_bufmgr.h> + #include <tbm_surface.h> + #include <tbm_surface_internal.h> + + int bufmgr_fd + tbm_bufmgr bufmgr; + tbm_surface_h surface; + uint32_t *format; + uint32_t format_num; + tbm_bo bo[2]; + + bufmgr = tbm_bufmgr_init (bufmgr_fd); + bo[1] = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + bo[2] = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT); + surface = tbm_surface_internal_create_with_bos (bufmgr, 128, 128, TBM_FORMAT_YUV420, TBM_BO_DEFAULT); + + ... + + tbm_surface_destroy (surface); + tbm_surface_bufmgr_deinit (bufmgr); + @endcode + */ +tbm_surface_h tbm_surface_internal_create_with_bos (tbm_bufmgr bufmgr, int width, int height, int format, tbm_bo *bos, int num); + +/** + * @brief Gets the number of buffer objects associated with the tbm_surface. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @return the number of buffer objects associated with the tbm_surface_h, otherwise -1. + * @par Example + @code + #include <tbm_surface.h> + #include <tbm_surface_internal.h> + + tbm_surface_h surface; + int num_bos; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420); + num_bos = tbm_surface_internal_get_num_bos (surface); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_internal_get_num_bos (tbm_surface_h surface); + +/** + * @brief Gets the buffor object by the bo_index. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @param[in] bo_idx : the bo index in the the tbm_surface + * @return the buffer object, otherwise NULL. + * @retval #tbm_bo + * @par Example + @code + #include <tbm_surface.h> + #include <tbm_surface_internal.h> + + tbm_surface_h surface; + int num_bos; + tbm_bo bo; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420); + num_bos = tbm_surface_internal_get_num_bos (surface); + + for (i=0 ; i < num_bos ; i++) + { + bo = tbm_surface_internal_get_bo (surface, i); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +tbm_bo tbm_surface_internal_get_bo (tbm_surface_h surface, int bo_idx); + +/** + * @brief Gets the size of the surface. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @return the size of tbm_surface, otherwise -1. + * @par Example + @code + #include <tbm_surface.h> + #include <tbm_surface_internal.h> + + tbm_surface_h surface; + int size; + + surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420); + size = tbm_surface_internal_get_size (surface); + + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_internal_get_size (tbm_surface_h surface); + +/** + * @brief Gets size, offset and pitch data of plane by the plane_index. + * @since_tizen 2.3 + * @param[in] surface : the tbm_surface_h + * @param[in] plane_idx : the bo index in the the tbm_surface + * @param[out] size : the size of plan in tbm_surface + * @param[out] offset : the offset of plan in tbm_surface + * @param[out] pitch : the pitch of plan in tbm_surface + * @return 1 if this function succeeds, otherwise 0. + * @par Example + @code + #include <tbm_surface.h> + #include <tbm_surface_internal.h> + + tbm_surface_h surface; + uint32_t size, offset, pitch; + int ret; + + surface = tbm_surfacel_create (128, 128, TBM_FORMAT_YUV420); + ret = tbm_surface_internal_get_plane_data (surface, 1, &size, &offset, &pitch); + + ... + + tbm_surface_destroy (surface); + @endcode + */ +int tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch); + +#ifdef __cplusplus +} +#endif + +/** +* @} +*/ + +#endif /* _TBM_SURFACE_INTERNAL_H_ */ + diff --git a/src/tbm_type.h b/src/tbm_type.h new file mode 100755 index 0000000..16aa6fc --- /dev/null +++ b/src/tbm_type.h @@ -0,0 +1,57 @@ +/************************************************************************** + +libtbm + +Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com> +Inpyo Kang <mantiger@samsung.com>, Dongyeon Kim <dy5.kim@samsung.com> +Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com> + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, 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_TYPE_H_ +#define _TBM_TYPE_H_ + +/** + * @addtogroup CAPI_UI_TBM_SURFACE_MODULE + * @{ + */ + +#include <stdint.h> + +/** + * @brief Definition for the tizen buffer surface + */ +typedef struct _tbm_surface * tbm_surface_h; +/** + * @brief Definition for the tizen buffer surface foramt + */ +typedef uint32_t tbm_format; + +/** +* @} +*/ + +#endif /* _TBM_TYPE_H_ */ + |