efl

Форк
0
/
edje_convert.c 
509 строк · 15.5 Кб
1
#include "edje_private.h"
2

3
static const Edje_File *_current_edje_file = NULL;
4

5
const Edje_File *
6
_edje_file_get(void)
7
{
8
   return _current_edje_file;
9
}
10

11
void
12
_edje_file_set(const Edje_File *edf)
13
{
14
   _current_edje_file = edf;
15
}
16

17
static void
18
_edje_font_string_free(void *data)
19
{
20
   Edje_Font_Directory_Entry *fe = data;
21

22
   eina_stringshare_del(fe->path);
23
   free(fe);
24
}
25

26
static void
27
_edje_collection_string_free(void *data)
28
{
29
   Edje_Part_Collection_Directory_Entry *ce = data;
30

31
   eina_stringshare_del(ce->entry);
32

33
   if (ce->ref)
34
     {
35
        Edje_File *edf;
36

37
        edf = (Edje_File *)_edje_file_get();
38

39
        if (!edf->warning)
40
          CRI("This program as probably called edje_shutdown() with "
41
              "active Edje objects still around. "
42
              "This can cause problems as both Evas and Edje retain "
43
              "references to the objects. "
44
              "You should shut down all canvases and objects "
45
              "before calling edje_shutdown(). "
46
              "The following errors are the edje object files and "
47
              "parts that are still hanging around, with their reference "
48
              "counts");
49

50
        edf->warning = 1;
51
        ERR("file: '%s', references: %i, part: '%s', references: %i",
52
            edf->path, edf->references,
53
            ce->ref->part, ce->ref->references);
54

55
        _edje_collection_free(edf, ce->ref, ce);
56
     }
57

58
   free(ce);
59
}
60

61
static Eina_Bool
62
_edje_file_convert_external(Edje_File *edf, Old_Edje_File *oedf)
63
{
64
   Edje_External_Directory_Entry *ede;
65
   unsigned int max;
66
   unsigned int i = 0;
67

68
   edf->external_dir = calloc(1, sizeof (Edje_External_Directory));
69
   if (!edf->external_dir) return EINA_FALSE;
70
   if (!oedf->external_dir) return EINA_TRUE;
71

72
   max = eina_list_count(oedf->external_dir->entries);
73
   edf->external_dir->entries = calloc(1, sizeof (Edje_External_Directory_Entry) * max);
74
   edf->external_dir->entries_count = max;
75

76
   if (!edf->external_dir->entries && max)
77
     return EINA_FALSE;
78

79
   EINA_LIST_FREE(oedf->external_dir->entries, ede)
80
     {
81
        edf->external_dir->entries[i++].entry = ede->entry;
82
        free(ede);
83
     }
84

85
   free(oedf->external_dir);
86
   oedf->external_dir = NULL;
87

88
   return EINA_TRUE;
89
}
90

91
static Eina_Bool
92
_edje_file_convert_images(Edje_File *edf, Old_Edje_File *oedf)
93
{
94
   Edje_Image_Directory_Entry *de;
95
   Edje_Image_Directory_Set *ds;
96
   Eina_List *l;
97
   int max;
98

99
   edf->image_dir = calloc(1, sizeof (Edje_Image_Directory));
100
   if (!edf->image_dir) return EINA_FALSE;
101
   if (!oedf->image_dir) return EINA_TRUE;
102

103
   max = -1;
104
   EINA_LIST_FOREACH(oedf->image_dir->entries, l, de)
105
     if (max < de->id)
106
       max = de->id;
107

108
   edf->image_dir->entries = calloc(1, sizeof (Edje_Image_Directory_Entry) * (max + 1));
109
   edf->image_dir->entries_count = max + 1;
110

111
   if (!edf->image_dir->entries && edf->image_dir->entries_count)
112
     return EINA_FALSE;
113

114
   EINA_LIST_FREE(oedf->image_dir->entries, de)
115
     {
116
        memcpy(edf->image_dir->entries + de->id,
117
               de,
118
               sizeof (Edje_Image_Directory_Entry));
119
        free(de);
120
     }
121

122
   max = -1;
123
   EINA_LIST_FOREACH(oedf->image_dir->sets, l, ds)
124
     if (max < ds->id)
125
       max = ds->id;
126

127
   edf->image_dir->sets = calloc(1, sizeof (Edje_Image_Directory_Set) * (max + 1));
128
   edf->image_dir->sets_count = max + 1;
129

130
   if (!edf->image_dir->sets && edf->image_dir->sets_count)
131
     {
132
        free(edf->image_dir->entries);
133
        edf->image_dir->entries = NULL;
134
        return EINA_FALSE;
135
     }
136

137
   EINA_LIST_FREE(oedf->image_dir->sets, ds)
138
     {
139
        memcpy(edf->image_dir->sets + ds->id,
140
               ds,
141
               sizeof (Edje_Image_Directory_Set));
142
        free(ds);
143
     }
144

145
   return EINA_TRUE;
146
}
147

