summaryrefslogtreecommitdiff
path: root/src/lib/edje/edje_main.c
blob: 13809e6a2cfbd110d4efd7eba8be29daed74afbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#include "edje_private.h"

static Edje_Version _version = { VMAJ, VMIN, VMIC, VREV };
EAPI Edje_Version * edje_version = &_version;

static int _edje_init_count = 0;
static Eina_Bool _need_imf = EINA_FALSE;

int _edje_default_log_dom = -1;
Eina_Mempool *_edje_real_part_mp = NULL;
Eina_Mempool *_edje_real_part_state_mp = NULL;

Eina_Cow *_edje_calc_params_map_cow = NULL;
Eina_Cow *_edje_calc_params_physics_cow = NULL;

static const Edje_Calc_Params_Map default_calc_map = {
   { 0, 0, 0 }, { 0.0, 0.0, 0.0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0.0, 0.0 }, NULL, 0
};

static const Edje_Calc_Params_Physics default_calc_physics = {
   0.0, 0.0, 0.0, 0.0, 0.0, { 0.0, 0.0 }, { 0.0, 0.0 }, 0, 0, { { 0, 0, 0 }, { 0, 0, 0 } }, 0, 0, 0, 0
};

/*============================================================================*
*                                   API                                      *
*============================================================================*/
EAPI int
edje_init(void)
{
   Eina_Strbuf *str;

   if (++_edje_init_count != 1)
     return _edje_init_count;

   srand(time(NULL));

   if (!eina_init())
     return --_edje_init_count;

   _edje_default_log_dom = eina_log_domain_register
       ("edje", EDJE_DEFAULT_LOG_COLOR);
   if (_edje_default_log_dom < 0)
     {
        EINA_LOG_ERR("Edje Can not create a general log domain.");
        goto shutdown_eina;
     }

   if (!ecore_init())
     {
        ERR("Ecore init failed");
        goto unregister_log_domain;
     }

   if (!embryo_init())
     {
        ERR("Embryo init failed");
        goto shutdown_ecore;
     }

   if (!eet_init())
     {
        ERR("Eet init failed");
        goto shutdown_embryo;
     }

   if (!evas_init())
     {
        ERR("Evas init failed");
        goto shutdown_eet;
     }

   if (!efreet_init())
     {
        ERR("Efreet init failed");
        goto shutdown_evas;
     }

   _edje_scale = FROM_DOUBLE(1.0);

   _edje_edd_init();
   _edje_text_init();
   _edje_box_init();
   _edje_external_init();
   _edje_module_init();
   _edje_message_init();
   _edje_multisense_init();
   edje_signal_init();

   _edje_real_part_mp = eina_mempool_add("chained_mempool",
                                         "Edje_Real_Part", NULL,
                                         sizeof (Edje_Real_Part), 256);
   if (!_edje_real_part_mp)
     {
        ERR("Mempool for Edje_Real_Part cannot be allocated.");
        goto shutdown_all;
     }

   _edje_real_part_state_mp = eina_mempool_add("chained_mempool",
                                               "Edje_Real_Part_State", NULL,
                                               sizeof (Edje_Real_Part_State), 64);
   if (!_edje_real_part_state_mp)
     {
        ERR("Mempool for Edje_Real_Part_State cannot be allocated.");
        goto shutdown_all;
     }

   _edje_calc_params_map_cow = eina_cow_add("Edje Calc Params Map", sizeof (Edje_Calc_Params_Map), 8, &default_calc_map, EINA_TRUE);
   _edje_calc_params_physics_cow = eina_cow_add("Edje Calc Params Physics", sizeof (Edje_Calc_Params_Physics), 8, &default_calc_physics, EINA_TRUE);

   _edje_language = eina_stringshare_add(getenv("LANGUAGE"));

   str = eina_strbuf_new();
   eina_strbuf_append_printf(str, "%s/edje", efreet_cache_home_get());
   _edje_cache_path = eina_stringshare_add(eina_strbuf_string_get(str));
   eina_strbuf_free(str);

   eina_log_timing(_edje_default_log_dom,
                   EINA_LOG_STATE_STOP,
                   EINA_LOG_STATE_INIT);

   return _edje_init_count;

shutdown_all:
   eina_mempool_del(_edje_real_part_state_mp);
   eina_mempool_del(_edje_real_part_mp);
   _edje_real_part_state_mp = NULL;
   _edje_real_part_mp = NULL;
   _edje_message_shutdown();
   _edje_module_shutdown();
   _edje_external_shutdown();
   _edje_box_shutdown();
   _edje_internal_proxy_shutdown();
   _edje_text_class_members_free();
   _edje_text_class_hash_free();
   _edje_size_class_members_free();
   _edje_size_class_hash_free();
   _edje_edd_shutdown();
   efreet_shutdown();
shutdown_evas:
   evas_shutdown();
shutdown_eet:
   eet_shutdown();
shutdown_embryo:
   embryo_shutdown();
shutdown_ecore:
   ecore_shutdown();
unregister_log_domain:
   eina_log_domain_unregister(_edje_default_log_dom);
   _edje_default_log_dom = -1;
shutdown_eina:
   eina_shutdown();
   return --_edje_init_count;
}

