bump up version 1.1.4 16/40316/3 accepted/tizen_3.0.2015.q2_common tizen_3.0.2015.q2_common accepted/tizen/3.0.2015.q2/common/20150615.091853 accepted/tizen/common/20150610.144511 accepted/tizen/mobile/20150612.003442 accepted/tizen/tv/20150612.003551 accepted/tizen/wearable/20150611.085714 submit/tizen/20150608.113003 submit/tizen/20150609.065415 submit/tizen_3.0.2015.q2_common/20150615.075539 submit/tizen_common/20150610.013111 submit/tizen_common/20150610.072250 submit/tizen_mobile/20150611.000000 submit/tizen_tv/20150611.000001 submit/tizen_wearable/20150611.000000
authorChangyeon Lee <cyeon.lee@samsung.com>
Tue, 2 Jun 2015 04:42:12 +0000 (13:42 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Wed, 3 Jun 2015 04:49:58 +0000 (21:49 -0700)
sync code spin tizen_2.4

Change-Id: I9a8e92243950f91bde9c26a4ed3f69c5a43cd4a2
Signed-off-by: Changyeon Lee <cyeon.lee@samsung.com>
17 files changed:
Makefile.am
configure.ac
drm_slp/Makefile.am [deleted file]
drm_slp/drm_slp_bufmgr.c [deleted file]
drm_slp/drm_slp_bufmgr.h [deleted file]
packaging/libtbm.spec
src/tbm_bufmgr.c
src/tbm_bufmgr.h
src/tbm_bufmgr_backend.c
src/tbm_bufmgr_backend.h
src/tbm_bufmgr_int.h
src/tbm_bufmgr_tgl.h
src/tbm_surface.c
src/tbm_surface.h
src/tbm_surface_internal.c
src/tbm_surface_internal.h
src/tbm_type.h

index 1146497..ceb4251 100644 (file)
@@ -1,10 +1,4 @@
-SUBDIRS =
-
-if HOST_CPU_X86_64
-SUBDIRS += src
-else
-SUBDIRS += src drm_slp
-endif
+SUBDIRS = src
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libtbm.pc
index 19d9312..d60b52b 100644 (file)
@@ -114,7 +114,6 @@ AM_CONDITIONAL(HOST_CPU_X86_64, test "x$HOST_CPU_X86_64" = "xyes")
 AC_OUTPUT([
     src/Makefile
        src/wayland-drm/Makefile
-    drm_slp/Makefile
        Makefile
        libtbm.pc])
 
diff --git a/drm_slp/Makefile.am b/drm_slp/Makefile.am
deleted file mode 100644 (file)
index 835562c..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-SUBDIRS = .
-
-AM_CFLAGS = \
-       $(WARN_CFLAGS) \
-       -I$(top_srcdir) \
-       -I$(top_srcdir)/src \
-       -I$(top_srcdir)/drm_slp \
-       $(PTHREADSTUBS_CFLAGS) \
-       -I$(top_srcdir)/include/drm
-
-libdrm_slp_la_LTLIBRARIES = libdrm_slp.la
-libdrm_slp_ladir = $(libdir)
-libdrm_slp_la_LDFLAGS = -version-number 1:0:0 -no-undefined
-libdrm_slp_la_LIBADD = ../src/libtbm.la @PTHREADSTUBS_LIBS@ @CLOCK_LIB@ -ldl
-
-libdrm_slp_la_SOURCES = \
-       drm_slp_bufmgr.c \
-       drm_slp_bufmgr.h
-
diff --git a/drm_slp/drm_slp_bufmgr.c b/drm_slp/drm_slp_bufmgr.c
deleted file mode 100755 (executable)
index 3082c23..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/**************************************************************************
-
-xserver-xorg-video-sec
-
-Copyright 2011 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#include "config.h"
-#include <stdio.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include "drm_slp_bufmgr.h"
-#include "tbm_bufmgr.h"
-#include "tbm_bufmgr_int.h"
-
-drm_slp_bufmgr
-drm_slp_bufmgr_init(int fd, void *arg)
-{
-    tbm_bufmgr bufmgr = NULL;
-
-    bufmgr = tbm_bufmgr_init (fd);
-    if (!bufmgr)
-    {
-        TBM_LOG ("[libdrm_slp:%d]: error bufmgr is null\n", getpid());
-        return NULL;
-    }
-
-    return (drm_slp_bufmgr)bufmgr;
-}
-
-void
-drm_slp_bufmgr_destroy(drm_slp_bufmgr bufmgr)
-{
-    tbm_bufmgr_deinit ((tbm_bufmgr)bufmgr);
-}
-
-void
-drm_slp_bo_unref(drm_slp_bo bo)
-{
-    tbm_bo_unref ((tbm_bo)bo);
-}
-
-drm_slp_bo
-drm_slp_bo_import(drm_slp_bufmgr bufmgr, unsigned int key)
-{
-    tbm_bo bo = NULL;
-
-    bo = tbm_bo_import ((tbm_bufmgr)bufmgr, key);
-    if (!bo)
-    {
-        TBM_LOG ("[libdrm_slp:%d]: error bo is null\n", getpid());
-        return NULL;
-    }
-
-    return (drm_slp_bo)bo;
-}
-
-void *
-drm_slp_bo_map(drm_slp_bo bo, int device, int opt)
-{
-    tbm_bo_handle bo_handle;
-    void *ret = NULL;
-
-    bo_handle = tbm_bo_map ((tbm_bo)bo, device, opt);
-    if (bo_handle.ptr == NULL)
-    {
-        TBM_LOG ("[libdrm_slp:%d]: error bo_handle is null\n", getpid());
-        return NULL;
-    }
-
-    switch (device)
-    {
-        case TBM_DEVICE_DEFAULT:
-        case TBM_DEVICE_2D:
-        case TBM_DEVICE_3D:
-        case TBM_DEVICE_MM:
-            ret = (void *)((uintptr_t)bo_handle.u32);
-            break;
-        case TBM_DEVICE_CPU:
-            ret = bo_handle.ptr;
-            break;
-        default:
-            TBM_LOG ("[libdrm_slp:%d]: error wrong device type\n", getpid());
-            return NULL;
-    }
-
-    return ret;
-}
-
-int
-drm_slp_bo_unmap(drm_slp_bo bo, int device)
-{
-    tbm_bo_unmap ((tbm_bo)bo);
-
-    return 1;
-}
-
diff --git a/drm_slp/drm_slp_bufmgr.h b/drm_slp/drm_slp_bufmgr.h
deleted file mode 100644 (file)
index 43147f6..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/**************************************************************************
-
-xserver-xorg-video-sec
-
-Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-#ifndef _DRM_SLP_BUFMGR_H_
-#define _DRM_SLP_BUFMGR_H_
-
-#include "tbm_bufmgr.h"
-
-typedef struct _drm_slp_bo * drm_slp_bo;
-typedef struct _drm_slp_bufmgr * drm_slp_bufmgr;
-
-/* Functions for buffer mnager */
-drm_slp_bufmgr drm_slp_bufmgr_init(int fd, void * arg);
-void           drm_slp_bufmgr_destroy(drm_slp_bufmgr bufmgr);
-
-/*Functions for bo*/
-void         drm_slp_bo_unref(drm_slp_bo bo);
-drm_slp_bo drm_slp_bo_import(drm_slp_bufmgr bufmgr, unsigned int key);
-void *drm_slp_bo_map(drm_slp_bo bo, int device, int opt);
-int          drm_slp_bo_unmap(drm_slp_bo bo, int device);
-
-#endif /* _DRM_SLP_BUFMGR_H_ */
index 4b24e36..e0b3bab 100644 (file)
@@ -2,7 +2,7 @@
 %bcond_with wayland
 
 Name:           libtbm
-Version:        1.1.1
+Version:        1.1.4
 Release:        1
 License:        MIT
 Summary:        The library for Tizen Buffer Manager
@@ -68,10 +68,6 @@ rm -rf %{buildroot}
 %defattr(-,root,root,-)
 /usr/share/license/%{name}
 %{_libdir}/libtbm.so.*
-%ifarch x86_64
-%else
-%{_libdir}/libdrm_slp.so.*
-%endif
 
 %files devel
 %defattr(-,root,root,-)
@@ -82,8 +78,4 @@ rm -rf %{buildroot}
 %{_includedir}/tbm_bufmgr_backend.h
 %{_includedir}/tbm_type.h
 %{_libdir}/libtbm.so
-%ifarch x86_64
-%else
-%{_libdir}/libdrm_slp.so
-%endif
 %{_libdir}/pkgconfig/libtbm.pc
index 014aa53..4d7ddbf 100644 (file)
@@ -99,6 +99,14 @@ typedef struct
 pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER;
 tbm_bufmgr gBufMgr = NULL;
 
+static __thread tbm_error_e tbm_last_error = TBM_ERROR_NONE;
+
+static void
+_tbm_set_last_result(tbm_error_e err)
+{
+       tbm_last_error = err;
+}
+
 static inline int
 _tgl_init (int fd, unsigned int key)
 {
@@ -320,14 +328,18 @@ _tbm_bo_init_state (tbm_bo bo, int opt)
     tbm_bufmgr bufmgr = bo->bufmgr;
     tbm_bo_cache_state cache_state;
 
+    if (bo->tgl_key == INITIAL_KEY)
+        bo->tgl_key = bufmgr->backend->bo_get_global_key (bo);
+
+    if (!bo->default_handle.u32)
+        bo->default_handle = bufmgr->backend->bo_get_handle (bo, TBM_DEVICE_DEFAULT);
+
     RETURN_VAL_CHECK_FLAG (TBM_ALL_CTRL_BACKEND_VALID(bufmgr->backend->flags), 1);
 
     cache_state.val = 0;
     switch (opt)
     {
     case CACHE_OP_CREATE:    /*Create*/
-        if (bo->tgl_key == INITIAL_KEY)
-           bo->tgl_key = bufmgr->backend->bo_get_global_key (bo);
 
         _tgl_init (bufmgr->lock_fd, bo->tgl_key);
 
@@ -339,8 +351,6 @@ _tbm_bo_init_state (tbm_bo bo, int opt)
         _tgl_set_data (bufmgr->lock_fd, bo->tgl_key, cache_state.val);
         break;
     case CACHE_OP_IMPORT:    /*Import*/
-        if (bo->tgl_key == INITIAL_KEY)
-           bo->tgl_key = bufmgr->backend->bo_get_global_key (bo);
 
         _tgl_init (bufmgr->lock_fd, bo->tgl_key);
         break;
@@ -485,6 +495,8 @@ _tbm_bo_lock (tbm_bo bo, int device, int opt)
             if (ret)
                 bo->lock_cnt++;
         }
+        else
+            ret = 1;
     }
     else if (bufmgr->lock_type == LOCK_TRY_ALWAYS)
     {
@@ -671,7 +683,7 @@ _check_version (TBMModuleVersionInfo *data)
     abimaj = GET_ABI_MAJOR (data->abiversion);
     abimin = GET_ABI_MINOR (data->abiversion);
 
-    TBM_LOG ("[libtbm:%d] "
+    DBG ("[libtbm:%d] "
             "TBM module %s: vendor=\"%s\" ABI=%d,%d\n",
             getpid(), data->modname ? data->modname : "UNKNOWN!",
             data->vendor ? data->vendor : "UNKNOWN!", abimaj, abimin);
@@ -781,7 +793,7 @@ _tbm_bufmgr_load_module (tbm_bufmgr bufmgr, int fd, const char *file)
 
     bufmgr->module_data = module_data;
 
-    TBM_LOG ("[libtbm:%d] "
+    DBG ("[libtbm:%d] "
             "Success to load module(%s)\n", getpid(), file);
 
     return 1;
@@ -833,6 +845,7 @@ tbm_bufmgr_init (int fd)
 {
     char *env;
     int fd_flag = 0;
+    int backend_flag = 0;
 
     pthread_mutex_lock (&gLock);
 
@@ -850,9 +863,22 @@ tbm_bufmgr_init (int fd)
     /* initialize buffer manager */
     if (gBufMgr)
     {
-        TBM_LOG ("[libtbm:%d] use previous gBufMgr\n", getpid());
+        DBG ("[libtbm:%d] use previous gBufMgr\n", getpid());
         gBufMgr->ref_count++;
-        TBM_LOG ("[libtbm:%d] bufmgr ref: fd=%d, ref_count:%d\n",
+
+        if (fd >= 0)
+        {
+            if (dup2(gBufMgr->fd, fd) < 0) {
+                _tbm_set_last_result (TBM_BO_ERROR_DUP_FD_FAILED);
+                DBG ("[libtbm:%d] Fail to duplicate(dup2) the drm fd\n", getpid());
+                pthread_mutex_unlock (&gLock);
+                return NULL;
+            }
+            DBG ("[libtbm:%d] duplicate the drm_fd(%d), new drm_fd(%d).\n",
+                        getpid(), gBufMgr->fd, fd);
+        }
+
+        DBG ("[libtbm:%d] bufmgr ref: fd=%d, ref_count:%d\n",
                     getpid(), gBufMgr->fd, gBufMgr->ref_count);
         pthread_mutex_unlock (&gLock);
         return gBufMgr;
@@ -867,6 +893,7 @@ tbm_bufmgr_init (int fd)
 #endif
         if (fd < 0)
         {
+            _tbm_set_last_result (TBM_BO_ERROR_GET_FD_FAILED);
             TBM_LOG ("[libtbm:%d] Fail get drm fd\n", getpid());
             pthread_mutex_unlock (&gLock);
             return NULL;
@@ -874,19 +901,43 @@ tbm_bufmgr_init (int fd)
         fd_flag = 1;
     }
 
-    TBM_LOG ("[libtbm:%d] bufmgr init: fd=%d\n", getpid(), fd);
+    DBG ("[libtbm:%d] bufmgr init: fd=%d\n", getpid(), fd);
 
     /* allocate bufmgr */
     gBufMgr = calloc (1, sizeof(struct _tbm_bufmgr));
     if (!gBufMgr)
     {
+        _tbm_set_last_result (TBM_BO_ERROR_HEAP_ALLOC_FAILED);
         pthread_mutex_unlock (&gLock);
         return NULL;
     }
 
+    gBufMgr->fd_flag = fd_flag;
+
+    if (fd_flag)
+    {
+        gBufMgr->fd = fd;
+    }
+    else
+    {
+        gBufMgr->fd = dup(fd);
+        if (gBufMgr->fd < 0)
+        {
+            _tbm_set_last_result (TBM_BO_ERROR_DUP_FD_FAILED);
+            TBM_LOG ("[libtbm:%d] Fail to duplicate(dup) the drm fd\n", getpid());
+            free (gBufMgr);
+            gBufMgr = NULL;
+            pthread_mutex_unlock (&gLock);
+            return NULL;
+        }
+        DBG ("[libtbm:%d] duplicate the drm_fd(%d), bufmgr use fd(%d).\n",
+                    getpid(), fd, gBufMgr->fd);
+    }
+
     /* load bufmgr priv from env */
-    if (!_tbm_load_module(gBufMgr, fd))
+    if (!_tbm_load_module(gBufMgr, gBufMgr->fd))
     {
+        _tbm_set_last_result (TBM_BO_ERROR_LOAD_MODULE_FAILED);
         TBM_LOG ("[libtbm:%d] "
                 "error : Fail to load bufmgr backend\n",
                 getpid());
@@ -895,15 +946,33 @@ tbm_bufmgr_init (int fd)
         pthread_mutex_unlock (&gLock);
         return NULL;
     }
+    else
+    {
+        backend_flag = gBufMgr->backend->flags;
+        /* log for tbm backend_flag */
+        DBG ("[libtbm:%d] ", getpid());
+        DBG ("cache_crtl:");
+        if (backend_flag&TBM_CACHE_CTRL_BACKEND) {
+            DBG ("BACKEND ");
+        } else {
+            DBG ("TBM ");
+        }
+        DBG ("lock_crtl:");
+        if (backend_flag&TBM_LOCK_CTRL_BACKEND) {
+            DBG ("BACKEND ");
+        } else {
+            DBG ("TBM ");
+        }
+        DBG ("\n");
+    }
 
-    gBufMgr->fd_flag = fd_flag;
-    gBufMgr->fd = fd;
     gBufMgr->ref_count = 1;
 
-    TBM_LOG ("[libtbm:%d] create tizen bufmgr: ref_count:%d\n", getpid(), gBufMgr->ref_count);
+    DBG ("[libtbm:%d] create tizen bufmgr: ref_count:%d\n", getpid(), gBufMgr->ref_count);
 
     if (pthread_mutex_init (&gBufMgr->lock, NULL) != 0)
     {
+        _tbm_set_last_result (TBM_BO_ERROR_THREAD_INIT_FAILED);
         gBufMgr->backend->bufmgr_deinit (gBufMgr->backend->priv);
         tbm_backend_free (gBufMgr->backend);
         dlclose (gBufMgr->module_data);
@@ -916,6 +985,7 @@ tbm_bufmgr_init (int fd)
     /* intialize the tizen global status */
     if (!_tbm_bufmgr_init_state (gBufMgr))
     {
+        _tbm_set_last_result (TBM_BO_ERROR_INIT_STATE_FAILED);
         TBM_LOG ("[libtbm:%d] "
                 "error: Fail to init state\n",
                 getpid());
@@ -1019,14 +1089,13 @@ tbm_bufmgr_deinit (tbm_bufmgr bufmgr)
 
     pthread_mutex_destroy (&bufmgr->lock);
 
-    TBM_LOG ("[libtbm:%d] "
+    DBG ("[libtbm:%d] "
             "tizen bufmgr destroy: bufmgr:%p\n",
             getpid(), bufmgr);
 
     dlclose (bufmgr->module_data);
 
-    if(bufmgr->fd_flag)
-        close(bufmgr->fd);
+    close(bufmgr->fd);
 
     free (bufmgr);
     bufmgr = NULL;
@@ -1092,7 +1161,10 @@ tbm_bo_alloc (tbm_bufmgr bufmgr, int size, int flags)
 
     bo = calloc (1, sizeof(struct _tbm_bo));
     if(!bo)
+    {
+        _tbm_set_last_result (TBM_BO_ERROR_HEAP_ALLOC_FAILED);
         return NULL;
+    }
 
     bo->bufmgr = bufmgr;
 
@@ -1101,6 +1173,7 @@ tbm_bo_alloc (tbm_bufmgr bufmgr, int size, int flags)
     bo_priv = bufmgr->backend->bo_alloc (bo, size, flags);
     if (!bo_priv)
     {
+        _tbm_set_last_result (TBM_BO_ERROR_BO_ALLOC_FAILED);
         free (bo);
         pthread_mutex_unlock (&bufmgr->lock);
         return NULL;
@@ -1114,6 +1187,7 @@ tbm_bo_alloc (tbm_bufmgr bufmgr, int size, int flags)
     /* init bo state */
     if (!_tbm_bo_init_state (bo, CACHE_OP_CREATE))
     {
+        _tbm_set_last_result (TBM_BO_ERROR_INIT_STATE_FAILED);
         _tbm_bo_unref (bo);
         pthread_mutex_unlock (&bufmgr->lock);
         return NULL;
@@ -1134,19 +1208,40 @@ tbm_bo_import (tbm_bufmgr bufmgr, unsigned int key)
     TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
 
     tbm_bo bo = NULL;
+    tbm_bo bo2 = NULL;
+    tbm_bo tmp = NULL;
     void * bo_priv = NULL;
 
+    pthread_mutex_lock (&bufmgr->lock);
+
+    /* find bo in list */
+    if(!LIST_IS_EMPTY (&bufmgr->bo_list))
+    {
+        LIST_FOR_EACH_ENTRY_SAFE (bo2, tmp, &bufmgr->bo_list, item_link)
+        {
+            if (bo2->tgl_key == key)
+            {
+                DBG ("[libtbm:%d] "
+                        "find bo(%p, ref:%d key:%d) in list \n",
+                        getpid(), bo2, bo2->ref_cnt, bo2->tgl_key);
+
+                bo2->ref_cnt++;
+                pthread_mutex_unlock (&bufmgr->lock);
+                return bo2;
+            }
+        }
+    }
+
     bo = calloc (1, sizeof(struct _tbm_bo));
     if(!bo)
         return NULL;
 
     bo->bufmgr = bufmgr;
 
-    pthread_mutex_lock (&bufmgr->lock);
-
     bo_priv = bufmgr->backend->bo_import (bo, key);
     if (!bo_priv)
     {
+        _tbm_set_last_result (TBM_BO_ERROR_IMPORT_FAILED);
         free (bo);
         pthread_mutex_unlock (&bufmgr->lock);
         return NULL;
@@ -1159,6 +1254,7 @@ tbm_bo_import (tbm_bufmgr bufmgr, unsigned int key)
     /* init bo state */
     if (!_tbm_bo_init_state (bo, CACHE_OP_IMPORT))
     {
+        _tbm_set_last_result (TBM_BO_ERROR_INIT_STATE_FAILED);
         _tbm_bo_unref (bo);
         pthread_mutex_unlock (&bufmgr->lock);
         return NULL;
@@ -1179,7 +1275,32 @@ tbm_bo_import_fd  (tbm_bufmgr bufmgr, tbm_fd fd)
     TBM_RETURN_VAL_IF_FAIL(TBM_BUFMGR_IS_VALID(bufmgr), NULL);
 
     tbm_bo bo = NULL;
+    tbm_bo bo2 = NULL;
+    tbm_bo tmp = NULL;
     void * bo_priv = NULL;
+    tbm_bo_handle default_handle;
+
+    pthread_mutex_lock (&bufmgr->lock);
+
+    default_handle = bufmgr->backend->fd_to_handle (bufmgr, fd, TBM_DEVICE_DEFAULT);
+
+    /* find bo in list */
+    if(!LIST_IS_EMPTY (&bufmgr->bo_list))
+    {
+        LIST_FOR_EACH_ENTRY_SAFE (bo2, tmp, &bufmgr->bo_list, item_link)
+        {
+            if (bo2->default_handle.u32 == default_handle.u32)
+            {
+                DBG ("[libtbm:%d] "
+                        "find bo(%p, ref:%d handle:%d) in list \n",
+                        getpid(), bo2, bo2->ref_cnt, bo2->default_handle.u32);
+
+                bo2->ref_cnt++;
+                pthread_mutex_unlock (&bufmgr->lock);
+                return bo2;
+            }
+        }
+    }
 
     bo = calloc (1, sizeof(struct _tbm_bo));
     if(!bo)
@@ -1187,11 +1308,10 @@ tbm_bo_import_fd  (tbm_bufmgr bufmgr, tbm_fd fd)
 
     bo->bufmgr = bufmgr;
 
-    pthread_mutex_lock (&bufmgr->lock);
-
     bo_priv = bufmgr->backend->bo_import_fd(bo, fd);
     if (!bo_priv)
     {
+        _tbm_set_last_result (TBM_BO_ERROR_IMPORT_FD_FAILED);
         free (bo);
         pthread_mutex_unlock (&bufmgr->lock);
         return NULL;
@@ -1204,6 +1324,7 @@ tbm_bo_import_fd  (tbm_bufmgr bufmgr, tbm_fd fd)
     /* init bo state */
     if (!_tbm_bo_init_state (bo, CACHE_OP_IMPORT))
     {
+        _tbm_set_last_result (TBM_BO_ERROR_INIT_STATE_FAILED);
         _tbm_bo_unref (bo);
         pthread_mutex_unlock (&bufmgr->lock);
         return NULL;
@@ -1230,6 +1351,12 @@ tbm_bo_export (tbm_bo bo)
 
     pthread_mutex_lock (&bufmgr->lock);
     ret = bufmgr->backend->bo_export (bo);
+    if (!ret)
+    {
+        _tbm_set_last_result (TBM_BO_ERROR_EXPORT_FAILED);
+        pthread_mutex_unlock (&bufmgr->lock);
+        return ret;
+    }
     pthread_mutex_unlock (&bufmgr->lock);
 
     return ret;
@@ -1247,6 +1374,12 @@ tbm_bo_export_fd (tbm_bo bo)
 
     pthread_mutex_lock (&bufmgr->lock);
     ret = bufmgr->backend->bo_export_fd (bo);
+    if (!ret)
+    {
+        _tbm_set_last_result (TBM_BO_ERROR_EXPORT_FD_FAILED);
+        pthread_mutex_unlock (&bufmgr->lock);
+        return ret;
+    }
     pthread_mutex_unlock (&bufmgr->lock);
 
     return ret;
@@ -1265,6 +1398,12 @@ tbm_bo_get_handle (tbm_bo bo, int device)
 
     pthread_mutex_lock (&bufmgr->lock);
     bo_handle = bufmgr->backend->bo_get_handle (bo, device);
+    if (bo_handle.ptr == NULL)
+    {
+        _tbm_set_last_result (TBM_BO_ERROR_GET_HANDLE_FAILED);
+        pthread_mutex_unlock (&bufmgr->lock);
+        return (tbm_bo_handle)NULL;
+    }
     pthread_mutex_unlock (&bufmgr->lock);
 
     return bo_handle;
@@ -1286,12 +1425,10 @@ tbm_bo_map (tbm_bo bo, int device, int opt)
 
     if (!_tbm_bo_lock (bo, device, opt))
     {
+        _tbm_set_last_result (TBM_BO_ERROR_LOCK_FAILED);
         TBM_LOG ("[libtbm:%d] "
                         "error %s:%d fail to lock bo:%p)\n",
                         getpid(), __FUNCTION__, __LINE__, bo);
-#ifdef HAVE_CAPI_0_1_1
-        set_last_result (TBM_ERROR_BO_LOCK_FAILED);
-#endif
         pthread_mutex_unlock (&bufmgr->lock);
         return (tbm_bo_handle)NULL;
     }
@@ -1299,14 +1436,12 @@ tbm_bo_map (tbm_bo bo, int device, int opt)
     bo_handle = bufmgr->backend->bo_map (bo, device, opt);
     if (bo_handle.ptr == NULL)
     {
+        _tbm_set_last_result (TBM_BO_ERROR_MAP_FAILED);
         TBM_LOG ("[libtbm:%d] "
                         "error %s:%d fail to map bo:%p\n",
                         getpid(), __FUNCTION__, __LINE__, bo);
 
         _tbm_bo_unlock(bo);
-#ifdef HAVE_CAPI_0_1_1
-        set_last_result (TBM_ERROR_BO_MAP_FAILED);
-#endif
         pthread_mutex_unlock (&bufmgr->lock);
         return (tbm_bo_handle)NULL;
     }
@@ -1337,6 +1472,8 @@ tbm_bo_unmap (tbm_bo bo)
     ret = bufmgr->backend->bo_unmap (bo);
     if (!ret)
     {
+
+        _tbm_set_last_result (TBM_BO_ERROR_UNMAP_FAILED);
         pthread_mutex_unlock (&bufmgr->lock);
         return ret;
     }
@@ -1363,10 +1500,15 @@ tbm_bo_swap (tbm_bo bo1, tbm_bo bo2)
     void* temp;
     unsigned int tmp_key;
 
+    pthread_mutex_lock (&bo1->bufmgr->lock);
+
     if (bo1->bufmgr->backend->bo_size (bo1) != bo2->bufmgr->backend->bo_size (bo2))
+    {
+        _tbm_set_last_result (TBM_BO_ERROR_SWAP_FAILED);
+        pthread_mutex_unlock (&bo1->bufmgr->lock);
         return 0;
+    }
 
-    pthread_mutex_lock (&bo1->bufmgr->lock);
 
     tmp_key = bo1->tgl_key;
     bo1->tgl_key = bo2->tgl_key;
@@ -1496,3 +1638,9 @@ tbm_bo_delete_user_data (tbm_bo bo, unsigned long key)
     return 1;
 }
 
+tbm_error_e
+tbm_get_last_error (void)
+{
+    return tbm_last_error;
+}
+
index 041776e..f0f6ae9 100644 (file)
@@ -34,12 +34,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <tbm_type.h>
 #include <stdint.h>
-#include <tizen_error.h>
 
-
-/* this define will be removed when the capi-common is the version 0.1.1 */
-#ifndef TIZEN_ERROR_TBM
-#define TIZEN_ERROR_TBM                        -0x02830000
+/* tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */
+#ifndef TBM_ERROR_BASE
+#define TBM_ERROR_BASE                 -0x02830000
 #endif
 
 /**
@@ -49,23 +47,23 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 /**
  * @brief Definition for the tizen buffer manager
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef struct _tbm_bufmgr * tbm_bufmgr;
 
 /**
  * @brief Definition for the tizen buffer object
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef struct _tbm_bo *tbm_bo;
 /**
  * @brief Definition for the key associated with the buffer object
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef uint32_t tbm_key;
 /**
  * @brief Definition for the file descripter of the system buffer manager
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef int32_t tbm_fd;
 
@@ -74,38 +72,38 @@ typedef int32_t tbm_fd;
 
 /**
  * @brief Definition for the device type to get the default handle
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_DEVICE_DEFAULT   0
 /**
  * @brief Definition for the device type to get the virtual memory
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_DEVICE_CPU       1
 /**
  * @brief Definition for the device type to get the 2D memory handle
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_DEVICE_2D        2
 /**
  * @brief Definition for the device type to get the 3D memory handle
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_DEVICE_3D        3
 /**
  * @brief Definition for the device type to get the multimedia handle
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_DEVICE_MM        4
 
 /**
  * @brief Definition for the cache invalidate
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_CACHE_INV            0x01
 /**
  * @brief Definition for the cache clean
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_CACHE_CLN            0x02
 
@@ -113,23 +111,23 @@ typedef int32_t tbm_fd;
 
 /**
  * @brief Definition for the access option to read
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_OPTION_READ      (1 << 0)
 /**
  * @brief Definition for the access option to write
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_OPTION_WRITE     (1 << 1)
 /**
  * @brief Definition for the vendor specific option that depends on the backend
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_OPTION_VENDOR    (0xffff0000)
 
 /**
  * @brief tbm_bo_handle abstraction of the memory handle by TBM_DEVICE_TYPE
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef union _tbm_bo_handle
 {
@@ -142,7 +140,7 @@ typedef union _tbm_bo_handle
 
 /**
  * @brief Enumeration of bo memory type
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 enum TBM_BO_FLAGS
 {
@@ -160,9 +158,23 @@ enum TBM_BO_FLAGS
  */
 typedef enum
 {
-    TBM_ERROR_NONE  = TIZEN_ERROR_NONE,                    /**< Successful */
-    TBM_ERROR_BO_LOCK_FAILED  = TIZEN_ERROR_TBM|0x0101,    /**< tbm_bo lock failed */
-    TBM_ERROR_BO_MAP_FAILED  = TIZEN_ERROR_TBM|0x0102,     /**< tbm_bo map failed */
+    TBM_ERROR_NONE  = 0,                    /**< Successful */
+    TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE|0x0101,       /**< failed to get fd failed */
+    TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_BASE|0x0102,   /**< failed to allocate the heap memory */
+    TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE|0x0103,  /**< failed to load module*/
+    TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE|0x0104,  /**< failed to initialize the pthread */
+    TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_BASE|0x0105,     /**< failed to allocate tbm_bo */
+    TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE|0x0106,   /**< failed to initialize the state of tbm_bo */
+    TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE|0x0107,       /**< failed to import the handle of tbm_bo */
+    TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE|0x0108,    /**< failed to import fd of tbm_bo */
+    TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE|0x0109,       /**< failed to export the handle of the tbm_bo */
+    TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE|0x01010,   /**< failed to export fd of tbm_bo */
+    TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE|0x0111,   /**< failed to get the tbm_bo_handle */
+    TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE|0x0112,         /**< failed to lock the tbm_bo */
+    TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE|0x0113,          /**< failed to map the tbm_bo to get the tbm_bo_handle */
+    TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE|0x0114,        /**< failed to unmap the tbm_bo */
+    TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE|0x0115,         /**< failed to swap the tbm_bos */
+    TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE|0x0116,       /**< failed to duplicate fd */
 } tbm_error_e;
 
 
@@ -185,7 +197,7 @@ extern "C" {
  * BUFMGR_MAP_CACHE default is true\n
  * true : use map cache flushing\n
  * false : to use map cache flushing
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] fd : file descripter of the system buffer manager
  * @return a buffer manager
  * @retval #tbm_bufmgr
@@ -211,7 +223,7 @@ tbm_bufmgr tbm_bufmgr_init   (int fd);
 
 /**
  * @brief Deinitializes the buffer manager.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bufmgr : the buffer manager
  * @see tbm_bufmgr_init()
  * @par Example
@@ -220,7 +232,13 @@ tbm_bufmgr tbm_bufmgr_init   (int fd);
 
    int bufmgr_fd;
    tbm_bufmgr bufmgr;
+   tbm_error_e error;
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
+   if (!bufmgr)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
 
    ....
 
@@ -240,7 +258,7 @@ void       tbm_bufmgr_deinit (tbm_bufmgr bufmgr);
  * #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bufmgr : the buffer manager
  * @param[in] size : the size of buffer object
  * @param[in] flags : the flags of memory type
@@ -253,9 +271,15 @@ void       tbm_bufmgr_deinit (tbm_bufmgr bufmgr);
    int bufmgr_fd;
    tbm_bufmgr bufmgr;
    tbm_bo;
+   tbm_error_e error;
 
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
    bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+   if (!bo)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
 
    ....
 
@@ -266,7 +290,7 @@ tbm_bo        tbm_bo_alloc      (tbm_bufmgr bufmgr, int size, int flags);
 
 /**
  * @brief Increases the reference count of bo.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @return a buffer object
  * @retval #tbm_bo
@@ -295,7 +319,7 @@ tbm_bo        tbm_bo_ref        (tbm_bo bo);
 
 /**
  * @brief Decreases the reference count of bo
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @see tbm_bo_ref()
  * @see tbm_bo_alloc()
@@ -333,7 +357,7 @@ void          tbm_bo_unref      (tbm_bo bo);
  * #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @param[in] device : the device type to get a handle
  * @param[in] opt : the option to access the buffer object
@@ -361,7 +385,7 @@ void          tbm_bo_unref      (tbm_bo bo);
    handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
    if (handle.ptr == NULL)
    {
-      error = get_last_result ();
+      error = tbm_get_last_error ();
       ...
    }
 
@@ -376,7 +400,7 @@ tbm_bo_handle tbm_bo_map        (tbm_bo bo, int device, int opt);
 
 /**
  * @brief Unmaps the buffer object.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @return 1 if this function succeeds, otherwise 0.
  * @see tbm_bo_map()
@@ -414,7 +438,7 @@ int           tbm_bo_unmap      (tbm_bo bo);
  * #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @param[in] device : the device type to get a handle
  * @return the handle of the buffer object
@@ -427,6 +451,7 @@ int           tbm_bo_unmap      (tbm_bo bo);
    tbm_bufmgr bufmgr;
    tbm_bo bo;
    tbm_bo_handle handle;
+   tbm_error_e error;
 
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
    bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
@@ -434,6 +459,11 @@ int           tbm_bo_unmap      (tbm_bo bo);
    ...
 
    handle = tbm_bo_get_handle (bo, TBM_DEVICE_2D);
+   if (handle.ptr == NULL)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
 
    ...
 
@@ -446,7 +476,7 @@ tbm_bo_handle tbm_bo_get_handle (tbm_bo bo, int device);
 /**
  * @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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @return key associated with the buffer object
  * @retval #tbm_key
@@ -459,10 +489,16 @@ tbm_bo_handle tbm_bo_get_handle (tbm_bo bo, int device);
    tbm_bufmgr bufmgr;
    tbm_bo;
    tbm_key key;
+   tbm_error_e error;
 
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
    bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
    key = tbm_bo_export (bo);
+   if (key == 0)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
 
    ...
 
@@ -475,7 +511,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @return fd associated with the buffer object
  * @retval #tbm_fd
@@ -488,10 +524,16 @@ tbm_key  tbm_bo_export     (tbm_bo bo);
    tbm_fd bo_fd;
    tbm_bufmgr bufmgr;
    tbm_bo;
+   tbm_error_e error;
 
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
    bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
    bo_fd = tbm_bo_export (bo);
+   if (bo_fd == 0)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
 
    ...
 
@@ -504,7 +546,7 @@ tbm_fd tbm_bo_export_fd (tbm_bo bo);
 /**
  * @brief Imports the buffer object associated with the key.
  * @details The reference count of the tbm_bo is 1.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bufmgr : the buffer manager
  * @param[in] key : the key associated with the buffer object
  * @return a buffer object
@@ -518,11 +560,17 @@ tbm_fd tbm_bo_export_fd (tbm_bo bo);
    int bo_key;
    tbm_bufmgr bufmgr;
    tbm_bo;
+   tbm_error_e error;
 
    ...
 
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
    bo = tbm_bo_import (key);
+   if (bo == NULL)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
 
    ...
 
@@ -535,7 +583,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bufmgr : the buffer manager
  * @param[in] fd : the fd associated with the buffer object
  * @return a buffer object
@@ -549,11 +597,17 @@ tbm_bo        tbm_bo_import     (tbm_bufmgr bufmgr, tbm_key key);
    tbm_fd bo_fd;
    tbm_bufmgr bufmgr;
    tbm_bo bo;
+   tbm_error_e error;
 
    ...
 
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
-   bo = tbm_bo_import_fd (bo_fd);
+   bo_fd = tbm_bo_import_fd (bo_fd);
+   if (bo_fd == 0)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
 
    ...
 
@@ -565,7 +619,7 @@ tbm_bo        tbm_bo_import_fd  (tbm_bufmgr bufmgr, tbm_fd fd);
 
 /**
  * @brief Gets the size of a bo.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @return 1 if this function succeeds, otherwise 0.
  * @see tbm_bo_alloc()
@@ -592,7 +646,7 @@ int           tbm_bo_size       (tbm_bo bo);
 
 /**
  * @brief Gets the state where the buffer object is locked.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @return 1 if this bo is locked, otherwise 0.
  * @see tbm_bo_map()
@@ -623,7 +677,7 @@ int           tbm_bo_locked     (tbm_bo bo);
 
 /**
  * @brief Swaps the buffer object.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo1 : the buffer object
  * @param[in] bo2 : the buffer object
  * @return 1 if this function succeeds, otherwise 0.
@@ -636,6 +690,7 @@ int           tbm_bo_locked     (tbm_bo bo);
    tbm_bo bo1;
    tbm_bo bo2;
    int ret;
+   tbm_error_e error;
 
    bufmgr = tbm_bufmgr_init (bufmgr_fd);
    bo1 = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
@@ -644,6 +699,11 @@ int           tbm_bo_locked     (tbm_bo bo);
    ...
 
    ret = tbm_bo_swap (bo1, bo2);
+   if (ret == 0)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
 
    ...
 
@@ -657,7 +717,7 @@ int           tbm_bo_swap       (tbm_bo bo1, tbm_bo bo2);
 
 /**
  * @brief Called when the user data is deleted in buffer object.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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.
@@ -668,7 +728,7 @@ typedef void (*tbm_data_free)(void *user_data);
 
 /**
  * @brief Adds a user_data to the buffer object.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @param[in] key : the key associated with the user_data
  * @param[in] data_free_func : the function pointer to free the user_data
@@ -723,7 +783,7 @@ int tbm_bo_add_user_data    (tbm_bo bo, unsigned long key, tbm_data_free data_fr
 
 /**
  * @brief Deletes the user_data in the buffer object.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @param[in] key : the key associated with the user_date
  * @return 1 if this function succeeds, otherwise 0.
@@ -774,7 +834,7 @@ int tbm_bo_delete_user_data (tbm_bo bo, unsigned long key);
 
 /**
  * @brief Sets a user_date to the buffer object.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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
@@ -826,7 +886,7 @@ int tbm_bo_set_user_data    (tbm_bo bo, unsigned long key, void* data);
 
 /**
  * @brief Gets a user_data from the buffer object with the key.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bo : the buffer object
  * @param[in] key : the key associated with the user_date
  * @param[out] data : to get the user data
@@ -876,6 +936,46 @@ int tbm_bo_set_user_data    (tbm_bo bo, unsigned long key, void* data);
  */
 int tbm_bo_get_user_data    (tbm_bo bo, unsigned long key, void** data);
 
+/**
+ * @brief Gets the latest tbm_error.
+ * @since_tizen 2.4
+ * @return the latest tbm_error
+ * @par Example
+   @code
+   #include <tbm_bufmgr.h>
+
+   int bufmgr_fd;
+   tbm_bufmgr bufmgr;
+   tbm_bo bo;
+   tbm_bo_handle handle;
+   tbm_error_e error;
+
+   bufmgr = tbm_bufmgr_init (bufmgr_fd);
+   bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+   if (!bo)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
+
+   ...
+
+   handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
+   if (handle.ptr == NULL)
+   {
+      error = tbm_get_last_error ();
+      ...
+   }
+
+   ...
+
+   tbm_bo_unmap (bo);
+   tbm_bo_unref (bo);
+   tbm_bufmgr_deinit (bufmgr);
+   @endcode
+ */
+tbm_error_e tbm_get_last_error    (void);
+
 #ifdef __cplusplus
 }
 #endif
index 462103b..18fed8c 100644 (file)
@@ -93,20 +93,6 @@ tbm_backend_init (tbm_bufmgr bufmgr, tbm_bufmgr_backend backend)
         }
     }
 
-    /* log for tbm flags */
-    TBM_LOG ("[libtbm:%d] ", getpid());
-    TBM_LOG ("cache_crtl:");
-    if (flags&TBM_CACHE_CTRL_BACKEND)
-        TBM_LOG ("BACKEND ");
-    else
-        TBM_LOG ("TBM ");
-    TBM_LOG ("lock_crtl:");
-    if (flags&TBM_LOCK_CTRL_BACKEND)
-        TBM_LOG ("BACKEND ");
-    else
-        TBM_LOG ("TBM ");
-    TBM_LOG ("\n");
-
     bufmgr->backend = backend;
 
     return 1;
@@ -120,6 +106,14 @@ tbm_backend_get_bufmgr_priv (tbm_bo bo)
     return backend->priv;
 }
 
+void *
+tbm_backend_get_priv_from_bufmgr (tbm_bufmgr bufmgr)
+{
+    tbm_bufmgr_backend backend = bufmgr->backend;
+
+    return backend->priv;
+}
+
 void
 tbm_backend_set_bo_priv (tbm_bo bo, void *bo_priv)
 {
index 3e3150f..91a1532 100644 (file)
@@ -250,6 +250,15 @@ struct _tbm_bufmgr_backend
     */
     tbm_fd             (*bo_export_fd)         (tbm_bo bo);
 
+    /**
+    * @brief get the tbm_bo_handle according to the device type and the prime fd.
+    * @param[in] bufmgr : the tizen buffer manager
+    * @param[in] fd : the prime fd associated with the buffer object
+    * @param[in] device : the option to access the buffer object
+    * @return the handle of the buffer object
+    */
+    tbm_bo_handle   (*fd_to_handle)  (tbm_bufmgr bufmgr, tbm_fd fd, int device);
+
     /* Padding for future extension */
     void (*reserved1)    (void);
     void (*reserved2)    (void);
@@ -289,6 +298,7 @@ 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_priv_from_bufmgr (tbm_bufmgr bufmgr);
 void *tbm_backend_get_bo_priv     (tbm_bo bo);
 
 #endif  /* _TBM_BUFMGR_BACKEND_H_ */
index 74b16d7..618a434 100644 (file)
@@ -140,6 +140,8 @@ struct _tbm_bo
     void *priv; /* bo private */
 
     struct list_head item_link; /* link of bo */
+
+    tbm_bo_handle default_handle; /*default handle */
 };
 
 /**
@@ -191,4 +193,11 @@ struct _tbm_surface {
 int tbm_bufmgr_get_drm_fd_x11(void);
 int tbm_bufmgr_get_drm_fd_wayland(void);
 
+/* functions for mutex */
+int          tbm_surface_internal_get_info (tbm_surface_h surface, int opt, tbm_surface_info_s *info, int map);
+void         tbm_surface_internal_unmap (tbm_surface_h surface);
+unsigned int tbm_surface_internal_get_width (tbm_surface_h surface);
+unsigned int tbm_surface_internal_get_height (tbm_surface_h surface);
+tbm_format   tbm_surface_internal_get_format (tbm_surface_h surface);
+
 #endif  /* _TBM_BUFMGR_INT_H_ */
index 95dd515..e0f9865 100644 (file)
@@ -1,34 +1,33 @@
 /**************************************************************************
-
-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.
-
-**************************************************************************/
-
+ *
+ * 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_TGL_H__
 #define __TBM_BUFMGR_TGL_H__
index fb9c710..db05c32 100644 (file)
@@ -34,50 +34,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #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)
 {
@@ -133,10 +89,9 @@ 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);
+    ret = tbm_surface_internal_get_info (surface, opt, info, 1);
     if (ret == 0)
         return TBM_SURFACE_ERROR_INVALID_OPERATION;
 
@@ -148,11 +103,7 @@ 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]);
+    tbm_surface_internal_unmap(surface);
 
     return TBM_SURFACE_ERROR_NONE;
 }
@@ -163,10 +114,9 @@ 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);
+    ret = tbm_surface_internal_get_info (surface, 0, info, 0);
     if (ret == 0)
         return TBM_SURFACE_ERROR_INVALID_OPERATION;
 
@@ -178,9 +128,7 @@ 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;
+    return tbm_surface_internal_get_width(surface);
 }
 
 int
@@ -188,9 +136,7 @@ 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;
+    return tbm_surface_internal_get_height(surface);
 }
 
 tbm_format
@@ -204,11 +150,9 @@ tbm_surface_get_format (tbm_surface_h surface)
         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;
+    return tbm_surface_internal_get_format(surface);
 }
 
index 1553c44..43dfc6c 100644 (file)
@@ -48,7 +48,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 /**
  * @brief Enumeration for tbm_surface error type.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef enum
 {
@@ -59,25 +59,25 @@ typedef enum
 
 /**
  * @brief Definition for the max number of TBM surface plane.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_SURF_PLANE_MAX 4
 
 /* option to map the tbm_surface */
 /**
  * @brief Definition for the access option to read.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_SURF_OPTION_READ      (1 << 0)
 /**
  * @brief Definition for the access option to write.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_SURF_OPTION_WRITE     (1 << 1)
 
 /**
  * @brief Definition for the TBM plane struct.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef struct _tbm_surface_plane
 {
@@ -93,7 +93,7 @@ typedef struct _tbm_surface_plane
 
 /**
  * @brief Definition for the TBM surface information struct.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef struct _tbm_surface_info
 {
@@ -117,240 +117,240 @@ typedef struct _tbm_surface_info
 /* color index */
 /**
  * @brief Definition for the TBM surface format C8 ([7:0] C).
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_FORMAT_AYUV     __tbm_fourcc_code('A', 'Y', 'U', 'V')
 
@@ -363,22 +363,22 @@ typedef struct _tbm_surface_info
  */
 /**
  * @brief Definition for the TBM surface format NV12 (2x2 subsampled Cr:Cb plane).
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_FORMAT_NV61     __tbm_fourcc_code('N', 'V', '6', '1')
 
@@ -397,47 +397,47 @@ typedef struct _tbm_surface_info
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 #define TBM_FORMAT_YVU444   __tbm_fourcc_code('Y', 'V', '2', '4')
 
@@ -447,7 +447,7 @@ extern "C" {
 
 /**
  * @brief Queries surface format list and number of format supported by the system.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @remarks You must release the formats using free().
  *
@@ -487,7 +487,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
  *
@@ -523,7 +523,7 @@ tbm_surface_h tbm_surface_create (int width, int height, tbm_format format);
 
 /**
  * @brief Destroys the tbm_surface.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] surface  The #tbm_surface_h
  *
@@ -558,7 +558,7 @@ int tbm_surface_destroy (tbm_surface_h surface);
  *          #TBM_SURF_OPTION_READ indicates access option to read. \n
  *          #TBM_SURF_OPTION_WRITE indicates access option to write.
  *
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]  surface  The #tbm_surface_h
  * @param[in]  opt      The option to access the tbm_surface
@@ -594,7 +594,7 @@ int tbm_surface_map (tbm_surface_h surface, int opt, tbm_surface_info_s *info);
 
 /**
  * @brief Unmaps the tbm_surface.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] surface  The #tbm_surface_h
  *
@@ -631,7 +631,7 @@ int tbm_surface_unmap (tbm_surface_h surface);
  *          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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in]   surface  The #tbm_surface_h
  * @param[out]  info     The information of the tbm_surface
@@ -665,7 +665,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] surface  The #tbm_surface_h
  *
@@ -696,7 +696,7 @@ int tbm_surface_get_width (tbm_surface_h surface);
 
 /**
  * @brief Gets the height of the tbm_surface.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @param[in] surface  The #tbm_surface_h
  *
@@ -727,7 +727,7 @@ int tbm_surface_get_height (tbm_surface_h surface);
 
 /**
  * @brief Gets the format of the tbm_surface.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
  * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section.
  *
index fef8118..8fb9cc4 100644 (file)
@@ -38,7 +38,122 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 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)
+static pthread_mutex_t tbm_surface_lock;
+
+static bool
+_tbm_surface_mutex_init (void)
+{
+    static bool tbm_surface_mutex_init = false;
+
+    if (tbm_surface_mutex_init)
+        return true;
+
+    if (pthread_mutex_init (&tbm_surface_lock, NULL))
+    {
+        TBM_LOG ("[libtbm] fail: tbm_surface mutex init\n");
+        return false;
+    }
+
+    tbm_surface_mutex_init = true;
+
+    return true;
+}
+
+void
+_tbm_surface_mutex_lock (void)
+{
+    if (!_tbm_surface_mutex_init ())
+        return;
+
+    pthread_mutex_lock (&tbm_surface_lock);
+}
+
+void
+_tbm_surface_mutex_unlock (void)
+{
+    pthread_mutex_unlock (&tbm_surface_lock);
+}
+
+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;
+}
+
+static int
+_tbm_surface_internal_query_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);
+
+    size = mgr->backend->surface_get_size (surf, surf->info.width, surf->info.height, surf->info.format);
+
+    return size;
+}
+
+static int
+_tbm_surface_internal_query_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);
+
+    ret = mgr->backend->surface_get_plane_data (surf, surf->info.width, surf->info.height, surf->info.format, plane_idx, size, offset, pitch);
+    if (!ret)
+        return 0;
+
+    return 1;
+}
+
+int
+tbm_surface_internal_query_supported_formats (uint32_t **formats, uint32_t *num)
+{
+    struct _tbm_bufmgr *mgr;
+    int ret = 0;
+
+    _tbm_surface_mutex_lock();
+
+    if (!g_surface_bufmgr)
+    {
+        _init_surface_bufmgr();
+        LIST_INITHEAD (&g_surface_list);
+    }
+
+    mgr = g_surface_bufmgr;
+    ret = mgr->backend->surface_supported_format (formats, num);
+
+    _tbm_surface_mutex_unlock();
+
+    return ret;
+}
+
+int tbm_surface_internal_get_num_planes (tbm_format format)
 {
     int num_planes = 0;
 
@@ -116,8 +231,7 @@ static int _tbm_surface_internal_get_num_planes (tbm_format format)
     return num_planes;
 }
 
-
-static int _tbm_surface_internal_get_bpp (tbm_format format)
+int tbm_surface_internal_get_bpp (tbm_format format)
 {
     int bpp = 0;
 
@@ -208,43 +322,6 @@ static int _tbm_surface_internal_get_bpp (tbm_format format)
     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)
@@ -252,39 +329,46 @@ tbm_surface_internal_create_with_flags (int width, int height, int format, int f
     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_bufmgr *mgr;
     struct _tbm_surface *surf = NULL;
     uint32_t size = 0;
     uint32_t offset = 0;
     uint32_t stride = 0;
     int i;
 
+    _tbm_surface_mutex_lock();
+
+    if (!g_surface_bufmgr)
+    {
+        _init_surface_bufmgr();
+        LIST_INITHEAD (&g_surface_list);
+    }
+
+    mgr = g_surface_bufmgr;
+    if (!TBM_BUFMGR_IS_VALID(mgr))
+    {
+        _tbm_surface_mutex_unlock();
+        return NULL;
+    }
     surf = calloc (1, sizeof(struct _tbm_surface));
     if (!surf)
+    {
+        _tbm_surface_mutex_unlock();
         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);
+    surf->info.bpp = tbm_surface_internal_get_bpp (format);
+    surf->info.size = _tbm_surface_internal_query_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);
+        _tbm_surface_internal_query_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;
@@ -304,21 +388,29 @@ tbm_surface_internal_create_with_flags (int width, int height, int format, int f
         {
             _deinit_surface_bufmgr ();
             LIST_DELINIT (&g_surface_list);
+            _tbm_surface_mutex_unlock();
             return NULL;
         }
     }
 
     LIST_ADD (&surf->item_link, &g_surface_list);
 
+    _tbm_surface_mutex_unlock();
+
     return surf;
 }
 
 tbm_surface_h
-tbm_surface_internal_create_with_bos (int width, int height, int format, tbm_bo *bos, int num)
+tbm_surface_internal_create_with_bos (tbm_surface_info_s *info, 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);
+    TBM_RETURN_VAL_IF_FAIL (info, NULL);
+
+    struct _tbm_bufmgr *mgr;
+    struct _tbm_surface *surf = NULL;
+    int i;
+
+    _tbm_surface_mutex_lock();
 
     if (!g_surface_bufmgr)
     {
@@ -326,36 +418,33 @@ tbm_surface_internal_create_with_bos (int width, int height, int format, tbm_bo
         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;
-
+    mgr = g_surface_bufmgr;
+    if (!TBM_BUFMGR_IS_VALID(mgr))
+    {
+        _tbm_surface_mutex_unlock();
+        return NULL;
+    }
     surf = calloc (1, sizeof(struct _tbm_surface));
     if (!surf)
+    {
+        _tbm_surface_mutex_unlock();
         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);
+    surf->info.width = info->width;
+    surf->info.height = info->height;
+    surf->info.format = info->format;
+    surf->info.bpp = info->bpp;
+    surf->info.size = info->size;
+    surf->info.num_planes = info->num_planes;
 
     /* get size, stride and offset */
-    for (i = 0; i < surf->info.num_planes; i++)
+    for (i = 0; i < 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->info.planes[i].size = info->planes[i].size;
+        surf->info.planes[i].offset = info->planes[i].offset;
+        surf->info.planes[i].stride = info->planes[i].stride;
     }
 
     surf->flags = TBM_BO_DEFAULT;
@@ -372,6 +461,8 @@ tbm_surface_internal_create_with_bos (int width, int height, int format, tbm_bo
 
     LIST_ADD (&surf->item_link, &g_surface_list);
 
+    _tbm_surface_mutex_unlock();
+
     return surf;
 bail1:
     for (i = 0; i < num; i++)
@@ -392,6 +483,8 @@ bail1:
         LIST_DELINIT (&g_surface_list);
     }
 
+    _tbm_surface_mutex_unlock();
+
     return NULL;
 }
 
@@ -404,6 +497,8 @@ tbm_surface_internal_destroy (tbm_surface_h surface)
     if (!surface)
         return;
 
+    _tbm_surface_mutex_lock();
+
     surface = (struct _tbm_surface *)surface;
 
     for (i = 0; i < surface->num_bos; i++)
@@ -422,6 +517,8 @@ tbm_surface_internal_destroy (tbm_surface_h surface)
         _deinit_surface_bufmgr ();
         LIST_DELINIT (&g_surface_list);
     }
+
+    _tbm_surface_mutex_unlock();
 }
 
 
@@ -430,9 +527,17 @@ 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;
+    struct _tbm_surface *surf;
+    int num;
+
+    _tbm_surface_mutex_lock();
+
+    surf = (struct _tbm_surface *) surface;
+    num = surf->num_bos;
 
-    return surf->num_bos;
+    _tbm_surface_mutex_unlock();
+
+    return num;
 }
 
 tbm_bo
