From: SooChan Lim Date: Fri, 5 Aug 2016 07:27:48 +0000 (+0900) Subject: add tbm_sync to support for the timeline and the fence X-Git-Tag: accepted/tizen/common/20160817.133106~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd7d9da0e96be112d1a4f18eb31a87747982d821;p=platform%2Fcore%2Fuifw%2Flibtbm.git add tbm_sync to support for the timeline and the fence There are two resources to manage the synchronization. two handle.. tbm_sync_timeline_h, tbm_sync_fence_h Change-Id: I680ce38370164d17c7b487400b9e29f1f5cac3f6 --- diff --git a/packaging/libtbm.spec b/packaging/libtbm.spec index c971fc3..da8f79b 100644 --- a/packaging/libtbm.spec +++ b/packaging/libtbm.spec @@ -99,5 +99,6 @@ rm -f %{_unitdir_user}/default.target.wants/tbm-drm-auth-user.path %{_includedir}/tbm_bufmgr_backend.h %{_includedir}/tbm_type.h %{_includedir}/tbm_drm_helper.h +%{_includedir}/tbm_sync.h %{_libdir}/libtbm.so %{_libdir}/pkgconfig/libtbm.pc diff --git a/src/Makefile.am b/src/Makefile.am index 7ead4f8..d40c7e4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,8 @@ libtbm_la_SOURCES = \ tbm_bufmgr_backend.c \ tbm_bufmgr.c \ tbm_drm_helper_server.c \ - tbm_drm_helper_client.c + tbm_drm_helper_client.c \ + tbm_sync.c nodist_libtbm_la_SOURCES = \ wayland-tbm-drm-auth-server-protocol.h \ @@ -38,6 +39,6 @@ nodist_libtbm_la_SOURCES = \ BUILT_SOURCES = $(nodist_libtbm_la_SOURCES) libtbmincludedir=$(includedir) -libtbminclude_HEADERS = tbm_bufmgr.h tbm_surface.h tbm_bufmgr_backend.h tbm_type.h tbm_surface_internal.h tbm_surface_queue.h tbm_drm_helper.h +libtbminclude_HEADERS = tbm_bufmgr.h tbm_surface.h tbm_bufmgr_backend.h tbm_type.h tbm_surface_internal.h tbm_surface_queue.h tbm_drm_helper.h tbm_sync.h CLEANFILES = $(BUILT_SOURCES) diff --git a/src/tbm_bufmgr.h b/src/tbm_bufmgr.h index 50fcf08..ff65efb 100644 --- a/src/tbm_bufmgr.h +++ b/src/tbm_bufmgr.h @@ -169,6 +169,7 @@ enum TBM_BUFMGR_CAPABILITY { TBM_BUFMGR_CAPABILITY_NONE = 0, /**< Not Support capability*/ TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1 << 0), /**< Support sharing buffer by tbm key */ TBM_BUFMGR_CAPABILITY_SHARE_FD = (1 << 1), /**< Support sharing buffer by tbm fd */ + TBM_BUFMGR_CAPABILITY_TBM_SYNC = (1 << 2), /**< Support tbm sync */ }; #ifdef __cplusplus diff --git a/src/tbm_sync.c b/src/tbm_sync.c new file mode 100644 index 0000000..569f69f --- /dev/null +++ b/src/tbm_sync.c @@ -0,0 +1,326 @@ +/************************************************************************** + +libtbm + +Copyright 2012 - 2016 Samsung Electronics co., Ltd. All Rights Reserved. + +Contact: SooChan Lim , + Changyeon Lee , + Boram Park , + Sangjin Lee + +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 "tbm_bufmgr.h" +#include "tbm_bufmgr_int.h" +#include "tbm_sync.h" + +static pthread_mutex_t tbm_sync_lock; +static int tbm_sync_support = 0; + +static bool +_tbm_sync_mutex_init(void) +{ + static bool tbm_sync_mutex_init = false; + + if (tbm_sync_mutex_init) + return true; + + if (pthread_mutex_init(&tbm_sync_lock, NULL)) { + TBM_LOG_E("fail: tbm_sync mutex init\n"); + return false; + } + + tbm_sync_mutex_init = true; + + return true; +} + +static void +_tbm_sync_mutex_lock(void) +{ + if (!_tbm_sync_mutex_init()) + return; + + pthread_mutex_lock(&tbm_sync_lock); +} + +static void +_tbm_sync_mutex_unlock(void) +{ + pthread_mutex_unlock(&tbm_sync_lock); +} + +static tbm_sync_error_e +_tbm_sync_check_capability(void) +{ + tbm_bufmgr bufmgr = NULL; + unsigned int capabilities = TBM_BUFMGR_CAPABILITY_NONE; + + if (tbm_sync_support) + return TBM_SYNC_ERROR_NONE; + + /* check the bufmgr */ + bufmgr = _tbm_bufmgr_get_bufmgr(); + if (!bufmgr) { + return TBM_SYNC_ERROR_INVALID_OPERATION; + } + + /* check the tbm_sync capability */ + capabilities = tbm_bufmgr_get_capability(bufmgr); + if ((capabilities&TBM_BUFMGR_CAPABILITY_TBM_SYNC) != TBM_BUFMGR_CAPABILITY_TBM_SYNC) { + //TODO: check the sw_sync device node... to verify the timeline sync + tbm_sync_support = 1; + + return TBM_SYNC_ERROR_INVALID_OPERATION; + } + + return TBM_SYNC_ERROR_NONE; +} + +tbm_sync_timeline_h +tbm_sync_timeline_create(tbm_sync_error_e *error) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + tbm_sync_timeline_h timeline = NULL; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_timeline_create */ + + +done: + if (error) + *error = ret; + + _tbm_sync_mutex_unlock(); + + return timeline; +} + +tbm_sync_error_e +tbm_sync_timeline_destroy(tbm_sync_timeline_h timeline) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_timeline_destroy */ + + +done: + _tbm_sync_mutex_unlock(); + + return ret; +} + +tbm_sync_timeline_h +tbm_sync_timeline_import(tbm_fd fd, tbm_sync_error_e *error) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + tbm_sync_timeline_h timeline = NULL; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_timeline_import */ + +done: + if (error) + *error = ret; + + _tbm_sync_mutex_unlock(); + + return timeline; +} + +tbm_sync_error_e +tbm_sync_timeline_increase_count(tbm_sync_timeline_h timeline, unsigned int interval) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_timeline_increase_count */ + +done: + _tbm_sync_mutex_unlock(); + + return ret; +} + +unsigned int +tbm_sync_timeline_get_cur_count(tbm_sync_timeline_h timeline, tbm_sync_error_e *error) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + unsigned int cur_count = 0; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_timeline_get_cur_count */ + +done: + if (error) + *error = ret; + + _tbm_sync_mutex_unlock(); + + return cur_count; +} + +tbm_sync_fence_h +tbm_sync_fence_create(tbm_sync_timeline_h timeline, const char *name, unsigned int count_val, tbm_sync_error_e *error) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + tbm_sync_fence_h fence = NULL; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_fence_create */ + +done: + if (error) + *error = ret; + + _tbm_sync_mutex_unlock(); + + return fence; +} + +tbm_sync_error_e +tbm_sync_fence_destroy(tbm_sync_fence_h fence) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_fence_destroy */ + +done: + _tbm_sync_mutex_unlock(); + + return ret; +} + +tbm_sync_error_e +tbm_sync_fence_wait(tbm_sync_fence_h fence, int timeout) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_fence_wait */ + +done: + _tbm_sync_mutex_unlock(); + + return ret; +} + +tbm_sync_fence_h +tbm_sync_fence_merge(tbm_sync_fence_h fence1, tbm_sync_fence_h fence2, const char *name, tbm_sync_error_e *error) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + tbm_sync_fence_h fence = NULL; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: tbm_sync_fence_merge */ + +done: + if (error) + *error = ret; + + _tbm_sync_mutex_unlock(); + + return fence; +} + +unsigned int +tbm_sync_fence_get_count_val(tbm_sync_fence_h fence, tbm_sync_error_e *error) +{ + tbm_sync_error_e ret = TBM_SYNC_ERROR_NONE; + unsigned int count_val = 0; + + _tbm_sync_mutex_lock(); + + /* check the tbm_sync capability */ + ret = _tbm_sync_check_capability();; + if (ret != TBM_SYNC_ERROR_NONE) + goto done; + + /* TODO: sync_fence_get_count_val */ + +done: + if (error) + *error = ret; + + _tbm_sync_mutex_unlock(); + + return count_val; +} + diff --git a/src/tbm_sync.h b/src/tbm_sync.h new file mode 100644 index 0000000..bd732ca --- /dev/null +++ b/src/tbm_sync.h @@ -0,0 +1,25 @@ +#ifndef _TBM_SYNC_H_ +#define _TBM_SYNC_H_ + +typedef enum { + TBM_SYNC_ERROR_NONE = 0, /**< Successful */ + TBM_SYNC_ERROR_INVALID_PARAMETER = -1, /**< Invalid parameter */ + TBM_SYNC_ERROR_INVALID_OPERATION = -2, /**< Invalid Operation */ +} tbm_sync_error_e; + +typedef void *tbm_sync_timeline_h; +typedef void *tbm_sync_fence_h; + +tbm_sync_timeline_h tbm_sync_timeline_create(tbm_sync_error_e *error); +tbm_sync_error_e tbm_sync_timeline_destroy(tbm_sync_timeline_h timeline); +tbm_sync_timeline_h tbm_sync_timeline_import(int fd, tbm_sync_error_e *error); +tbm_sync_error_e tbm_sync_timeline_increase_count(tbm_sync_timeline_h timeline, unsigned int interval); +unsigned int tbm_sync_timeline_get_cur_count(tbm_sync_timeline_h timeline, tbm_sync_error_e *error); + +tbm_sync_fence_h tbm_sync_fence_create(tbm_sync_timeline_h timeline, const char *name, unsigned int count_val, tbm_sync_error_e *error); +tbm_sync_error_e tbm_sync_fence_destroy(tbm_sync_fence_h fence); +tbm_sync_error_e tbm_sync_fence_wait(tbm_sync_fence_h fence, int timeout); +tbm_sync_fence_h tbm_sync_fence_merge(tbm_sync_fence_h fence1, tbm_sync_fence_h fence2, const char *name, tbm_sync_error_e *error); +unsigned int tbm_sync_fence_get_count_val(tbm_sync_fence_h fence, tbm_sync_error_e *error); + +#endif /* _TBM_SYNC_H */