add handling of more prior client than current one
[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 #define CHECK_ERR(val) if (WL_KEYROUTER_ERROR_NONE != val) return;
7 #define CHECK_ERR_VAL(val) if (WL_KEYROUTER_ERROR_NONE != val) return val;
8 #define CHECK_NULL(val) if (!val) return;
9 #define CHECK_NULL_VAL(val) if (!val) return val;
10
11 #define EOM_ERR(msg, ARG...) ERR("[eom module][%s:%d] "msg"\n", __FUNCTION__, __LINE__, ##ARG)
12 #define EOM_WARN(msg, ARG...) WARN("[eom module][%s:%d] "msg"\n", __FUNCTION__, __LINE__, ##ARG)
13 #define EOM_DBG(msg, ARG...) DBG("[eom module][%s:%d] "msg"\n", __FUNCTION__, __LINE__, ##ARG)
14
15 #define RETURNIFTRUE(statement, msg, ARG...)    \
16 if (statement)    \
17 {    \
18    EOM_ERR( msg, ##ARG);    \
19    return;    \
20 }
21
22 #define RETURNVALIFTRUE(statement, ret, msg, ARG...)    \
23 if (statement)    \
24 {    \
25    EOM_ERR( msg, ##ARG);    \
26    return ret;    \
27 }
28
29 #define GOTOIFTRUE(statement, lable, msg, ARG...)    \
30 if (statement)    \
31 {    \
32    EOM_ERR( msg, ##ARG);    \
33    goto lable;    \
34 }
35
36 /* E Module */
37 E_API extern E_Module_Api e_modapi;
38 E_API void *e_modapi_init(E_Module *m);
39 E_API int   e_modapi_shutdown(E_Module *m);
40 E_API int   e_modapi_save(E_Module *m);
41
42 #define NUM_MAIN_BUF 2
43 #define NUM_ATTR 3
44
45 typedef struct _E_Eom E_Eom, *E_EomPtr;
46 typedef struct _E_Eom_Out_Mode E_EomOutMode, *E_EomOutModePtr;
47 typedef struct _E_Eom_Event_Data E_EomEventData, *E_EomEventDataPtr;
48 typedef struct _E_Eom_Output E_EomOutput, *E_EomOutputPtr;
49 typedef struct _E_Eom_Fake_Buffers E_EomFakeBuffers, *E_EomFakeBuffersPtr;
50 typedef struct _E_Eom_Client_Buffer E_EomClientBuffer, *E_EomClientBufferPtr;
51 typedef struct _E_Eom_Client E_EomClient, *E_EomClientPtr;
52
53 typedef enum
54 {
55    DOWN = 0,
56    UP,
57 } E_EomFlag;
58
59 struct _E_Eom_Out_Mode
60 {
61    int w;
62    int h;
63 };
64
65 struct _E_Eom_Output
66 {
67    unsigned int id;
68    eom_output_type_e type;
69    eom_output_mode_e mode;
70    unsigned int w;
71    unsigned int h;
72    unsigned int phys_width;
73    unsigned int phys_height;
74
75    tdm_output_conn_status status;
76    E_EomFlag mirror_run;
77    eom_output_attribute_e attribute;
78    eom_output_attribute_state_e attribute_state;
79
80    /* external output data */
81    char *ext_output_name;
82    E_EomFlag is_external_init;
83    E_EomOutMode src_mode;
84    E_Comp_Wl_Output *wl_output;
85
86    /* internal output data */
87    char *int_output_name;
88    E_EomFlag is_internal_grab;
89    E_EomOutMode dst_mode;
90 };
91
92 struct _E_Eom
93 {
94    struct wl_global *global;
95    Eina_List *eom_clients;
96    Eina_List *handlers;
97
98    tdm_display *dpy;
99    tbm_bufmgr bufmgr;
100    int fd;
101
102    Eina_List *outputs;
103    unsigned int output_count;
104
105 #if 1
106    /* eom state */
107    enum wl_eom_mode eom_mode;
108    enum wl_eom_attribute eom_attribute;
109    enum wl_eom_attribute_state eom_attribute_state;
110    enum wl_eom_status eom_status;
111
112    /*data related to cooperating with clients */
113    E_EomFlag is_mirror_mode;
114    struct wl_resource *current_client;
115
116    /* external output data */
117    char *ext_output_name;
118    E_EomFlag is_external_init;
119    int id;
120    E_EomOutMode src_mode;
121    E_Comp_Wl_Output *wl_output;
122
123    /* internal output data */
124    char *int_output_name;
125    E_EomFlag is_internal_grab;
126    E_EomOutMode dst_mode;
127 #endif
128 };
129
130 struct _E_Eom_Event_Data
131 {
132    tdm_output *output;
133    tdm_layer *layer;
134    tdm_pp *pp;
135
136    /* mirror mode data*/
137    tbm_surface_h dst_buffers[NUM_MAIN_BUF];
138    int current_buffer;
139    int pp_buffer;
140
141    /* extended mode data */
142    Eina_List *client_buffers_list;
143 };
144
145 struct _E_Eom_Client_Buffer
146 {
147    E_Comp_Wl_Buffer *wl_buffer;
148    tbm_surface_h tbm_buffer;
149
150    unsigned long stamp;
151 };
152
153 struct _E_Eom_Client
154 {
155         struct wl_resource *resource;
156         Eina_Bool curent;
157 };
158
159 struct _E_Eom_Fake_Buffers
160 {
161    tbm_surface_h fake_buffers[NUM_MAIN_BUF];
162    int current_fake_buffer;
163 };
164
165 /* handle external output */
166 static E_Comp_Wl_Output *_e_eom_e_comp_wl_output_get(const Eina_List *outputs, const char *id);
167 static Eina_Bool _e_eom_set_up_external_output(const char *output_name, int width, int height);
168 static tdm_output * _e_eom_hal_output_get(const char *id);
169 static tdm_layer * _e_eom_hal_layer_get(tdm_output *output, int width, int height);
170 static Eina_Bool _e_eom_create_output_buffers(E_EomEventDataPtr eom_data, int width, int height);
171 static enum wl_eom_type _e_eom_output_name_to_eom_type(const char *output_name);
172
173 /* handle internal output, pp */
174 static Eina_Bool _e_eom_mirror_start(const char *output_name, int width, int height);
175 static tbm_surface_h _e_eom_root_internal_tdm_surface_get(const char *name);
176 static Eina_Bool _e_eom_pp_src_to_dst( tbm_surface_h src_buffer);
177 static Eina_Bool _e_eom_pp_is_needed(int src_w, int src_h, int dst_w, int dst_h);
178 static void _e_eom_pp_calculate_new_size(int *x, int *new_w, int src_w, int src_h, int dst_w, int dst_h);
179
180 /* tdm handlers */
181 static void _e_eom_pp_cb(tbm_surface_h surface, void *user_data);
182 static void _e_eom_commit_cb(tdm_output *output EINA_UNUSED, unsigned int sequence EINA_UNUSED,
183                                     unsigned int tv_sec EINA_UNUSED, unsigned int tv_usec EINA_UNUSED,
184                                     void *user_data);
185
186 /* clients buffers */
187 static E_EomClientBufferPtr _e_eom_create_client_buffer(E_Comp_Wl_Buffer *wl_buffer, tbm_surface_h tbm_buffer);
188 static void _e_eom_add_client_buffer_to_list(E_EomClientBufferPtr client_buffer);
189 static void _e_eom_client_buffers_list_free();
190 static E_EomClientBufferPtr _e_eom_get_client_buffer_from_list();
191
192 /*eom utils functions*/
193 static int _e_eom_get_time_in_mseconds();
194 static void _e_eom_create_fake_buffers(int width, int height);
195
196
197 #endif