Add tbm surface user data 95/58795/3
authorChangyeon Lee <cyeon.lee@samsung.com>
Wed, 3 Feb 2016 10:28:48 +0000 (19:28 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Thu, 4 Feb 2016 01:20:43 +0000 (17:20 -0800)
Change-Id: I61318114dd59db0f3b9804906bf5ea47b55a4869
Signed-off-by: Changyeon Lee <cyeon.lee@samsung.com>
src/tbm_bufmgr.c
src/tbm_bufmgr_int.h
src/tbm_surface_internal.c
src/tbm_surface_internal.h
src/tbm_user_data.c [new file with mode: 0644]
src/tbm_user_data.h [new file with mode: 0644]

index 1c76a93..1d5f1ef 100644 (file)
@@ -36,6 +36,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "tbm_bufmgr_backend.h"
 #include "tbm_bufmgr_tgl.h"
 #include "list.h"
+#include "tbm_user_data.h"
 
 #define DEBUG
 #ifdef DEBUG
@@ -86,15 +87,6 @@ enum {
        DEVICE_CO                                       /* cache oblivious device */
 };
 
-typedef struct {
-       unsigned long key;
-       void *data;
-       tbm_data_free free_func;
-
-       /* link of user_data */
-       struct list_head item_link;
-} tbm_user_data;
-
 pthread_mutex_t gLock = PTHREAD_MUTEX_INITIALIZER;
 tbm_bufmgr gBufMgr = NULL;
 
@@ -253,49 +245,6 @@ static inline unsigned int _tgl_get_data(int fd, unsigned int key, unsigned int
 
        return arg.data1;
 }
-
-static tbm_user_data *_user_data_lookup(struct list_head *user_data_list, unsigned long key)
-{
-       tbm_user_data *user_data = NULL;
-       tbm_user_data *old_data = NULL, *tmp = NULL;
-
-       if (!LIST_IS_EMPTY(user_data_list)) {
-               LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, user_data_list, item_link) {
-                       if (old_data->key == key) {
-                               user_data = old_data;
-                               return user_data;
-                       }
-               }
-       }
-
-       return user_data;
-}
-
-static tbm_user_data *_user_data_create(unsigned long key, tbm_data_free data_free_func)
-{
-       tbm_user_data *user_data = NULL;
-
-       user_data = calloc(1, sizeof(tbm_user_data));
-       if (!user_data)
-               return NULL;
-
-       user_data->key = key;
-       user_data->free_func = data_free_func;
-       user_data->data = (void *)0;
-
-       return user_data;
-}
-
-static void _user_data_delete(tbm_user_data * user_data)
-{
-       if (user_data->data && user_data->free_func)
-               user_data->free_func(user_data->data);
-
-       LIST_DEL(&user_data->item_link);
-
-       free(user_data);
-}
-
 static int _bo_lock(tbm_bo bo, int device, int opt)
 {
        tbm_bufmgr bufmgr = bo->bufmgr;
@@ -591,7 +540,7 @@ static void _tbm_bo_unref(tbm_bo bo)
                        LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &bo->user_data_list, item_link) {
                                DBG("[libtbm:%d] free user_data \n",
                                        getpid());
-                               _user_data_delete(old_data);
+                               user_data_delete(old_data);
                        }
                }
 
