#include "tbm_bufmgr_backend.h"
#include "tbm_bufmgr_tgl.h"
#include "list.h"
+#include "tbm_user_data.h"
#define DEBUG
#ifdef DEBUG
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;
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;
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);
}
}
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",
return 0;
}
- data = _user_data_create(key, data_free_func);
+ data = user_data_create(key, data_free_func);
if (!data)
return 0;
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;
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;
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;
}
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);
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_ */
#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;
{
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;
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);
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;
+}
+
*/
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
--- /dev/null
+/**************************************************************************
+
+libtbm
+
+Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
+Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#include "config.h"
+#include "tbm_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);
+}
+
--- /dev/null
+/**************************************************************************
+
+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_ */
+