summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorHermet Park <hermetpark@gmail.com>2019-06-21 17:30:19 +0900
committerHermet Park <hermetpark@gmail.com>2019-06-21 17:35:48 +0900
commit23af6ec640c4166aa912f8d6be1e3b78b0780913 (patch)
treeb844eb6e5dab6dccdb8dda72d028fda3958e7c69 /src/modules
parent1c02b7740de0938bcbad2e26ee055ad570cdf77c (diff)
evas vector: support json loader for rlottie integration.
Summary: Introduce a new evas json loader to support lottie animation. This json loader uses rlottie library which is a new github open project. These days most ui frameworks (windowpws, skia, qt, xamarin, react, nativescript) supports lottie, the rlottie was designed to support lottie as a standalone library and compatible with efl as well. To enable this,please install rlottie library then remove json disabler in meson_options.txt For more information, See lottie/rlottie project and its a introdcution article: https://airbnb.io/lottie/#/ https://github.com/samsung/rlottie https://hermet.pe.kr/143 Co-authored-by: JunsuChoi <jsuya.choi@samsung.com> {D8941} {D8944} Reviewers: #committers, jsuya, bu5hm4n Subscribers: bu5hm4n, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8940
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/evas/meson.build2
-rw-r--r--src/modules/evas/vg_loaders/json/evas_vg_load_json.c139
-rw-r--r--src/modules/evas/vg_loaders/meson.build37
3 files changed, 165 insertions, 13 deletions
diff --git a/src/modules/evas/meson.build b/src/modules/evas/meson.build
index a79dc6800b..c49a24c3ea 100644
--- a/src/modules/evas/meson.build
+++ b/src/modules/evas/meson.build
@@ -2,7 +2,7 @@
2png = dependency('libpng') 2png = dependency('libpng')
3tiff = dependency('libtiff-4') 3tiff = dependency('libtiff-4')
4giflib = cc.find_library('gif') 4giflib = cc.find_library('gif')
5 5json = dependency('rlottie', required: get_option('evas-loaders-disabler').contains('json') == false)
6webp = dependency('libwebp', required: get_option('evas-loaders-disabler').contains('webp') == false) 6webp = dependency('libwebp', required: get_option('evas-loaders-disabler').contains('webp') == false)
7 7
8#there are a few modules that should NEVER be build as a module but rather be build as static lib and linked in later 8#there are a few modules that should NEVER be build as a module but rather be build as static lib and linked in later
diff --git a/src/modules/evas/vg_loaders/json/evas_vg_load_json.c b/src/modules/evas/vg_loaders/json/evas_vg_load_json.c
new file mode 100644
index 0000000000..6dabff71a6
--- /dev/null
+++ b/src/modules/evas/vg_loaders/json/evas_vg_load_json.c
@@ -0,0 +1,139 @@
1#include <rlottie_capi.h>
2#include "vg_common.h"
3
4#ifdef ERR
5# undef ERR
6#endif
7#define ERR(...) EINA_LOG_DOM_ERR(_evas_vg_loader_json_log_dom, __VA_ARGS__)
8
9#ifdef INF
10# undef INF
11#endif
12#define INF(...) EINA_LOG_DOM_INFO(_evas_vg_loader_json_log_dom, __VA_ARGS__)
13
14static int _evas_vg_loader_json_log_dom = -1;
15
16static Eina_Bool
17evas_vg_load_file_close_json(Vg_File_Data *vfd)
18{
19 if (!vfd) return EINA_FALSE;
20
21 Lottie_Animation *lot_anim = (Lottie_Animation *) vfd->loader_data;
22 lottie_animation_destroy(lot_anim);
23 if (vfd->anim_data) free(vfd->anim_data);
24 if (vfd->root) efl_unref(vfd->root);
25 free(vfd);
26
27 return EINA_TRUE;
28}
29
30static Eina_Bool
31evas_vg_load_file_data_json(Vg_File_Data *vfd)
32{
33 return vg_common_json_create_vg_node(vfd);
34}
35
36static Vg_File_Data*
37evas_vg_load_file_open_json(Eina_File *file,
38 const char *key,
39 int *error EINA_UNUSED)
40{
41 Vg_File_Data *vfd = calloc(1, sizeof(Vg_File_Data));
42 if (!vfd) return NULL;
43
44 Lottie_Animation *lot_anim = NULL;
45
46 const char *data = (const char*) eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
47 if (!data) goto err;
48 //@TODO pass corrct external_resource path.
49 lot_anim = lottie_animation_from_data(data, key ? key:eina_file_filename_get(file), " ");
50 eina_file_map_free(file, (void *) data);
51
52 if (!lot_anim)
53 {
54 ERR("Failed lottie_animation_from_file");
55 goto err;
56 }
57
58 unsigned int frame_cnt = lottie_animation_get_totalframe(lot_anim);
59
60 //Support animation
61 if (frame_cnt > 1)
62 {
63 vfd->anim_data = calloc(1, sizeof(Vg_File_Anim_Data));
64 if (!vfd->anim_data) goto err;
65 vfd->anim_data->duration = lottie_animation_get_duration(lot_anim);
66 vfd->anim_data->frame_cnt = frame_cnt;
67 }
68
69 //default size
70 size_t w, h;
71 lottie_animation_get_size(lot_anim, &w, &h);
72 vfd->w = (int) w;
73 vfd->h = (int) h;
74
75 vfd->loader_data = (void *) lot_anim;
76 vfd->no_share = EINA_TRUE;
77
78 return vfd;
79
80err:
81 if (vfd)
82 {
83 if (vfd->anim_data) free(vfd->anim_data);
84 free(vfd);
85 }
86 if (lot_anim) lottie_animation_destroy(lot_anim);
87
88 return NULL;
89}
90
91static Evas_Vg_Load_Func evas_vg_load_json_func =
92{
93 evas_vg_load_file_open_json,
94 evas_vg_load_file_close_json,
95 evas_vg_load_file_data_json
96};
97
98static int
99module_open(Evas_Module *em)
100{
101 if (!em) return 0;
102 em->functions = (void *)(&evas_vg_load_json_func);
103 _evas_vg_loader_json_log_dom = eina_log_domain_register
104 ("vg-load-json", EVAS_DEFAULT_LOG_COLOR);
105 if (_evas_vg_loader_json_log_dom < 0)
106 {
107 EINA_LOG_ERR("Can not create a module log domain.");
108 return 0;
109 }
110 return 1;
111}
112
113static void
114module_close(Evas_Module *em EINA_UNUSED)
115{
116 if (_evas_vg_loader_json_log_dom >= 0)
117 {
118 eina_log_domain_unregister(_evas_vg_loader_json_log_dom);
119 _evas_vg_loader_json_log_dom = -1;
120 }
121}
122
123static Evas_Module_Api evas_modapi =
124{
125 EVAS_MODULE_API_VERSION,
126 "json",
127 "none",
128 {
129 module_open,
130 module_close
131 }
132};
133
134EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_VG_LOADER, vg_loader, json);
135
136#ifndef EVAS_STATIC_BUILD_VG_JSON
137EVAS_EINA_MODULE_DEFINE(vg_loader, json);
138#endif
139
diff --git a/src/modules/evas/vg_loaders/meson.build b/src/modules/evas/vg_loaders/meson.build
index 584501a825..5ffe8f0ffe 100644
--- a/src/modules/evas/vg_loaders/meson.build
+++ b/src/modules/evas/vg_loaders/meson.build
@@ -1,13 +1,26 @@
1evas_vg_loaders_file = ['eet', 'svg'] 1evas_vg_loaders_file = [
2 2 ['eet', [eet]],
3foreach loader : evas_vg_loaders_file 3 ['json', [json]],
4 file = join_paths(loader, 'evas_vg_load_'+loader+'.c') 4 ['svg', []],
5 static_library('vg_loader_'+loader, file, 5]
6 include_directories : config_dir, 6
7 dependencies : evas_pre 7foreach loader_inst : evas_vg_loaders_file
8 ) 8 loader = loader_inst[0]
9 evas_static_list += [declare_dependency( 9 loader_deps = loader_inst[1]
10 sources: file, 10
11 )] 11 if (get_option('evas-loaders-disabler').contains(loader) == false)
12 config_h.set('EVAS_STATIC_BUILD_VG_'+loader.to_upper(), '1') 12 file = join_paths(loader, 'evas_vg_load_'+loader+'.c')
13
14 static_library('vg_loader_'+loader, file,
15 include_directories : config_dir,
16 dependencies : [evas_pre] + loader_deps
17 )
18
19 evas_static_list += [declare_dependency(
20 sources: file,
21 dependencies: loader_deps,
22 )]
23
24 config_h.set('EVAS_STATIC_BUILD_VG_'+loader.to_upper(), '1')
25 endif
13endforeach 26endforeach