PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs)
PKG_CHECK_MODULES(LIBDRM, libdrm)
+PKG_CHECK_MODULES(LIBDRI2, libdri2)
+PKG_CHECK_MODULES(DLOG, dlog)
+PKG_CHECK_MODULES(X11, x11)
+PKG_CHECK_MODULES(CAPI, [capi-base-common >= 0.1.1], [capi_0_1_1=yes], [capi_0_1_1=no])
+if test x"$capi_0_1_1" = xyes; then
+ AC_DEFINE(HAVE_CAPI_0_1_1,1,[The version of capi-base-common is over 0.1.1])
+fi
-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 $DLOG_LIBS $X11_LIBS $CAPI_LIBS"
AC_SUBST(LIBTBM_CFLAGS)
AC_SUBST(LIBTBM_LIBS)
--- /dev/null
+
+#ifndef __TIZEN_UI_TBM_SURFACE_DOC_H__
+#define __TIZEN_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_FRAMEWORK
+ *
+ * @section CAPI_UI_TBM_SURFACE_MODULE_HEADER Required Header
+ * \#include <tbm_surface.h>
+ * @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 /* __TIZEN_UI_TBM_SURFACE_DOC_H__ */
+
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: capi-base-common
+Libs: -L${libdir} -ltbm
+Cflags: -I${includedir}
+
Name: libtbm
-Version: 1.0.9
-Release: 1
-VCS: framework/uifw/libtbm#REBASE-31-gdb11679e1cc2e6d3c56bbfe621fc0820322cc2dc
+Version: 1.1.1
+Release: 4
License: MIT
-Summary: the library for Tizen Buffer Manager
+Summary: The library for Tizen Buffer Manager
Group: System/Libraries
Source0: %{name}-%{version}.tar.gz
BuildRequires: pkgconfig(pthread-stubs)
BuildRequires: pkgconfig(libdrm)
+BuildRequires: pkgconfig(x11)
+BuildRequires: pkgconfig(libdri2)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(dlog)
%description
Description: %{summary}
%package devel
-Summary: the library for Tizen Buffer Manager
+Summary: Tizen Buffer Manager Library - Development
Group: Development/Libraries
-Requires: libdrm2
+Requires: libtbm = %{version}
+Requires: pkgconfig(capi-base-common)
%description devel
-the library for Tizen Buffer Manager
+The library for Tizen Buffer Manager.
+
+Development Files.
%prep
%setup -q
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
+
%files
%manifest libtbm.manifest
%defattr(-,root,root,-)
%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
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
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
#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
#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
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)
int ret = 0;
if (!bo)
- return 0;
+ return ret;
bufmgr = bo->bufmgr;
if (ret)
bo->lock_cnt++;
}
+ else
+ ret = 1;
}
else if (bufmgr->lock_type == LOCK_TRY_ALWAYS)
{
bo->lock_cnt++;
}
else
- TBM_LOG ("[libtbm:%d] "
+ TBM_DLOG ("[libtbm:%d] "
"error %s:%d bo:%p lock_type is wrong.\n",
getpid(), __FUNCTION__, __LINE__, bo);
DBG_LOCK ("[libtbm:%d] >> LOCK bo:%p(%d, %d->%d)\n", getpid(),
bo, bo->tgl_key, old, bo->lock_cnt);
- return 1;
+ return ret;
}
static void
bo, bo->tgl_key, old, bo->lock_cnt);
}
+static int
+_tbm_bo_is_valid(tbm_bo bo)
+{
+ tbm_bo old_data=NULL, tmp = NULL;;
+
+ if( bo == NULL )
+ return 0;
+
+ if(!LIST_IS_EMPTY (&gBufMgr->bo_list))
+ {
+ LIST_FOR_EACH_ENTRY_SAFE (old_data, tmp, &gBufMgr->bo_list, item_link)
+ {
+ if(old_data == bo)
+ {
+ return 1;
+ }
+ }
+
+ }
+ return 0;
+}
static void
_tbm_bo_ref (tbm_bo bo)
if (!ret && strstr (namelist[n]->d_name, PREFIX_LIB))
{
p = strstr (namelist[n]->d_name, SUFFIX_LIB);
- if (!strcmp (p, SUFFIX_LIB))
+ if (p != NULL)
{
- ret = _tbm_bufmgr_load_module (bufmgr, fd, namelist[n]->d_name);
+ if (!strcmp (p, SUFFIX_LIB))
+ {
+ ret = _tbm_bufmgr_load_module (bufmgr, fd, namelist[n]->d_name);
+ }
}
}
free(namelist[n]);
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");
#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++;
+
+ if (dup2(gBufMgr->fd, fd) < 0) {
+ TBM_LOG ("[libtbm:%d] Fail to duplicate the drm fd\n", getpid());
+ pthread_mutex_unlock (&gLock);
+ }
+ TBM_LOG ("[libtbm:%d] duplicate the drm_fd(%d), new drm_fd(%d).\n",
+ getpid(), gBufMgr->fd, fd);
+
+ 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->backend->priv);
- tbm_backend_free (bufmgr->backend);
- dlclose (bufmgr->module_data);
- 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->backend->priv);
- tbm_backend_free (bufmgr->backend);
- pthread_mutex_destroy (&bufmgr->lock);
- dlclose (bufmgr->module_data);
- 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"))
- bufmgr->lock_type = LOCK_TRY_ONCE;
+ gBufMgr->lock_type = LOCK_TRY_ONCE;
else
- bufmgr->lock_type = LOCK_TRY_ALWAYS;
+ 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
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;
}
}
}
+ /* 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);
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;
-}
+ gBufMgr = NULL;
+ pthread_mutex_unlock (&gLock);
+}
int
tbm_bo_size (tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), 0);
+ TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), 0);
tbm_bufmgr bufmgr = bo->bufmgr;
int size;
pthread_mutex_lock(&bufmgr->lock);
+
size = bufmgr->backend->bo_size(bo);
+
pthread_mutex_unlock(&bufmgr->lock);
return size;
tbm_bo
tbm_bo_ref (tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BO_IS_VALID(bo), NULL);
+ TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), NULL);
tbm_bufmgr bufmgr = bo->bufmgr;
void
tbm_bo_unref (tbm_bo bo)
{
- TBM_RETURN_IF_FAIL(TBM_BO_IS_VALID(bo));
+ TBM_RETURN_IF_FAIL(_tbm_bo_is_valid(bo));
tbm_bufmgr bufmgr = bo->bufmgr;
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)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), 0);
+ TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), 0);
tbm_bufmgr bufmgr;
int ret;
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)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), (tbm_bo_handle)0);
+ TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), (tbm_bo_handle)0);
tbm_bufmgr bufmgr;
tbm_bo_handle bo_handle;
tbm_bo_handle
tbm_bo_map (tbm_bo bo, int device, int opt)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), (tbm_bo_handle)0);
+ TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), (tbm_bo_handle)0);
tbm_bufmgr bufmgr;
tbm_bo_handle bo_handle;
+ int ret = 0;
bufmgr = bo->bufmgr;
bo_handle = bufmgr->backend->bo_get_handle (bo, device);
- _tbm_bo_lock (bo, device, opt);
+ ret = _tbm_bo_lock (bo, device, opt);
+ if(!ret)
+ {
+ pthread_mutex_unlock (&bufmgr->lock);
+ TBM_DLOG ("[libtbm:%d] "
+ "error %s:%d LOCK Failed \n",
+ getpid(), __FUNCTION__, __LINE__);
+ return (tbm_bo_handle)NULL;
+
+ }
bo_handle = bufmgr->backend->bo_map (bo, device, opt);
+ //As tbm_bo_handle is union just checking for NULL in first 32 bits only.
+ if(bo_handle.u32 == 0)
+ {
+ //clean up lock if map fails.
+ _tbm_bo_unlock (bo);
+ pthread_mutex_unlock (&bufmgr->lock);
+ TBM_DLOG ("[libtbm:%d] "
+ "error %s:%d LOCK Failed \n",
+ getpid(), __FUNCTION__, __LINE__);
+ return (tbm_bo_handle)NULL;
+
+ }
if (bufmgr->use_map_cache == 1 && bo->map_cnt == 0)
_tbm_bo_set_state (bo, device, opt);
int
tbm_bo_unmap (tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), 0);
+ TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), 0);
tbm_bufmgr bufmgr;
int ret;
int
tbm_bo_swap (tbm_bo bo1, tbm_bo bo2)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo1), 0);
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo2), 0);
+ TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo1), 0);
+ TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo2), 0);
void* temp;
unsigned int tmp_key;
int
tbm_bo_locked (tbm_bo bo)
{
- TBM_RETURN_VAL_IF_FAIL (TBM_BO_IS_VALID(bo), 0);
+ TBM_RETURN_VAL_IF_FAIL (_tbm_bo_is_valid(bo), 0);
tbm_bufmgr bufmgr;
int
tbm_bo_add_user_data (tbm_bo bo, unsigned long key, tbm_data_free data_free_func)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BO_IS_VALID(bo), 0);
+ TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
tbm_user_data *data;
int
tbm_bo_set_user_data (tbm_bo bo, unsigned long key, void* data)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BO_IS_VALID(bo), 0);
+ TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
tbm_user_data *old_data;
int
tbm_bo_get_user_data (tbm_bo bo, unsigned long key, void** data)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BO_IS_VALID(bo), 0);
+ TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
tbm_user_data* old_data;
int
tbm_bo_delete_user_data (tbm_bo bo, unsigned long key)
{
- TBM_RETURN_VAL_IF_FAIL(TBM_BO_IS_VALID(bo), 0);
+ TBM_RETURN_VAL_IF_FAIL(_tbm_bo_is_valid(bo), 0);
tbm_user_data *old_data = (void *)0;
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
#ifndef _TBM_BUFMGR_H_
#define _TBM_BUFMGR_H_
+#include <tbm_type.h>
#include <stdint.h>
/**
* \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
{
/**
* @brief Enumeration of bo memory type
+ * @since_tizen 2.3
*/
enum TBM_BO_FLAGS
{
/* 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 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 import the buffer object associated with the key.
+ * @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 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 get the size of a bo.
+ * @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);
-/**
- * @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 tbm_bo_cache_flush (tbm_bo bo, int flags);
+
#ifdef __cplusplus
}
#endif
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
-/**************************************************************************\r
-\r
-libtbm\r
-\r
-Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.\r
-\r
-Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a\r
-copy of this software and associated documentation files (the\r
-"Software"), to deal in the Software without restriction, including\r
-without limitation the rights to use, copy, modify, merge, publish,\r
-distribute, sub license, and/or sell copies of the Software, and to\r
-permit persons to whom the Software is furnished to do so, subject to\r
-the following conditions:\r
-\r
-The above copyright notice and this permission notice (including the\r
-next paragraph) shall be included in all copies or substantial portions\r
-of the Software.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\r
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR\r
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-\r
-**************************************************************************/\r
-\r
-/*\r
- * This file is referenced by the xf86Module.h in xorg server.\r
- */\r
-\r
-#ifndef _TBM_BUFMGR_BACKEND_H_\r
-#define _TBM_BUFMGR_BACKEND_H_\r
-\r
-#include <tbm_bufmgr.h>\r
-#include <pthread.h>\r
-\r
-/**\r
- * \file tbm_bufmgr_backend.h\r
- * \brief backend header for Tizen Buffer Manager\r
- * This header is for the implementation of the TBM backend module.\r
- */\r
-\r
-\r
-#define ABI_MINOR_MASK 0x0000FFFF\r
-#define ABI_MAJOR_MASK 0xFFFF0000\r
-#define GET_ABI_MINOR(v) ((v) & ABI_MINOR_MASK)\r
-#define GET_ABI_MAJOR(v) (((v) & ABI_MAJOR_MASK) >> 16)\r
-\r
-/*\r
- * ABI versions. Each version has a major and minor revision. Modules\r
- * using lower minor revisions must work with servers of a higher minor\r
- * revision. There is no compatibility between different major revisions.\r
- * Whenever the ABI_ANSIC_VERSION is changed, the others must also be\r
- * changed. The minor revision mask is 0x0000FFFF and the major revision\r
- * mask is 0xFFFF0000.\r
- */\r
-#define SET_ABI_VERSION(maj, min) \\r
- ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK))\r
-\r
-#define TBM_ABI_VERSION SET_ABI_VERSION(1, 0) /**< current abi vertion */\r
-\r
-/* TBM_CACHE */\r
-#define TBM_CACHE_INV 0x01 /**< cache invalidate */\r
-#define TBM_CACHE_CLN 0x02 /**< cache clean */\r
-#define TBM_CACHE_ALL 0x10 /**< cache all */\r
-#define TBM_CACHE_FLUSH (TBM_CACHE_INV|TBM_CACHE_CLN) /**< cache flush */\r
-#define TBM_CACHE_FLUSH_ALL (TBM_CACHE_FLUSH|TBM_CACHE_ALL) /**< cache flush all */\r
-\r
-/* TBM flag for cache control and lock control */\r
-/**\r
- * TBM_CACHE_CTRL_BACKEND indicates that the backend control the cache coherency.\r
+/**************************************************************************
+
+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, 1) /**< 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)\r
+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.\r
+ * @brief tbm module data
+ * data type for the entry point of the backend module
*/
-#define TBM_LOCK_CTRL_BACKEND (1 << 1)\r
-\r
-typedef struct _tbm_bufmgr_backend *tbm_bufmgr_backend;\r
-\r
-/**\r
- * @brief TBM backend functions\r
- * the set of function pointers for the backend module of TBM.\r
- */\r
-struct _tbm_bufmgr_backend\r
-{\r
- int flags;\r
-\r
- void *priv; /**< bufmgr private */\r
-\r
- /**\r
- * @brief deinitialize the bufmgr private.\r
- * @param[in] bufmgr : the private of the bufmgr\r
- * @return 1 if this function succeeds, otherwise 0.\r
- */\r
- void (*bufmgr_deinit) (void *priv);\r
-\r
- /**\r
- * @brief get the size of a bo.\r
- * @param[in] bo : the buffer object\r
- * @return 1 if this function succeeds, otherwise 0.\r
- */\r
- int (*bo_size) (tbm_bo bo);\r
-\r
- /**\r
- * @brief allocate the buffer object\r
- * @param[in] bo : the buffer object\r
- * @param[in] size : the size of buffer object\r
- * @param[in] flags : the flags of memory type\r
- * @return pointer of the bo private.\r
- */\r
- void * (*bo_alloc) (tbm_bo bo, int size, int flags);\r
-\r
- /**\r
- * @brief free the buffer object.\r
- * @param[in] bo : the buffer object\r
- */\r
- void (*bo_free) (tbm_bo bo);\r
-\r
- /**\r
- * @brief import the buffer object associated with the key.\r
- * @param[in] bo : the buffer object\r
- * @param[in] key : the key associated with the buffer object\r
- * @return pointer of the bo private.\r
- */\r
- void * (*bo_import) (tbm_bo bo, unsigned int key);\r
-\r
- /**\r
- * @brief export the buffer object\r
- * @param[in] bo : the buffer object\r
- * @return key associated with the buffer object\r
- */\r
- unsigned int (*bo_export) (tbm_bo bo);\r
-\r
- /**\r
- * @brief get the tbm_bo_handle according to the device type.\r
- * @param[in] bo : the buffer object\r
- * @param[in] device : the device type to get a handle\r
- * @return the handle of the buffer object\r
- */\r
- tbm_bo_handle (*bo_get_handle) (tbm_bo bo, int device);\r
-\r
- /**\r
- * @brief map the buffer object according to the device type and the option.\r
- * @param[in] bo : the buffer object\r
- * @param[in] device : the device type to get a handle\r
- * @param[in] option : the option to access the buffer object\r
- * @return the handle of the buffer object\r
- */\r
- tbm_bo_handle (*bo_map) (tbm_bo bo, int device, int opt);\r
-\r
- /**\r
- * @brief unmap the buffer object.\r
- * @param[in] bo : the buffer object\r
- * @return 1 if this function succeeds, otherwise 0.\r
- */\r
- int (*bo_unmap) (tbm_bo bo);\r
-\r
- /**\r
- * @brief flush the cache of the buffer object.\r
- * @param[in] bo : the buffer object\r
- * @param[in] flags : the flags of cache flush type\r
- * @return 1 if this function succeeds, otherwise 0.\r
- */\r
- int (*bo_cache_flush) (tbm_bo bo, int flags);\r
-\r
- /**\r
- * @brief get the global key associated with the buffer object.\r
- * @param[in] bo : the buffer object\r
- * @return global key associated with the buffer object.\r
- */\r
- int (*bo_get_global_key) (tbm_bo bo);\r
-\r
- /**\r
- * @brief lock the buffer object.\r
- * @param[in] bo : the buffer object\r
- * @return 1 if this function succeeds, otherwise 0.\r
- * @remark This function pointer could be null. (default: use the tizen global lock)\r
- */\r
- int (*bo_lock) (tbm_bo bo);\r
-\r
- /**\r
- * @brief unlock the buffer object.\r
- * @param[in] bo : the buffer object\r
- * @return 1 if this function succeeds, otherwise 0.\r
- * @remark This function pointer could be null. (default: use the tizen global lock)\r
- */\r
- int (*bo_unlock) (tbm_bo bo);\r
-\r
- /**\r
- * @brief lock the buffer object with a device and an opt.\r
- * @param[in] bo : the buffer object\r
- * @param[in] device : the device type to get a handle\r
- * @param[in] option : the option to access the buffer object\r
- * @return 1 if this function succeeds, otherwise 0.\r
- * @remark This function pointer could be null. (default: use the tizen global lock)\r
- */\r
- int (*bo_lock2) (tbm_bo bo, int device, int opt);\r
-\r
- /* Padding for future extension */\r
- void (*reserved1) (void);\r
- void (*reserved2) (void);\r
- void (*reserved3) (void);\r
-};\r
-\r
-/**\r
- * @brief tbm module information\r
- * data type for the module information\r
- */\r
-typedef struct\r
-{\r
- const char *modname; /**< name of module, e.g. "foo" */\r
- const char *vendor; /**< vendor specific string */\r
- unsigned long abiversion; /**< ABI version */\r
-} TBMModuleVersionInfo;\r
-\r
-typedef int (*ModuleInitProc) (tbm_bufmgr, int);\r
-\r
-#define MODULEINITPPROTO(func) int func(tbm_bufmgr, int) /**< prototype for init symbol of bakcend module */\r
-\r
-/**\r
- * @brief tbm module data\r
- * data type for the entry point of the backend module\r
- */\r
-typedef struct\r
-{\r
- TBMModuleVersionInfo *vers; /**< tbm module informtaion */\r
- ModuleInitProc init; /**< init function of a backend module */\r
-} TBMModuleData;\r
-\r
-tbm_bufmgr_backend tbm_backend_alloc (void);\r
-void tbm_backend_free (tbm_bufmgr_backend backend);\r
-int tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend);\r
-\r
-void *tbm_backend_get_bufmgr_priv (tbm_bo bo);\r
-void *tbm_backend_get_bo_priv (tbm_bo bo);\r
-\r
-#endif /* _TBM_BUFMGR_BACKEND_H_ */\r
+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_ */
-/**************************************************************************\r
-\r
-libtbm\r
-\r
-Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.\r
-\r
-Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>\r
-\r
-Permission is hereby granted, free of charge, to any person obtaining a\r
-copy of this software and associated documentation files (the\r
-"Software"), to deal in the Software without restriction, including\r
-without limitation the rights to use, copy, modify, merge, publish,\r
-distribute, sub license, and/or sell copies of the Software, and to\r
-permit persons to whom the Software is furnished to do so, subject to\r
-the following conditions:\r
-\r
-The above copyright notice and this permission notice (including the\r
-next paragraph) shall be included in all copies or substantial portions\r
-of the Software.\r
-\r
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\r
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR\r
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-\r
-**************************************************************************/\r
-\r
-#ifndef _TBM_BUFMGR_INT_H_\r
-#define _TBM_BUFMGR_INT_H_\r
-\r
-#include <tbm_bufmgr.h>\r
-#include <pthread.h>\r
-#include "tbm_bufmgr_backend.h"\r
-\r
-#define TBM_LOG(...) fprintf (stderr, __VA_ARGS__)\r
-\r
-typedef union _tbm_bo_cache_state tbm_bo_cache_state;\r
-\r
-struct list_head\r
-{\r
- struct list_head *prev;\r
- struct list_head *next;\r
-};\r
-\r
-union _tbm_bo_cache_state\r
-{\r
- unsigned int val;\r
- struct {\r
- unsigned int cntFlush:16; /*Flush all index for sync*/\r
- unsigned int isCacheable:1;\r
- unsigned int isCached:1;\r
- unsigned int isDirtied:2;\r
- } data;\r
-};\r
-\r
-/**\r
- * @brief tbm buffer object\r
- * buffer object of Tizen Buffer Manager\r
- */\r
-struct _tbm_bo\r
-{\r
- tbm_bufmgr bufmgr; /**< tbm buffer manager */\r
-\r
- int ref_cnt; /**< ref count of bo */\r
-\r
- int flags; /**< TBM_BO_FLAGS :bo memory type */\r
-\r
- unsigned int tgl_key; /**< global key for tizen global lock */\r
-\r
- /* for cache control */\r
- unsigned int map_cnt; /**< device map count */\r
- tbm_bo_cache_state cache_state; /**< cache state */\r
-\r
- int lock_cnt; /**< lock count of bo */\r
-\r
- struct list_head user_data_list; /**< list of the user_date in bo */\r
-\r
- void *priv; /**< bo private */\r
-\r
- struct list_head item_link; /**< link of bo */\r
-};\r
-\r
-/**\r
- * @brief tbm_bufmgr : structure for tizen buffer manager\r
- *\r
- */\r
-struct _tbm_bufmgr\r
-{\r
- int ref_count; /**< ref count of bufmgr */\r
-\r
- pthread_mutex_t lock; /**< mutex lock */\r
-\r
- int fd; /**< bufmgr fd */\r
-\r
- int lock_fd; /**< fd of tizen global lock */\r
-\r
- int lock_type; /**< lock_type of bufmgr */\r
-\r
- int use_map_cache; /**< flag to use the map_cahce */\r
-\r
- struct list_head bo_list; /**< list of bos belonging to bufmgr */\r
-\r
- void *module_data;\r
-\r
- tbm_bufmgr_backend backend; /**< bufmgr backend */\r
-\r
- struct list_head link; /**< link of bufmgr */\r
-};\r
-\r
-#endif /* _TBM_BUFMGR_INT_H_ */\r
+/**************************************************************************
+
+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>
+
+#include </usr/include/dlog/dlog.h>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "TBM"
+
+/* check condition */
+#define TBM_RETURN_IF_FAIL(cond) {\
+ if (!(cond)) {\
+ TBM_DLOG ("[%s] : '%s' failed.\n", __FUNCTION__, #cond);\
+ return;\
+ }\
+}
+#define TBM_RETURN_VAL_IF_FAIL(cond, val) {\
+ if (!(cond)) {\
+ TBM_DLOG ("[%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__)
+#define TBM_DLOG(...) LOGE (__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_ */
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd.
+/**************************************************************************
*
- * This program is free software and is provided to you under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
+ * libtbm
*
- * A copy of the licence is included with the program, and can also be obtained from Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
+ * 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_TGL_H__
#define __TBM_BUFMGR_TGL_H__
--- /dev/null
+/**************************************************************************
+
+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_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 (!tbm_surface_internal_query_supported_formats (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))
+ {
+#ifdef HAVE_CAPI_0_1_1
+ set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER);
+#endif
+ return NULL;
+ }
+
+ struct _tbm_surface *surf = NULL;
+
+ surf = tbm_surface_internal_create_with_flags (width, height, format, TBM_BO_DEFAULT);
+ if (!surf)
+ {
+#ifdef HAVE_CAPI_0_1_1
+ set_last_result (TBM_SURFACE_ERROR_INVALID_OPERATION);
+#endif
+ return NULL;
+ }
+
+#ifdef HAVE_CAPI_0_1_1
+ set_last_result (TBM_SURFACE_ERROR_NONE);
+#endif
+ return surf;
+}
+
+
+int
+tbm_surface_destroy (tbm_surface_h surface)
+{
+ if (!surface)
+ return TBM_SURFACE_ERROR_INVALID_PARAMETER;
+
+ tbm_surface_internal_destroy (surface);
+
+ 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)
+ {
+#ifdef HAVE_CAPI_0_1_1
+ set_last_result (TBM_SURFACE_ERROR_INVALID_PARAMETER);
+#endif
+ return 0;
+ }
+
+ struct _tbm_surface *surf = (struct _tbm_surface *)surface;
+
+#ifdef HAVE_CAPI_0_1_1
+ set_last_result (TBM_SURFACE_ERROR_NONE);
+#endif
+ return surf->info.format;
+}
+
--- /dev/null
+/**************************************************************************
+
+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 for 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 plane struct.
+ * @since_tizen 2.3
+ */
+typedef struct _tbm_surface_plane
+{
+ unsigned char *ptr; /**< Plane pointer */
+ uint32_t size; /**< Plane size */
+ uint32_t offset; /**< Plane offset */
+ uint32_t stride; /**< Plane stride */
+
+ void *reserved1; /**< Reserved pointer1 */
+ void *reserved2; /**< Reserved pointer2 */
+ void *reserved3; /**< Reserved pointer3 */
+} tbm_surface_plane_s;
+
+/**
+ * @brief Definition for the TBM surface information 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 format*/
+ uint32_t bpp; /**< TBM surface bbp */
+ uint32_t size; /**< TBM surface size */
+
+ uint32_t num_planes; /**< The number of planes */
+ tbm_surface_plane_s planes[TBM_SURF_PLANE_MAX]; /**< Array of planes */
+
+ void *reserved4; /**< Reserved pointer4 */
+ void *reserved5; /**< Reserved pointer5 */
+ void *reserved6; /**< Reserved pointer6 */
+} 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 format 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 You must release the formats using free().
+ *
+ * @param[out] formats The format array which the system can support \n
+ * 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 an error status value
+ *
+ * @retval #TBM_SURFACE_ERROR_NONE Success
+ * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION 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 creates the tbm_surface with the given width, height, and 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 #tbm_surface_h on success,
+ * otherwise @c NULL
+ *
+ * @retval #tbm_surface_h The TBM surface handle
+ *
+ * @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 Destroys the tbm_surface.
+ * @since_tizen 2.3
+ *
+ * @param[in] surface The #tbm_surface_h
+ *
+ * @return #TBM_SURFACE_ERROR_NONE on success,
+ * otherwise an error status value
+ *
+ * @retval #TBM_SURFACE_ERROR_NONE Success
+ * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER 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 indicates access option to read. \n
+ * #TBM_SURF_OPTION_WRITE indicates 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 information of the tbm_surface
+ *
+ * @return #TBM_SURFACE_ERROR_NONE on success,
+ * otherwise an error status value
+ *
+ * @retval #TBM_SURFACE_ERROR_NONE Success
+ * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION 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 on success,
+ * otherwise an error status value
+ *
+ * @retval #TBM_SURFACE_ERROR_NONE Success
+ * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER 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 information of the tbm_surface
+ *
+ * @return #TBM_SURFACE_ERROR_NONE on success,
+ * otherwise an error status value
+ *
+ * @retval #TBM_SURFACE_ERROR_NONE Success
+ * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TBM_SURFACE_ERROR_INVALID_OPERATION 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 on success,
+ * otherwise an error status value
+ *
+ * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER 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 an error status value
+ *
+ * @retval #TBM_SURFACE_ERROR_INVALID_PARAMETER 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 on success,
+ * otherwise @c 0 on failure
+ *
+ * @retval #tbm_format The format of surface
+ *
+ * @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_ */
+
--- /dev/null
+/**************************************************************************
+
+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"
+#include "list.h"
+
+static tbm_bufmgr g_surface_bufmgr = NULL;
+struct list_head g_surface_list; /* list of surfaces belonging to bufmgr */
+
+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;
+}
+
+static void
+_init_surface_bufmgr()
+{
+ g_surface_bufmgr = tbm_bufmgr_init (-1);
+}
+
+static void
+_deinit_surface_bufmgr()
+{
+ if (!g_surface_bufmgr)
+ return;
+
+ tbm_bufmgr_deinit (g_surface_bufmgr);
+ g_surface_bufmgr = NULL;
+}
+
+
+int
+tbm_surface_internal_query_supported_formats (uint32_t **formats, uint32_t *num)
+{
+ if (!g_surface_bufmgr)
+ {
+ _init_surface_bufmgr();
+ LIST_INITHEAD (&g_surface_list);
+ }
+
+ struct _tbm_bufmgr *mgr = g_surface_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 (int width, int height, int format, int flags)
+{
+ TBM_RETURN_VAL_IF_FAIL (width > 0, NULL);
+ TBM_RETURN_VAL_IF_FAIL (height > 0, NULL);
+
+ if (!g_surface_bufmgr)
+ {
+ _init_surface_bufmgr();
+ LIST_INITHEAD (&g_surface_list);
+ }
+
+ struct _tbm_bufmgr *mgr = g_surface_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 = mgr;
+ 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;
+
+ if(LIST_IS_EMPTY (&g_surface_list))
+ {
+ _deinit_surface_bufmgr ();
+ LIST_DELINIT (&g_surface_list);
+ return NULL;
+ }
+ }
+
+ LIST_ADD (&surf->item_link, &g_surface_list);
+
+ return surf;
+}
+
+tbm_surface_h
+tbm_surface_internal_create_with_bos (int width, int height, int format, tbm_bo *bos, int num)
+{
+ TBM_RETURN_VAL_IF_FAIL (width > 0, NULL);
+ TBM_RETURN_VAL_IF_FAIL (height > 0, NULL);
+ TBM_RETURN_VAL_IF_FAIL (bos, NULL);
+
+ if (!g_surface_bufmgr)
+ {
+ _init_surface_bufmgr();
+ LIST_INITHEAD (&g_surface_list);
+ }
+
+
+ struct _tbm_bufmgr *mgr = g_surface_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 = mgr;
+ 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 = TBM_BO_DEFAULT;
+
+ /* create only one bo */
+ surf->num_bos = num;
+ for (i = 0; i < num; i++)
+ {
+ if (bos[i] == NULL)
+ goto bail1;
+
+ surf->bos[i] = tbm_bo_ref(bos[i]);
+ }
+
+ LIST_ADD (&surf->item_link, &g_surface_list);
+
+ return surf;
+bail1:
+ for (i = 0; i < num; i++)
+ {
+ if (surf->bos[i])
+ {
+ tbm_bo_unref (surf->bos[i]);
+ surf->bos[i] = NULL;
+ }
+ }
+
+ free (surf);
+ surf = NULL;
+
+ if(LIST_IS_EMPTY (&g_surface_list))
+ {
+ _deinit_surface_bufmgr ();
+ LIST_DELINIT (&g_surface_list);
+ }
+
+ return NULL;
+}
+
+
+void
+tbm_surface_internal_destroy (tbm_surface_h surface)
+{
+ int i;
+
+ if (!surface)
+ return;
+
+ surface = (struct _tbm_surface *)surface;
+
+ for (i = 0; i < surface->num_bos; i++)
+ {
+ tbm_bo_unref (surface->bos[i]);
+ surface->bos[i] = NULL;
+ }
+
+ LIST_DEL (&surface->item_link);
+
+ free (surface);
+ surface = NULL;
+
+ if(LIST_IS_EMPTY (&g_surface_list))
+ {
+ _deinit_surface_bufmgr ();
+ LIST_DELINIT (&g_surface_list);
+ }
+}
+
+
+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 (mgr != NULL, 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 (mgr != NULL, 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)
+ {
+ pthread_mutex_unlock (&mgr->lock);
+ return 0;
+ }
+
+ pthread_mutex_unlock (&mgr->lock);
+
+ return 1;
+}
+
+
+
--- /dev/null
+/**************************************************************************
+
+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_
+
+#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 (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 (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 (int width, int height, int format, tbm_bo *bos, int num);
+
+
+/**
+ * @brief Destroy the tbm surface
+ TODO:
+ */
+void tbm_surface_internal_destroy (tbm_surface_h surface);
+
+/**
+ * @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_ */
+
--- /dev/null
+/**************************************************************************
+
+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 format.
+ */
+typedef uint32_t tbm_format;
+
+/**
+* @}
+*/
+
+#endif /* _TBM_TYPE_H_ */
+