remove redundant apis.
[platform/core/uifw/lottie-player.git] / src / binding / c / lottieanimation_capi.cpp
1 #include "lottieanimation.h"
2 #include "vdebug.h"
3
4 using namespace lottie;
5
6 extern "C" {
7
8 struct Lottie_Animation_S
9 {
10     std::unique_ptr<Animation> mAnimation;
11     size_t                     mCurFrame{0};
12     std::future<Surface>       mRenderTask;
13     size_t                     mFrameNo{0};
14     size_t                     mArraySize{0};
15     size_t                     mWidth{0};
16     size_t                     mHeight{0};
17 };
18
19 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *file)
20 {
21     if (auto animation = Animation::loadFromFile(file) ) {
22         Lottie_Animation_S *handle = new Lottie_Animation_S();
23         handle->mAnimation = std::move(animation);
24         return handle;
25     } else {
26         return nullptr;
27     }
28 }
29
30 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key)
31 {
32     if (auto animation = Animation::loadFromData(data, key) ) {
33         Lottie_Animation_S *handle = new Lottie_Animation_S();
34         handle->mAnimation = std::move(animation);
35         return handle;
36     } else {
37         return nullptr;
38     }
39 }
40
41 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation_S *animation)
42 {
43     if (animation)
44         delete animation;
45 }
46
47 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation_S *animation, size_t *w, size_t *h)
48 {
49    if (!animation) return;
50
51    animation->mAnimation->size(*w, *h);
52 }
53
54 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation_S *animation)
55 {
56    if (!animation) return 0;
57
58    return animation->mAnimation->duration();
59 }
60
61 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation_S *animation)
62 {
63    if (!animation) return 0;
64
65    return animation->mAnimation->totalFrame();
66 }
67
68
69 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation_S *animation)
70 {
71    if (!animation) return 0;
72
73    return animation->mAnimation->frameRate();
74 }
75
76 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation_S *animation, size_t frameNo, size_t w, size_t h)
77 {
78     if (!animation) return nullptr;
79
80     animation->mFrameNo = frameNo;
81     animation->mWidth = w;
82     animation->mHeight = h;
83     return animation->mAnimation->renderTree(frameNo, w, h);
84 }
85
86 LOT_EXPORT void
87 lottie_animation_render_async(Lottie_Animation_S *animation,
88                               size_t frame_number,
89                               uint32_t *buffer,
90                               size_t width,
91                               size_t height,
92                               size_t bytes_per_line)
93 {
94     if (!animation) return;
95
96     lottie::Surface surface(buffer, width, height, bytes_per_line);
97     animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
98 }
99
100 LOT_EXPORT void
101 lottie_animation_render_flush(Lottie_Animation_S *animation)
102 {
103     if (!animation) return;
104
105     if (animation->mRenderTask.valid()) {
106         animation->mRenderTask.get();
107     }
108 }
109
110 }