1 /**************************************************************************
5 Copyright 2014 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Inpyo Kang <mantiger@samsung.com>, Dongyeon Kim <dy5.kim@samsung.com>
9 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
11 Permission is hereby granted, free of charge, to any person obtaining a
12 copy of this software and associated documentation files (the
13 "Software"), to deal in the Software without restriction, including
14 without limitation the rights to use, copy, modify, merge, publish,
15 distribute, sub license, and/or sell copies of the Software, and to
16 permit persons to whom the Software is furnished to do so, subject to
17 the following conditions:
19 The above copyright notice and this permission notice (including the
20 next paragraph) shall be included in all copies or substantial portions
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
26 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
27 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 **************************************************************************/
33 #ifndef _TBM_SURFACE_INTERNAL_H_
34 #define _TBM_SURFACE_INTERNAL_H_
36 #include <tbm_bufmgr.h>
43 * @brief Queries formats which the system can support.
44 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
45 * @remarks The formats must be released using free().
46 * @param[in] bufmgr : the buffer manager
47 * @param[out] *formats : format array which the system can support. This pointer has to be freed by user.
48 * @param[out] num : the number of formats.
49 * @return a tbm_surface_h if this function succeeds, otherwise NULL
52 #include <tbm_surface.h>
53 #include <tbm_surface_internal.h>
59 bufmgr = tbm_bufmgr_create (-1);
60 ret = tbm_surface_internal_query_surpported_foramts (bufmgr, &formats, &format_num);
65 tbm_surface_bufmgr_deinit (bufmgr);
68 int tbm_surface_internal_query_supported_formats (uint32_t **formats, uint32_t *num);
71 * @brief Creates the tbm_surface with memory type.
72 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
74 * #TBM_BO_DEFAULT is default memory: it depends on the backend\n
75 * #TBM_BO_SCANOUT is scanout memory\n
76 * #TBM_BO_NONCACHABLE is non-cachable memory\n
77 * #TBM_BO_WC is write-combine memory\n
78 * #TBM_BO_VENDOR vendor specific memory: it depends on the tbm backend\n
79 * @param[in] bufmgr : the buffer manager
80 * @param[in] width : the width of surface
81 * @param[in] height : the height of surface
82 * @param[in] format : the format of surface
83 * @param[in] flags : the flags of memory type
84 * @return a tbm_surface_h if this function succeeds, otherwise NULL
85 * @retval #tbm_surface_h
88 #include <tbm_surface.h>
89 #include <tbm_surface_internal.h>
93 tbm_surface_h surface;
97 bufmgr = tbm_bufmgr_create (bufmgr_fd);
98 surface = tbm_surface_internal_create_with_flags (128, 128, TBM_FORMAT_YUV420, TBM_BO_DEFAULT);
102 tbm_surface_destroy (surface);
103 tbm_surface_bufmgr_deinit (bufmgr);
106 tbm_surface_h tbm_surface_internal_create_with_flags (int width, int height, int format, int flags);
109 * @brief Creates the tbm_surface with buffer objects.
110 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
111 * @param[in] bufmgr : the buffer manager
112 * @param[in] width : the width of surface
113 * @param[in] height : the height of surface
114 * @param[in] format : the format of surface
115 * @param[in] *bos : the array pointer of buffer objects
116 * @param[in] num : the number of buffer objects
117 * @return a tbm_surface_h if this function succeeds, otherwise NULL
118 * @retval #tbm_surface_h
121 #include <tbm_bufmgr.h>
122 #include <tbm_surface.h>
123 #include <tbm_surface_internal.h>
127 tbm_surface_h surface;
128 tbm_surface_info_s info;
133 bufmgr = tbm_bufmgr_init (bufmgr_fd);
134 bo[0] = tbm_bo_alloc (bufmgr, 128 * 128, TBM_BO_DEFAULT);
138 info.format = TBM_FORMAT_ARGB8888;
142 info.planes[0].size = 65536;
143 info.planes[0].offset = 0;
144 info.planes[0].stride = 512;
146 surface = tbm_surface_internal_create_with_bos (&info, bo, 1);
150 tbm_surface_destroy (surface);
151 tbm_surface_bufmgr_deinit (bufmgr);
154 tbm_surface_h tbm_surface_internal_create_with_bos (tbm_surface_info_s *info, tbm_bo *bos, int num);
158 * @brief Destroy the tbm surface
161 void tbm_surface_internal_destroy (tbm_surface_h surface);
164 * @brief reference the tbm surface
167 void tbm_surface_internal_ref (tbm_surface_h surface);
170 * @brief unreference the tbm surface
173 void tbm_surface_internal_unref (tbm_surface_h surface);
176 * @brief Gets the number of buffer objects associated with the tbm_surface.
177 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
178 * @param[in] surface : the tbm_surface_h
179 * @return the number of buffer objects associated with the tbm_surface_h, otherwise -1.
182 #include <tbm_surface.h>
183 #include <tbm_surface_internal.h>
185 tbm_surface_h surface;
188 surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420);
189 num_bos = tbm_surface_internal_get_num_bos (surface);
193 tbm_surface_destroy (surface);
196 int tbm_surface_internal_get_num_bos (tbm_surface_h surface);
199 * @brief Gets the buffor object by the bo_index.
200 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
201 * @param[in] surface : the tbm_surface_h
202 * @param[in] bo_idx : the bo index in the the tbm_surface
203 * @return the buffer object, otherwise NULL.
207 #include <tbm_surface.h>
208 #include <tbm_surface_internal.h>
210 tbm_surface_h surface;
214 surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420);
215 num_bos = tbm_surface_internal_get_num_bos (surface);
217 for (i=0 ; i < num_bos ; i++)
219 bo = tbm_surface_internal_get_bo (surface, i);
223 tbm_surface_destroy (surface);
226 tbm_bo tbm_surface_internal_get_bo (tbm_surface_h surface, int bo_idx);
229 * @brief Gets the size of the surface.
230 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
231 * @param[in] surface : the tbm_surface_h
232 * @return the size of tbm_surface, otherwise -1.
235 #include <tbm_surface.h>
236 #include <tbm_surface_internal.h>
238 tbm_surface_h surface;
241 surface = tbm_surface_create (128, 128, TBM_FORMAT_YUV420);
242 size = tbm_surface_internal_get_size (surface);
244 tbm_surface_destroy (surface);
247 int tbm_surface_internal_get_size (tbm_surface_h surface);
250 * @brief Gets size, offset and pitch data of plane by the plane_index.
251 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
252 * @param[in] surface : the tbm_surface_h
253 * @param[in] plane_idx : the bo index in the the tbm_surface
254 * @param[out] size : the size of plan in tbm_surface
255 * @param[out] offset : the offset of plan in tbm_surface
256 * @param[out] pitch : the pitch of plan in tbm_surface
257 * @return 1 if this function succeeds, otherwise 0.
260 #include <tbm_surface.h>
261 #include <tbm_surface_internal.h>
263 tbm_surface_h surface;
264 uint32_t size, offset, pitch;
267 surface = tbm_surfacel_create (128, 128, TBM_FORMAT_YUV420);
268 ret = tbm_surface_internal_get_plane_data (surface, 1, &size, &offset, &pitch);
272 tbm_surface_destroy (surface);
275 int tbm_surface_internal_get_plane_data (tbm_surface_h surface, int plane_idx, uint32_t *size, uint32_t *offset, uint32_t *pitch);
278 * @brief Gets number of planes by the format.
279 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
280 * @param[in] format : the format of surface
281 * @return number of planes by the format, otherwise 0.
284 #include <tbm_surface.h>
285 #include <tbm_surface_internal.h>
289 num = tbm_surface_internal_get_num_planes (TBM_FORMAT_YUV420);
295 int tbm_surface_internal_get_num_planes (tbm_format format);
298 * @brief Gets bpp by the format.
299 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
300 * @param[in] format : the format of surface
301 * @return bpp by the format, otherwise 0.
304 #include <tbm_surface.h>
305 #include <tbm_surface_internal.h>
309 bpp = tbm_surface_internal_get_bpp (TBM_FORMAT_YUV420);
315 int tbm_surface_internal_get_bpp (tbm_format format);
318 * @brief Gets bo index of plane.
320 * @param[in] surface : the tbm_surface_h
321 * @param[in] plane_idx : the bo index in the the tbm_surface
322 * @return bo index of plane, otherwise -1.
325 #include <tbm_surface.h>
326 #include <tbm_surface_internal.h>
329 tbm_surface_h surface;
331 surface = tbm_surfacel_create (128, 128, TBM_FORMAT_YUV420);
332 bo_idx = tbm_surface_internal_get_plane_bo_idx (surface, 0);
338 int tbm_surface_internal_get_plane_bo_idx (tbm_surface_h surface, int plane_idx);
341 * @brief Set the pid to the tbm_surface for debugging.
343 * @param[in] surface : the tbm_surface_h
344 * @param[in] pid : the pid
346 void tbm_surface_internal_set_debug_pid(tbm_surface_h surface, unsigned int pid);
352 #endif /* _TBM_SURFACE_INTERNAL_H_ */