From: Hermet Park Date: Fri, 17 Aug 2018 12:43:20 +0000 (+0900) Subject: add c interface. X-Git-Tag: submit/tizen/20180917.042405~93 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ca6738b3da5f407e9d4b14c0fd46e3fd3be455df;p=platform%2Fcore%2Fuifw%2Flottie-player.git add c interface. Change-Id: Ifc81f35479aa6e0ef18ead5b863ae80b34f98f85 --- 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 0000000..e312a37 Binary files /dev/null and b/src/binding/.lottieplayer.cpp.swp differ diff --git a/src/binding/c/lotplayer_capi.h b/src/binding/c/lotplayer_capi.h new file mode 100644 index 0000000..ccf679e --- /dev/null +++ b/src/binding/c/lotplayer_capi.h @@ -0,0 +1,27 @@ +#ifndef _LOTPLAYER_CAPI_H_ +#define _LOTPLAYER_CAPI_H_ + +#include + +#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,