From ca6738b3da5f407e9d4b14c0fd46e3fd3be455df Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 17 Aug 2018 21:43:20 +0900 Subject: [PATCH] add c interface. Change-Id: Ifc81f35479aa6e0ef18ead5b863ae80b34f98f85 --- example/lottieview.cpp | 2 +- example/lottieview.h | 2 +- inc/lotcommon.h | 8 ++-- inc/lotplayer.h | 4 +- src/binding/.lottieplayer.cpp.swp | Bin 0 -> 12288 bytes src/binding/c/lotplayer_capi.h | 27 ++++++++++++ src/binding/c/lottieplayer.cpp | 86 ++++++++++++++++++++++++++++++++++++++ src/binding/c/meson.build | 8 ++++ src/binding/meson.build | 2 + src/lottie/lottieplayer.cpp | 4 +- src/meson.build | 4 +- 11 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 src/binding/.lottieplayer.cpp.swp create mode 100644 src/binding/c/lotplayer_capi.h create mode 100644 src/binding/c/lottieplayer.cpp create mode 100644 src/binding/c/meson.build create mode 100644 src/binding/meson.build diff --git a/example/lottieview.cpp b/example/lottieview.cpp index c9b68d6..9025db4 100644 --- a/example/lottieview.cpp +++ b/example/lottieview.cpp @@ -1,6 +1,6 @@ #include"lottieview.h" -using namespace lotplayer; +using namespace lottieplayer; static Eina_Bool animator(void *data , double pos) diff --git a/example/lottieview.h b/example/lottieview.h index 32122ac..032cbd0 100644 --- a/example/lottieview.h +++ b/example/lottieview.h @@ -54,7 +54,7 @@ public: Evas_Object *mVg; int mRepeatCount; LottieView::RepeatMode mRepeatMode; - lotplayer::LOTPlayer *mPlayer; + lottieplayer::LOTPlayer *mPlayer; Ecore_Animator *mAnimator{nullptr}; bool mLoop; int mCurCount; diff --git a/inc/lotcommon.h b/inc/lotcommon.h index b8efeb6..d07369f 100644 --- a/inc/lotcommon.h +++ b/inc/lotcommon.h @@ -23,7 +23,7 @@ #endif #endif -struct LOTNode { +typedef struct LOTNode { #define ChangeFlagNone 0x0000 #define ChangeFlagPath 0x0001 @@ -73,14 +73,14 @@ struct LOTNode { Color mColor; Stroke mStroke; Gradient mGradient; -}; +} lotnode; -struct LOTBuffer { +typedef struct LOTBuffer { uint32_t *buffer; int width; int height; int bytesPerLine; bool clear; -}; +} lotbuf; #endif // _LOTCOMMON_H_ diff --git a/inc/lotplayer.h b/inc/lotplayer.h index 75ccaa4..f1554b1 100644 --- a/inc/lotplayer.h +++ b/inc/lotplayer.h @@ -11,7 +11,7 @@ class LOTPlayerPrivate; #define _LOTPLAYER_DECLARE_PRIVATE(A) \ class A##Private *d; -namespace lotplayer { +namespace lottieplayer { class LOT_EXPORT LOTPlayer { public: @@ -22,7 +22,7 @@ public: float playTime() const; - float pos(); + float pos() const; const std::vector &renderList(float pos) const; diff --git a/src/binding/.lottieplayer.cpp.swp b/src/binding/.lottieplayer.cpp.swp new file mode 100644 index 0000000000000000000000000000000000000000..e312a378e09c380c9279c04beb74d1bbdba214e1 GIT binary patch literal 12288 zcmeI2OKcNI7{|ZR6VUJor(UW7gs_cYX;q2VG^c`u6i6gOgv7&gcE|BX&hB=1OrTN9 z<4kzoK_G5C!~p>p4jkcxs!AL|w5mWow8!?)s{ff;ZyYx^^w{=W>E~U0XTJHq-_BTx zJX7V#z5B$@VwrGkAbRoS_~Ds#XFoW%o~R+CS*i4m{)aCE-z$Vp|5ilb+JL3;D43Cs zic8A-M*8-(`dP7DY6ePqvJf_FCuLNMBd0Xw`L5?rCwJ_Pq7#Pi8jA0;0XEQSprz`C zorCo0C&Ol`Z{4z4Y#KV)*@Cax02^QfY=8~00XDz}*Z>>&j~h_o0G&dOtCBh=lk-5= zIeE(`Hoykh02^QfY=8~00XDz}*Z><~18m@5XrSg2eYBcraSf8k@Bi)p|KH;G|2NOW-0n1SUZR41tZ{ z_d%lHz|Y_<~18m@bX<(uAAR$B~RV(s^-RoHxiKOq!Xw-{UCJf^2Vb48rw1U64gjmoo zIFb(g4~~vj2=BeR$e@)N`Lb7#VvLQanQT_fn?Sn5W;Ks_M@&=|>`GZ{P3w zZaSdJLHAd>f10VyqMc2TVY{>@M*5_n$4`n`o`9B6b%K_!dZo}Iq(?ST)vx}-a6bX) z`+l{TZF$yDVZ=;=++1Gd8hzXshIQqhZzh55YP_4?J;u!ow9g5IHs?lH)!lhWbwJNY zH2dX4*x$Ys3USgHco+*Nsilwbcq@c@T2AMDjFC?g$gj=HIIKBR Zhs0)js|=C0dcM + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct lotplayer_s lotplayer; + +LOT_EXPORT lotplayer *lotplayer_create(void); +LOT_EXPORT int lotplayer_destroy(lotplayer *player); +LOT_EXPORT int lotplayer_set_file(lotplayer *player, const char *file); +LOT_EXPORT int lotplayer_set_size(lotplayer *player, int w, int h); +LOT_EXPORT int lotplayer_get_size(const lotplayer *player, int* w, int* h); +LOT_EXPORT float lotplayer_get_playtime(const lotplayer *player); +LOT_EXPORT float lotplayer_get_pos(const lotplayer *player); +LOT_EXPORT size_t lotplayer_get_node_count(const lotplayer *player, float pos); +LOT_EXPORT const lotnode* lotplayer_get_node(lotplayer *player, float pos, size_t idx); + +#ifdef __cplusplus +} +#endif + +#endif //_LOTPLAYER_CAPI_H_ + diff --git a/src/binding/c/lottieplayer.cpp b/src/binding/c/lottieplayer.cpp new file mode 100644 index 0000000..9db88d7 --- /dev/null +++ b/src/binding/c/lottieplayer.cpp @@ -0,0 +1,86 @@ +#include + +extern "C" { + +using namespace lottieplayer; + +using lotplayer = LOTPlayer; + +LOT_EXPORT lotplayer *lotplayer_create(void) +{ + lotplayer* p = new LOTPlayer(); + if (!p) { + //TODO: Print Error + } + return p; +} + +LOT_EXPORT int lotplayer_destroy(lotplayer *player) +{ + if (!player) return -1; + delete(player); + + return 0; +} + +LOT_EXPORT int lotplayer_set_file(lotplayer *player, const char *file) +{ + if (!player) return -1; + bool ret = player->setFilePath(file); + + if (!ret) return -1; + + return 0; +} + +LOT_EXPORT int lotplayer_set_size(lotplayer *player, int w, int h) +{ + if (!player) return -1; + + player->setSize(w, h); + + return 0; +} + +LOT_EXPORT int lotplayer_get_size(const lotplayer *player, int* w, int* h) +{ + if (!player) return -1; + + player->size(*w, *h); + + return 0; +} + +LOT_EXPORT float lotplayer_get_pos(const lotplayer *player) +{ + if (!player) return -1.0f; + + return player->pos(); +} + +LOT_EXPORT size_t lotplayer_get_node_count(const lotplayer *player, float pos) +{ + if (!player) return 0; + + return player->renderList(pos).size(); +} + +LOT_EXPORT float lotplayer_get_playtime(const lotplayer *player) +{ + if (!player) return 0.0f; + + return player->playTime(); +} + +LOT_EXPORT const lotnode* lotplayer_get_node(lotplayer *player, float pos, size_t idx) +{ + if (!player) return nullptr; + + if (idx >= player->renderList(pos).size()) { + return nullptr; + } + + return player->renderList(pos)[idx]; +} + +} diff --git a/src/binding/c/meson.build b/src/binding/c/meson.build new file mode 100644 index 0000000..223e5f7 --- /dev/null +++ b/src/binding/c/meson.build @@ -0,0 +1,8 @@ +install_headers(['lotplayer_capi.h']) + +source_file = files('lottieplayer.cpp') + +binding_c_dep = declare_dependency( + include_directories : include_directories('.'), + sources : source_file + ) diff --git a/src/binding/meson.build b/src/binding/meson.build new file mode 100644 index 0000000..4be2509 --- /dev/null +++ b/src/binding/meson.build @@ -0,0 +1,2 @@ +subdir('c') +binding_dep = binding_c_dep diff --git a/src/lottie/lottieplayer.cpp b/src/lottie/lottieplayer.cpp index 825d84f..da90742 100644 --- a/src/lottie/lottieplayer.cpp +++ b/src/lottie/lottieplayer.cpp @@ -6,7 +6,7 @@ #include -using namespace lotplayer; +using namespace lottieplayer; class LOTPlayerPrivate { @@ -251,7 +251,7 @@ float LOTPlayer::playTime() const return d->playTime(); } -float LOTPlayer::pos() +float LOTPlayer::pos() const { return d->pos(); } diff --git a/src/meson.build b/src/meson.build index 6f6bb37..dc6a837 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,8 +1,10 @@ subdir('vector') subdir('lottie') +subdir('binding') -library_deps = [vector_dep] +library_deps = vector_dep library_deps += lottie_dep +library_deps += binding_dep lottie_player_lib = shared_library( 'lottie-player', include_directories : inc, -- 2.7.4