1 /**************************************************************************
5 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 JinYoung Jeon <jy0.jeon@samsung.com>,
9 Taeheon Kim <th908.kim@samsung.com>,
10 YoungJun Cho <yj44.cho@samsung.com>,
11 SooChan Lim <sc1.lim@samsung.com>,
12 Boram Park <sc1.lim@samsung.com>
14 Permission is hereby granted, free of charge, to any person obtaining a
15 copy of this software and associated documentation files (the
16 "Software"), to deal in the Software without restriction, including
17 without limitation the rights to use, copy, modify, merge, publish,
18 distribute, sub license, and/or sell copies of the Software, and to
19 permit persons to whom the Software is furnished to do so, subject to
20 the following conditions:
22 The above copyright notice and this permission notice (including the
23 next paragraph) shall be included in all copies or substantial portions
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
36 #ifndef _TDM_PRIVATE_H_
37 #define _TDM_PRIVATE_H_
46 #include <sys/types.h>
52 #include <sys/syscall.h>
53 #include <sys/types.h>
55 #include <tbm_bufmgr.h>
56 #include <tbm_surface_queue.h>
58 #include "tdm_backend.h"
68 * @brief The private header file for a frontend library
71 extern int tdm_debug_buffer;
72 extern int tdm_debug_mutex;
73 extern int tdm_debug_thread;
79 #if defined(__GNUC__) && __GNUC__ >= 4
80 #define EXTERN __attribute__ ((visibility("default")))
85 #if defined(__GNUC__) && __GNUC__ >= 4
86 #define INTERN __attribute__ ((visibility("hidden")))
91 #if defined(__GNUC__) && __GNUC__ >= 4
92 #define DEPRECATED __attribute__ ((deprecated))
98 #define TDM_RETURN_IF_FAIL(cond) {\
100 TDM_ERR ("'%s' failed", #cond);\
104 #define TDM_RETURN_VAL_IF_FAIL(cond, val) {\
106 TDM_ERR ("'%s' failed", #cond);\
110 #define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) {\
112 TDM_ERR ("'%s' failed", #cond);\
114 if (error) *error = ret;\
119 #define TDM_WARNING_IF_FAIL(cond) {\
121 TDM_ERR ("'%s' failed", #cond);\
123 #define TDM_GOTO_IF_FAIL(cond, dst) {\
125 TDM_ERR ("'%s' failed", #cond);\
132 #define TDM_TRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_GRAPHICS, "TDM:"#NAME)
133 #define TDM_TRACE_END() traceEnd(TTRACE_TAG_GRAPHICS)
135 #define TDM_TRACE_BEGIN(NAME)
136 #define TDM_TRACE_END()
139 #define TDM_NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
141 #define TDM_SNPRINTF(p, len, fmt, ARG...) \
143 if (p && len && *len > 0) \
145 int s = snprintf(p, *len, fmt, ##ARG); \
151 #define C(b,m) (((b) >> (m)) & 0xFF)
152 #define B(c,s) ((((unsigned int)(c)) & 0xff) << (s))
153 #define FOURCC(a,b,c,d) (B(d,24) | B(c,16) | B(b,8) | B(a,0))
154 #define FOURCC_STR(id) C(id,0), C(id,8), C(id,16), C(id,24)
155 #define FOURCC_ID(str) FOURCC(((char*)str)[0],((char*)str)[1],((char*)str)[2],((char*)str)[3])
158 TDM_CAPTURE_TARGET_OUTPUT,
159 TDM_CAPTURE_TARGET_LAYER,
160 } tdm_capture_target;
162 typedef struct _tdm_private_display tdm_private_display;
163 typedef struct _tdm_private_output tdm_private_output;
164 typedef struct _tdm_private_layer tdm_private_layer;
165 typedef struct _tdm_private_pp tdm_private_pp;
166 typedef struct _tdm_private_capture tdm_private_capture;
167 typedef struct _tdm_private_loop tdm_private_loop;
168 typedef struct _tdm_private_thread tdm_private_thread;
169 typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler;
170 typedef struct _tdm_private_commit_handler tdm_private_commit_handler;
171 typedef struct _tdm_private_change_handler tdm_private_change_handler;
173 struct _tdm_private_display {
174 pthread_mutex_t lock;
175 unsigned int init_count;
177 /* backend module info */
179 tdm_backend_module *module_data;
180 tdm_backend_data *bdata;
182 /* backend function */
183 tdm_display_capability capabilities;
184 tdm_func_display func_display;
185 tdm_func_output func_output;
186 tdm_func_layer func_layer;
188 tdm_func_capture func_capture;
190 /* backend capability */
191 tdm_caps_display caps_display;
193 tdm_caps_capture caps_capture;
195 /* output, pp list */
196 struct list_head output_list;
197 struct list_head pp_list;
198 struct list_head capture_list;
202 /* for event handling */
203 tdm_private_loop *private_loop;
205 /* for own event thread */
206 tdm_private_thread *private_thread;
209 struct _tdm_private_output {
210 struct list_head link;
214 tdm_private_display *private_display;
216 tdm_caps_output caps;
217 tdm_output *output_backend;
221 int regist_vblank_cb;
222 int regist_commit_cb;
223 int regist_change_cb;
225 struct list_head layer_list;
226 struct list_head capture_list;
227 struct list_head vblank_handler_list;
228 struct list_head commit_handler_list;
229 struct list_head change_handler_list;
234 struct _tdm_private_layer {
235 struct list_head link;
237 tdm_private_display *private_display;
238 tdm_private_output *private_output;
241 tdm_layer *layer_backend;
243 tbm_surface_h pending_buffer;
244 tbm_surface_h waiting_buffer;
245 tbm_surface_h showing_buffer;
246 tbm_surface_queue_h buffer_queue;
248 struct list_head capture_list;
253 struct _tdm_private_pp {
254 struct list_head link;
258 tdm_private_display *private_display;
262 struct list_head src_pending_buffer_list;
263 struct list_head dst_pending_buffer_list;
264 struct list_head src_buffer_list;
265 struct list_head dst_buffer_list;
268 struct _tdm_private_capture {
269 struct list_head link;
270 struct list_head display_link;
274 tdm_capture_target target;
276 tdm_private_display *private_display;
277 tdm_private_output *private_output;
278 tdm_private_layer *private_layer;
280 tdm_capture *capture_backend;
282 struct list_head pending_buffer_list;
283 struct list_head buffer_list;
286 struct _tdm_private_vblank_handler {
287 struct list_head link;
289 tdm_private_output *private_output;
290 tdm_output_vblank_handler func;
294 struct _tdm_private_commit_handler {
295 struct list_head link;
297 tdm_private_output *private_output;
298 tdm_output_commit_handler func;
302 struct _tdm_private_change_handler {
303 struct list_head link;
305 tdm_private_output *private_output;
306 tdm_output_change_handler func;
310 typedef struct _tdm_buffer_info {
311 tbm_surface_h buffer;
313 /* ref_count for backend */
314 int backend_ref_count;
316 struct list_head release_funcs;
317 struct list_head destroy_funcs;
319 struct list_head *list;
320 struct list_head link;
324 tdm_display_find_output_stamp(tdm_private_display *private_display,
325 unsigned long stamp);
327 tdm_pp_find_stamp(tdm_private_display *private_display, unsigned long stamp);
328 tdm_private_capture *
329 tdm_capture_find_stamp(tdm_private_display *private_display, unsigned long stamp);
332 tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
333 unsigned int tv_sec, unsigned int tv_usec, void *user_data);
335 tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
336 unsigned int tv_sec, unsigned int tv_usec, void *user_data);
338 tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status,
341 tdm_pp_cb_done(tdm_pp *pp_backend, tbm_surface_h src, tbm_surface_h dst,
344 tdm_capture_cb_done(tdm_capture *capture_backend, tbm_surface_h buffer,
348 tdm_output_call_change_handler_internal(tdm_private_output *private_output,
349 tdm_output_change_type type,
353 tdm_pp_create_internal(tdm_private_display *private_display, tdm_error *error);
355 tdm_pp_destroy_internal(tdm_private_pp *private_pp);
357 tdm_private_capture *
358 tdm_capture_create_output_internal(tdm_private_output *private_output,
360 tdm_private_capture *
361 tdm_capture_create_layer_internal(tdm_private_layer *private_layer,
364 tdm_capture_destroy_internal(tdm_private_capture *private_capture);
366 /* utility buffer functions for private */
368 tdm_buffer_get_info(tbm_surface_h buffer);
370 tdm_buffer_list_get_first_entry(struct list_head *list);
372 tdm_buffer_list_dump(struct list_head *list);
374 /* event functions for private */
376 tdm_event_loop_init(tdm_private_display *private_display);
378 tdm_event_loop_deinit(tdm_private_display *private_display);
380 tdm_event_loop_create_backend_source(tdm_private_display *private_display);
382 tdm_event_loop_get_fd(tdm_private_display *private_display);
384 tdm_event_loop_dispatch(tdm_private_display *private_display);
386 tdm_event_loop_add_socket(tdm_private_display *private_display, const char *name);
391 TDM_THREAD_CB_OUTPUT_COMMIT,
392 TDM_THREAD_CB_OUTPUT_VBLANK,
393 TDM_THREAD_CB_OUTPUT_STATUS,
394 TDM_THREAD_CB_PP_DONE,
395 TDM_THREAD_CB_CAPTURE_DONE,
396 } tdm_thread_cb_type;
398 typedef struct _tdm_thread_cb_base tdm_thread_cb_base;
399 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_commit;
400 typedef struct _tdm_thread_cb_output_vblank tdm_thread_cb_output_vblank;
401 typedef struct _tdm_thread_cb_output_status tdm_thread_cb_output_status;
402 typedef struct _tdm_thread_cb_pp_done tdm_thread_cb_pp_done;
403 typedef struct _tdm_thread_cb_capture_done tdm_thread_cb_capture_done;
405 struct _tdm_thread_cb_base {
406 tdm_thread_cb_type type;
410 struct _tdm_thread_cb_output_vblank {
411 tdm_thread_cb_base base;
412 unsigned long output_stamp;
413 unsigned int sequence;
415 unsigned int tv_usec;
419 struct _tdm_thread_cb_output_status {
420 tdm_thread_cb_base base;
421 unsigned long output_stamp;
422 tdm_output_conn_status status;
426 struct _tdm_thread_cb_pp_done {
427 tdm_thread_cb_base base;
428 unsigned long pp_stamp;
434 struct _tdm_thread_cb_capture_done {
435 tdm_thread_cb_base base;
436 unsigned long capture_stamp;
437 tbm_surface_h buffer;
442 tdm_thread_init(tdm_private_display *private_display);
444 tdm_thread_deinit(tdm_private_display *private_display);
446 tdm_thread_get_fd(tdm_private_display *private_display);
448 tdm_thread_send_cb(tdm_private_display *private_display, tdm_thread_cb_base *base);
450 tdm_thread_handle_cb(tdm_private_display *private_display);
452 tdm_thread_in_display_thread(tdm_private_display *private_display);
455 tdm_helper_get_time_in_millis(void);
457 #define _pthread_mutex_lock(l) \
458 do {if (tdm_debug_mutex) TDM_INFO("mutex lock"); pthread_mutex_lock(l);} while (0)
459 #define _pthread_mutex_unlock(l) \
460 do {if (tdm_debug_mutex) TDM_INFO("mutex unlock"); pthread_mutex_unlock(l);} while (0)
466 #endif /* _TDM_PRIVATE_H_ */