@@ -1481,7 +1430,7 @@ int tbm_bo_add_user_data(tbm_bo bo, unsigned long key, tbm_data_free data_free_f
        tbm_user_data *data;
 
        /* check if the data according to the key exist if so, return false. */
-       data = _user_data_lookup(&bo->user_data_list, key);
+       data = user_data_lookup(&bo->user_data_list, key);
        if (data) {
                TBM_LOG("[libtbm:%d] "
                        "waring: %s:%d user data already exist. key:%ld\n",
@@ -1489,7 +1438,7 @@ int tbm_bo_add_user_data(tbm_bo bo, unsigned long key, tbm_data_free data_free_f
                return 0;
        }
 
-       data = _user_data_create(key, data_free_func);
+       data = user_data_create(key, data_free_func);
        if (!data)
                return 0;
 
@@ -1507,7 +1456,7 @@ int tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data)
        if (LIST_IS_EMPTY(&bo->user_data_list))
                return 0;
 
-       old_data = _user_data_lookup(&bo->user_data_list, key);
+       old_data = user_data_lookup(&bo->user_data_list, key);
        if (!old_data)
                return 0;
 
@@ -1528,7 +1477,7 @@ int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data)
        if (!data || LIST_IS_EMPTY(&bo->user_data_list))
                return 0;
 
-       old_data = _user_data_lookup(&bo->user_data_list, key);
+       old_data = user_data_lookup(&bo->user_data_list, key);
        if (!old_data) {
                *data = NULL;
                return 0;
@@ -1548,11 +1497,11 @@ int tbm_bo_delete_user_data(tbm_bo bo, unsigned long key)
        if (LIST_IS_EMPTY(&bo->user_data_list))
                return 0;
 
-       old_data = _user_data_lookup(&bo->user_data_list, key);
+       old_data = user_data_lookup(&bo->user_data_list, key);
        if (!old_data)
                return 0;
 
-       _user_data_delete(old_data);
+       user_data_delete(old_data);
 
        return 1;
 }
index 816a18f..c78207b 100644 (file)
@@ -197,6 +197,8 @@ struct _tbm_surface {
        unsigned int debug_pid;
 
        struct list_head item_link; /* link of surface */
+
+       struct list_head user_data_list;        /* list of the user_date in surface */
 };
 
 int tbm_bufmgr_get_drm_fd_x11(void);
@@ -213,5 +215,4 @@ tbm_format tbm_surface_internal_get_format(tbm_surface_h surface);
 unsigned int _tbm_surface_internal_get_debug_pid(tbm_surface_h surface);
 char * _tbm_surface_internal_format_to_str(tbm_format format);
 
-
 #endif                                                 /* _TBM_BUFMGR_INT_H_ */
index bc59750..30e235f 100644 (file)
@@ -34,6 +34,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "tbm_bufmgr_int.h"
 #include "tbm_surface_internal.h"
 #include "list.h"
+#include "tbm_user_data.h"
 
 static tbm_bufmgr g_surface_bufmgr = NULL;
 static pthread_mutex_t tbm_surface_lock;
@@ -275,6 +276,7 @@ static void _tbm_surface_internal_destroy(tbm_surface_h surface)
 {
        int i;
        tbm_bufmgr bufmgr = surface->bufmgr;
+       tbm_user_data *old_data = NULL, *tmp = NULL;
 
        for (i = 0; i < surface->num_bos; i++) {
                surface->bos[i]->surface = NULL;
@@ -283,6 +285,15 @@ static void _tbm_surface_internal_destroy(tbm_surface_h surface)
                surface->bos[i] = NULL;
        }
 
+       /* destory the user_data_list */
+       if (!LIST_IS_EMPTY(&surface->user_data_list)) {
+               LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, &surface->user_data_list, item_link) {
+                       TBM_LOG("[tbm_surface:%d] free user_data \n",
+                               getpid());
+                       user_data_delete(old_data);
+               }
+       }
+
        LIST_DEL(&surface->item_link);
 
        free(surface);
@@ -950,3 +961,86 @@ void tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid)
        surface->debug_pid = pid;
 }
 
+int tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key, tbm_data_free data_free_func)
+{
+       TBM_RETURN_VAL_IF_FAIL(surface, 0);
+
+       tbm_user_data *data;
+
+       /* check if the data according to the key exist if so, return false. */
+       data = user_data_lookup(&surface->user_data_list, key);
+       if (data) {
+               TBM_LOG("[libtbm:%d] "
+                       "waring: %s:%d user data already exist. key:%ld\n",
+                       getpid(), __FUNCTION__, __LINE__, key);
+               return 0;
+       }
+
+       data = user_data_create(key, data_free_func);
+       if (!data)
+               return 0;
+
+       LIST_ADD(&data->item_link, &surface->user_data_list);
+
+       return 1;
+}
+
+int tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, void *data)
+{
+       TBM_RETURN_VAL_IF_FAIL(surface, 0);
+
+       tbm_user_data *old_data;
+
+       if (LIST_IS_EMPTY(&surface->user_data_list))
+               return 0;
+
+       old_data = user_data_lookup(&surface->user_data_list, key);
+       if (!old_data)
+               return 0;
+
+       if (old_data->data && old_data->free_func)
+               old_data->free_func(old_data->data);
+
+       old_data->data = data;
+
+       return 1;
+}
+
+int tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, void **data)
+{
+       TBM_RETURN_VAL_IF_FAIL(surface, 0);
+
+       tbm_user_data *old_data;
+
+       if (!data || LIST_IS_EMPTY(&surface->user_data_list))
+               return 0;
+
+       old_data = user_data_lookup(&surface->user_data_list, key);
+       if (!old_data) {
+               *data = NULL;
+               return 0;
+       }
+
+       *data = old_data->data;
+
+       return 1;
+}
+
+int tbm_surface_internal_delete_user_data(tbm_surface_h surface, unsigned long key)
+{
+       TBM_RETURN_VAL_IF_FAIL(surface, 0);
+
+       tbm_user_data *old_data = (void *)0;
+
+       if (LIST_IS_EMPTY(&surface->user_data_list))
+               return 0;
+
+       old_data = user_data_lookup(&surface->user_data_list, key);
+       if (!old_data)
+               return 0;
+
+       user_data_delete(old_data);
+
+       return 1;
+}
+
index 7944a18..8108faa 100644 (file)
@@ -344,6 +344,50 @@ int tbm_surface_internal_get_plane_bo_idx(tbm_surface_h surface, int plane_idx);
  */
 void tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid);
 
