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 * @remarks You must release the fd using close().
516 * @param[in] bo : the buffer object
517 * @return fd associated with the buffer object
519 * @see tbm_bo_import_fd()
522 #include <tbm_bufmgr.h>
530 bufmgr = tbm_bufmgr_init (bufmgr_fd);
531 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
532 bo_fd = tbm_bo_export (bo);
535 error = tbm_get_last_error ();
542 tbm_bufmgr_deinit (bufmgr);
545 tbm_fd tbm_bo_export_fd (tbm_bo bo);
548 * @brief Imports the buffer object associated with the key.
549 * @details The reference count of the tbm_bo is 1.
550 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
551 * @param[in] bufmgr : the buffer manager
552 * @param[in] key : the key associated with the buffer object
553 * @return a buffer object
555 * @see tbm_bo_export()
558 #include <tbm_bufmgr.h>
568 bufmgr = tbm_bufmgr_init (bufmgr_fd);
569 bo = tbm_bo_import (key);
572 error = tbm_get_last_error ();
579 tbm_bufmgr_deinit (bufmgr);
582 tbm_bo tbm_bo_import (tbm_bufmgr bufmgr, tbm_key key);
585 * @brief Imports the buffer object associated with the fd.
586 * @details The reference count of the tbm_bo is 1.
587 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
588 * @remarks You must release the fd using close().
589 * @param[in] bufmgr : the buffer manager
590 * @parak[in] fd : the fd associated with the buffer object
591 * @return a buffer object
593 * @see tbm_bo_export_fd()
596 #include <tbm_bufmgr.h>
606 bufmgr = tbm_bufmgr_init (bufmgr_fd);
607 bo_fd = tbm_bo_import_fd (bo_fd);
610 error = tbm_get_last_error ();
617 tbm_bufmgr_deinit (bufmgr);
620 tbm_bo tbm_bo_import_fd (tbm_bufmgr bufmgr, tbm_fd fd);
623 * @brief Gets the size of a bo.
624 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
625 * @param[in] bo : the buffer object
626 * @return 1 if this function succeeds, otherwise 0.
627 * @see tbm_bo_alloc()
630 #include <tbm_bufmgr.h>
637 bufmgr = tbm_bufmgr_init (bufmgr_fd);
638 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
639 size = tbm_bo_size (bo);
644 tbm_bufmgr_deinit (bufmgr);
647 int tbm_bo_size (tbm_bo bo);
650 * @brief Gets the state where the buffer object is locked.
651 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
652 * @param[in] bo : the buffer object
653 * @return 1 if this bo is locked, otherwise 0.
655 * @see tbm_bo_unmap()
658 #include <tbm_bufmgr.h>
664 bufmgr = tbm_bufmgr_init (bufmgr_fd);
665 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
669 if (tbm_bo_locked (bo))
675 tbm_bufmgr_deinit (bufmgr);
678 int tbm_bo_locked (tbm_bo bo);
681 * @brief Swaps the buffer object.
682 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
683 * @param[in] bo1 : the buffer object
684 * @param[in] bo2 : the buffer object
685 * @return 1 if this function succeeds, otherwise 0.
688 #include <tbm_bufmgr.h>
697 bufmgr = tbm_bufmgr_init (bufmgr_fd);
698 bo1 = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
699 bo2 = tbm_bo_alloc (bufmgr, 256 * 256, TBM_BO_DEFAULT);
703 ret = tbm_bo_swap (bo1, bo2);
706 error = tbm_get_last_error ();
714 tbm_bufmgr_deinit (bufmgr);
717 int tbm_bo_swap (tbm_bo bo1, tbm_bo bo2);
721 * @brief Called when the user data is deleted in buffer object.
722 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
723 * @param[in] user_data User_data to be passed to callback function
724 * @pre The callback must be registered using tbm_bo_add_user_data().\n
725 * tbm_bo_delete_user_data() must be called to invoke this callback.
726 * @see tbm_bo_add_user_data()
727 * @see tbm_bo_delete_user_data()
729 typedef void (*tbm_data_free)(void *user_data);
732 * @brief Adds a user_data to the buffer object.
733 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
734 * @param[in] bo : the buffer object
735 * @param[in] key : the key associated with the user_data
736 * @param[in] data_free_func : the function pointer to free the user_data
737 * @return 1 if this function succeeds, otherwise 0.
738 * @post tbm_data_free() will be called under certain conditions, after calling tbm_bo_delete_user_data().
739 * @see tbm_data_free()
740 * @see tbm_bo_set_user_data()
741 * @see tbm_bo_get_user_data()
742 * @see tbm_bo_delete_user_data()
745 #include <tbm_bufmgr.h>
747 void example_data_free (void *user_data)
749 char *data = (char*) user_data;
762 bufmgr = tbm_bufmgr_init (bufmgr_fd);
763 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
764 user_data = (char*) malloc (sizeof(char) * 128);
768 tbm_bo_add_user_data (bo, 1, example_data_free);
769 tbm_bo_set_user_data (bo, 1, user_data);
773 ret = tbm_bo_get_user_data (bo, 1, &get_data);
774 tbm_bo_delete_user_data (bo, 1);
779 tbm_bufmgr_deinit (bufmgr);
784 int tbm_bo_add_user_data (tbm_bo bo, unsigned long key, tbm_data_free data_free_func);
787 * @brief Deletes the user_data in the buffer object.
788 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
789 * @param[in] bo : the buffer object
790 * @param[in] key : the key associated with the user_date
791 * @return 1 if this function succeeds, otherwise 0.
792 * @see tbm_bo_add_user_data()
793 * @see tbm_bo_get_user_data()
794 * @see tbm_bo_delete_user_data()
797 #include <tbm_bufmgr.h>
799 void example_data_free (void *user_data)
801 char *data = (char*) user_data;
814 bufmgr = tbm_bufmgr_init (bufmgr_fd);
815 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
816 user_data = (char*) malloc (sizeof(char) * 128);
820 tbm_bo_add_user_data (bo, 1, example_data_free);
821 tbm_bo_set_user_data (bo, 1, user_data);
825 ret = tbm_bo_get_user_data (bo, 1, &get_data);
826 tbm_bo_delete_user_data (bo, 1);
831 tbm_bufmgr_deinit (bufmgr);
835 int tbm_bo_delete_user_data (tbm_bo bo, unsigned long key);
838 * @brief Sets a user_date to the buffer object.
839 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
840 * @param[in] bo : the buffer object
841 * @param[in] key : the key associated with the user_date
842 * @param[in] data : a pointer of the user_data
843 * @return 1 if this function succeeds, otherwise 0.
844 * @see tbm_bo_add_user_data()
845 * @see tbm_bo_set_user_data()
846 * @see tbm_bo_delete_user_data()
849 #include <tbm_bufmgr.h>
851 void example_data_free (void *user_data)
853 char *data = (char*) user_data;
866 bufmgr = tbm_bufmgr_init (bufmgr_fd);
867 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
868 user_data = (char*) malloc (sizeof(char) * 128);
872 tbm_bo_add_user_data (bo, 1, example_data_free);
873 tbm_bo_set_user_data (bo, 1, user_data);
877 ret = tbm_bo_get_user_data (bo, 1, &get_data);
878 tbm_bo_delete_user_data (bo, 1);
883 tbm_bufmgr_deinit (bufmgr);
887 int tbm_bo_set_user_data (tbm_bo bo, unsigned long key, void* data);
890 * @brief Gets a user_data from the buffer object with the key.
891 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
892 * @param[in] bo : the buffer object
893 * @param[in] key : the key associated with the user_date
894 * @param[out] data : to get the user data
895 * @return 1 if this function succeeds, otherwise 0.
896 * @see tbm_bo_add_user_data()
897 * @see tbm_bo_set_user_data()
898 * @see tbm_bo_get_user_data()
901 #include <tbm_bufmgr.h>
903 void example_data_free (void *user_data)
905 char *data = (char*) user_data;
918 bufmgr = tbm_bufmgr_init (bufmgr_fd);
919 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
920 user_data = (char*) malloc (sizeof(char) * 128);
924 tbm_bo_add_user_data (bo, 1, example_data_free);
925 tbm_bo_set_user_data (bo, 1, user_data);
929 ret = tbm_bo_get_user_data (bo, 1, &get_data);
930 tbm_bo_delete_user_data (bo, 1);
935 tbm_bufmgr_deinit (bufmgr);
939 int tbm_bo_get_user_data (tbm_bo bo, unsigned long key, void** data);
942 * @brief Gets the latest tbm_error.
944 * @return the latest tbm_error
947 #include <tbm_bufmgr.h>
952 tbm_bo_handle handle;
955 bufmgr = tbm_bufmgr_init (bufmgr_fd);
956 bo = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
959 error = tbm_get_last_error ();
965 handle = tbm_bo_map (bo, TBM_DEVICE_2D, TBM_OPTION_READ|TBM_OPTION_WRITE);
966 if (handle.ptr == NULL)
968 error = tbm_get_last_error ();
976 tbm_bufmgr_deinit (bufmgr);
979 tbm_error_e tbm_get_last_error (void);
985 #endif /* _TBM_BUFMGR_H_ */