1 /**************************************************************************
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
32 #ifndef _TBM_BUFMGR_H_
33 #define _TBM_BUFMGR_H_
38 /* tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */
39 #ifndef TBM_ERROR_BASE
40 #define TBM_ERROR_BASE -0x02830000
45 * \brief Tizen Buffer Manager
49 * @brief Definition for the tizen buffer manager
50 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
52 typedef struct _tbm_bufmgr *tbm_bufmgr;
55 * @brief Definition for the tizen buffer object
56 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
58 typedef struct _tbm_bo *tbm_bo;
60 * @brief Definition for the key associated with the buffer object
61 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
63 typedef uint32_t tbm_key;
65 * @brief Definition for the file descripter of the system buffer manager
66 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
68 typedef int32_t tbm_fd;
73 * @brief Definition for the device type to get the default handle
74 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
76 #define TBM_DEVICE_DEFAULT 0
78 * @brief Definition for the device type to get the virtual memory
79 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
81 #define TBM_DEVICE_CPU 1
83 * @brief Definition for the device type to get the 2D memory handle
84 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
86 #define TBM_DEVICE_2D 2
88 * @brief Definition for the device type to get the 3D memory handle
89 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
91 #define TBM_DEVICE_3D 3
93 * @brief Definition for the device type to get the multimedia handle
94 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
96 #define TBM_DEVICE_MM 4
99 * @brief Definition for the cache invalidate
100 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
102 #define TBM_CACHE_INV 0x01
104 * @brief Definition for the cache clean
105 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
107 #define TBM_CACHE_CLN 0x02
112 * @brief Definition for the access option to read
113 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
115 #define TBM_OPTION_READ (1 << 0)
117 * @brief Definition for the access option to write
118 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
120 #define TBM_OPTION_WRITE (1 << 1)
122 * @brief Definition for the vendor specific option that depends on the backend
123 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
125 #define TBM_OPTION_VENDOR (0xffff0000)
128 * @brief tbm_bo_handle abstraction of the memory handle by TBM_DEVICE_TYPE
129 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
131 typedef union _tbm_bo_handle {
140 * @brief Enumeration of bo memory type
141 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
144 TBM_BO_DEFAULT = 0, /**< default memory: it depends on the backend */
145 TBM_BO_SCANOUT = (1 << 0), /**< scanout memory */
146 TBM_BO_NONCACHABLE = (1 << 1), /**< non-cachable memory */
147 TBM_BO_WC = (1 << 2), /**< write-combine memory */
148 TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */
152 * @brief Enumeration for tbm error type.
156 TBM_ERROR_NONE = 0, /**< Successful */
157 TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE | 0x0101, /**< failed to get fd failed */
158 TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_BASE | 0x0102, /**< failed to allocate the heap memory */
159 TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE | 0x0103,/**< failed to load module*/
160 TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE | 0x0104,/**< failed to initialize the pthread */
161 TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_BASE | 0x0105, /**< failed to allocate tbm_bo */
162 TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE | 0x0106, /**< failed to initialize the state of tbm_bo */
163 TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE | 0x0107, /**< failed to import the handle of tbm_bo */
164 TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE | 0x0108, /**< failed to import fd of tbm_bo */
165 TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE | 0x0109, /**< failed to export the handle of the tbm_bo */
166 TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE | 0x01010, /**< failed to export fd of tbm_bo */
167 TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE | 0x0111, /**< failed to get the tbm_bo_handle */
168 TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE | 0x0112, /**< failed to lock the tbm_bo */
169 TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE | 0x0113, /**< failed to map the tbm_bo to get the tbm_bo_handle */
170 TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE | 0x0114, /**< failed to unmap the tbm_bo */
171 TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE | 0x0115, /**< failed to swap the tbm_bos */
172 TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE | 0x0116, /**< failed to duplicate fd */
176 * @brief Enumeration of tbm buffer manager capability.
179 enum TBM_BUFMGR_CAPABILITY {
180 TBM_BUFMGR_CAPABILITY_NONE = 0, /**< Not Support capability*/
181 TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1 << 0), /**< Support sharing buffer by tbm key */
182 TBM_BUFMGR_CAPABILITY_SHARE_FD = (1 << 1), /**< Support sharing buffer by tbm fd */
189 /* Functions for buffer manager */
192 * @brief Initializes the buffer manager.
193 * @details If fd is lower than zero, fd is get drm fd in tbm_bufmgr_init function\n
194 * The user can decide the lock type and cache flush type with the environment variables, which are BUFMGR_LOCK_TYPE and BUFMGR_MAP_CACHE.\n
196 * BUFMGR_LOCK default is once\n
197 * once : The previous bo which is locked is unlock when the new bo is trying to be locked\n
198 * always : The new bo is locked until the previous bo which is locked is unlocked\n
199 * never : Every bo is never locked.\n
201 * BUFMGR_MAP_CACHE default is true\n
202 * true : use map cache flushing\n
203 * false : to use map cache flushing
204 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
205 * @param[in] fd : file descripter of the system buffer manager
206 * @return a buffer manager
207 * @retval #tbm_bufmgr
208 * @see tbm_bufmgr_deinit();
211 #include <tbm_bufmgr.h>
214 setenv("BUFMGR_LOCK_TYPE", "once", 1);
215 setenv("BUFMGR_MAP_CACHE", "true", 1);
218 bufmgr = tbm_bufmgr_init (bufmgr_fd);
222 tbm_bufmgr_deinit (bufmgr);
225 tbm_bufmgr tbm_bufmgr_init(int fd);
228 * @brief Deinitializes the buffer manager.
229 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
230 * @param[in] bufmgr : the buffer manager
231 * @see tbm_bufmgr_init()
234 #include <tbm_bufmgr.h>
239 bufmgr = tbm_bufmgr_init (bufmgr_fd);
242 error = tbm_get_last_error ();
248 tbm_bufmgr_deinit (bufmgr);
251 void tbm_bufmgr_deinit(tbm_bufmgr bufmgr);
253 /* Functions for bo */
256 * @brief Allocates the buffer object.
257 * @details This function create tbm_bo and set reference count to 1.\n
258 * The user can craete tbm_bo with memory type flag #TBM_BO_FLAGS\n\n
259 * #TBM_BO_DEFAULT indecates default memory: it depends on the backend\n
260 * #TBM_BO_SCANOUT indecates scanout memory\n
261 * #TBM_BO_NONCACHABLE indecates non-cachable memory\n
262 * #TBM_BO_WC indecates write-combine memory\n
263 * #TBM_BO_VENDOR indecates vendor specific memory: it depends on the tbm backend
264 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
265 * @param[in] bufmgr : the buffer manager
266 * @param[in] size : the size of buffer object
267 * @param[in] flags : the flags of memory type
268 * @return a buffer object
272 #include <tbm_bufmgr.h>
279 bufmgr = tbm_bufmgr_init (bufmgr_fd);
280 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
283 error = tbm_get_last_error ();
289 tbm_bufmgr_deinit (bufmgr);
292 tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags);
295 * @brief Increases the reference count of bo.
296 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
297 * @param[in] bo : the buffer object
298 * @return a buffer object
300 * @see tbm_bo_unref()
303 #include <tbm_bufmgr.h>
309 bufmgr = tbm_bufmgr_init (bufmgr_fd);
310 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
314 bo = tbm_bo_ref (bo);
318 tbm_bufmgr_deinit (bufmgr);
321 tbm_bo tbm_bo_ref(tbm_bo bo);
324 * @brief Decreases the reference count of bo
325 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
326 * @param[in] bo : the buffer object
328 * @see tbm_bo_alloc()
331 #include <tbm_bufmgr.h>
337 bufmgr = tbm_bufmgr_init (bufmgr_fd);
338 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
343 tbm_bufmgr_deinit (bufmgr);
346 void tbm_bo_unref(tbm_bo bo);
349 * @brief Maps the buffer object according to the device type and the option.
350 * @details Cache flushing and Locking is executed, while tbm_bo is mapping in the proper condition according to the device type and the access option.\n
351 * If the cache flush type of bufmgr set true, the map cache flushing is executed
352 * If the lock type of bufmgr set once, the previous bo which is locked is unlock when the new bo is trying to be locked.\n
353 * If the lock type of bufmgr set always, the new bo is locked until the previous bo which is locked is unlocked.\n
354 * If the lock type of bufmgr set never, Every bo is never locked.\n\n
355 * #TBM_DEVICE_DEFAULT indecates the default handle.\n
356 * #TBM_DEVICE_2D indecates the 2D memory handle.\n
357 * #TBM_DEVICE_3D indecates the 3D memory handle.\n
358 * #TBM_DEVICE_CPU indecates the virtual memory handle.\n
359 * #TBM_DEVICE_MM indecates the multimedia handle.\n\n
360 * #TBM_OPTION_READ indecates the accss option to read.\n
361 * #TBM_OPTION_WRITE indecates the access option to write.\n
362 * #TBM_OPTION_VENDOR indecates the vendor specific option that depends on the backend.
363 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
364 * @param[in] bo : the buffer object
365 * @param[in] device : the device type to get a handle
366 * @param[in] opt : the option to access the buffer object
367 * @return the handle of the buffer object
368 * @exception #TBM_ERROR_NONE Success
369 * @exception #TBM_ERROR_BO_LOCK_FAILED tbm_bo lock failed
370 * @exception #TBM_ERROR_BO_MAP_FAILED tbm_bo map failed
372 * @see tbm_bo_unmap()
375 #include <tbm_bufmgr.h>
380 tbm_bo_handle handle;
383 bufmgr = tbm_bufmgr_init (bufmgr_fd);
384 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
388 handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
389 if (handle.ptr == NULL)
391 error = tbm_get_last_error ();
399 tbm_bufmgr_deinit (bufmgr);
402 tbm_bo_handle tbm_bo_map(tbm_bo bo, int device, int opt);
405 * @brief Unmaps the buffer object.
406 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
407 * @param[in] bo : the buffer object
408 * @return 1 if this function succeeds, otherwise 0.
412 #include <tbm_bufmgr.h>
417 tbm_bo_handle handle;
419 bufmgr = tbm_bufmgr_init (bufmgr_fd);
420 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
424 handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
430 tbm_bufmgr_deinit (bufmgr);
433 int tbm_bo_unmap(tbm_bo bo);
436 * @brief Gets the tbm_bo_handle according to the device type.
437 * @details The tbm_bo_handle can be get without the map of the tbm_bo.\n
438 * In this case, TBM does not guarantee the lock and the cache flush of the tbm_bo.\n\n
439 * #TBM_DEVICE_DEFAULT indecates the default handle.\n
440 * #TBM_DEVICE_2D indecates the 2D memory handle.\n
441 * #TBM_DEVICE_3D indecates the 3D memory handle.\n
442 * #TBM_DEVICE_CPU indecates the virtual memory handle.\n
443 * #TBM_DEVICE_MM indecates the multimedia handle.
444 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
445 * @param[in] bo : the buffer object
446 * @param[in] device : the device type to get a handle
447 * @return the handle of the buffer object
448 * @retval #tbm_bo_handle
451 #include <tbm_bufmgr.h>
456 tbm_bo_handle handle;
459 bufmgr = tbm_bufmgr_init (bufmgr_fd);
460 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
464 handle = tbm_bo_get_handle (bo, TBM_DEVICE_2D);
465 if (handle.ptr == NULL)
467 error = tbm_get_last_error ();
474 tbm_bufmgr_deinit (bufmgr);
477 tbm_bo_handle tbm_bo_get_handle(tbm_bo bo, int device);
480 * @brief Exports the buffer object by key.
481 * @details The tbm_bo can be exported to the anther process with the unique key associated with the the tbm_bo.
482 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
483 * @param[in] bo : the buffer object
484 * @return key associated with the buffer object
486 * @see tbm_bo_import()
489 #include <tbm_bufmgr.h>
497 bufmgr = tbm_bufmgr_init (bufmgr_fd);
498 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
499 key = tbm_bo_export (bo);
502 error = tbm_get_last_error ();
509 tbm_bufmgr_deinit (bufmgr);
512 tbm_key tbm_bo_export(tbm_bo bo);
515 * @brief Exports the buffer object by fd.
516 * @details The tbm_bo can be exported to the anther process with the unique fd associated with the the tbm_bo.
517 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
518 * @remarks You must release the fd using close().
519 * @param[in] bo : the buffer object
520 * @return fd associated with the buffer object
522 * @see tbm_bo_import_fd()
525 #include <tbm_bufmgr.h>
533 bufmgr = tbm_bufmgr_init (bufmgr_fd);
534 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
535 bo_fd = tbm_bo_export (bo);
538 error = tbm_get_last_error ();
545 tbm_bufmgr_deinit (bufmgr);
548 tbm_fd tbm_bo_export_fd(tbm_bo bo);
551 * @brief Imports the buffer object associated with the key.
552 * @details The reference count of the tbm_bo is 1.
553 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
554 * @param[in] bufmgr : the buffer manager
555 * @param[in] key : the key associated with the buffer object
556 * @return a buffer object
558 * @see tbm_bo_export()
561 #include <tbm_bufmgr.h>
571 bufmgr = tbm_bufmgr_init (bufmgr_fd);
572 bo = tbm_bo_import (key);
575 error = tbm_get_last_error ();
582 tbm_bufmgr_deinit (bufmgr);
585 tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, tbm_key key);
588 * @brief Imports the buffer object associated with the fd.
589 * @details The reference count of the tbm_bo is 1.
590 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
591 * @remarks You must release the fd using close().
592 * @param[in] bufmgr : the buffer manager
593 * @param[in] fd : the fd associated with the buffer object
594 * @return a buffer object
596 * @see tbm_bo_export_fd()
599 #include <tbm_bufmgr.h>
609 bufmgr = tbm_bufmgr_init (bufmgr_fd);
610 bo_fd = tbm_bo_import_fd (bo_fd);
613 error = tbm_get_last_error ();
620 tbm_bufmgr_deinit (bufmgr);
623 tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd);
626 * @brief Gets the size of a bo.
627 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
628 * @param[in] bo : the buffer object
629 * @return 1 if this function succeeds, otherwise 0.
630 * @see tbm_bo_alloc()
633 #include <tbm_bufmgr.h>
640 bufmgr = tbm_bufmgr_init (bufmgr_fd);
641 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
642 size = tbm_bo_size (bo);
647 tbm_bufmgr_deinit (bufmgr);
650 int tbm_bo_size(tbm_bo bo);
653 * @brief Gets the state where the buffer object is locked.
654 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
655 * @param[in] bo : the buffer object
656 * @return 1 if this bo is locked, otherwise 0.
658 * @see tbm_bo_unmap()
661 #include <tbm_bufmgr.h>
667 bufmgr = tbm_bufmgr_init (bufmgr_fd);
668 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
672 if (tbm_bo_locked (bo))
678 tbm_bufmgr_deinit (bufmgr);
681 int tbm_bo_locked(tbm_bo bo);
684 * @brief Swaps the buffer object.
685 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
686 * @param[in] bo1 : the buffer object
687 * @param[in] bo2 : the buffer object
688 * @return 1 if this function succeeds, otherwise 0.
691 #include <tbm_bufmgr.h>
700 bufmgr = tbm_bufmgr_init (bufmgr_fd);
701 bo1 = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
702 bo2 = tbm_bo_alloc (bufmgr, 256 * 256, TBM_BO_DEFAULT);
706 ret = tbm_bo_swap (bo1, bo2);
709 error = tbm_get_last_error ();
717 tbm_bufmgr_deinit (bufmgr);
720 int tbm_bo_swap(tbm_bo bo1, tbm_bo bo2);
723 * @brief Called when the user data is deleted in buffer object.
724 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
725 * @param[in] user_data User_data to be passed to callback function
726 * @pre The callback must be registered using tbm_bo_add_user_data().\n
727 * tbm_bo_delete_user_data() must be called to invoke this callback.
728 * @see tbm_bo_add_user_data()
729 * @see tbm_bo_delete_user_data()
731 typedef void (*tbm_data_free) (void *user_data);
734 * @brief Adds a user_data to the buffer object.
735 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
736 * @param[in] bo : the buffer object
737 * @param[in] key : the key associated with the user_data
738 * @param[in] data_free_func : the function pointer to free the user_data
739 * @return 1 if this function succeeds, otherwise 0.
740 * @post tbm_data_free() will be called under certain conditions, after calling tbm_bo_delete_user_data().
741 * @see tbm_data_free()
742 * @see tbm_bo_set_user_data()
743 * @see tbm_bo_get_user_data()
744 * @see tbm_bo_delete_user_data()
747 #include <tbm_bufmgr.h>
749 void example_data_free (void *user_data)
751 char *data = (char*) user_data;
764 bufmgr = tbm_bufmgr_init (bufmgr_fd);
765 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
766 user_data = (char*) malloc (sizeof(char) * 128);
770 tbm_bo_add_user_data (bo, 1, example_data_free);
771 tbm_bo_set_user_data (bo, 1, user_data);
775 ret = tbm_bo_get_user_data (bo, 1, &get_data);
776 tbm_bo_delete_user_data (bo, 1);
781 tbm_bufmgr_deinit (bufmgr);
786 int tbm_bo_add_user_data(tbm_bo bo, unsigned long key, tbm_data_free data_free_func);
789 * @brief Deletes the user_data in the buffer object.
790 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
791 * @param[in] bo : the buffer object
792 * @param[in] key : the key associated with the user_date
793 * @return 1 if this function succeeds, otherwise 0.
794 * @see tbm_bo_add_user_data()
795 * @see tbm_bo_get_user_data()
796 * @see tbm_bo_delete_user_data()
799 #include <tbm_bufmgr.h>
801 void example_data_free (void *user_data)
803 char *data = (char*) user_data;
816 bufmgr = tbm_bufmgr_init (bufmgr_fd);
817 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
818 user_data = (char*) malloc (sizeof(char) * 128);
822 tbm_bo_add_user_data (bo, 1, example_data_free);
823 tbm_bo_set_user_data (bo, 1, user_data);
827 ret = tbm_bo_get_user_data (bo, 1, &get_data);
828 tbm_bo_delete_user_data (bo, 1);
833 tbm_bufmgr_deinit (bufmgr);
837 int tbm_bo_delete_user_data(tbm_bo bo, unsigned long key);
840 * @brief Sets a user_date to the buffer object.
841 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
842 * @param[in] bo : the buffer object
843 * @param[in] key : the key associated with the user_date
844 * @param[in] data : a pointer of the user_data
845 * @return 1 if this function succeeds, otherwise 0.
846 * @see tbm_bo_add_user_data()
847 * @see tbm_bo_set_user_data()
848 * @see tbm_bo_delete_user_data()
851 #include <tbm_bufmgr.h>
853 void example_data_free (void *user_data)
855 char *data = (char*) user_data;
868 bufmgr = tbm_bufmgr_init (bufmgr_fd);
869 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
870 user_data = (char*) malloc (sizeof(char) * 128);
874 tbm_bo_add_user_data (bo, 1, example_data_free);
875 tbm_bo_set_user_data (bo, 1, user_data);
879 ret = tbm_bo_get_user_data (bo, 1, &get_data);
880 tbm_bo_delete_user_data (bo, 1);
885 tbm_bufmgr_deinit (bufmgr);
889 int tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data);
892 * @brief Gets a user_data from the buffer object with the key.
893 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
894 * @param[in] bo : the buffer object
895 * @param[in] key : the key associated with the user_date
896 * @param[out] data : to get the user data
897 * @return 1 if this function succeeds, otherwise 0.
898 * @see tbm_bo_add_user_data()
899 * @see tbm_bo_set_user_data()
900 * @see tbm_bo_get_user_data()
903 #include <tbm_bufmgr.h>
905 void example_data_free (void *user_data)
907 char *data = (char*) user_data;
920 bufmgr = tbm_bufmgr_init (bufmgr_fd);
921 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
922 user_data = (char*) malloc (sizeof(char) * 128);
926 tbm_bo_add_user_data (bo, 1, example_data_free);
927 tbm_bo_set_user_data (bo, 1, user_data);
931 ret = tbm_bo_get_user_data (bo, 1, &get_data);
932 tbm_bo_delete_user_data (bo, 1);
937 tbm_bufmgr_deinit (bufmgr);
941 int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data);
944 * @brief Gets the latest tbm_error.
946 * @return the latest tbm_error
949 #include <tbm_bufmgr.h>
954 tbm_bo_handle handle;
957 bufmgr = tbm_bufmgr_init (bufmgr_fd);
958 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
961 error = tbm_get_last_error ();
967 handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
968 if (handle.ptr == NULL)
970 error = tbm_get_last_error ();
978 tbm_bufmgr_deinit (bufmgr);
981 tbm_error_e tbm_get_last_error(void);
984 * @brief Gets the tbm buffer capability.
986 * @param[in] bufmgr : the buffer manager
987 * @return the tbm bufmgr capability
990 #include <tbm_bufmgr.h>
994 unsigned int capability;
996 bufmgr = tbm_bufmgr_init (bufmgr_fd);
998 capability = tbm_bufmgr_get_capability (bufmgr);
1000 tbm_bufmgr_deinit (bufmgr);
1003 unsigned int tbm_bufmgr_get_capability(tbm_bufmgr bufmgr);
1006 * @brief Gets the tbm bo flags.
1008 * @param[in] bo : the buffer object
1009 * @return the tbm bo flags
1013 #include <tbm_bufmgr.h>
1020 bufmgr = tbm_bufmgr_init (bufmgr_fd);
1021 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
1022 flags = tbm_bo_get_flags (bo);
1027 tbm_bufmgr_deinit (bufmgr);
1031 int tbm_bo_get_flags(tbm_bo bo);
1034 * @brief Print out the information of tbm_bos.
1036 * @param[in] bufmgr : the buffer manager
1038 void tbm_bufmgr_debug_show (tbm_bufmgr bufmgr);
1041 * @brief Print out the trace of tbm_bos.
1043 * @param[in] bufmgr : the buffer manager
1044 * @param[in] onoff : 1 is on, and 0 is off
1046 void tbm_bufmgr_debug_trace (tbm_bufmgr bufmgr, int onoff);
1053 #endif /* _TBM_BUFMGR_H_ */