use %license macro to copy the COPYING file.
[platform/core/uifw/e-mod-tizen-eom.git] / src / e_mod_main.h
1 #ifndef E_MOD_MAIN_H
2 #define E_MOD_MAIN_H
3
4 #include "eom-server-protocol.h"
5
6 #if 0
7   #define DRAW_DUMMY
8 #endif
9
10 #if 0
11   #define DUMP_PRESENTATION
12   #define DUMP_NUM 30
13 #endif
14
15 #if 0
16   #define FRAMES
17   #include <time.h>
18 #endif
19
20 extern Eina_Bool eom_server_debug_on;
21
22 #define ALEN(array) (sizeof(array) / sizeof(array)[0])
23
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;
28
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)
31
32 #define EOM_DBG(msg, ARG...)    \
33 {    \
34    if (eom_server_debug_on)    \
35      DBG("[eom module][%s:%d] DBG: " msg "\n", __FUNCTION__, __LINE__, ##ARG);    \
36 }
37
38 #define EOM_WARN(msg, ARG...)    \
39 {    \
40    if (eom_server_debug_on)    \
41      WARN("[eom module][%s:%d] WARN: " msg "\n", __FUNCTION__, __LINE__, ##ARG);    \
42 }
43
44 #define RETURNIFTRUE(statement, msg, ARG...)    \
45 if (statement)    \
46 {    \
47    EOM_ERR( msg, ##ARG);    \
48    return;    \
49 }
50
51 #define RETURNVALIFTRUE(statement, ret, msg, ARG...)    \
52 if (statement)    \
53 {    \
54    EOM_ERR( msg, ##ARG);    \
55    return ret;    \
56 }
57
58 #define GOTOIFTRUE(statement, lable, msg, ARG...)    \
59 if (statement)    \
60 {    \
61    EOM_ERR( msg, ##ARG);    \
62    goto lable;    \
63 }
64
65 /* E Module */
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);
70
71 #define NUM_MAIN_BUF 2
72 #define NUM_ATTR 3
73 #define EOM_CONNECT_CHECK_TIMEOUT 7.0
74
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;
81
82 typedef enum
83 {
84    DOWN = 0,
85    UP,
86 } E_EomFlag;
87
88 typedef enum
89 {
90    NONE = 0,
91    MIRROR,
92    PRESENTATION,
93 } E_EomOutputState;
94
95 struct _E_Eom_Out_Mode
96 {
97    int w;
98    int h;
99 };
100
101 struct _E_Eom_Output
102 {
103    unsigned int id;
104    eom_output_type_e type;
105    eom_output_mode_e mode;
106    unsigned int width;
107    unsigned int height;
108    unsigned int phys_width;
109    unsigned int phys_height;
110
111    const char *name;
112
113    tdm_output *output;
114    tdm_layer *layer;
115    tdm_pp *pp;
116
117    E_EomOutputState state;
118    tdm_output_conn_status status;
119    eom_output_attribute_e attribute;
120    eom_output_attribute_state_e attribute_state;
121
122    /* external output data */
123    E_Comp_Wl_Output *wl_output;
124
125    /* mirror mode data */
126    tbm_surface_h dst_buffers[NUM_MAIN_BUF];
127    tbm_surface_h src_buffer;
128    int current_buffer;
129    int pp_buffer;
130
131    tbm_surface_h dummy_buffer;
132
133 #ifdef DUMP_PRESENTATION
134    Eina_Bool dump_do;
135    int dump_count;
136 #endif
137 #ifdef FRAMES
138    /* for testing purposes */
139    struct timeval prev;
140    struct timeval curr;
141
142    int num_frames;
143 #endif
144 };
145
146 struct _E_Eom
147 {
148    struct wl_global *global;
149
150    tdm_display *dpy;
151    tbm_bufmgr bufmgr;
152    int fd;
153
154    /* Internal output data */
155    E_EomFlag main_output_state;
156    char *main_output_name;
157    int width;
158    int height;
159    char check_first_boot;
160    Ecore_Timer *timer;
161
162    unsigned int output_count;
163    Eina_List *outputs;
164    Eina_List *clients;
165    Eina_List *handlers;
166    Eina_List *comp_object_intercept_hooks;
167 };
168
169 struct _E_Eom_Client
170 {
171    struct wl_resource *resource;
172    Eina_Bool current;
173
174    /* EOM output the client related to */
175    int output_id;
176    /* E_Client the client related to */
177    E_Client *ec;
178
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;
185 };
186
187 struct _E_Eom_Client_Buffer
188 {
189    E_Comp_Wl_Buffer *wl_buffer;
190    tbm_surface_h tbm_buffer;
191
192    unsigned long stamp;
193 };
194
195 struct _E_Eom_Comp_Object_Intercept_Hook_Data
196 {
197    E_Client *ec;
198    E_Comp_Object_Intercept_Hook *hook;
199 };
200
201 static Eina_Bool _e_eom_init();
202 static Eina_Bool _e_eom_init_internal();
203 static void _e_eom_deinit();
204
205 static void _e_eom_cb_wl_request_set_attribute(struct wl_client *client,
206                                                struct wl_resource *resource,
207                                                uint32_t output_id,
208                                                uint32_t attribute);
209 static void _e_eom_cb_wl_request_set_xdg_window(struct wl_client *client,
210                                                 struct wl_resource *resource,
211                                                 uint32_t output_id,
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,
215                                                   uint32_t output_id,
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,
219                                                  uint32_t output_id);
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,
228                              void *user_data);
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);
232
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);
244
245 static void _e_eom_window_set_internal(struct wl_resource *resource, int output_id, E_Client *ec);
246
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);
249
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);
260 #if 0
261 static int _e_eom_util_get_stamp();
262 #endif
263 #ifdef DRAW_DUMMY
264 static void _e_eom_util_draw(tbm_surface_h surface);
265 #endif
266 #ifdef FRAMES
267 static void _e_eom_util_check_frames(E_EomOutputPtr eom_output);
268 #endif
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);
275
276 #endif
277