/**************************************************************************
-
-libtdm
-
-Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
-
-Contact: Eunchul Kim <chulspro.kim@samsung.com>,
- JinYoung Jeon <jy0.jeon@samsung.com>,
- Taeheon Kim <th908.kim@samsung.com>,
- YoungJun Cho <yj44.cho@samsung.com>,
- SooChan Lim <sc1.lim@samsung.com>,
- Boram Park <sc1.lim@samsung.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
+ *
+ * libtdm
+ *
+ * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
+ * JinYoung Jeon <jy0.jeon@samsung.com>,
+ * Taeheon Kim <th908.kim@samsung.com>,
+ * YoungJun Cho <yj44.cho@samsung.com>,
+ * SooChan Lim <sc1.lim@samsung.com>,
+ * Boram Park <sc1.lim@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
**************************************************************************/
#ifndef _TDM_PRIVATE_H_
#include <stdio.h>
#include <string.h>
+#include <strings.h>
#include <stdlib.h>
+#include <assert.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
-#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <dirent.h>
+#include <poll.h>
+#include <sys/syscall.h>
+#include <sys/eventfd.h>
+#include <math.h>
+#include <wayland-server-protocol.h>
#include <tbm_bufmgr.h>
#include <tbm_surface_queue.h>
+#include <tbm_surface_internal.h>
+#include <tbm_drm_helper.h>
-#include "tdm_backend.h"
-#include "tdm_log.h"
-#include "tdm_list.h"
+#include "tdm_private_types.h"
+#include "tdm_macro.h"
+#include "tdm_helper.h"
+#include "tdm_thread.h"
+#include "tdm_config.h"
#ifdef __cplusplus
extern "C" {
#endif
-/**
- * @file tdm_private.h
- * @brief The private header file for a frontend library
- */
-
-#undef EXTERN
-#undef DEPRECATED
-#undef INTERN
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define EXTERN __attribute__ ((visibility("default")))
-#else
-#define EXTERN
-#endif
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define INTERN __attribute__ ((visibility("hidden")))
-#else
-#define INTERN
-#endif
-
-#if defined(__GNUC__) && __GNUC__ >= 4
-#define DEPRECATED __attribute__ ((deprecated))
-#else
-#define DEPRECATED
-#endif
-
-/* check condition */
-#define TDM_RETURN_IF_FAIL(cond) {\
- if (!(cond)) {\
- TDM_ERR ("'%s' failed", #cond);\
- return;\
- }\
-}
-#define TDM_RETURN_VAL_IF_FAIL(cond, val) {\
- if (!(cond)) {\
- TDM_ERR ("'%s' failed", #cond);\
- return val;\
- }\
-}
-#define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) {\
- if (!(cond)) {\
- TDM_ERR ("'%s' failed", #cond);\
- ret = error_v;\
- if (error) *error = ret;\
- return val;\
- }\
-}
-
-#define TDM_WARNING_IF_FAIL(cond) {\
- if (!(cond))\
- TDM_ERR ("'%s' failed", #cond);\
-}
-#define TDM_GOTO_IF_FAIL(cond, dst) {\
- if (!(cond)) {\
- TDM_ERR ("'%s' failed", #cond);\
- goto dst;\
- }\
-}
-
-#define TDM_NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")
-
-#define TDM_SNPRINTF(p, len, fmt, ARG...) \
- do { \
- if (p && len && *len > 0) \
- { \
- int s = snprintf(p, *len, fmt, ##ARG); \
- p += s; \
- *len -= s; \
- } \
- } while (0)
-
-#define C(b,m) (((b) >> (m)) & 0xFF)
-#define B(c,s) ((((unsigned int)(c)) & 0xff) << (s))
-#define FOURCC(a,b,c,d) (B(d,24) | B(c,16) | B(b,8) | B(a,0))
-#define FOURCC_STR(id) C(id,0), C(id,8), C(id,16), C(id,24)
-#define FOURCC_ID(str) FOURCC(((char*)str)[0],((char*)str)[1],((char*)str)[2],((char*)str)[3])
-
-typedef enum
-{
- TDM_CAPTURE_TARGET_OUTPUT,
- TDM_CAPTURE_TARGET_LAYER,
-} tdm_capture_target;
-
-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_pp tdm_private_pp;
-typedef struct _tdm_private_capture tdm_private_capture;
-typedef struct _tdm_private_vblank_handler tdm_private_vblank_handler;
-typedef struct _tdm_private_commit_handler tdm_private_commit_handler;
-
-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;
-
- /* backend function */
- tdm_display_capability capabilities;
- tdm_func_display func_display;
- tdm_func_output func_output;
- tdm_func_layer func_layer;
- 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;
-
- void **outputs_ptr;
-
- tbm_bufmgr bufmgr;
-};
-
-struct _tdm_private_output
-{
- struct list_head link;
-
- tdm_private_display *private_display;
-
- tdm_caps_output caps;
- tdm_output *output_backend;
-
- unsigned int pipe;
-
- int regist_vblank_cb;
- int regist_commit_cb;
-
- struct list_head layer_list;
- struct list_head capture_list;
- struct list_head vblank_handler_list;
- struct list_head commit_handler_list;
-
- void **layers_ptr;
-};
-
-struct _tdm_private_layer
-{
- struct list_head link;
-
- tdm_private_display *private_display;
- tdm_private_output *private_output;
-
- tdm_caps_layer caps;
- tdm_layer *layer_backend;
-
- tbm_surface_h waiting_buffer;
- tbm_surface_h showing_buffer;
- tbm_surface_queue_h buffer_queue;
-
- struct list_head capture_list;
-
- unsigned int usable;
-};
-
-struct _tdm_private_pp
-{
- struct list_head link;
-
- tdm_private_display *private_display;
-
- tdm_pp *pp_backend;
-};
-
-struct _tdm_private_capture
-{
- struct list_head link;
-
- tdm_capture_target target;
-
- tdm_private_display *private_display;
- tdm_private_output *private_output;
- tdm_private_layer *private_layer;
-
- tdm_capture *capture_backend;
-};
-
-struct _tdm_private_vblank_handler
-{
- struct list_head link;
-
- tdm_private_output *private_output;
- tdm_output_vblank_handler func;
- void *user_data;
-};
-
-struct _tdm_private_commit_handler
-{
- struct list_head link;
-
- tdm_private_output *private_output;
- tdm_output_commit_handler func;
- void *user_data;
-};
-
-tdm_private_pp* tdm_pp_create_internal(tdm_private_display *private_display, tdm_error *error);
-void tdm_pp_destroy_internal(tdm_private_pp *private_pp);
-
-tdm_private_capture* tdm_capture_create_output_internal(tdm_private_output *private_output, tdm_error *error);
-tdm_private_capture* tdm_capture_create_layer_internal(tdm_private_layer *private_layer, tdm_error *error);
-void tdm_capture_destroy_internal(tdm_private_capture *private_capture);
+//#define INIT_BUFMGR
+
+/*****************************************************************************
+ * This file includes
+ * - other private headers
+ * - function prototypes
+ *****************************************************************************/
+
+extern int tdm_debug_dump;
+extern int tdm_ttrace_module;
+extern int tdm_ttrace_output;
+
+int
+tdm_display_is_valid(tdm_display *display);
+tdm_private_display *
+tdm_display_get(void);
+
+int
+tdm_backend_check_module_abi(tdm_private_backend *private_backend, int abimaj, int abimin);
+
+void *
+tdm_display_find_output_stamp(tdm_private_display *private_display, double stamp);
+tdm_private_output *
+tdm_display_find_private_output(tdm_private_display *private_display, tdm_output *output_backend);
+
+tdm_error
+tdm_output_init(tdm_private_display *private_display);
+int
+tdm_output_is_valid(tdm_output *output);
+
+void
+tdm_output_thread_cb_change(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data);
+void
+tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status,
+ void *user_data);
+void
+tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms,
+ void *user_data);
+tdm_error
+tdm_output_cb_need_validate(tdm_private_output *private_output);
+
+void
+tdm_output_vblank_print_wait_information(tdm_private_output *private_output, void *user_data);
+tdm_error
+tdm_output_wait_vblank_add_front(tdm_output *output, int interval, int sync,
+ tdm_output_vblank_handler func, void *user_data);
+tdm_error
+tdm_output_commit_internal(tdm_output *output, int sync, tdm_output_commit_handler func, void *user_data);
+tdm_error
+tdm_output_get_dpms_internal(tdm_output *output, tdm_output_dpms *dpms_value);
+
+tdm_error
+tdm_output_need_validate_event_init(tdm_output *output);
+void
+tdm_output_need_validate_handler_thread(tdm_private_display *private_display, void *object, tdm_thread_cb_base *cb_base, void *user_data);
+tdm_error
+tdm_output_choose_commit_per_vblank_mode(tdm_private_output *private_output, int mode);
+
+void
+tdm_output_remove_vblank_handler_internal(tdm_output *output, tdm_output_vblank_handler func, void *user_data);
+void
+tdm_output_remove_commit_handler_internal(tdm_output *output, tdm_output_commit_handler func, void *user_data);
+void
+tdm_layer_remove_commit_handler_internal(tdm_layer *layer, tdm_layer_commit_handler func, void *user_data);
+
+tdm_error
+tdm_layer_commit_internal(tdm_private_layer *private_layer, tdm_layer_commit_handler func, void *user_data);
+tdm_error
+tdm_layer_commit_pending_data(tdm_private_layer *private_layer);
+void
+tdm_layer_committed(tdm_private_layer *private_layer, tdm_private_layer_buffer **committed_buffer);
+tdm_error
+tdm_layer_set_info_internal(tdm_private_layer *private_layer, tdm_info_layer *info);
+tdm_error
+tdm_layer_set_buffer_internal(tdm_private_layer *private_layer, tbm_surface_h buffer);
+tdm_error
+tdm_layer_unset_buffer_internal(tdm_private_layer *private_layer);
+
+tdm_error
+tdm_vblank_init(tdm_display *dpy);
+void
+tdm_vblank_deinit(tdm_display *dpy);
+tdm_error
+tdm_vblank_set_add_front(tdm_vblank *vblank, unsigned int add_front);
+tdm_error
+tdm_vblank_set_resource(tdm_vblank *vblank, struct wl_resource *resource);
+double
+tdm_vblank_get_stamp(tdm_vblank *vblank);
+tdm_error
+tdm_vblank_set_client_vblank_fps(unsigned int pid, const char *name, unsigned int fps);
+void
+tdm_vblank_get_vblank_list_information(tdm_display *dpy, char *reply, int *len);
+
+tdm_error
+tdm_pp_init(tdm_private_display *private_display);
+tdm_private_pp *
+tdm_pp_create_internal(tdm_private_backend *private_backend, tdm_error *error);
+void
+tdm_pp_destroy_internal(tdm_private_pp *private_pp);
+
+tdm_hwc_window *
+tdm_hwc_window_create_internal(tdm_private_output *private_output, int is_video, tdm_error *error);
+tdm_error
+tdm_hwc_window_destroy_internal(tdm_private_hwc_window * private_hwc_window);
+
+tdm_error
+tdm_capture_init(tdm_private_display *private_display);
+tdm_private_capture *
+tdm_capture_create_output_internal(tdm_private_output *private_output,
+ tdm_error *error);
+tdm_private_capture *
+tdm_capture_create_layer_internal(tdm_private_layer *private_layer,
+ tdm_error *error);
+void
+tdm_capture_destroy_internal(tdm_private_capture *private_capture);
+
+/* utility buffer functions for private */
+tdm_buffer_info*
+tdm_buffer_get_info(tbm_surface_h buffer);
+void
+tdm_buffer_remove_release_handler_internal(tbm_surface_h buffer);
+
+/* event functions for private */
+tdm_error
+tdm_event_loop_init(tdm_private_display *private_display);
+void
+tdm_event_loop_deinit(tdm_private_display *private_display);
+void
+tdm_event_loop_stop(tdm_private_display *private_display);
+void
+tdm_event_loop_create_backend_source(tdm_private_display *private_display);
+int
+tdm_event_loop_get_fd(tdm_private_display *private_display);
+tdm_error
+tdm_event_loop_dispatch(tdm_private_display *private_display);
+void
+tdm_event_loop_flush(tdm_private_display *private_display);
+tdm_error
+tdm_event_loop_trace_enable(tdm_private_display *private_display, unsigned int enable);
+
+tdm_error
+tdm_server_init(tdm_private_loop *private_loop);
+void
+tdm_server_deinit(tdm_private_loop *private_loop);
+const char*
+tdm_server_get_client_name(pid_t pid);
+tdm_error
+tdm_server_enable_ttrace_client_vblank(tdm_display *dpy, tdm_output *output, int enable);
+
+char *
+tdm_helper_dump_make_directory(const char *path, char *reply, int *len);
+double
+tdm_helper_get_time(void);
+
+extern int tdm_dump_enable;
+extern char *tdm_debug_dump_dir;
+
+tdm_error
+tdm_display_update_output(tdm_private_backend *private_backend,
+ tdm_output *output_backend, int pipe);
+tdm_error
+tdm_display_enable_debug_module(const char*modules);
+tdm_error
+tdm_display_enable_dump(tdm_private_display *private_display, const char *dump_str, char *reply, int *len);
+tdm_error
+tdm_display_enable_ttrace(tdm_private_display *private_display, const char *ttrace, int output_id, char *reply, int *len);
+tdm_error
+tdm_display_enable_fps(tdm_private_display *private_display, int enable);
+
+void
+tdm_monitor_server_command(tdm_display *dpy, const char *options, char *reply, int *len);
#ifdef __cplusplus
}