lottie/capi: added missing frame_at_pos() api and changed the render_flush() signature. 02/195502/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 14 Dec 2018 04:30:35 +0000 (13:30 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Fri, 14 Dec 2018 04:55:05 +0000 (13:55 +0900)
Change-Id: I029beb82b81448122ee6d0c59f68f758cc600895

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

index c1378d7..5d3ae01 100644 (file)
@@ -136,6 +136,21 @@ LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *a
                                                              size_t width, size_t height);
 
 /**
+ *  @brief Maps position to frame number and returns it.
+ *
+ *  @param[in] animation Animation object.
+ *  @param[in] pos position in the range [ 0.0 .. 1.0 ].
+ *
+ *  @return mapped frame numbe in the range [ start_frame .. end_frame ].
+ *          @c 0 if the Lottie resource has no animation.
+ *
+ *
+ *  @ingroup Lottie_Animation
+ *  @internal
+ */
+LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
+
+/**
  *  @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
  *
  *  @param[in] animation Animation object.
@@ -168,10 +183,12 @@ lottie_animation_render_async(Lottie_Animation *animation,
  *  @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
  *  in pair to get the benefit of async rendering.
  *
+ *  @return the pixel buffer it finished rendering.
+ *
  *  @ingroup Lottie_Animation
  *  @internal
  */
-LOT_EXPORT void
+LOT_EXPORT uint32_t *
 lottie_animation_render_flush(Lottie_Animation *animation);
 
 #ifdef __cplusplus
index 80ec93e..427135c 100644 (file)
@@ -9,6 +9,7 @@ struct Lottie_Animation_S
 {
     std::unique_ptr<Animation> mAnimation;
     std::future<Surface>       mRenderTask;
+    uint32_t                  *mBufferRef;
 };
 
 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *path)
@@ -75,6 +76,14 @@ LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation_S
     return animation->mAnimation->renderTree(frame_num, width, height);
 }
 
+LOT_EXPORT size_t
+lottie_animation_get_frame_at_pos(const Lottie_Animation_S *animation, float pos)
+{
+    if (!animation) return 0;
+
+    return animation->mAnimation->frameAtPos(pos);
+}
+
 LOT_EXPORT void
 lottie_animation_render_async(Lottie_Animation_S *animation,
                               size_t frame_number,
@@ -87,16 +96,19 @@ lottie_animation_render_async(Lottie_Animation_S *animation,
 
     lottie::Surface surface(buffer, width, height, bytes_per_line);
     animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
+    animation->mBufferRef = buffer;
 }
 
-LOT_EXPORT void
+LOT_EXPORT uint32_t *
 lottie_animation_render_flush(Lottie_Animation_S *animation)
 {
-    if (!animation) return;
+    if (!animation) return nullptr;
 
     if (animation->mRenderTask.valid()) {
         animation->mRenderTask.get();
     }
+
+    return animation->mBufferRef;
 }
 
 }