4 #include "eom-server-protocol.h"
11 #define DUMP_PRESENTATION
20 extern Eina_Bool eom_server_debug_on;
22 #define ALEN(array) (sizeof(array) / sizeof(array)[0])
24 #define CHECK_ERR(val) if (WL_KEYROUTER_ERROR_NONE != val) return;
25 #define CHECK_ERR_VAL(val) if (WL_KEYROUTER_ERROR_NONE != val) return val;
26 #define CHECK_NULL(val) if (!val) return;
27 #define CHECK_NULL_VAL(val) if (!val) return val;
29 #define EOM_INF(msg, ARG...) INF("[eom module][%s:%d] " msg "\n", __FUNCTION__, __LINE__, ##ARG)
30 #define EOM_ERR(msg, ARG...) ERR("[eom module][%s:%d] ERR: " msg "\n", __FUNCTION__, __LINE__, ##ARG)
32 #define EOM_DBG(msg, ARG...) \
34 if (eom_server_debug_on) \
35 DBG("[eom module][%s:%d] DBG: " msg "\n", __FUNCTION__, __LINE__, ##ARG); \
38 #define EOM_WARN(msg, ARG...) \
40 if (eom_server_debug_on) \
41 WARN("[eom module][%s:%d] WARN: " msg "\n", __FUNCTION__, __LINE__, ##ARG); \
44 #define RETURNIFTRUE(statement, msg, ARG...) \
47 EOM_ERR( msg, ##ARG); \
51 #define RETURNVALIFTRUE(statement, ret, msg, ARG...) \
54 EOM_ERR( msg, ##ARG); \
58 #define GOTOIFTRUE(statement, lable, msg, ARG...) \
61 EOM_ERR( msg, ##ARG); \
66 E_API extern E_Module_Api e_modapi;
67 E_API void *e_modapi_init(E_Module *m);
68 E_API int e_modapi_shutdown(E_Module *m);
69 E_API int e_modapi_save(E_Module *m);
71 #define NUM_MAIN_BUF 2
73 #define EOM_CONNECT_CHECK_TIMEOUT 7.0
75 typedef struct _E_Eom E_Eom, *E_EomPtr;
76 typedef struct _E_Eom_Out_Mode E_EomOutMode, *E_EomOutModePtr;
77 typedef struct _E_Eom_Output E_EomOutput, *E_EomOutputPtr;
78 typedef struct _E_Eom_Client_Buffer E_EomClientBuffer, *E_EomClientBufferPtr;
79 typedef struct _E_Eom_Client E_EomClient, *E_EomClientPtr;
80 typedef struct _E_Eom_Comp_Object_Intercept_Hook_Data E_EomCompObjectInterceptHookData;
95 struct _E_Eom_Out_Mode
104 eom_output_type_e type;
105 eom_output_mode_e mode;
108 unsigned int phys_width;
109 unsigned int phys_height;
117 E_EomOutputState state;
118 tdm_output_conn_status status;
119 eom_output_attribute_e attribute;
120 eom_output_attribute_state_e attribute_state;
122 /* external output data */
123 E_Comp_Wl_Output *wl_output;
125 /* mirror mode data */
126 tbm_surface_h dst_buffers[NUM_MAIN_BUF];
127 tbm_surface_h src_buffer;
131 tbm_surface_h dummy_buffer;
133 #ifdef DUMP_PRESENTATION
138 /* for testing purposes */
148 struct wl_global *global;
154 /* Internal output data */
155 E_EomFlag main_output_state;
156 char *main_output_name;
159 char check_first_boot;
162 unsigned int output_count;
166 Eina_List *comp_object_intercept_hooks;
171 struct wl_resource *resource;
174 /* EOM output the client related to */
176 /* E_Client the client related to */
179 /*TODO: As I understand there are cannot be more than one client buffer on
180 *server side, but for future extendabilty store it in the list */
181 /*Client's buffers */
182 Eina_List *buffers_show;
183 Eina_List *buffers_del;
184 Eina_Bool first_buffer;
187 struct _E_Eom_Client_Buffer
189 E_Comp_Wl_Buffer *wl_buffer;
190 tbm_surface_h tbm_buffer;
195 struct _E_Eom_Comp_Object_Intercept_Hook_Data
198 E_Comp_Object_Intercept_Hook *hook;
201 static Eina_Bool _e_eom_init();
202 static Eina_Bool _e_eom_init_internal();
203 static void _e_eom_deinit();
205 static void _e_eom_cb_wl_request_set_attribute(struct wl_client *client,
206 struct wl_resource *resource,
209 static void _e_eom_cb_wl_request_set_xdg_window(struct wl_client *client,
210 struct wl_resource *resource,
212 struct wl_resource *surface);
213 static void _e_eom_cb_wl_request_set_shell_window(struct wl_client *client,
214 struct wl_resource *resource,
216 struct wl_resource *surface);
217 static void _e_eom_cb_wl_request_get_output_info(struct wl_client *client,
218 struct wl_resource *resource,
220 static void _e_eom_cb_wl_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id);
221 static void _e_eom_cb_wl_resource_destory(struct wl_resource *resource);
222 static Eina_Bool _e_eom_cb_ecore_drm_output(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
223 static Eina_Bool _e_eom_cb_ecore_drm_activate(void *data, int type EINA_UNUSED, void *event);
224 static Eina_Bool _e_eom_cb_client_buffer_change(void *data, int type, void *event);
225 static void _e_eom_cb_pp(tbm_surface_h surface, void *user_data);
226 static void _e_eom_cb_commit(tdm_output *output EINA_UNUSED, unsigned int sequence EINA_UNUSED,
227 unsigned int tv_sec EINA_UNUSED, unsigned int tv_usec EINA_UNUSED,
229 static void _e_eom_cb_tdm_output_status_change(tdm_output *output, tdm_output_change_type type,
230 tdm_value value, void *user_data);
231 static Eina_Bool _e_eom_cb_comp_object_redirected(void *data, E_Client *ec);
233 static Eina_Bool _e_eom_output_init(tdm_display *dpy);
234 static const tdm_output_mode *_e_eom_output_get_best_mode(tdm_output *output);
235 static int _e_eom_output_get_position(void);
236 static void _e_eom_output_start_mirror(E_EomOutputPtr eom_output);
237 static void _e_eom_output_stop_mirror(E_EomOutputPtr eom_output);
238 static void _e_eom_output_stop_presentation(E_EomOutputPtr eom_output);
239 static void _e_eom_output_deinit(E_EomOutputPtr eom_output, int pp);
240 static tdm_layer *_e_eom_output_get_layer(E_EomOutputPtr eom_output);
241 static E_EomOutputPtr _e_eom_output_get_by_id(int id);
242 static Eina_Bool _e_eom_output_start_pp(E_EomOutputPtr eom_output);
243 static Eina_Bool _e_eom_output_create_buffers(E_EomOutputPtr eom_output, int width, int height);
245 static void _e_eom_window_set_internal(struct wl_resource *resource, int output_id, E_Client *ec);
247 static Eina_Bool _e_eom_pp_init(E_EomOutputPtr eom_output, tbm_surface_h src_buffer);
248 static Eina_Bool _e_eom_pp_is_needed(int src_w, int src_h, int dst_w, int dst_h);
250 static void _e_eom_util_get_debug_env();
251 static tbm_surface_h _e_eom_util_create_buffer(int width, int height, int format, int flags);
252 static E_EomClientBufferPtr _e_eom_util_create_client_buffer(E_EomClientPtr client,
253 E_Comp_Wl_Buffer *wl_buffer,
254 tbm_surface_h tbm_buffer);
255 static void _e_eom_util_calculate_fullsize(int src_h, int src_v, int dst_size_h, int dst_size_v,
256 int *dst_x, int *dst_y, int *dst_w, int *dst_h);
257 static tbm_surface_h _e_eom_util_get_output_surface(const char *name);
258 static Eina_Bool _e_eom_util_add_comp_object_redirected_hook(E_Client *ec);
259 static int _e_eom_output_connected(E_EomOutputPtr eom_output);
261 static int _e_eom_util_get_stamp();
264 static void _e_eom_util_draw(tbm_surface_h surface);
267 static void _e_eom_util_check_frames(E_EomOutputPtr eom_output);
269 static void _e_eom_client_add_buffer(E_EomClientPtr client, E_EomClientBufferPtr buffer);
270 static void _e_eom_client_free_buffers(E_EomClientPtr client);
271 static E_EomClientBufferPtr _e_eom_client_get_buffer(E_EomClientPtr client);
272 static E_EomClientPtr _e_eom_client_get_by_resource(struct wl_resource *resource);
273 static E_EomClientPtr _e_eom_client_get_current_by_id(int id);
274 static E_EomClientPtr _e_eom_client_get_current_by_ec(E_Client *ec);