From 97367909da3c9a3659f0536db7bb48401bd06ac0 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 7 Sep 2018 20:37:26 +0900 Subject: [PATCH] evas json: revise implementation along with lottie player - #10 lottie-player API has been changed to lottie-animation. @feature Change-Id: I7dd04326de713969a2b51b5de0d52e9b243b782f --- m4/evas_check_loader.m4 | 4 +-- .../evas/vg_loaders/json/evas_vg_load_json.c | 29 ++++++++-------------- src/static_libs/vg_common/vg_common.h | 2 +- src/static_libs/vg_common/vg_common_json.c | 14 +++++------ 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/m4/evas_check_loader.m4 b/m4/evas_check_loader.m4 index 06302f2..98a5872 100644 --- a/m4/evas_check_loader.m4 +++ b/m4/evas_check_loader.m4 @@ -67,11 +67,11 @@ have_dep="no" evas_vg_loader_[]$1[]_cflags="" evas_vg_loader_[]$1[]_libs="" -AC_CHECK_HEADER([lotplayer_capi.h], [have_dep="yes"]) +AC_CHECK_HEADER([lottieanimation_capi.h], [have_dep="yes"]) if test "x${have_dep}" = "xyes" ; then AC_CHECK_LIB([lottie-player], - [lotplayer_create], + [lottie_animation_from_file], [ evas_vg_loader_[]$1[]_libs="-llottie-player" ] 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 index eb6c83f..1222180 100644 --- a/src/modules/evas/vg_loaders/json/evas_vg_load_json.c +++ b/src/modules/evas/vg_loaders/json/evas_vg_load_json.c @@ -1,4 +1,4 @@ -#include +#include #include "vg_common.h" #ifdef ERR @@ -18,8 +18,8 @@ evas_vg_load_file_close_json(Vg_File_Data *vfd) { if (!vfd) return EINA_FALSE; - LOTPlayer *player = (LOTPlayer *) vfd->loader_data; - lotplayer_destroy(player); + Lottie_Animation *lot_anim = (Lottie_Animation *) vfd->loader_data; + lottie_animation_destroy(lot_anim); if (vfd->anim_data) free(vfd->anim_data); free(vfd); @@ -40,32 +40,25 @@ evas_vg_load_file_open_json(const char *file, Vg_File_Data *vfd = calloc(1, sizeof(Vg_File_Data)); if (!vfd) return NULL; - LOTPlayer *player = lotplayer_create(); - if (!player) + Lottie_Animation *lot_anim = lottie_animation_from_file(file); + if (!lot_anim) { - ERR("Failed to create LOTPlayer"); + ERR("Failed lottie_animation_from_file"); goto err; } - int ret = lotplayer_set_file(player, file); - if (LOT_PLAYER_ERROR_NONE != ret) - { - ERR("Failed to lotplayer_set_file(), result = %d", ret); - goto err; - } - - unsigned int frame_cnt = lotplayer_get_totalframe(player); + unsigned int frame_cnt = lottie_animation_get_totalframe(lot_anim); //Support animation if (frame_cnt > 1) { vfd->anim_data = calloc(1, sizeof(Vg_File_Anim_Data)); if (!vfd->anim_data) goto err; - vfd->anim_data->duration = lotplayer_get_playtime(player); + vfd->anim_data->duration = lottie_animation_get_duration(lot_anim); vfd->anim_data->frame_cnt = frame_cnt; } - vfd->loader_data = (void *) player; + vfd->loader_data = (void *) lot_anim; return vfd; @@ -75,7 +68,7 @@ err: if (vfd->anim_data) free(vfd->anim_data); free(vfd); } - if (player) lotplayer_destroy(player); + if (lot_anim) lottie_animation_destroy(lot_anim); return NULL; } @@ -126,6 +119,6 @@ static Evas_Module_Api evas_modapi = EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_VG_LOADER, vg_loader, json); #ifndef EVAS_STATIC_BUILD_VG_JSON -EVAS_EINA_MODULE_DEFINE(vg_loader, json); +EVAS_EINA_MODULE_DEFINE(vg_loader, json) #endif diff --git a/src/static_libs/vg_common/vg_common.h b/src/static_libs/vg_common/vg_common.h index 03cfb8e..1215dd1 100644 --- a/src/static_libs/vg_common/vg_common.h +++ b/src/static_libs/vg_common/vg_common.h @@ -322,7 +322,7 @@ void vg_common_svg_node_free(Svg_Node *node); * Lottie Compatible feature implementation ******************************************************************************************/ #ifdef BUILD_VG_LOADER_JSON -# include +# include #endif Eina_Bool vg_common_json_create_vg_node(Vg_File_Data *vfd); diff --git a/src/static_libs/vg_common/vg_common_json.c b/src/static_libs/vg_common/vg_common_json.c index 8354f13..4c33775 100644 --- a/src/static_libs/vg_common/vg_common_json.c +++ b/src/static_libs/vg_common/vg_common_json.c @@ -9,8 +9,8 @@ Eina_Bool vg_common_json_create_vg_node(Vg_File_Data *vfd) { #ifdef BUILD_VG_LOADER_JSON - LOTPlayer *player = (LOTPlayer *) vfd->loader_data; - if (!player) return EINA_FALSE; + Lottie_Animation *lot_anim = (Lottie_Animation *) vfd->loader_data; + if (!lot_anim) return EINA_FALSE; //Root node if (vfd->root) efl_unref(vfd->root); @@ -18,17 +18,15 @@ vg_common_json_create_vg_node(Vg_File_Data *vfd) Efl_VG *root = vfd->root; if (!root) return EINA_FALSE; - lotplayer_set_size(player, vfd->view_box.w, vfd->view_box.h); + lottie_animation_prepare_frame(lot_anim, vfd->anim_data->frame_num, vfd->view_box.w, vfd->view_box.h); + int size = lottie_animation_get_node_count(lot_anim); - float progress = ((float) vfd->anim_data->frame_num / (float) vfd->anim_data->frame_cnt); - int size = lotplayer_get_node_count(player, progress); - - //ERR("data json vfd = %p, player = %p, size = %d, root(%p) viewbox(%d %d %d %d) progress(%f)", vfd, player, size, root, vfd->view_box.x, vfd->view_box.y, vfd->view_box.w, vfd->view_box.h, progress); + //ERR("data json vfd = %p, lot_anim = %p, size = %d, root(%p) viewbox(%d %d %d %d) progress(%f)", vfd, lot_anim, size, root, vfd->view_box.x, vfd->view_box.y, vfd->view_box.w, vfd->view_box.h, progress); //Construct vg tree for (int i = 0; i < size; i++) { - const LOTNode *p = lotplayer_get_node(player, progress, i); + const LOTNode *p = lottie_animation_get_node(lot_anim, i); if (!p) continue; #ifdef PRINT_LOTTIE_INFO -- 2.7.4