@@ -441,9 +546,17 @@ 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;
+    struct _tbm_surface *surf;
+    tbm_bo bo;
+
+    _tbm_surface_mutex_lock();
+
+    surf = (struct _tbm_surface *) surface;
+    bo = surf->bos[bo_idx];
 
-    return surf->bos[bo_idx];
+    _tbm_surface_mutex_unlock();
+
+    return bo;
 }
 
 int
@@ -451,20 +564,15 @@ 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;
+    struct _tbm_surface *surf;
+    unsigned int size;
 
-    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);
+    _tbm_surface_mutex_lock();
 
-    pthread_mutex_lock (&mgr->lock);
+    surf = (struct _tbm_surface *) surface;
+    size = surf->info.size;
 
-    size = mgr->backend->surface_get_size (surf, surf->info.width, surf->info.height, surf->info.format);
-
-    pthread_mutex_unlock (&mgr->lock);
+    _tbm_surface_mutex_unlock();
 
     return size;
 }
@@ -475,28 +583,146 @@ tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, uint3
     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;
+    struct _tbm_surface *surf;
 
-    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);
+    _tbm_surface_mutex_lock();
 
-    pthread_mutex_lock (&mgr->lock);
+    surf = (struct _tbm_surface *) surface;
 
-    ret = mgr->backend->surface_get_plane_data (surf, surf->info.width, surf->info.height, surf->info.format, plane_idx, size, offset, pitch);
-    if (!ret)
+    if (plane_idx >= surf->info.num_planes)
     {
-        pthread_mutex_unlock (&mgr->lock);
+        _tbm_surface_mutex_unlock();
         return 0;
     }
 
