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;
74 * @brief Definition for the device type to get the default handle
75 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
77 #define TBM_DEVICE_DEFAULT 0
79 * @brief Definition for the device type to get the virtual memory
80 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
82 #define TBM_DEVICE_CPU 1
84 * @brief Definition for the device type to get the 2D memory handle
85 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
87 #define TBM_DEVICE_2D 2
89 * @brief Definition for the device type to get the 3D memory handle
90 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
92 #define TBM_DEVICE_3D 3
94 * @brief Definition for the device type to get the multimedia handle
95 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
97 #define TBM_DEVICE_MM 4
100 * @brief Definition for the cache invalidate
101 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
103 #define TBM_CACHE_INV 0x01
105 * @brief Definition for the cache clean
106 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
108 #define TBM_CACHE_CLN 0x02
113 * @brief Definition for the access option to read
114 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
116 #define TBM_OPTION_READ (1 << 0)
118 * @brief Definition for the access option to write
119 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
121 #define TBM_OPTION_WRITE (1 << 1)
123 * @brief Definition for the vendor specific option that depends on the backend
124 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
126 #define TBM_OPTION_VENDOR (0xffff0000)
129 * @brief tbm_bo_handle abstraction of the memory handle by TBM_DEVICE_TYPE
130 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
132 typedef union _tbm_bo_handle
142 * @brief Enumeration of bo memory type
143 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
147 TBM_BO_DEFAULT = 0, /**< default memory: it depends on the backend */
148 TBM_BO_SCANOUT = (1<<0), /**< scanout memory */
149 TBM_BO_NONCACHABLE = (1<<1), /**< non-cachable memory */
150 TBM_BO_WC = (1<<2), /**< write-combine memory */
151 TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */
156 * @brief Enumeration for tbm error type.
161 TBM_ERROR_NONE = 0, /**< Successful */
162 TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE|0x0101, /**< failed to get fd failed */
163 TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_BASE|0x0102, /**< failed to allocate the heap memory */
164 TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE|0x0103, /**< failed to load module*/
165 TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE|0x0104, /**< failed to initialize the pthread */
166 TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_BASE|0x0105, /**< failed to allocate tbm_bo */
167 TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE|0x0106, /**< failed to initialize the state of tbm_bo */
168 TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE|0x0107, /**< failed to import the handle of tbm_bo */
169 TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE|0x0108, /**< failed to import fd of tbm_bo */
170 TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE|0x0109, /**< failed to export the handle of the tbm_bo */
171 TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE|0x01010, /**< failed to export fd of tbm_bo */
172 TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE|0x0111, /**< failed to get the tbm_bo_handle */
173 TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE|0x0112, /**< failed to lock the tbm_bo */
174 TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE|0x0113, /**< failed to map the tbm_bo to get the tbm_bo_handle */
175 TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE|0x0114, /**< failed to unmap the tbm_bo */
176 TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE|0x0115, /**< failed to swap the tbm_bos */
177 TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE|0x0116, /**< failed to duplicate fd */
185 /* Functions for buffer manager */
188 * @brief Initializes the buffer manager.
189 * @details If fd is lower than zero, fd is get drm fd in tbm_bufmgr_init function\n
190 * 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
192 * BUFMGR_LOCK default is once\n
193 * once : The previous bo which is locked is unlock when the new bo is trying to be locked\n
194 * always : The new bo is locked until the previous bo which is locked is unlocked\n
195 * never : Every bo is never locked.\n
197 * BUFMGR_MAP_CACHE default is true\n
198 * true : use map cache flushing\n
199 * false : to use map cache flushing
200 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
201 * @param[in] fd : file descripter of the system buffer manager
202 * @return a buffer manager
203 * @retval #tbm_bufmgr
204 * @see tbm_bufmgr_deinit();
207 #include <tbm_bufmgr.h>
211 setenv("BUFMGR_LOCK_TYPE", "once", 1);
212 setenv("BUFMGR_MAP_CACHE", "true", 1);
215 bufmgr = tbm_bufmgr_init (bufmgr_fd);
219 tbm_bufmgr_deinit (bufmgr);
222 tbm_bufmgr tbm_bufmgr_init (int fd);
225 * @brief Deinitializes the buffer manager.
226 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
227 * @param[in] bufmgr : the buffer manager
228 * @see tbm_bufmgr_init()
231 #include <tbm_bufmgr.h>
236 bufmgr = tbm_bufmgr_init (bufmgr_fd);
239 error = tbm_get_last_error ();
245 tbm_bufmgr_deinit (bufmgr);
248 void tbm_bufmgr_deinit (tbm_bufmgr bufmgr);
250 /* Functions for bo */
253 * @brief Allocates the buffer object.
254 * @details This function create tbm_bo and set reference count to 1.\n
255 * The user can craete tbm_bo with memory type flag #TBM_BO_FLAGS\n\n
256 * #TBM_BO_DEFAULT indecates default memory: it depends on the backend\n
257 * #TBM_BO_SCANOUT indecates scanout memory\n
258 * #TBM_BO_NONCACHABLE indecates non-cachable memory\n
259 * #TBM_BO_WC indecates write-combine memory\n
260 * #TBM_BO_VENDOR indecates vendor specific memory: it depends on the tbm backend
261 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
262 * @param[in] bufmgr : the buffer manager
263 * @param[in] size : the size of buffer object
264 * @param[in] flags : the flags of memory type
265 * @return a buffer object
269 #include <tbm_bufmgr.h>
276 bufmgr = tbm_bufmgr_init (bufmgr_fd);
277 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
280 error = tbm_get_last_error ();
286 tbm_bufmgr_deinit (bufmgr);
289 tbm_bo tbm_bo_alloc (tbm_bufmgr bufmgr, int size, int flags);
292 * @brief Increases the reference count of bo.
293 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
294 * @param[in] bo : the buffer object
295 * @return a buffer object
297 * @see tbm_bo_unref()
300 #include <tbm_bufmgr.h>
306 bufmgr = tbm_bufmgr_init (bufmgr_fd);
307 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
311 bo = tbm_bo_ref (bo);
315 tbm_bufmgr_deinit (bufmgr);
318 tbm_bo tbm_bo_ref (tbm_bo bo);
321 * @brief Decreases the reference count of bo
322 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
323 * @param[in] bo : the buffer object
325 * @see tbm_bo_alloc()
328 #include <tbm_bufmgr.h>
334 bufmgr = tbm_bufmgr_init (bufmgr_fd);
335 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
340 tbm_bufmgr_deinit (bufmgr);
343 void tbm_bo_unref (tbm_bo bo);
346 * @brief Maps the buffer object according to the device type and the option.
347 * @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
348 * If the cache flush type of bufmgr set true, the map cache flushing is executed
349 * 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
350 * If the lock type of bufmgr set always, the new bo is locked until the previous bo which is locked is unlocked.\n
351 * If the lock type of bufmgr set never, Every bo is never locked.\n\n
352 * #TBM_DEVICE_DEFAULT indecates the default handle.\n
353 * #TBM_DEVICE_2D indecates the 2D memory handle.\n
354 * #TBM_DEVICE_3D indecates the 3D memory handle.\n
355 * #TBM_DEVICE_CPU indecates the virtual memory handle.\n
356 * #TBM_DEVICE_MM indecates the multimedia handle.\n\n
357 * #TBM_OPTION_READ indecates the accss option to read.\n
358 * #TBM_OPTION_WRITE indecates the access option to write.\n
359 * #TBM_OPTION_VENDOR indecates the vendor specific option that depends on the backend.
360 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
361 * @param[in] bo : the buffer object
362 * @param[in] device : the device type to get a handle
363 * @param[in] opt : the option to access the buffer object
364 * @return the handle of the buffer object
365 * @exception #TBM_ERROR_NONE Success
366 * @exception #TBM_ERROR_BO_LOCK_FAILED tbm_bo lock failed
367 * @exception #TBM_ERROR_BO_MAP_FAILED tbm_bo map failed
369 * @see tbm_bo_unmap()
372 #include <tbm_bufmgr.h>
377 tbm_bo_handle handle;
380 bufmgr = tbm_bufmgr_init (bufmgr_fd);
381 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
385 handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
386 if (handle.ptr == NULL)
388 error = tbm_get_last_error ();
396 tbm_bufmgr_deinit (bufmgr);
399 tbm_bo_handle tbm_bo_map (tbm_bo bo, int device, int opt);
402 * @brief Unmaps the buffer object.
403 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
404 * @param[in] bo : the buffer object
405 * @return 1 if this function succeeds, otherwise 0.
409 #include <tbm_bufmgr.h>
414 tbm_bo_handle handle;
416 bufmgr = tbm_bufmgr_init (bufmgr_fd);
417 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
421 handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
427 tbm_bufmgr_deinit (bufmgr);
430 int tbm_bo_unmap (tbm_bo bo);
433 * @brief Gets the tbm_bo_handle according to the device type.
434 * @details The tbm_bo_handle can be get without the map of the tbm_bo.\n
435 * In this case, TBM does not guarantee the lock and the cache flush of the tbm_bo.\n\n
436 * #TBM_DEVICE_DEFAULT indecates the default handle.\n
437 * #TBM_DEVICE_2D indecates the 2D memory handle.\n
438 * #TBM_DEVICE_3D indecates the 3D memory handle.\n
439 * #TBM_DEVICE_CPU indecates the virtual memory handle.\n
440 * #TBM_DEVICE_MM indecates the multimedia handle.
441 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
442 * @param[in] bo : the buffer object
443 * @param[in] device : the device type to get a handle
444 * @return the handle of the buffer object
445 * @retval #tbm_bo_handle
448 #include <tbm_bufmgr.h>
453 tbm_bo_handle handle;
456 bufmgr = tbm_bufmgr_init (bufmgr_fd);
457 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
461 handle = tbm_bo_get_handle (bo, TBM_DEVICE_2D);
462 if (handle.ptr == NULL)
464 error = tbm_get_last_error ();
471 tbm_bufmgr_deinit (bufmgr);
474 tbm_bo_handle tbm_bo_get_handle (tbm_bo bo, int device);
477 * @brief Exports the buffer object by key.
478 * @details The tbm_bo can be exported to the anther process with the unique key associated with the the tbm_bo.
479 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
480 * @param[in] bo : the buffer object
481 * @return key associated with the buffer object
483 * @see tbm_bo_import()
486 #include <tbm_bufmgr.h>
494 bufmgr = tbm_bufmgr_init (bufmgr_fd);
495 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
496 key = tbm_bo_export (bo);
499 error = tbm_get_last_error ();
506 tbm_bufmgr_deinit (bufmgr);
509 tbm_key tbm_bo_export (tbm_bo bo);
512 * @brief Exports the buffer object by fd.
513 * @details The tbm_bo can be exported to the anther process with the unique fd associated with the the tbm_bo.
514 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
515 * @param[in] bo : the buffer object
516 * @return fd associated with the buffer object
518 * @see tbm_bo_import_fd()
521 #include <tbm_bufmgr.h>
529 bufmgr = tbm_bufmgr_init (bufmgr_fd);
530 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
531 bo_fd = tbm_bo_export (bo);
534 error = tbm_get_last_error ();
541 tbm_bufmgr_deinit (bufmgr);
544 tbm_fd tbm_bo_export_fd (tbm_bo bo);
547 * @brief Imports the buffer object associated with the key.
548 * @details The reference count of the tbm_bo is 1.
549 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
550 * @param[in] bufmgr : the buffer manager
551 * @param[in] key : the key associated with the buffer object
552 * @return a buffer object
554 * @see tbm_bo_export()
557 #include <tbm_bufmgr.h>
567 bufmgr = tbm_bufmgr_init (bufmgr_fd);
568 bo = tbm_bo_import (key);
571 error = tbm_get_last_error ();
578 tbm_bufmgr_deinit (bufmgr);
581 tbm_bo tbm_bo_import (tbm_bufmgr bufmgr, tbm_key key);
584 * @brief Imports the buffer object associated with the fd.
585 * @details The reference count of the tbm_bo is 1.
586 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
587 * @param[in] bufmgr : the buffer manager
588 * @param[in] fd : the fd associated with the buffer object
589 * @return a buffer object
591 * @see tbm_bo_export_fd()
594 #include <tbm_bufmgr.h>
604 bufmgr = tbm_bufmgr_init (bufmgr_fd);
605 bo_fd = tbm_bo_import_fd (bo_fd);
608 error = tbm_get_last_error ();
615 tbm_bufmgr_deinit (bufmgr);
618 tbm_bo tbm_bo_import_fd (tbm_bufmgr bufmgr, tbm_fd fd);
621 * @brief Gets the size of a bo.
622 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
623 * @param[in] bo : the buffer object
624 * @return 1 if this function succeeds, otherwise 0.
625 * @see tbm_bo_alloc()
628 #include <tbm_bufmgr.h>
635 bufmgr = tbm_bufmgr_init (bufmgr_fd);
636 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
637 size = tbm_bo_size (bo);
642 tbm_bufmgr_deinit (bufmgr);
645 int tbm_bo_size (tbm_bo bo);
648 * @brief Gets the state where the buffer object is locked.
649 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
650 * @param[in] bo : the buffer object
651 * @return 1 if this bo is locked, otherwise 0.
653 * @see tbm_bo_unmap()
656 #include <tbm_bufmgr.h>
662 bufmgr = tbm_bufmgr_init (bufmgr_fd);
663 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
667 if (tbm_bo_locked (bo))
673 tbm_bufmgr_deinit (bufmgr);
676 int tbm_bo_locked (tbm_bo bo);
679 * @brief Swaps the buffer object.
680 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
681 * @param[in] bo1 : the buffer object
682 * @param[in] bo2 : the buffer object
683 * @return 1 if this function succeeds, otherwise 0.
686 #include <tbm_bufmgr.h>
695 bufmgr = tbm_bufmgr_init (bufmgr_fd);
696 bo1 = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
697 bo2 = tbm_bo_alloc (bufmgr, 256 * 256, TBM_BO_DEFAULT);
701 ret = tbm_bo_swap (bo1, bo2);
704 error = tbm_get_last_error ();
712 tbm_bufmgr_deinit (bufmgr);
715 int tbm_bo_swap (tbm_bo bo1, tbm_bo bo2);
719 * @brief Called when the user data is deleted in buffer object.
720 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
721 * @param[in] user_data User_data to be passed to callback function
722 * @pre The callback must be registered using tbm_bo_add_user_data().\n
723 * tbm_bo_delete_user_data() must be called to invoke this callback.
724 * @see tbm_bo_add_user_data()
725 * @see tbm_bo_delete_user_data()
727 typedef void (*tbm_data_free)(void *user_data);
730 * @brief Adds a user_data to the buffer object.
731 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
732 * @param[in] bo : the buffer object
733 * @param[in] key : the key associated with the user_data
734 * @param[in] data_free_func : the function pointer to free the user_data
735 * @return 1 if this function succeeds, otherwise 0.
736 * @post tbm_data_free() will be called under certain conditions, after calling tbm_bo_delete_user_data().
737 * @see tbm_data_free()
738 * @see tbm_bo_set_user_data()
739 * @see tbm_bo_get_user_data()
740 * @see tbm_bo_delete_user_data()
743 #include <tbm_bufmgr.h>
745 void example_data_free (void *user_data)
747 char *data = (char*) user_data;
760 bufmgr = tbm_bufmgr_init (bufmgr_fd);
761 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
762 user_data = (char*) malloc (sizeof(char) * 128);
766 tbm_bo_add_user_data (bo, 1, example_data_free);
767 tbm_bo_set_user_data (bo, 1, user_data);
771 ret = tbm_bo_get_user_data (bo, 1, &get_data);
772 tbm_bo_delete_user_data (bo, 1);
777 tbm_bufmgr_deinit (bufmgr);
782 int tbm_bo_add_user_data (tbm_bo bo, unsigned long key, tbm_data_free data_free_func);
785 * @brief Deletes the user_data in the buffer object.
786 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
787 * @param[in] bo : the buffer object
788 * @param[in] key : the key associated with the user_date
789 * @return 1 if this function succeeds, otherwise 0.
790 * @see tbm_bo_add_user_data()
791 * @see tbm_bo_get_user_data()
792 * @see tbm_bo_delete_user_data()
795 #include <tbm_bufmgr.h>
797 void example_data_free (void *user_data)
799 char *data = (char*) user_data;
812 bufmgr = tbm_bufmgr_init (bufmgr_fd);
813 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
814 user_data = (char*) malloc (sizeof(char) * 128);
818 tbm_bo_add_user_data (bo, 1, example_data_free);
819 tbm_bo_set_user_data (bo, 1, user_data);
823 ret = tbm_bo_get_user_data (bo, 1, &get_data);
824 tbm_bo_delete_user_data (bo, 1);
829 tbm_bufmgr_deinit (bufmgr);
833 int tbm_bo_delete_user_data (tbm_bo bo, unsigned long key);
836 * @brief Sets a user_date to the buffer object.
837 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
838 * @param[in] bo : the buffer object
839 * @param[in] key : the key associated with the user_date
840 * @param[in] data : a pointer of the user_data
841 * @return 1 if this function succeeds, otherwise 0.
842 * @see tbm_bo_add_user_data()
843 * @see tbm_bo_set_user_data()
844 * @see tbm_bo_delete_user_data()
847 #include <tbm_bufmgr.h>
849 void example_data_free (void *user_data)
851 char *data = (char*) user_data;
864 bufmgr = tbm_bufmgr_init (bufmgr_fd);
865 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
866 user_data = (char*) malloc (sizeof(char) * 128);
870 tbm_bo_add_user_data (bo, 1, example_data_free);
871 tbm_bo_set_user_data (bo, 1, user_data);
875 ret = tbm_bo_get_user_data (bo, 1, &get_data);
876 tbm_bo_delete_user_data (bo, 1);
881 tbm_bufmgr_deinit (bufmgr);
885 int tbm_bo_set_user_data (tbm_bo bo, unsigned long key, void* data);
888 * @brief Gets a user_data from the buffer object with the key.
889 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
890 * @param[in] bo : the buffer object
891 * @param[in] key : the key associated with the user_date
892 * @param[out] data : to get the user data
893 * @return 1 if this function succeeds, otherwise 0.
894 * @see tbm_bo_add_user_data()
895 * @see tbm_bo_set_user_data()
896 * @see tbm_bo_get_user_data()
899 #include <tbm_bufmgr.h>
901 void example_data_free (void *user_data)
903 char *data = (char*) user_data;
916 bufmgr = tbm_bufmgr_init (bufmgr_fd);
917 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
918 user_data = (char*) malloc (sizeof(char) * 128);
922 tbm_bo_add_user_data (bo, 1, example_data_free);
923 tbm_bo_set_user_data (bo, 1, user_data);
927 ret = tbm_bo_get_user_data (bo, 1, &get_data);
928 tbm_bo_delete_user_data (bo, 1);
933 tbm_bufmgr_deinit (bufmgr);
937 int tbm_bo_get_user_data (tbm_bo bo, unsigned long key, void** data);
940 * @brief Gets the latest tbm_error.
942 * @return the latest tbm_error
945 #include <tbm_bufmgr.h>
950 tbm_bo_handle handle;
953 bufmgr = tbm_bufmgr_init (bufmgr_fd);
954 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
957 error = tbm_get_last_error ();
963 handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
964 if (handle.ptr == NULL)
966 error = tbm_get_last_error ();
974 tbm_bufmgr_deinit (bufmgr);
977 tbm_error_e tbm_get_last_error (void);
983 #endif /* _TBM_BUFMGR_H_ */