b004dc666780ad6710e524279bfb685335ab19b9
[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
52 typedef enum
53 {
54    DOWN = 0,
55    UP,
56 } E_EomFlag;
57
58 struct _E_Eom_Out_Mode
59 {
60    int w;
61    int h;
62 };
63
64 struct _E_Eom_Output
65 {
66    unsigned int id;
67    eom_output_type_e type;
68    eom_output_mode_e mode;
69    unsigned int w;
70    unsigned int h;
71    unsigned int phys_width;
72    unsigned int phys_height;
73
74    tdm_output_conn_status status;
75    E_EomFlag mirror_run;
76    eom_output_attribute_e attribute;
77    eom_output_attribute_state_e attribute_state;
78
79    /* external output data */
80    char *ext_output_name;
81    E_EomFlag is_external_init;
82    E_EomOutMode src_mode;
83    E_Comp_Wl_Output *wl_output;
84
85    /* internal output data */
86    char *int_output_name;
87    E_EomFlag is_internal_grab;
88    E_EomOutMode dst_mode;
89 };
90
91 struct _E_Eom
92 {
93    struct wl_global *global;
94    Eina_List *eom_clients;
95    Eina_List *handlers;
96
97    tdm_display *dpy;
98    tbm_bufmgr bufmgr;
99    int fd;
100
101    Eina_List *outputs;
102    unsigned int output_count;
103
104 #if 1
105    /* eom state */
106    enum wl_eom_mode eom_mode;
107    enum wl_eom_attribute eom_attribute;
108    enum wl_eom_attribute_state eom_attribute_state;
109    enum wl_eom_status eom_status;
110
111    /*data related to cooperating with clients */
112    E_EomFlag is_mirror_mode;
113
114    /* external output data */
115    char *ext_output_name;
116    E_EomFlag is_external_init;
117    int id;
118    E_EomOutMode src_mode;
119    E_Comp_Wl_Output *wl_output;
120
121    /* internal output data */
122    char *int_output_name;
123    E_EomFlag is_internal_grab;
124    E_EomOutMode dst_mode;
125 #endif
126 };
127
128 struct _E_Eom_Event_Data
129 {
130    tdm_output *output;
131    tdm_layer *layer;
132    tdm_pp *pp;
133
134    /* mirror mode data*/
135    tbm_surface_h dst_buffers[NUM_MAIN_BUF];
136    int current_buffer;
137    int pp_buffer;
138
139    /* extended mode data */
140    Eina_List *client_buffers_list;
141 };
142
143 struct _E_Eom_Client_Buffer
144 {
145    E_Comp_Wl_Buffer *wl_buffer;
146    tbm_surface_h tbm_buffer;
147
148    unsigned long stamp;
149 };
150
151 struct _E_Eom_Fake_Buffers
152 {
153    tbm_surface_h fake_buffers[NUM_MAIN_BUF];
154    int current_fake_buffer;
155 };
156
157
158 /* handle external output */
159 static E_Comp_Wl_Output *_e_eom_e_comp_wl_output_get(const Eina_List *outputs, const char *id);
160 static Eina_Bool _e_eom_set_up_external_output(const char *output_name, int width, int height);
161 static tdm_output * _e_eom_hal_output_get(const char *id);
162 static tdm_layer * _e_eom_hal_layer_get(tdm_output *output, int width, int height);
163 static Eina_Bool _e_eom_create_output_buffers(E_EomEventDataPtr eom_data, int width, int height);
164 static enum wl_eom_type _e_eom_output_name_to_eom_type(const char *output_name);
165
166 /* handle internal output, pp */
167 static Eina_Bool _e_eom_mirror_start(const char *output_name, int width, int height);
168 static tbm_surface_h _e_eom_root_internal_tdm_surface_get(const char *name);
169 static Eina_Bool _e_eom_pp_src_to_dst( tbm_surface_h src_buffer);
170 static Eina_Bool _e_eom_pp_is_needed(int src_w, int src_h, int dst_w, int dst_h);
171 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);
172
173 /* tdm handlers */
174 static void _e_eom_pp_cb(tbm_surface_h surface, void *user_data);
175 static void _e_eom_commit_cb(tdm_output *output EINA_UNUSED, unsigned int sequence EINA_UNUSED,
176                                     unsigned int tv_sec EINA_UNUSED, unsigned int tv_usec EINA_UNUSED,
177                                     void *user_data);
178
179 /* clients buffers */
180 static E_EomClientBufferPtr _e_eom_create_client_buffer(E_Comp_Wl_Buffer *wl_buffer, tbm_surface_h tbm_buffer);
181 static void _e_eom_add_client_buffer_to_list(E_EomClientBufferPtr client_buffer);
182 static void _e_eom_client_buffers_list_free();
183 static E_EomClientBufferPtr _e_eom_get_client_buffer_from_list();
184
185 /*eom utils functions*/
186 static int _e_eom_get_time_in_mseconds();
187 static void _e_eom_create_fake_buffers(int width, int height);
188
189
190 #endif