static int _edje_users = 0;

static void
_edje_shutdown_core(void)
{
   if (_edje_users > 0) return;

   eina_log_timing(_edje_default_log_dom,
                   EINA_LOG_STATE_START,
                   EINA_LOG_STATE_SHUTDOWN);

   _edje_file_cache_shutdown();
   _edje_color_class_members_free();
   _edje_color_class_hash_free();

   eina_stringshare_del(_edje_cache_path);
   eina_stringshare_del(_edje_language);
   _edje_cache_path = NULL;
   _edje_language = NULL;

   eina_mempool_del(_edje_real_part_state_mp);
   eina_mempool_del(_edje_real_part_mp);
   _edje_real_part_state_mp = NULL;
   _edje_real_part_mp = NULL;

   edje_signal_shutdown();
   _edje_multisense_shutdown();
   _edje_message_shutdown();
   _edje_module_shutdown();
   _edje_external_shutdown();
   _edje_box_shutdown();
   _edje_text_class_members_free();
   _edje_text_class_hash_free();
   _edje_size_class_members_free();
   _edje_size_class_hash_free();
   _edje_edd_shutdown();

   eina_cow_del(_edje_calc_params_map_cow);
   eina_cow_del(_edje_calc_params_physics_cow);
   _edje_calc_params_map_cow = NULL;
   _edje_calc_params_physics_cow = NULL;

#ifdef HAVE_ECORE_IMF
   if (_need_imf)
     ecore_imf_shutdown();
#endif

   efreet_shutdown();
   evas_shutdown();
   eet_shutdown();
   embryo_shutdown();
   ecore_shutdown();
   eina_log_domain_unregister(_edje_default_log_dom);
   _edje_default_log_dom = -1;
   eina_shutdown();
}

void
_edje_lib_ref(void)
{
   _edje_users++;
}

void
_edje_lib_unref(void)
{
   _edje_users--;
   if (_edje_users != 0) return;
   if (_edje_init_count == 0) _edje_shutdown_core();
}

EAPI int
edje_shutdown(void)
{
   if (_edje_init_count <= 0)
     {
        ERR("Init count not greater than 0 in shutdown.");
        return 0;
     }
   if (--_edje_init_count != 0)
     return _edje_init_count;

   _edje_shutdown_core();

   return _edje_init_count;
}

/* Private Routines */
void
_edje_del(Edje *ed)
{
   Edje_Text_Insert_Filter_Callback *cb;

   if (ed->processing_messages)
     {
        ed->delete_me = EINA_TRUE;
        return;
     }
   _edje_message_del(ed);
   _edje_signal_callback_free(ed->callbacks);
   ed->callbacks = NULL;
   _edje_file_del(ed);
   if (ed->path) eina_stringshare_del(ed->path);
   if (ed->group) eina_stringshare_del(ed->group);
   if (ed->parent) eina_stringshare_del(ed->parent);
   ed->path = NULL;
   ed->group = NULL;
   ed->parent = NULL;
   eina_hash_free(ed->color_classes);
   eina_hash_free(ed->text_classes);
   eina_hash_free(ed->size_classes);
   ed->color_classes = NULL;
   ed->text_classes = NULL;
   ed->size_classes = NULL;
   EINA_LIST_FREE(ed->text_insert_filter_callbacks, cb)
     {
        eina_stringshare_del(cb->part);
        free(cb);
     }
   EINA_LIST_FREE(ed->markup_filter_callbacks, cb)
     {
        eina_stringshare_del(cb->part);
        free(cb);
     }

   _edje_color_class_member_clean(ed);
   _edje_text_class_members_clean(ed);
   _edje_size_class_members_clean(ed);
}

void
_edje_clean_objects(Edje *ed)
{
   evas_object_del(ed->base->clipper);
   ed->base->evas = NULL;
   ed->obj = NULL;
   ed->base->clipper = NULL;
}

void
_edje_ref(Edje *ed)
{
   if (ed->references <= 0) return;
   ed->references++;
}

void
_edje_unref(Edje *ed)
{
   ed->references--;
   if (ed->references == 0) _edje_del(ed);
}

void
_edje_need_imf(void)
{
   if (_need_imf) return;
#ifdef HAVE_ECORE_IMF
   _need_imf = EINA_TRUE;
   ecore_imf_init();
#endif
}