-    pthread_mutex_unlock (&mgr->lock);
+    *size = surf->info.planes[plane_idx].size;
+    *offset = surf->info.planes[plane_idx].offset;
+    *pitch = surf->info.planes[plane_idx].stride;
+
+    _tbm_surface_mutex_unlock();
+
+    return 1;
+}
+
+int
+tbm_surface_internal_get_info (tbm_surface_h surface, int opt, tbm_surface_info_s *info, int map)
+{
+    struct _tbm_surface *surf;
+    tbm_bo_handle bo_handles[4];
+    int i;
+
+    _tbm_surface_mutex_lock();
+
+    surf = (struct _tbm_surface *)surface;
+
+    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)
+            {
+                _tbm_surface_mutex_unlock();
+                return 0;
+            }
+        }
+        else
+        {
+            bo_handles[0] = tbm_bo_get_handle (surf->bos[0], TBM_DEVICE_CPU);
+            if (bo_handles[0].ptr == NULL)
+            {
+                _tbm_surface_mutex_unlock();
+                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 */
+    }
+
+    _tbm_surface_mutex_unlock();
 
     return 1;
 }
 
+void
+tbm_surface_internal_unmap (tbm_surface_h surface)
+{
+    struct _tbm_surface *surf;
+    int i;
+
+    _tbm_surface_mutex_lock();
+
+    surf = (struct _tbm_surface *)surface;
+
+    for (i = 0; i < surf->num_bos; i++)
+        tbm_bo_unmap (surf->bos[i]);
+
+    _tbm_surface_mutex_unlock();
+}
+
+unsigned int
+tbm_surface_internal_get_width (tbm_surface_h surface)
+{
+    struct _tbm_surface *surf;
+    unsigned int width;
+
+    _tbm_surface_mutex_lock();
+
+    surf = (struct _tbm_surface *)surface;
+    width = surf->info.width;
+
+    _tbm_surface_mutex_unlock();
+
+    return width;
+}
+
+unsigned int
+tbm_surface_internal_get_height (tbm_surface_h surface)
+{
+    struct _tbm_surface *surf;
+    unsigned int height;
+
+    _tbm_surface_mutex_lock();
+
+    surf = (struct _tbm_surface *)surface;
+    height = surf->info.height;
+
+    _tbm_surface_mutex_unlock();
+
+    return height;
+
+}
+
+tbm_format
+tbm_surface_internal_get_format (tbm_surface_h surface)
+{
+    struct _tbm_surface *surf;
+    tbm_format format;
+
+    _tbm_surface_mutex_lock();
+
+    surf = (struct _tbm_surface *)surface;
+    format = surf->info.format;
 
+    _tbm_surface_mutex_unlock();
+
+    return format;
+}
 
