add c interface. 62/187062/6
authorHermet Park <hermetpark@gmail.com>
Fri, 17 Aug 2018 12:43:20 +0000 (21:43 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 21 Aug 2018 02:08:34 +0000 (02:08 +0000)
Change-Id: Ifc81f35479aa6e0ef18ead5b863ae80b34f98f85

example/lottieview.cpp
example/lottieview.h
inc/lotcommon.h
inc/lotplayer.h
src/binding/.lottieplayer.cpp.swp [new file with mode: 0644]
src/binding/c/lotplayer_capi.h [new file with mode: 0644]
src/binding/c/lottieplayer.cpp [new file with mode: 0644]
src/binding/c/meson.build [new file with mode: 0644]
src/binding/meson.build [new file with mode: 0644]
src/lottie/lottieplayer.cpp
src/meson.build

index c9b68d6..9025db4 100644 (file)
@@ -1,6 +1,6 @@
 #include"lottieview.h"
 
-using namespace lotplayer;
+using namespace lottieplayer;
 
 static Eina_Bool
 animator(void *data , double pos)
index 32122ac..032cbd0 100644 (file)
@@ -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;
index b8efeb6..d07369f 100644 (file)
@@ -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_
index 75ccaa4..f1554b1 100644 (file)
@@ -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<LOTNode *> &renderList(float pos) const;
 
diff --git a/src/binding/.lottieplayer.cpp.swp b/src/binding/.lottieplayer.cpp.swp
new file mode 100644 (file)
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 (file)
index 0000000..ccf679e
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef _LOTPLAYER_CAPI_H_
+#define _LOTPLAYER_CAPI_H_
+
+#include <lotcommon.h>
+
+#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 (file)
index 0000000..9db88d7
--- /dev/null
@@ -0,0 +1,86 @@
+#include <lotplayer.h>
+
+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 (file)
index 0000000..223e5f7
--- /dev/null
@@ -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 (file)
index 0000000..4be2509
--- /dev/null
@@ -0,0 +1,2 @@
+subdir('c')
+binding_dep = binding_c_dep
index 825d84f..da90742 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <fstream>
 
-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();
 }
index 6f6bb37..dc6a837 100644 (file)
@@ -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,