diff options
author | Jean-Philippe Andre <jp.andre@samsung.com> | 2015-06-17 13:49:18 +0900 |
---|---|---|
committer | Jean-Philippe Andre <jp.andre@samsung.com> | 2015-06-25 14:36:09 +0900 |
commit | a18107309dc5233e76b77016b6eb3ef09ddf25ec (patch) | |
tree | 60d0eb5ce121e807af84b16eeed4afa2fc4eb087 | |
parent | 88b81d240a3d29aebbc1d9b05dcb4335a69d1e63 (diff) |
Edje: Factorise filter code for TEXT and IMAGE
TODO: eo-ify the filter API properly and stabilize it.
-rw-r--r-- | src/lib/edje/edje_calc.c | 166 | ||||
-rw-r--r-- | src/lib/edje/edje_data.c | 2 | ||||
-rw-r--r-- | src/lib/edje/edje_text.c | 104 |
3 files changed, 167 insertions, 105 deletions
diff --git a/src/lib/edje/edje_calc.c b/src/lib/edje/edje_calc.c index c1e7e1b618..30478a6ac8 100644 --- a/src/lib/edje/edje_calc.c +++ b/src/lib/edje/edje_calc.c | |||
@@ -2403,6 +2403,165 @@ _edje_part_recalc_single_map(Edje *ed, | |||
2403 | EINA_COW_CALC_MAP_END(params, params_write); | 2403 | EINA_COW_CALC_MAP_END(params, params_write); |
2404 | } | 2404 | } |
2405 | 2405 | ||
2406 | static inline const char * | ||
2407 | _edje_filter_get(Edje *ed, Edje_Part_Description_Spec_Filter *filter) | ||
2408 | { | ||
2409 | if (EINA_UNLIKELY(!filter->checked_data)) | ||
2410 | { | ||
2411 | Edje_String *st; | ||
2412 | filter->checked_data = 1; | ||
2413 | st = eina_hash_find(ed->file->data, filter->code); | ||
2414 | if (st) | ||
2415 | { | ||
2416 | eina_stringshare_del(filter->code); | ||
2417 | filter->code = st->str; | ||
2418 | filter->no_free = 1; | ||
2419 | } | ||
2420 | } | ||
2421 | return filter->code; | ||
2422 | } | ||
2423 | |||
2424 | static void | ||
2425 | _edje_part_recalc_single_filter(Edje *ed, | ||
2426 | Edje_Real_Part *ep, | ||
2427 | Edje_Part_Description_Common *desc, | ||
2428 | Edje_Part_Description_Common *chosen_desc, | ||
2429 | double pos) | ||
2430 | { | ||
2431 | Edje_Part_Description_Spec_Filter *filter; | ||
2432 | Eina_List *filter_sources = NULL, *prev_sources = NULL; | ||
2433 | const char *src1, *src2, *part, *code; | ||
2434 | Evas_Object *obj = ep->object; | ||
2435 | Eina_List *li1, *li2; | ||
2436 | Eina_Bool im = 0; | ||
2437 | |||
2438 | /* handle TEXT and IMAGE part types here */ | ||
2439 | if (ep->part->type == EDJE_PART_TYPE_TEXT) | ||
2440 | { | ||
2441 | Edje_Part_Description_Text *chosen_edt = (Edje_Part_Description_Text *) chosen_desc; | ||
2442 | Edje_Part_Description_Text *edt = (Edje_Part_Description_Text *) desc; | ||
2443 | filter = &chosen_edt->text.filter; | ||
2444 | if (edt->text.filter.sources != filter->sources) | ||
2445 | { | ||
2446 | prev_sources = ep->typedata.text->filter.sources; | ||
2447 | filter_sources = edt->text.filter.sources; | ||
2448 | } | ||
2449 | #if 0 | ||
2450 | // old form | ||
2451 | if (ep->typedata.text->filter.code) | ||
2452 | filter = &ep->typedata.text->filter; | ||
2453 | else | ||
2454 | filter = &chosen_edt->text.filter; | ||
2455 | if (ep->typedata.text->filter.sources != chosen_edt->text.filter.sources) | ||
2456 | { | ||
2457 | prev_sources = ep->typedata.text->filter.sources; | ||
2458 | filter_sources = chosen_edt->text.filter.sources; | ||
2459 | //ep->typedata.text->filter.sources = chosen_edt->text.filter.sources; | ||
2460 | } | ||
2461 | #endif | ||
2462 | } | ||
2463 | else if (ep->part->type == EDJE_PART_TYPE_IMAGE) | ||
2464 | { | ||
2465 | Edje_Part_Description_Image *chosen_edi = (Edje_Part_Description_Image *) chosen_desc; | ||
2466 | Edje_Part_Description_Image *edi = (Edje_Part_Description_Image *) desc; | ||
2467 | filter = &chosen_edi->image.filter; | ||
2468 | if (edi->image.filter.sources != filter->sources) | ||
2469 | { | ||
2470 | prev_sources = edi->image.filter.sources; | ||
2471 | filter_sources = chosen_edi->image.filter.sources; | ||
2472 | } | ||
2473 | im = 1; | ||
2474 | } | ||
2475 | else | ||
2476 | { | ||
2477 | CRI("Invalid call to filter recalc"); | ||
2478 | return; | ||
2479 | } | ||
2480 | |||
2481 | // FIXME: Implement proper EO interface/mixin and remove this ugly thing | ||
2482 | #define efl_gfx_filter_program_set(...) do { \ | ||
2483 | if (!im) evas_obj_text_filter_program_set(__VA_ARGS__); \ | ||
2484 | else evas_obj_text_filter_program_set(__VA_ARGS__); } while (0) | ||
2485 | #define efl_gfx_filter_source_set(...) do { \ | ||
2486 | if (!im) evas_obj_text_filter_source_set(__VA_ARGS__); \ | ||
2487 | else evas_obj_image_filter_source_set(__VA_ARGS__); } while (0) | ||
2488 | #define efl_gfx_filter_state_set(...) do { \ | ||
2489 | if (!im) evas_obj_text_filter_state_set(__VA_ARGS__); \ | ||
2490 | /* else evas_obj_image_filter_state_set(__VA_ARGS__); */ } while (0) | ||
2491 | // End of pure ugliness | ||
2492 | |||
2493 | /* common code below */ | ||
2494 | code = _edje_filter_get(ed, filter); | ||
2495 | if (!code) | ||
2496 | { | ||
2497 | eo_do(obj, efl_gfx_filter_program_set(NULL)); | ||
2498 | return; | ||
2499 | } | ||
2500 | |||
2501 | eo_do(obj, | ||
2502 | efl_gfx_filter_program_set(code); | ||
2503 | if (prev_sources != filter_sources) | ||
2504 | { | ||
2505 | /* remove sources that are not there anymore | ||
2506 | * this O(n^2) loop assumes a very small number of sources */ | ||
2507 | EINA_LIST_FOREACH(prev_sources, li1, src1) | ||
2508 | { | ||
2509 | Eina_Bool found = 0; | ||
2510 | EINA_LIST_FOREACH(filter_sources, li2, src2) | ||
2511 | { | ||
2512 | if (!strcmp(src1, src2)) | ||
2513 | { | ||
2514 | found = 1; | ||
2515 | break; | ||
2516 | } | ||
2517 | } | ||
2518 | if (!found) | ||
2519 | { | ||
2520 | part = strchr(src1, ':'); | ||
2521 | if (!part) | ||
2522 | efl_gfx_filter_source_set(src1, NULL); | ||
2523 | else | ||
2524 | { | ||
2525 | char *name = strdup(src1); | ||
2526 | name[part - src1] = 0; | ||
2527 | efl_gfx_filter_source_set(name, NULL); | ||
2528 | free(name); | ||
2529 | } | ||
2530 | } | ||
2531 | } | ||
2532 | /* add all sources by part name */ | ||
2533 | EINA_LIST_FOREACH(filter_sources, li1, src1) | ||
2534 | { | ||
2535 | Edje_Real_Part *rp; | ||
2536 | char *name = NULL; | ||
2537 | if ((part = strchr(src1, ':')) != NULL) | ||
2538 | { | ||
2539 | name = strdup(src1); | ||
2540 | name[part - src1] = 0; | ||
2541 | part++; | ||
2542 | } | ||
2543 | else | ||
2544 | part = src1; | ||
2545 | rp = _edje_real_part_get(ed, part); | ||
2546 | efl_gfx_filter_source_set(name ? name : part, rp ? rp->object : NULL); | ||
2547 | free(name); | ||
2548 | } | ||
2549 | } | ||
2550 | /* pass edje state for transitions */ | ||
2551 | if (ep->param2) | ||
2552 | { | ||
2553 | efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value, | ||
2554 | ep->param2->description->state.name, ep->param2->description->state.value, | ||
2555 | pos); | ||
2556 | } | ||
2557 | else | ||
2558 | { | ||
2559 | efl_gfx_filter_state_set(chosen_desc->state.name, chosen_desc->state.value, | ||
2560 | NULL, 0.0, pos); | ||
2561 | } | ||
2562 | ); | ||
2563 | } | ||
2564 | |||
2406 | static void | 2565 | static void |
2407 | _edje_part_recalc_single(Edje *ed, | 2566 | _edje_part_recalc_single(Edje *ed, |
2408 | Edje_Real_Part *ep, | 2567 | Edje_Real_Part *ep, |
@@ -2564,7 +2723,10 @@ _edje_part_recalc_single(Edje *ed, | |||
2564 | if (ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) | 2723 | if (ep->part->type == EDJE_PART_TYPE_TEXTBLOCK) |
2565 | _edje_part_recalc_single_textblock(sc, ed, ep, (Edje_Part_Description_Text *)chosen_desc, params, &minw, &minh, &maxw, &maxh); | 2724 | _edje_part_recalc_single_textblock(sc, ed, ep, (Edje_Part_Description_Text *)chosen_desc, params, &minw, &minh, &maxw, &maxh); |
2566 | else if (ep->part->type == EDJE_PART_TYPE_TEXT) | 2725 | else if (ep->part->type == EDJE_PART_TYPE_TEXT) |
2567 | _edje_part_recalc_single_text(sc, ed, ep, (Edje_Part_Description_Text*) desc, (Edje_Part_Description_Text*) chosen_desc, params, &minw, &minh, &maxw, &maxh, pos); | 2726 | { |
2727 | _edje_part_recalc_single_text(sc, ed, ep, (Edje_Part_Description_Text*) desc, (Edje_Part_Description_Text*) chosen_desc, params, &minw, &minh, &maxw, &maxh, pos); | ||
2728 | _edje_part_recalc_single_filter(ed, ep, desc, chosen_desc, pos); | ||
2729 | } | ||
2568 | 2730 | ||
2569 | if ((ep->part->type == EDJE_PART_TYPE_TABLE) && | 2731 | if ((ep->part->type == EDJE_PART_TYPE_TABLE) && |
2570 | (((((Edje_Part_Description_Table *)chosen_desc)->table.min.h) || | 2732 | (((((Edje_Part_Description_Table *)chosen_desc)->table.min.h) || |
@@ -2626,6 +2788,8 @@ _edje_part_recalc_single(Edje *ed, | |||
2626 | if ((maxw <= 0) || (w < maxw)) maxw = w; | 2788 | if ((maxw <= 0) || (w < maxw)) maxw = w; |
2627 | if ((maxh <= 0) || (h < maxh)) maxh = h; | 2789 | if ((maxh <= 0) || (h < maxh)) maxh = h; |
2628 | } | 2790 | } |
2791 | |||
2792 | _edje_part_recalc_single_filter(ed, ep, desc, chosen_desc, pos); | ||
2629 | } | 2793 | } |
2630 | 2794 | ||
2631 | /* remember what our size is BEFORE we go limit it */ | 2795 | /* remember what our size is BEFORE we go limit it */ |
diff --git a/src/lib/edje/edje_data.c b/src/lib/edje/edje_data.c index 5f3c3c3cb0..c85dcd8af8 100644 --- a/src/lib/edje/edje_data.c +++ b/src/lib/edje/edje_data.c | |||
@@ -957,6 +957,8 @@ _edje_edd_init(void) | |||
957 | EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.fill.angle", image.fill.angle, EET_T_INT); | 957 | EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.fill.angle", image.fill.angle, EET_T_INT); |
958 | EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.fill.spread", image.fill.spread, EET_T_INT); | 958 | EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.fill.spread", image.fill.spread, EET_T_INT); |
959 | EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.fill.type", image.fill.type, EET_T_CHAR); | 959 | EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.fill.type", image.fill.type, EET_T_CHAR); |
960 | EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.filter.code", image.filter.code, EET_T_STRING); | ||
961 | EET_DATA_DESCRIPTOR_ADD_LIST_STRING(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.filter.sources", image.filter.sources); | ||
960 | 962 | ||
961 | EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Part_Description_Proxy); | 963 | EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Edje_Part_Description_Proxy); |
962 | eddc.func.mem_free = mem_free_proxy; | 964 | eddc.func.mem_free = mem_free_proxy; |
diff --git a/src/lib/edje/edje_text.c b/src/lib/edje/edje_text.c index 5e2743bcfb..0f65671b93 100644 --- a/src/lib/edje/edje_text.c +++ b/src/lib/edje/edje_text.c | |||
@@ -193,24 +193,6 @@ _edje_text_class_font_get(Edje *ed, Edje_Part_Description_Text *chosen_desc, int | |||
193 | return font; | 193 | return font; |
194 | } | 194 | } |
195 | 195 | ||
196 | static inline const char * | ||
197 | _edje_filter_get(Edje *ed, Edje_Part_Description_Spec_Filter *filter) | ||
198 | { | ||
199 | if (EINA_UNLIKELY(!filter->checked_data)) | ||
200 | { | ||
201 | Edje_String *st; | ||
202 | filter->checked_data = 1; | ||
203 | st = eina_hash_find(ed->file->data, filter->code); | ||
204 | if (st) | ||
205 | { | ||
206 | eina_stringshare_del(filter->code); | ||
207 | filter->code = st->str; | ||
208 | filter->no_free = 1; | ||
209 | } | ||
210 | } | ||
211 | return filter->code; | ||
212 | } | ||
213 | |||
214 | void | 196 | void |
215 | _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, | 197 | _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, |
216 | Edje_Calc_Params *params, | 198 | Edje_Calc_Params *params, |
@@ -222,8 +204,6 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, | |||
222 | char *font2 = NULL; | 204 | char *font2 = NULL; |
223 | char *sfont = NULL; | 205 | char *sfont = NULL; |
224 | int size; | 206 | int size; |
225 | const char *filter; | ||
226 | Eina_List *filter_sources = NULL, *prev_sources = NULL; | ||
227 | Evas_Coord tw, th; | 207 | Evas_Coord tw, th; |
228 | Evas_Coord sw, sh; | 208 | Evas_Coord sw, sh; |
229 | int inlined_font = 0, free_text = 0; | 209 | int inlined_font = 0, free_text = 0; |
@@ -251,17 +231,6 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep, | |||
251 | if (ep->typedata.text->font) font = ep->typedata.text->font; | 231 | if (ep->typedata.text->font) font = ep->typedata.text->font; |
252 | if (ep->typedata.text->size > 0) size = ep->typedata.text->size; | 232 | if (ep->typedata.text->size > 0) size = ep->typedata.text->size; |
253 | 233 | ||
254 | if (ep->typedata.text->filter.code) | ||
255 | filter = _edje_filter_get(ed, &ep->typedata.text->filter); | ||
256 | else | ||
257 | filter = _edje_filter_get(ed, &chosen_desc->text.filter); | ||
258 | if (ep->typedata.text->filter.sources != chosen_desc->text.filter.sources) | ||
259 | { | ||
260 | prev_sources = ep->typedata.text->filter.sources; | ||
261 | filter_sources = chosen_desc->text.filter.sources; | ||
262 | ep->typedata.text->filter.sources = chosen_desc->text.filter.sources; | ||
263 | } | ||
264 | |||
265 | if (ep->typedata.text->text_source) | 234 | if (ep->typedata.text->text_source) |
266 | { | 235 | { |
267 | Edje_Part_Description_Text *et; | 236 | Edje_Part_Description_Text *et; |
@@ -549,79 +518,6 @@ arrange_text: | |||
549 | efl_text_set(text)); | 518 | efl_text_set(text)); |
550 | part_get_geometry(ep, &tw, &th); | 519 | part_get_geometry(ep, &tw, &th); |
551 | 520 | ||
552 | /* filters */ | ||
553 | if (filter) | ||
554 | { | ||
555 | const char *src1, *src2, *part; | ||
556 | Eina_List *li1, *li2; | ||
557 | |||
558 | eo_do(ep->object, | ||
559 | evas_obj_text_filter_program_set(filter); | ||
560 | /* update sources. really not optimal. lots of strxxx and loops */ | ||
561 | if (prev_sources != filter_sources) | ||
562 | { | ||
563 | /* remove sources that are not there anymore | ||
564 | * this O(n^2) loop assumes a very small number of sources */ | ||
565 | EINA_LIST_FOREACH(prev_sources, li1, src1) | ||
566 | { | ||
567 | Eina_Bool found = 0; | ||
568 | EINA_LIST_FOREACH(filter_sources, li2, src2) | ||
569 | { | ||
570 | if (!strcmp(src1, src2)) | ||
571 | { | ||
572 | found = 1; | ||
573 | break; | ||
574 | } | ||
575 | } | ||
576 | if (!found) | ||
577 | { | ||
578 | part = strchr(src1, ':'); | ||
579 | if (!part) | ||
580 | evas_obj_text_filter_source_set(src1, NULL); | ||
581 | else | ||
582 | { | ||
583 | char *name = strdup(src1); | ||
584 | name[part - src1] = 0; | ||
585 | evas_obj_text_filter_source_set(name, NULL); | ||
586 | free(name); | ||
587 | } | ||
588 | } | ||
589 | } | ||
590 | /* add all sources by part name */ | ||
591 | EINA_LIST_FOREACH(filter_sources, li1, src1) | ||
592 | { | ||
593 | Edje_Real_Part *rp; | ||
594 | char *name = NULL; | ||
595 | if ((part = strchr(src1, ':')) != NULL) | ||
596 | { | ||
597 | name = strdup(src1); | ||
598 | name[part - src1] = 0; | ||
599 | part++; | ||
600 | } | ||
601 | else | ||
602 | part = src1; | ||
603 | rp = _edje_real_part_get(ed, part); | ||
604 | evas_obj_text_filter_source_set(name ? name : part, rp ? rp->object : NULL); | ||
605 | free(name); | ||
606 | } | ||
607 | } | ||
608 | /* pass edje state for transitions */ | ||
609 | if (ep->param2) | ||
610 | { | ||
611 | evas_obj_text_filter_state_set(chosen_desc->common.state.name, chosen_desc->common.state.value, | ||
612 | ep->param2->description->state.name, ep->param2->description->state.value, | ||
613 | state_val); | ||
614 | } | ||
615 | else | ||
616 | { | ||
617 | evas_obj_text_filter_state_set(chosen_desc->common.state.name, chosen_desc->common.state.value, | ||
618 | NULL, 0.0, state_val); | ||
619 | } | ||
620 | ); | ||
621 | } | ||
622 | else | ||
623 | eo_do(ep->object, evas_obj_text_filter_program_set(NULL)); | ||
624 | |||
625 | /* Handle alignment */ | 521 | /* Handle alignment */ |
626 | { | 522 | { |
627 | FLOAT_T align_x; | 523 | FLOAT_T align_x; |