CAPI: Support Marker feature for CAPI.
authorJunsuChoi <jsuya.choi@samsung.com>
Fri, 18 Oct 2019 02:27:32 +0000 (11:27 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Mon, 11 Nov 2019 20:58:10 +0000 (05:58 +0900)
Add lottie_animation_get_markerlist() api
User can use this api and get information about each marker.

inc/rlottie_capi.h
inc/rlottiecommon.h
src/binding/c/lottieanimation_capi.cpp

index 653c86d..9f99162 100644 (file)
@@ -255,6 +255,21 @@ LOT_EXPORT uint32_t *lottie_animation_render_flush(Lottie_Animation *animation);
  * */
 LOT_EXPORT void lottie_animation_property_override(Lottie_Animation *animation, const Lottie_Animation_Property type, const char *keypath, ...);
 
+
+/**
+ *  @brief Returns list of markers in the Lottie resource
+ *  @p LOTMarkerList has a @p LOTMarker list and size of list
+ *  @p LOTMarker has the marker's name, start frame, and end frame.
+ *
+ *  @param[in] animation Animation object.
+ *
+ *  @return The list of marker. If there is no marker, return null.
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ * */
+LOT_EXPORT const LOTMarkerList* lottie_animation_get_markerlist(Lottie_Animation *animation);
+
 #ifdef __cplusplus
 }
 #endif
index f87b5c4..9d067a5 100644 (file)
@@ -118,6 +118,17 @@ typedef enum
     MatteLumaInv
 } LOTMatteType;
 
+typedef struct LOTMarker {
+   char *name;
+   size_t startframe;
+   size_t endframe;
+} LOTMarker;
+
+typedef struct LOTMarkerList {
+   LOTMarker *ptr;
+   size_t size;
+} LOTMarkerList;
+
 typedef struct LOTNode {
 
 #define ChangeFlagNone 0x0000
index 7793607..991ae9f 100644 (file)
@@ -28,9 +28,10 @@ extern "C" {
 
 struct Lottie_Animation_S
 {
-    std::unique_ptr<Animation> mAnimation;
-    std::future<Surface>       mRenderTask;
-    uint32_t                  *mBufferRef;
+    std::unique_ptr<Animation>      mAnimation;
+    std::future<Surface>            mRenderTask;
+    uint32_t                       *mBufferRef;
+    LOTMarkerList                  *mMarkerList;
 };
 
 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *path)
@@ -58,6 +59,14 @@ LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, cons
 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation_S *animation)
 {
     if (animation) {
+        if (animation->mMarkerList) {
+            for(size_t i = 0; i < animation->mMarkerList->size; i++) {
+                if (animation->mMarkerList->ptr[i].name) free(animation->mMarkerList->ptr[i].name);
+            }
+            delete[] animation->mMarkerList->ptr;
+            delete animation->mMarkerList;
+        }
+
         if (animation->mRenderTask.valid()) {
             animation->mRenderTask.get();
         }
@@ -205,4 +214,26 @@ lottie_animation_property_override(Lottie_Animation_S *animation,
     }
     va_end(prop);
 }
+
+LOT_EXPORT const LOTMarkerList*
+lottie_animation_get_markerlist(Lottie_Animation_S *animation)
+{
+   if (!animation) return nullptr;
+
+   auto markers = animation->mAnimation->markers();
+   if (markers.size() == 0) return nullptr;
+   if (animation->mMarkerList) return (const LOTMarkerList*)animation->mMarkerList;
+
+   animation->mMarkerList = new LOTMarkerList();
+   animation->mMarkerList->size = markers.size();
+   animation->mMarkerList->ptr = new LOTMarker[markers.size()]();
+
+   for(size_t i = 0; i < markers.size(); i++) {
+       animation->mMarkerList->ptr[i].name = strdup(std::get<0>(markers[i]).c_str());
+       animation->mMarkerList->ptr[i].startframe= std::get<1>(markers[i]);
+       animation->mMarkerList->ptr[i].endframe= std::get<2>(markers[i]);
+   }
+   return (const LOTMarkerList*)animation->mMarkerList;
+}
+
 }