index 68a2233..242fd54 100644 (file)
@@ -41,7 +41,7 @@ extern "C" {
 
 /**
  * @brief Queries formats which the system can support.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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.
@@ -69,7 +69,7 @@ int tbm_surface_internal_query_supported_formats (uint32_t **formats, uint32_t *
 
 /**
  * @brief Creates the tbm_surface with memory type.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @details
  * #TBM_BO_DEFAULT is default memory: it depends on the backend\n
  * #TBM_BO_SCANOUT is scanout memory\n
@@ -95,7 +95,7 @@ int tbm_surface_internal_query_supported_formats (uint32_t **formats, uint32_t *
    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);
+   surface = tbm_surface_internal_create_with_flags (128, 128, TBM_FORMAT_YUV420, TBM_BO_DEFAULT);
 
    ...
 
@@ -107,7 +107,7 @@ tbm_surface_h tbm_surface_internal_create_with_flags (int width, int height, int
 
 /**
  * @brief Creates the tbm_surface with buffer objects.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] bufmgr : the buffer manager
  * @param[in] width  : the width of surface
  * @param[in] height : the height of surface
@@ -125,14 +125,25 @@ tbm_surface_h tbm_surface_internal_create_with_flags (int width, int height, int
    int bufmgr_fd
    tbm_bufmgr bufmgr;
    tbm_surface_h surface;
+   tbm_surface_info_s info;
    uint32_t *format;
    uint32_t format_num;
-   tbm_bo bo[2];
+   tbm_bo bo[1];
 
    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);
+   bo[0] = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
+
+   info.with = 128;
+   info.height = 128;
+   info.format = TBM_FORMAT_ARGB8888;
+   info.bpp = 32;
+   info.size = 65536;
+   info.num_planes = 1;
+   info.planes[0].size = 65536;
+   info.planes[0].offset = 0;
+   info.planes[0].stride = 512;
+
+   surface = tbm_surface_internal_create_with_bos (&info, bo, 1);
 
    ...
 
@@ -140,7 +151,7 @@ tbm_surface_h tbm_surface_internal_create_with_flags (int width, int height, int
    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);
+tbm_surface_h tbm_surface_internal_create_with_bos (tbm_surface_info_s *info, tbm_bo *bos, int num);
 
 
 /**
@@ -151,7 +162,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] surface : the tbm_surface_h
  * @return the number of buffer objects associated with the tbm_surface_h, otherwise -1.
  * @par Example
@@ -174,7 +185,7 @@ int tbm_surface_internal_get_num_bos (tbm_surface_h surface);
 
 /**
  * @brief Gets the buffor object by the bo_index.
- * @since_tizen 2.3
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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.
@@ -204,7 +215,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @param[in] surface : the tbm_surface_h
  * @return the size of tbm_surface, otherwise -1.
  * @par Example
@@ -225,7 +236,7 @@ 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
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  * @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
@@ -251,6 +262,46 @@ int tbm_surface_internal_get_size (tbm_surface_h surface);
  */
 int tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch);
 