+/**
+ * @brief Adds a user_data to the tbm surface.
+ * @since_tizen 3.0
+ * @param[in] surface : the tbm surface.
+ * @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 the tbm_surface_data_free() will be called under certain conditions, after calling tbm_surface_internal_delete_user_data().
+ * @see tbm_surface_free()
+ * @see tbm_surface_set_user_data()
+ * @see tbm_surface_get_user_data()
+ * @see tbm_surface_delete_user_data()
+ */
+int tbm_surface_internal_add_user_data(tbm_surface_h surface, unsigned long key, tbm_data_free data_free_func);
+
+/**
+ * @brief Sets a user_date to the tbm surface.
+ * @since_tizen 3.0
+ * @param[in] surface : the tbm surface.
+ * @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.
+ */
+int tbm_surface_internal_set_user_data(tbm_surface_h surface, unsigned long key, void *data);
+
+/**
+ * @brief Gets a user_data from the tbm surface with the key.
+ * @since_tizen 3.0
+ * @param[in] surface : the tbm surface.
+ * @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.
+ */
+int tbm_surface_internal_get_user_data(tbm_surface_h surface, unsigned long key, void **data);
+
+/**
+ * @brief Deletes the user_data in the tbm surface.
+ * @since_tizen 3.0
+ * @param[in] surface : the tbm surface.
+ * @param[in] key : the key associated with the user_date
+ * @return 1 if this function succeeds, otherwise 0.
+ */
+int tbm_surface_internal_delete_user_data(tbm_surface_h surface, unsigned long key);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/tbm_user_data.c b/src/tbm_user_data.c
new file mode 100644 (file)
index 0000000..0ae9ba9
--- /dev/null
@@ -0,0 +1,76 @@
+/**************************************************************************
+
+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_user_data.h"
+
+tbm_user_data *user_data_lookup(struct list_head *user_data_list, unsigned long key)
+{
+       tbm_user_data *user_data = NULL;
+       tbm_user_data *old_data = NULL, *tmp = NULL;
+
+       if (!LIST_IS_EMPTY(user_data_list)) {
+               LIST_FOR_EACH_ENTRY_SAFE(old_data, tmp, user_data_list, item_link) {
+                       if (old_data->key == key) {
+                               user_data = old_data;
+                               return user_data;
+                       }
+               }
+       }
+
+       return user_data;
+}
+
+tbm_user_data *user_data_create(unsigned long key, tbm_data_free data_free_func)
+{
+       tbm_user_data *user_data = NULL;
+
+       user_data = calloc(1, sizeof(tbm_user_data));
+       if (!user_data)
+               return NULL;
+
+       user_data->key = key;
+       user_data->free_func = data_free_func;
+       user_data->data = (void *)0;
+
+       return user_data;
+}
+
+void user_data_delete(tbm_user_data * user_data)
+{
+       if (user_data->data && user_data->free_func)
+               user_data->free_func(user_data->data);
+
+       LIST_DEL(&user_data->item_link);
+
+       free(user_data);
+}
+
diff --git a/src/tbm_user_data.h b/src/tbm_user_data.h
new file mode 100644 (file)
index 0000000..9d6986e
--- /dev/null
@@ -0,0 +1,55 @@
+/**************************************************************************
+
+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_USER_DATA_H_
+#define _TBM_USER_DATA_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+typedef struct {
+       unsigned long key;
+       void *data;
+       tbm_data_free free_func;
+
+       /* link of user_data */
+       struct list_head item_link;
+} tbm_user_data;
+
+tbm_user_data *user_data_lookup(struct list_head *user_data_list, unsigned long key);
+tbm_user_data *user_data_create(unsigned long key, tbm_data_free data_free_func);
+void user_data_delete(tbm_user_data * user_data);
+
+#ifdef __cplusplus
+}
+#endif
+#endif                                                 /* _TBM_USER_DATA_H_ */
+