-#ifdef HAVE_TTRACE
-#include <ttrace.h>
-#define TDM_TRACE_BEGIN(fmt, ...) traceBegin(TTRACE_TAG_GRAPHICS, fmt, ##__VA_ARGS__)
-#define TDM_TRACE_END() traceEnd(TTRACE_TAG_GRAPHICS)
-#define TDM_TRACE_ASYNC_BEGIN(key, name,...) traceAsyncBegin(TTRACE_TAG_GRAPHICS, key, name, ##__VA_ARGS__)
-#define TDM_TRACE_ASYNC_END(key, name,...) traceAsyncEnd(TTRACE_TAG_GRAPHICS, key, name, ##__VA_ARGS__)
-#define TDM_TRACE_COUNT(count, fmt, ...) traceCounter(TTRACE_TAG_GRAPHICS, count, fmt, ##__VA_ARGS__)
-#define TDM_TRACE_MARK(fmt, ...) traceMark(TTRACE_TAG_GRAPHICS, fmt, ##__VA_ARGS__)
-#else
-#define TDM_TRACE_BEGIN(fmt, ...)
-#define TDM_TRACE_END()
-#define TDM_TRACE_ASYNC_BEGIN(key, name,...)
-#define TDM_TRACE_ASYNC_END(key, name,...)
-#define TDM_TRACE_COUNT(count, fmt, ...)
-#define TDM_TRACE_MARK(fmt, ...)
-#endif
-
-typedef enum {
- TDM_CAPTURE_TARGET_OUTPUT,
- TDM_CAPTURE_TARGET_LAYER,
-} tdm_capture_target;
-
-enum {
- TDM_DUMP_FLAG_LAYER = (1 << 0),
- TDM_DUMP_FLAG_PP = (1 << 1),
- TDM_DUMP_FLAG_CAPTURE = (1 << 2),
- TDM_DUMP_FLAG_WINDOW = (1 << 3),
-};
-
-#define TDM_DUMP_DIR "/tmp"
-
-typedef enum {
- TDM_COMMIT_TYPE_NONE,
- TDM_COMMIT_TYPE_OUTPUT,
- TDM_COMMIT_TYPE_LAYER,
-} tdm_commit_type;
-
-typedef struct _tdm_private_display tdm_private_display;
-typedef struct _tdm_private_output tdm_private_output;
-typedef struct _tdm_private_layer tdm_private_layer;
-typedef struct _tdm_private_hwc_window tdm_private_hwc_window;
-typedef struct _tdm_private_pp tdm_private_pp;
-typedef struct _tdm_private_capture tdm_private_capture;
-typedef struct _tdm_private_loop tdm_private_loop;
-typedef struct _tdm_private_server tdm_private_server;
-typedef struct _tdm_private_thread tdm_private_thread;
-typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler;
-typedef struct _tdm_private_output_commit_handler tdm_private_output_commit_handler;
-typedef struct _tdm_private_layer_commit_handler tdm_private_layer_commit_handler;
-typedef struct _tdm_private_change_handler tdm_private_change_handler;
-typedef struct _tdm_private_layer_buffer tdm_private_layer_buffer;
-
-struct _tdm_private_display {
- pthread_mutex_t lock;
- unsigned int init_count;
-
- /* backend module info */
- void *module;
- tdm_backend_module *module_data;
- tdm_backend_data *bdata;
-
-#ifdef INIT_BUFMGR
- tbm_bufmgr bufmgr;
-#endif
-
- /* backend function */
- tdm_display_capability capabilities;
- tdm_func_display func_display;
- tdm_func_output func_output;
- tdm_func_layer func_layer;
- tdm_func_hwc_window func_hwc_window;
- tdm_func_pp func_pp;
- tdm_func_capture func_capture;
-
- /* backend capability */
- tdm_caps_display caps_display;
- tdm_caps_pp caps_pp;
- tdm_caps_capture caps_capture;
-
- /* output, pp list */
- struct list_head output_list;
- struct list_head pp_list;
- struct list_head capture_list;
-
- void **outputs_ptr;
-
- /* for event handling */
- tdm_private_loop *private_loop;
-
- /* output order */
- tdm_output **outputs;
-
- int print_fps;
-};
-
-struct _tdm_private_output {
- struct list_head link;
-
- int index;
- double stamp;
-
- tdm_private_display *private_display;
-
- tdm_caps_output caps;
- tdm_output *output_backend;
-
- unsigned int pipe;
- tdm_output_dpms current_dpms_value;
- unsigned int waiting_dpms_change;
- const tdm_output_mode *current_mode;
-
- int regist_vblank_cb;
- int regist_commit_cb;
- int regist_change_cb;
- int regist_dpms_cb;
-
- struct list_head layer_list;
- struct list_head hwc_window_list;
- struct list_head capture_list;
- struct list_head vblank_handler_list;
- struct list_head output_commit_handler_list;
-
- /* for layer commit */
- struct list_head layer_commit_handler_list;
- struct list_head pending_commit_handler_list;
- tdm_vblank *vblank;
- int layer_waiting_vblank;
-
- /* seperate list for multi-thread*/
- struct list_head change_handler_list_main;
- struct list_head change_handler_list_sub;
-
- void **layers_ptr;
-
- /* TODO: temp solution for handling DPMS things in sub-htread */
- tdm_event_loop_source *dpms_changed_timer;
-
- struct {
- /* look at the tdm_output_set_need_revalidate_handler() declaration for the details */
- tdm_output_need_validate_handler hndl;
- int event_fd;
- } need_validate;
-
- /* calling a output commit per a vblank */
- int commit_per_vblank;
- tdm_commit_type commit_type;
-};
-
-struct _tdm_private_layer {
- struct list_head link;
-
- int index;
-
- tdm_private_display *private_display;
- tdm_private_output *private_output;
-
- tdm_caps_layer caps;
- tdm_layer *layer_backend;
-
- /* pending data until committed */
- unsigned int pending_info_changed;
- tdm_info_layer pending_info;
- unsigned int pending_buffer_changed;
- tbm_surface_h pending_buffer;
-
- /* When a buffer is set to a layer, it will be stored to waiting_buffer.
- * And when a layer is committed, it will be moved to committed_buffer.
- * Finally when a commit handler is called, it will be moved to showing_buffer.
- */
- tdm_private_layer_buffer *waiting_buffer;
- tdm_private_layer_buffer *committed_buffer; /* for output_commit */
- tdm_private_layer_buffer *showing_buffer;
- tbm_surface_queue_h buffer_queue;
-
- struct list_head capture_list;
-
- unsigned int usable;
- unsigned int committing;
-
- double fps_stamp;
- unsigned int fps_count;
-};
-
-struct _tdm_private_hwc_window {
- struct list_head link;
-
- int index;
- uint32_t zpos;
-
- tdm_private_display *private_display;
- tdm_private_output *private_output;
-
- tdm_hwc_window *hwc_window_backend;
-};
-
-
-struct _tdm_private_pp {
- struct list_head link;
-
- double stamp;
-
- tdm_private_display *private_display;
-
- tdm_pp *pp_backend;
-
- struct list_head pending_buffer_list;
- struct list_head buffer_list;
-
- tdm_info_pp info;
- pid_t owner_tid;
-
- tdm_pp_done_handler done_func;
- void *done_user_data;
-};
-
-struct _tdm_private_capture {
- struct list_head link;
- struct list_head display_link;
-
- double stamp;
-
- tdm_capture_target target;
-
- tdm_private_display *private_display;
- tdm_private_output *private_output;
- tdm_private_layer *private_layer;
-
- tdm_capture *capture_backend;
-
- struct list_head pending_buffer_list;
- struct list_head buffer_list;
-
- tdm_info_capture info;
- pid_t owner_tid;
-
- tdm_capture_done_handler done_func;
- void *done_user_data;
-};
-
-/* CAUTION:
- * Note that we don't need to (un)lock mutex to use this structure. If there is
- * no TDM thread, all TDM resources are protected by private_display's mutex.
- * If there is a TDM thread, this struct will be used only in a TDM thread.
- * So, we don't need to protect this structure by mutex. Not thread-safe.
- */
-struct _tdm_private_loop {
- /* TDM uses wl_event_loop to handle various event sources including the TDM
- * backend's fd.
- */
- struct wl_display *wl_display;
- struct wl_event_loop *wl_loop;
-
- int backend_fd;
- tdm_event_loop_source *backend_source;
-
- /* In event loop, all resources are accessed by this dpy.
- * CAUTION:
- * - DO NOT include other private structure in this structure because this
- * struct is not protected by mutex.
- */
- tdm_display *dpy;
-
- /* for handling TDM client requests */
- tdm_private_server *private_server;
-
- /* To have a TDM event thread. If TDM_THREAD enviroment variable is not set
- * private_thread is NULL.
- */
- tdm_private_thread *private_thread;
-};
-
-struct _tdm_private_vblank_handler {
- struct list_head link;
-
- tdm_private_output *private_output;
- int interval;
- int sync;
- tdm_output_vblank_handler func;
- void *user_data;
-
- pid_t owner_tid;
-};
-
-struct _tdm_private_output_commit_handler {
- struct list_head link;
-
- tdm_private_output *private_output;
- tdm_output_commit_handler func;
- void *user_data;
-
- pid_t owner_tid;
-};
-
-struct _tdm_private_layer_commit_handler {
- struct list_head link;
-
- tdm_private_layer *private_layer;
- tdm_layer_commit_handler func;
- void *user_data;
-
- tdm_private_layer_buffer *committed_buffer; /* for layer_commit */
-};
-
-struct _tdm_private_change_handler {
- struct list_head link;
-
- tdm_private_output *private_output;
- tdm_output_change_handler func;
- void *user_data;
-
- pid_t owner_tid;
-};
-
-struct _tdm_private_layer_buffer {
- tbm_surface_h buffer;
- struct list_head link;
-};
-
-typedef struct _tdm_buffer_info {
- tbm_surface_h buffer;
-
- /* ref_count for backend */
- int backend_ref_count;
-
- struct list_head release_funcs;
- struct list_head destroy_funcs;
-
- struct list_head *list;
- struct list_head link;
-} tdm_buffer_info;
-
-typedef struct _tdm_pp_private_buffer {
- tbm_surface_h src;
- tbm_surface_h dst;
- struct list_head link;
- struct list_head commit_link;
-} tdm_pp_private_buffer;
-
-typedef struct _tdm_capture_private_buffer {
- tbm_surface_h buffer;
- struct list_head link;
- struct list_head commit_link;
-} tdm_capture_private_buffer;