+/**
+ * @brief Gets number of planes by the format.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] format : the format of surface
+ * @return number of planes by the format, otherwise 0.
+ * @par Example
+   @code
+   #include <tbm_surface.h>
+   #include <tbm_surface_internal.h>
+
+   int num;
+
+   num = tbm_surface_internal_get_num_planes (TBM_FORMAT_YUV420);
+
+   ...
+
+   @endcode
+ */
+int tbm_surface_internal_get_num_planes (tbm_format format);
+
+/**
+ * @brief Gets bpp by the format.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
+ * @param[in] format : the format of surface
+ * @return bpp by the format, otherwise 0.
+ * @par Example
+   @code
+   #include <tbm_surface.h>
+   #include <tbm_surface_internal.h>
+
+   int bpp;
+
+   bpp = tbm_surface_internal_get_bpp (TBM_FORMAT_YUV420);
+
+   ...
+
+   @endcode
+ */
+int tbm_surface_internal_get_bpp (tbm_format format);
+
 #ifdef __cplusplus
 }
 #endif
index b4057ff..51794c8 100644 (file)
@@ -42,10 +42,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 /**
  * @brief Definition for the Tizen buffer surface.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef struct _tbm_surface * tbm_surface_h;
 /**
  * @brief Definition for the Tizen buffer surface format.
+ * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  */
 typedef uint32_t tbm_format;