148
Edje_File *
149
_edje_file_convert(Eet_File *file, Old_Edje_File *oedf)
150
{
151
   Edje_Part_Collection_Directory_Entry *ce;
152
   Edje_Font_Directory_Entry *fnt;
153
   Edje_File *edf;
154
   Eina_List *l;
155
   Edje_Data *ed;
156

157
   edf = calloc(1, sizeof (Edje_File));
158
   if (!edf) return NULL;
159

160
   edf->free_strings = eet_dictionary_get(file) ? 0 : 1;
161

162
   if (edf->free_strings)
163
     {
164
        edf->fonts = eina_hash_string_small_new(_edje_font_string_free);
165
        edf->collection = eina_hash_string_small_new(_edje_collection_string_free);
166
        edf->data = eina_hash_string_small_new((Eina_Free_Cb)eina_stringshare_del);
167
     }
168
   else
169
     {
170
        edf->fonts = eina_hash_string_small_new(free);
171
        edf->collection = eina_hash_string_small_new(free);
172
        edf->data = eina_hash_string_small_new(NULL);
173
     }
174

175
   if (!edf->fonts || !edf->collection || !edf->data)
176
     goto on_error;
177

178
   EINA_LIST_FREE(oedf->data, ed)
179
     {
180
        eina_hash_direct_add(edf->data, ed->key, ed->value);
181
        free(ed);
182
     }
183

184
   EINA_LIST_FOREACH(oedf->collection_dir->entries, l, ce)
185
     if (ce->entry)
186
       eina_hash_direct_add(edf->collection, ce->entry, ce);
187

188
   if (oedf->font_dir)
189
     EINA_LIST_FOREACH(oedf->font_dir->entries, l, fnt)
190
       {
191
          char *tmp;
192
          int length;
193

194
          length = strlen(fnt->entry) + 7;
195
          tmp = alloca(length);
196

197
          snprintf(tmp, length, "fonts/%s", fnt->entry);
198
          fnt->path = eina_stringshare_add(tmp);
199
          if (edf->free_strings)
200
            eina_stringshare_del(fnt->entry);
201
          fnt->entry = fnt->path + 6;
202

203
          eina_hash_direct_add(edf->fonts, fnt->entry, fnt);
204
       }
205

206
   if (!_edje_file_convert_images(edf, oedf))
207
     goto on_error;
208

209
   if (!_edje_file_convert_external(edf, oedf))
210
     goto on_error;
211

212
   edf->oef = oedf;
213
   edf->styles = oedf->styles;
214
   edf->color_classes = oedf->color_classes;
215
   edf->text_classes = oedf->text_classes;
216
   edf->size_classes = oedf->size_classes;
217
   edf->version = oedf->version;
218
   edf->feature_ver = oedf->feature_ver;
219
   edf->efl_version.major = oedf->efl_version.major;
220
   edf->efl_version.minor = oedf->efl_version.minor;
221
   edf->compiler = oedf->compiler;
222

223
   edf->dangling = EINA_FALSE;
224
   edf->warning = EINA_FALSE;
225

226
   /* Below you will find all memory structure that could be cleaned when under
227
      memory pressure */
228
   edf->collection_cache = NULL;
229
   edf->collection_patterns = NULL;
230

231
   return edf;
232

233
on_error:
234
   eina_hash_free(edf->fonts);
235
   eina_hash_free(edf->collection);
236
   eina_hash_free(edf->data);
237
   free(edf->image_dir);
238
   free(edf->external_dir);
239
   free(edf);
240
   return NULL;
241
}
242

