From 0c3cb67811b2535648335bdd2a56307e0d52d75b Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Fri, 14 Dec 2018 13:30:35 +0900 Subject: [PATCH] lottie/capi: added missing frame_at_pos() api and changed the render_flush() signature. Change-Id: I029beb82b81448122ee6d0c59f68f758cc600895 --- inc/lottieanimation_capi.h | 19 ++++++++++++++++++- src/binding/c/lottieanimation_capi.cpp | 16 ++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/inc/lottieanimation_capi.h b/inc/lottieanimation_capi.h index c1378d7..5d3ae01 100644 --- a/inc/lottieanimation_capi.h +++ b/inc/lottieanimation_capi.h @@ -135,6 +135,21 @@ LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *a size_t frame_num, 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. * @@ -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 diff --git a/src/binding/c/lottieanimation_capi.cpp b/src/binding/c/lottieanimation_capi.cpp index 80ec93e..427135c 100644 --- a/src/binding/c/lottieanimation_capi.cpp +++ b/src/binding/c/lottieanimation_capi.cpp @@ -9,6 +9,7 @@ struct Lottie_Animation_S { std::unique_ptr mAnimation; std::future 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; } } -- 2.34.1