diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/edje/src/lib/edje_cache.c | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/edje/src/lib/edje_cache.c')
-rw-r--r-- | libraries/edje/src/lib/edje_cache.c | 567 |
1 files changed, 0 insertions, 567 deletions
diff --git a/libraries/edje/src/lib/edje_cache.c b/libraries/edje/src/lib/edje_cache.c deleted file mode 100644 index 02d16b5..0000000 --- a/libraries/edje/src/lib/edje_cache.c +++ /dev/null | |||
@@ -1,567 +0,0 @@ | |||
1 | #include "edje_private.h" | ||
2 | |||
3 | |||
4 | /** | ||
5 | * @cond | ||
6 | */ | ||
7 | |||
8 | static Eina_Hash *_edje_file_hash = NULL; | ||
9 | static int _edje_file_cache_size = 16; | ||
10 | static Eina_List *_edje_file_cache = NULL; | ||
11 | |||
12 | static int _edje_collection_cache_size = 16; | ||
13 | |||
14 | static Edje_Part_Collection * | ||
15 | _edje_file_coll_open(Edje_File *edf, const char *coll) | ||
16 | { | ||
17 | Edje_Part_Collection *edc = NULL; | ||
18 | Edje_Part_Collection_Directory_Entry *ce; | ||
19 | int id = -1, size = 0; | ||
20 | Eina_List *l; | ||
21 | char buf[256]; | ||
22 | char *buffer; | ||
23 | void *data; | ||
24 | |||
25 | ce = eina_hash_find(edf->collection, coll); | ||
26 | if (!ce) return NULL; | ||
27 | |||
28 | if (ce->ref) | ||
29 | { | ||
30 | ce->ref->references++; | ||
31 | return ce->ref; | ||
32 | } | ||
33 | |||
34 | EINA_LIST_FOREACH(edf->collection_cache, l, edc) | ||
35 | { | ||
36 | if (!strcmp(edc->part, coll)) | ||
37 | { | ||
38 | edc->references = 1; | ||
39 | ce->ref = edc; | ||
40 | |||
41 | edf->collection_cache = eina_list_remove_list(edf->collection_cache, l); | ||
42 | return ce->ref; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | id = ce->id; | ||
47 | if (id < 0) return NULL; | ||
48 | |||
49 | #define INIT_EMP(Tp, Sz, Ce) \ | ||
50 | buffer = alloca(strlen(ce->entry) + strlen(#Tp) + 2); \ | ||
51 | sprintf(buffer, "%s/%s", ce->entry, #Tp); \ | ||
52 | Ce->mp.Tp = eina_mempool_add("one_big", buffer, NULL, sizeof (Sz), Ce->count.Tp); \ | ||
53 | _emp_##Tp = Ce->mp.Tp; | ||
54 | |||
55 | #define INIT_EMP_BOTH(Tp, Sz, Ce) \ | ||
56 | INIT_EMP(Tp, Sz, Ce) \ | ||
57 | Ce->mp_rtl.Tp = eina_mempool_add("one_big", buffer, NULL, \ | ||
58 | sizeof (Sz), Ce->count.Tp); | ||
59 | |||
60 | INIT_EMP_BOTH(RECTANGLE, Edje_Part_Description_Common, ce); | ||
61 | INIT_EMP_BOTH(TEXT, Edje_Part_Description_Text, ce); | ||
62 | INIT_EMP_BOTH(IMAGE, Edje_Part_Description_Image, ce); | ||
63 | INIT_EMP_BOTH(PROXY, Edje_Part_Description_Proxy, ce); | ||
64 | INIT_EMP_BOTH(SWALLOW, Edje_Part_Description_Common, ce); | ||
65 | INIT_EMP_BOTH(TEXTBLOCK, Edje_Part_Description_Text, ce); | ||
66 | INIT_EMP_BOTH(GROUP, Edje_Part_Description_Common, ce); | ||
67 | INIT_EMP_BOTH(BOX, Edje_Part_Description_Box, ce); | ||
68 | INIT_EMP_BOTH(TABLE, Edje_Part_Description_Table, ce); | ||
69 | INIT_EMP_BOTH(EXTERNAL, Edje_Part_Description_External, ce); | ||
70 | INIT_EMP(part, Edje_Part, ce); | ||
71 | |||
72 | snprintf(buf, sizeof(buf), "edje/collections/%i", id); | ||
73 | edc = eet_data_read(edf->ef, _edje_edd_edje_part_collection, buf); | ||
74 | if (!edc) return NULL; | ||
75 | |||
76 | edc->references = 1; | ||
77 | edc->part = ce->entry; | ||
78 | |||
79 | /* For Edje file build with Edje 1.0 */ | ||
80 | if (edf->version <= 3 && edf->minor <= 1) | ||
81 | { | ||
82 | /* This will preserve previous rendering */ | ||
83 | unsigned int i; | ||
84 | |||
85 | /* people expect signal to not be broadcasted */ | ||
86 | edc->broadcast_signal = EINA_FALSE; | ||
87 | |||
88 | /* people expect text.align to be 0.0 0.0 */ | ||
89 | for (i = 0; i < edc->parts_count; ++i) | ||
90 | { | ||
91 | if (edc->parts[i]->type == EDJE_PART_TYPE_TEXTBLOCK) | ||
92 | { | ||
93 | Edje_Part_Description_Text *text; | ||
94 | unsigned int j; | ||
95 | |||
96 | text = (Edje_Part_Description_Text*) edc->parts[i]->default_desc; | ||
97 | text->text.align.x = TO_DOUBLE(0.0); | ||
98 | text->text.align.y = TO_DOUBLE(0.0); | ||
99 | |||
100 | for (j = 0; j < edc->parts[i]->other.desc_count; ++j) | ||
101 | { | ||
102 | text = (Edje_Part_Description_Text*) edc->parts[i]->other.desc[j]; | ||
103 | text->text.align.x = TO_DOUBLE(0.0); | ||
104 | text->text.align.y = TO_DOUBLE(0.0); | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | |||
110 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/compiled/%i", id); | ||
111 | data = eet_read(edf->ef, buf, &size); | ||
112 | |||
113 | if (data) | ||
114 | { | ||
115 | edc->script = embryo_program_new(data, size); | ||
116 | _edje_embryo_script_init(edc); | ||
117 | free(data); | ||
118 | } | ||
119 | |||
120 | snprintf(buf, sizeof(buf), "edje/scripts/lua/%i", id); | ||
121 | data = eet_read(edf->ef, buf, &size); | ||
122 | |||
123 | if (data) | ||
124 | { | ||
125 | _edje_lua2_script_load(edc, data, size); | ||
126 | free(data); | ||
127 | } | ||
128 | |||
129 | ce->ref = edc; | ||
130 | |||
131 | return edc; | ||
132 | } | ||
133 | |||
134 | static Edje_File * | ||
135 | _edje_file_open(const char *file, const char *coll, int *error_ret, Edje_Part_Collection **edc_ret, time_t mtime) | ||
136 | { | ||
137 | Edje_File *edf; | ||
138 | Edje_Part_Collection *edc; | ||
139 | Eet_File *ef; | ||
140 | |||
141 | ef = eet_open(file, EET_FILE_MODE_READ); | ||
142 | if (!ef) | ||
143 | { | ||
144 | *error_ret = EDJE_LOAD_ERROR_UNKNOWN_FORMAT; | ||
145 | return NULL; | ||
146 | } | ||
147 | edf = eet_data_read(ef, _edje_edd_edje_file, "edje/file"); | ||
148 | if (!edf) | ||
149 | { | ||
150 | *error_ret = EDJE_LOAD_ERROR_CORRUPT_FILE; | ||
151 | eet_close(ef); | ||
152 | return NULL; | ||
153 | } | ||
154 | |||
155 | edf->ef = ef; | ||
156 | edf->mtime = mtime; | ||
157 | |||
158 | if (edf->version != EDJE_FILE_VERSION) | ||
159 | { | ||
160 | *error_ret = EDJE_LOAD_ERROR_INCOMPATIBLE_FILE; | ||
161 | _edje_file_free(edf); | ||
162 | return NULL; | ||
163 | } | ||
164 | if (!edf->collection) | ||
165 | { | ||
166 | *error_ret = EDJE_LOAD_ERROR_CORRUPT_FILE; | ||
167 | _edje_file_free(edf); | ||
168 | return NULL; | ||
169 | } | ||
170 | |||
171 | if (edf->minor > EDJE_FILE_MINOR) | ||
172 | { | ||
173 | WRN("`%s` may use feature from a newer edje and could not show up as expected.", file); | ||
174 | } | ||
175 | |||
176 | edf->path = eina_stringshare_add(file); | ||
177 | edf->references = 1; | ||
178 | |||
179 | /* This should be done at edje generation time */ | ||
180 | _edje_textblock_style_parse_and_fix(edf); | ||
181 | |||
182 | if (coll) | ||
183 | { | ||
184 | edc = _edje_file_coll_open(edf, coll); | ||
185 | if (!edc) | ||
186 | { | ||
187 | *error_ret = EDJE_LOAD_ERROR_UNKNOWN_COLLECTION; | ||
188 | } | ||
189 | if (edc_ret) *edc_ret = edc; | ||
190 | } | ||
191 | |||
192 | return edf; | ||
193 | } | ||
194 | |||
195 | static void | ||
196 | _edje_file_dangling(Edje_File *edf) | ||
197 | { | ||
198 | if (edf->dangling) return; | ||
199 | edf->dangling = EINA_TRUE; | ||
200 | |||
201 | eina_hash_del(_edje_file_hash, edf->path, edf); | ||
202 | if (!eina_hash_population(_edje_file_hash)) | ||
203 | { | ||
204 | eina_hash_free(_edje_file_hash); | ||
205 | _edje_file_hash = NULL; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | Edje_File * | ||
210 | _edje_cache_file_coll_open(const char *file, const char *coll, int *error_ret, Edje_Part_Collection **edc_ret) | ||
211 | { | ||
212 | Edje_File *edf; | ||
213 | Eina_List *l, *hist; | ||
214 | Edje_Part_Collection *edc; | ||
215 | Edje_Part *ep; | ||
216 | struct stat st; | ||
217 | |||
218 | if (stat(file, &st) != 0) | ||
219 | return NULL; | ||
220 | |||
221 | if (!_edje_file_hash) | ||
222 | { | ||
223 | _edje_file_hash = eina_hash_string_small_new(NULL); | ||
224 | goto open_new; | ||
225 | } | ||
226 | |||
227 | edf = eina_hash_find(_edje_file_hash, file); | ||
228 | if (edf) | ||
229 | { | ||
230 | if (edf->mtime != st.st_mtime) | ||
231 | { | ||
232 | _edje_file_dangling(edf); | ||
233 | goto open_new; | ||
234 | } | ||
235 | |||
236 | edf->references++; | ||
237 | goto open; | ||
238 | } | ||
239 | |||
240 | EINA_LIST_FOREACH(_edje_file_cache, l, edf) | ||
241 | { | ||
242 | if (!strcmp(edf->path, file)) | ||
243 | { | ||
244 | if (edf->mtime != st.st_mtime) | ||
245 | { | ||
246 | _edje_file_cache = eina_list_remove_list(_edje_file_cache, l); | ||
247 | _edje_file_free(edf); | ||
248 | goto open_new; | ||
249 | } | ||
250 | |||
251 | edf->references = 1; | ||
252 | _edje_file_cache = eina_list_remove_list(_edje_file_cache, l); | ||
253 | eina_hash_add(_edje_file_hash, file, edf); | ||
254 | goto open; | ||
255 | } | ||
256 | } | ||
257 | |||
258 | open_new: | ||
259 | if (!_edje_file_hash) | ||
260 | _edje_file_hash = eina_hash_string_small_new(NULL); | ||
261 | |||
262 | edf = _edje_file_open(file, coll, error_ret, edc_ret, st.st_mtime); | ||
263 | if (!edf) | ||
264 | return NULL; | ||
265 | |||
266 | eina_hash_add(_edje_file_hash, file, edf); | ||
267 | return edf; | ||
268 | |||
269 | open: | ||
270 | if (!coll) | ||
271 | return edf; | ||
272 | |||
273 | edc = _edje_file_coll_open(edf, coll); | ||
274 | if (!edc) | ||
275 | { | ||
276 | *error_ret = EDJE_LOAD_ERROR_UNKNOWN_COLLECTION; | ||
277 | } | ||
278 | else | ||
279 | { | ||
280 | if (!edc->checked) | ||
281 | { | ||
282 | unsigned int j; | ||
283 | |||
284 | for (j = 0; j < edc->parts_count; ++j) | ||
285 | { | ||
286 | Edje_Part *ep2; | ||
287 | |||
288 | ep = edc->parts[j]; | ||
289 | |||
290 | /* Register any color classes in this parts descriptions. */ | ||
291 | hist = NULL; | ||
292 | hist = eina_list_append(hist, ep); | ||
293 | ep2 = ep; | ||
294 | while (ep2->dragable.confine_id >= 0) | ||
295 | { | ||
296 | if (ep2->dragable.confine_id >= (int) edc->parts_count) | ||
297 | { | ||
298 | ERR("confine_to above limit. invalidating it."); | ||
299 | ep2->dragable.confine_id = -1; | ||
300 | break; | ||
301 | } | ||
302 | |||
303 | ep2 = edc->parts[ep2->dragable.confine_id]; | ||
304 | if (eina_list_data_find(hist, ep2)) | ||
305 | { | ||
306 | ERR("confine_to loops. invalidating loop."); | ||
307 | ep2->dragable.confine_id = -1; | ||
308 | break; | ||
309 | } | ||
310 | hist = eina_list_append(hist, ep2); | ||
311 | } | ||
312 | eina_list_free(hist); | ||
313 | hist = NULL; | ||
314 | hist = eina_list_append(hist, ep); | ||
315 | ep2 = ep; | ||
316 | while (ep2->dragable.event_id >= 0) | ||
317 | { | ||
318 | Edje_Part* prev; | ||
319 | |||
320 | if (ep2->dragable.event_id >= (int) edc->parts_count) | ||
321 | { | ||
322 | ERR("event_id above limit. invalidating it."); | ||
323 | ep2->dragable.event_id = -1; | ||
324 | break; | ||
325 | } | ||
326 | prev = ep2; | ||
327 | |||
328 | ep2 = edc->parts[ep2->dragable.event_id]; | ||
329 | if (!ep2->dragable.x && !ep2->dragable.y) | ||
330 | { | ||
331 | prev->dragable.event_id = -1; | ||
332 | break; | ||
333 | } | ||
334 | |||
335 | if (eina_list_data_find(hist, ep2)) | ||
336 | { | ||
337 | ERR("events_to loops. invalidating loop."); | ||
338 | ep2->dragable.event_id = -1; | ||
339 | break; | ||
340 | } | ||
341 | hist = eina_list_append(hist, ep2); | ||
342 | } | ||
343 | eina_list_free(hist); | ||
344 | hist = NULL; | ||
345 | hist = eina_list_append(hist, ep); | ||
346 | ep2 = ep; | ||
347 | while (ep2->clip_to_id >= 0) | ||
348 | { | ||
349 | if (ep2->clip_to_id >= (int) edc->parts_count) | ||
350 | { | ||
351 | ERR("clip_to_id above limit. invalidating it."); | ||
352 | ep2->clip_to_id = -1; | ||
353 | break; | ||
354 | } | ||
355 | |||
356 | ep2 = edc->parts[ep2->clip_to_id]; | ||
357 | if (eina_list_data_find(hist, ep2)) | ||
358 | { | ||
359 | ERR("clip_to loops. invalidating loop."); | ||
360 | ep2->clip_to_id = -1; | ||
361 | break; | ||
362 | } | ||
363 | hist = eina_list_append(hist, ep2); | ||
364 | } | ||
365 | eina_list_free(hist); | ||
366 | hist = NULL; | ||
367 | } | ||
368 | edc->checked = 1; | ||
369 | } | ||
370 | } | ||
371 | if (edc_ret) *edc_ret = edc; | ||
372 | |||
373 | return edf; | ||
374 | } | ||
375 | |||
376 | void | ||
377 | _edje_cache_coll_clean(Edje_File *edf) | ||
378 | { | ||
379 | while ((edf->collection_cache) && | ||
380 | (eina_list_count(edf->collection_cache) > (unsigned int) _edje_collection_cache_size)) | ||
381 | { | ||
382 | Edje_Part_Collection_Directory_Entry *ce; | ||
383 | Edje_Part_Collection *edc; | ||
384 | |||
385 | edc = eina_list_data_get(eina_list_last(edf->collection_cache)); | ||
386 | edf->collection_cache = eina_list_remove_list(edf->collection_cache, eina_list_last(edf->collection_cache)); | ||
387 | |||
388 | ce = eina_hash_find(edf->collection, edc->part); | ||
389 | _edje_collection_free(edf, edc, ce); | ||
390 | } | ||
391 | } | ||
392 | |||
393 | void | ||
394 | _edje_cache_coll_flush(Edje_File *edf) | ||
395 | { | ||
396 | while (edf->collection_cache) | ||
397 | { | ||
398 | Edje_Part_Collection_Directory_Entry *ce; | ||
399 | Edje_Part_Collection *edc; | ||
400 | Eina_List *last; | ||
401 | |||
402 | last = eina_list_last(edf->collection_cache); | ||
403 | edc = eina_list_data_get(last); | ||
404 | edf->collection_cache = eina_list_remove_list(edf->collection_cache, | ||
405 | last); | ||
406 | |||
407 | ce = eina_hash_find(edf->collection, edc->part); | ||
408 | _edje_collection_free(edf, edc, ce); | ||
409 | } | ||
410 | } | ||
411 | |||
412 | void | ||
413 | _edje_cache_coll_unref(Edje_File *edf, Edje_Part_Collection *edc) | ||
414 | { | ||
415 | Edje_Part_Collection_Directory_Entry *ce; | ||
416 | |||
417 | edc->references--; | ||
418 | if (edc->references != 0) return; | ||
419 | |||
420 | ce = eina_hash_find(edf->collection, edc->part); | ||
421 | if (!ce) | ||
422 | { | ||
423 | ERR("Something is wrong with reference count of '%s'.", edc->part); | ||
424 | } | ||
425 | else if (ce->ref) | ||
426 | { | ||
427 | ce->ref = NULL; | ||
428 | |||
429 | if (edf->dangling) | ||
430 | { | ||
431 | /* No need to keep the collection around if the file is dangling */ | ||
432 | _edje_collection_free(edf, edc, ce); | ||
433 | _edje_cache_coll_flush(edf); | ||
434 | } | ||
435 | else | ||
436 | { | ||
437 | edf->collection_cache = eina_list_prepend(edf->collection_cache, edc); | ||
438 | _edje_cache_coll_clean(edf); | ||
439 | } | ||
440 | } | ||
441 | } | ||
442 | |||
443 | static void | ||
444 | _edje_cache_file_clean(void) | ||
445 | { | ||
446 | int count; | ||
447 | |||
448 | count = eina_list_count(_edje_file_cache); | ||
449 | while ((_edje_file_cache) && (count > _edje_file_cache_size)) | ||
450 | { | ||
451 | Eina_List *last; | ||
452 | Edje_File *edf; | ||
453 | |||
454 | last = eina_list_last(_edje_file_cache); | ||
455 | edf = eina_list_data_get(last); | ||
456 | _edje_file_cache = eina_list_remove_list(_edje_file_cache, last); | ||
457 | _edje_file_free(edf); | ||
458 | count = eina_list_count(_edje_file_cache); | ||
459 | } | ||
460 | } | ||
461 | |||
462 | void | ||
463 | _edje_cache_file_unref(Edje_File *edf) | ||
464 | { | ||
465 | edf->references--; | ||
466 | if (edf->references != 0) return; | ||
467 | |||
468 | if (edf->dangling) | ||
469 | { | ||
470 | _edje_file_free(edf); | ||
471 | return; | ||
472 | } | ||
473 | |||
474 | eina_hash_del(_edje_file_hash, edf->path, edf); | ||
475 | if (!eina_hash_population(_edje_file_hash)) | ||
476 | { | ||
477 | eina_hash_free(_edje_file_hash); | ||
478 | _edje_file_hash = NULL; | ||
479 | } | ||
480 | _edje_file_cache = eina_list_prepend(_edje_file_cache, edf); | ||
481 | _edje_cache_file_clean(); | ||
482 | } | ||
483 | |||
484 | void | ||
485 | _edje_file_cache_shutdown(void) | ||
486 | { | ||
487 | edje_file_cache_flush(); | ||
488 | } | ||
489 | |||
490 | |||
491 | |||
492 | /** | ||
493 | * @endcond | ||
494 | */ | ||
495 | |||
496 | /*============================================================================* | ||
497 | * Global * | ||
498 | *============================================================================*/ | ||
499 | |||
500 | /*============================================================================* | ||
501 | * API * | ||
502 | *============================================================================*/ | ||
503 | |||
504 | |||
505 | EAPI void | ||
506 | edje_file_cache_set(int count) | ||
507 | { | ||
508 | if (count < 0) count = 0; | ||
509 | _edje_file_cache_size = count; | ||
510 | _edje_cache_file_clean(); | ||
511 | } | ||
512 | |||
513 | |||
514 | EAPI int | ||
515 | edje_file_cache_get(void) | ||
516 | { | ||
517 | return _edje_file_cache_size; | ||
518 | } | ||
519 | |||
520 | |||
521 | EAPI void | ||
522 | edje_file_cache_flush(void) | ||
523 | { | ||
524 | int ps; | ||
525 | |||
526 | ps = _edje_file_cache_size; | ||
527 | _edje_file_cache_size = 0; | ||
528 | _edje_cache_file_clean(); | ||
529 | _edje_file_cache_size = ps; | ||
530 | } | ||
531 | |||
532 | |||
533 | EAPI void | ||
534 | edje_collection_cache_set(int count) | ||
535 | { | ||
536 | Eina_List *l; | ||
537 | Edje_File *edf; | ||
538 | |||
539 | if (count < 0) count = 0; | ||
540 | _edje_collection_cache_size = count; | ||
541 | EINA_LIST_FOREACH(_edje_file_cache, l, edf) | ||
542 | _edje_cache_coll_clean(edf); | ||
543 | /* FIXME: freach in file hash too! */ | ||
544 | } | ||
545 | |||
546 | |||
547 | EAPI int | ||
548 | edje_collection_cache_get(void) | ||
549 | { | ||
550 | return _edje_collection_cache_size; | ||
551 | } | ||
552 | |||
553 | |||
554 | EAPI void | ||
555 | edje_collection_cache_flush(void) | ||
556 | { | ||
557 | int ps; | ||
558 | Eina_List *l; | ||
559 | Edje_File *edf; | ||
560 | |||
561 | ps = _edje_collection_cache_size; | ||
562 | _edje_collection_cache_size = 0; | ||
563 | EINA_LIST_FOREACH(_edje_file_cache, l, edf) | ||
564 | _edje_cache_coll_flush(edf); | ||
565 | /* FIXME: freach in file hash too! */ | ||
566 | _edje_collection_cache_size = ps; | ||
567 | } | ||