243
static void
244
_edje_collection_program_add(Edje_Program ***array,
245
                             unsigned int *count,
246
                             Edje_Program *add)
247
{
248
   Edje_Program **tmp;
249

250
   tmp = realloc(*array, sizeof (Edje_Program *) * (*count + 1));
251
   if (!tmp) return;
252

253
   tmp[(*count)++] = add;
254
   *array = tmp;
255
}
256

257
Edje_Part_Collection *
258
_edje_collection_convert(Edje_File *file, Old_Edje_Part_Collection *oedc)
259
{
260
   Edje_Part_Collection_Directory_Entry *ce;
261
   Edje_Part_Collection *edc;
262
   Old_Edje_Part *part;
263
   Edje_Program *pg;
264
   Edje_Data *di;
265
   Eina_List *l;
266
   unsigned int k;
267

268
   ce = eina_hash_find(file->collection, oedc->part);
269

270
   /* Count each type part and their respective state */
271
   EINA_LIST_FOREACH(oedc->parts, l, part)
272
     {
273
        int *count;
274
        int dummy = 0;
275

276
        switch (part->type)
277
          {
278
#define CSP(Tp, Ce)       \
279
case EDJE_PART_TYPE_##Tp: \
280
  count = &Ce->count.Tp;  \
281
  break;
282

283
             CSP(RECTANGLE, ce);
284
             CSP(TEXT, ce);
285
             CSP(IMAGE, ce);
286
             CSP(SWALLOW, ce);
287
             CSP(TEXTBLOCK, ce);
288
             CSP(GROUP, ce);
289
             CSP(BOX, ce);
290
             CSP(TABLE, ce);
291
             CSP(EXTERNAL, ce);
292
             CSP(VECTOR, ce);
293

294
           default:
295
             count = &dummy;
296
             break;
297
          }
298

299
        *count += eina_list_count(part->other_desc) + 1;
300
     }
301
   ce->count.part = eina_list_count(oedc->parts);
302

303
#define CONVERT_EMN(Tp, Sz, Ce) \
304
  Ce->mp.Tp = eina_mempool_add("one_big", #Tp, NULL, sizeof (Sz), Ce->count.Tp);
305

306
   CONVERT_EMN(RECTANGLE, Edje_Part_Description_Common, ce);
307
   CONVERT_EMN(TEXT, Edje_Part_Description_Text, ce);
308
   CONVERT_EMN(IMAGE, Edje_Part_Description_Image, ce);
309
   CONVERT_EMN(SWALLOW, Edje_Part_Description_Common, ce);
310
   CONVERT_EMN(TEXTBLOCK, Edje_Part_Description_Text, ce);
311
   CONVERT_EMN(GROUP, Edje_Part_Description_Common, ce);
312
   CONVERT_EMN(BOX, Edje_Part_Description_Box, ce);
313
   CONVERT_EMN(TABLE, Edje_Part_Description_Table, ce);
314
   CONVERT_EMN(EXTERNAL, Edje_Part_Description_External, ce);
315
   CONVERT_EMN(part, Edje_Part, ce);
316
   CONVERT_EMN(VECTOR, Edje_Part_Description_Vector, ce);
317

318
   /* Change structure layout */
319
   edc = calloc(1, sizeof (Edje_Part_Collection));
320
   if (!edc) return NULL;
321
   ce->ref = edc;
322

323
   EINA_LIST_FREE(oedc->programs, pg)
324
     {
325
        if (!pg->signal && !pg->source)
326
          _edje_collection_program_add(&edc->programs.nocmp,
327
                                       &edc->programs.nocmp_count,
328
                                       pg);
329
        else if (pg->signal && !strpbrk(pg->signal, "*?[\\")
330
                 && pg->source && !strpbrk(pg->source, "*?[\\"))
331
          _edje_collection_program_add(&edc->programs.strcmp,
332
                                       &edc->programs.strcmp_count,
333
                                       pg);
334
        else if (pg->signal && edje_program_is_strncmp(pg->signal)
335
                 && pg->source && edje_program_is_strncmp(pg->source))
336
          _edje_collection_program_add(&edc->programs.strncmp,
337
                                       &edc->programs.strncmp_count,
338
                                       pg);
339
        else if (pg->signal && edje_program_is_strrncmp(pg->signal)
340
                 && pg->source && edje_program_is_strrncmp(pg->source))
341
          _edje_collection_program_add(&edc->programs.strrncmp,
342
                                       &edc->programs.strrncmp_count,
343
                                       pg);
344
        else
345
          _edje_collection_program_add(&edc->programs.fnmatch,
346
                                       &edc->programs.fnmatch_count,
347
                                       pg);
348
     }
349

350
   edc->data = eina_hash_string_small_new(NULL);
351
   EINA_LIST_FREE(oedc->data, di)
352
     {
353
        eina_hash_direct_add(edc->data, di->key, di->value);
354
        free(di);
355
     }
356

357
   edc->parts_count = eina_list_count(oedc->parts);
358
   edc->parts = calloc(edc->parts_count, sizeof (Edje_Part *));
359
   k = 0;
360

361
   EINA_LIST_FREE(oedc->parts, part)
362
     {
363
        Old_Edje_Part_Description *oepd;
364
        Edje_Pack_Element *elm;
365
        Edje_Part *replacement;
366
        unsigned int i;
367

368
        replacement = eina_mempool_malloc(ce->mp.part, sizeof (Edje_Part));
369

370
        replacement->name = part->name;
371
        replacement->default_desc = _edje_description_convert(part->type, ce, part->default_desc);
372

373
        replacement->other_count = eina_list_count(part->other_desc);
374
        replacement->other_desc = calloc(replacement->other_count, sizeof (Edje_Part_Description_Common *));
375

376
        i = 0;
377
        EINA_LIST_FREE(part->other_desc, oepd)
378
          replacement->other_desc[i++] = _edje_description_convert(part->type, ce, oepd);
379

380
        replacement->source = part->source;
381
        replacement->source2 = part->source2;
382
        replacement->source3 = part->source3;
383
        replacement->source4 = part->source4;
384
        replacement->source5 = part->source5;
385
        replacement->source6 = part->source6;
386
        replacement->id = part->id;
387
        replacement->clip_to_id = part->clip_to_id;
388
        replacement->dragable = part->dragable;
389
        replacement->items_count = eina_list_count(part->items);
390
        replacement->items = calloc(replacement->items_count, sizeof (Edje_Pack_Element *));
391

392
        i = 0;
393
        EINA_LIST_FREE(part->items, elm)
394
          replacement->items[i++] = elm;
395

396
        replacement->type = part->type;
397
        replacement->effect = part->effect;
398
        replacement->mouse_events = part->mouse_events;
399
        replacement->repeat_events = part->repeat_events;
400
        replacement->ignore_flags = part->ignore_flags;
401
        replacement->mask_flags = part->mask_flags;
402
        replacement->scale = part->scale;
403
        replacement->precise_is_inside = part->precise_is_inside;
404
        replacement->use_alternate_font_metrics = part->use_alternate_font_metrics;
405
        replacement->pointer_mode = part->pointer_mode;
406
        replacement->entry_mode = part->entry_mode;
407
        replacement->select_mode = part->select_mode;
408
        replacement->multiline = part->multiline;
409
        replacement->api = part->api;
410
        replacement->required = part->required;
411

412
        edc->parts[k++] = replacement;
413

414
        free(part);
415
     }
416

417
   edc->id = oedc->id;
418
   edc->alias = oedc->alias;
419
   edc->prop.min = oedc->prop.min;
420
   edc->prop.max = oedc->prop.max;
421
   edc->script = oedc->script;
422
   edc->part = oedc->part;
423
   edc->lua_script_only = oedc->lua_script_only;
424
   edc->checked = oedc->checked;
425

426
   free(oedc);
427

428
   return edc;
429
}
430

431
Edje_Part_Description_Common *
432
_edje_description_convert(int type,
433
                          Edje_Part_Collection_Directory_Entry *ce,
434
                          Old_Edje_Part_Description *oed)
435
{
436
   Edje_Part_Description_Common *result = NULL;
437

438
   switch (type)
439
     {
440
      case EDJE_PART_TYPE_RECTANGLE:
441
        result = eina_mempool_malloc(ce->mp.RECTANGLE,
442
                                     sizeof (Edje_Part_Description_Common));
443
        break;
444

445
      case EDJE_PART_TYPE_SWALLOW:
446
        result = eina_mempool_malloc(ce->mp.SWALLOW,
447
                                     sizeof (Edje_Part_Description_Common));
448
        break;
449

450
      case EDJE_PART_TYPE_GROUP:
451
        result = eina_mempool_malloc(ce->mp.GROUP,
452
                                     sizeof (Edje_Part_Description_Common));
453
        break;
454

455
      case EDJE_PART_TYPE_IMAGE:
456
      {
457
         Edje_Part_Description_Image *img;
458
         Edje_Part_Image_Id *id;
459
         unsigned int i = 0;
460

461
         img = eina_mempool_malloc(ce->mp.IMAGE, sizeof (Edje_Part_Description_Image));
462

463
         img->image.tweens_count = eina_list_count(oed->image.tween_list);
464
         img->image.tweens = calloc(img->image.tweens_count,
465
                                    sizeof (Edje_Part_Image_Id *));
466
         if (img->image.tweens_count > 0 && !img->image.tweens)
467
           {
468
              eina_mempool_free(ce->mp.IMAGE, img);
469
              return NULL;
470
           }
471

472
         EINA_LIST_FREE(oed->image.tween_list, id)
473
           img->image.tweens[i++] = id;
474

475
         img->image.id = oed->image.id;
476
         img->image.scale_hint = oed->image.scale_hint;
477
         img->image.set = oed->image.set;
478

479
         img->image.border = oed->image.border;
480
         img->image.fill = oed->image.fill;
481

482
         result = &img->common;
483
         break;
484
      }
485

486
#define CONVERT_ALLOC_POOL(Short, Type, Name)                                       \
487
case EDJE_PART_TYPE_##Short:                                                        \
488
{                                                                                   \
489
   Edje_Part_Description_##Type * Name;                                             \
490
                                                                                    \
491
   Name = eina_mempool_malloc(ce->mp.Short, sizeof (Edje_Part_Description_##Type)); \
492
   Name->Name = oed->Name;                                                          \
493
   result = &Name->common;                                                          \
494
   break;                                                                           \
495
}
496

497
        CONVERT_ALLOC_POOL(TEXT, Text, text);
498
        CONVERT_ALLOC_POOL(TEXTBLOCK, Text, text);
499
        CONVERT_ALLOC_POOL(BOX, Box, box);
500
        CONVERT_ALLOC_POOL(TABLE, Table, table);
501
        CONVERT_ALLOC_POOL(EXTERNAL, External, external_params);
502
        CONVERT_ALLOC_POOL(VECTOR, Vector, vector);
503
     }
504

505
   *result = oed->common;
506

507
   free(oed);
508
   return result;
509
}
510

511

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.