Put samsung copyright header to all our own source code.
[platform/core/uifw/lottie-player.git] / inc / lottieanimation_capi.h
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef _LOTTIE_ANIMATION_CAPI_H_
18 #define _LOTTIE_ANIMATION_CAPI_H_
19
20 #include <stddef.h>
21 #include <stdint.h>
22 #include <lottiecommon.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 typedef struct Lottie_Animation_S Lottie_Animation;
29
30 /**
31  *  @brief Constructs an animation object from file path.
32  *
33  *  @param[in] path Lottie resource file path
34  *
35  *  @return Animation object that can build the contents of the
36  *          Lottie resource represented by file path.
37  *
38  *  @see lottie_animation_destroy()
39  *
40  *  @ingroup Lottie_Animation
41  *  @internal
42  */
43 LOT_EXPORT Lottie_Animation *lottie_animation_from_file(const char *path);
44
45 /**
46  *  @brief Constructs an animation object from JSON string data.
47  *
48  *  @param[in] data The JSON string data.
49  *  @param[in] key the string that will be used to cache the JSON string data.
50  *
51  *  @return Animation object that can build the contents of the
52  *          Lottie resource represented by JSON string data.
53  *
54  *  @ingroup Lottie_Animation
55  *  @internal
56  */
57 LOT_EXPORT Lottie_Animation *lottie_animation_from_data(const char *data, const char *key);
58
59 /**
60  *  @brief Free given Animation object resource.
61  *
62  *  @param[in] animation Animation object to free.
63  *
64  *  @see lottie_animation_from_file()
65  *  @see lottie_animation_from_data()
66  *
67  *  @ingroup Lottie_Animation
68  *  @internal
69  */
70 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation *animation);
71
72 /**
73  *  @brief Returns default viewport size of the Lottie resource.
74  *
75  *  @param[in] animation Animation object.
76  *  @param[out] w default width of the viewport.
77  *  @param[out] h default height of the viewport.
78  *
79  *  @ingroup Lottie_Animation
80  *  @internal
81  */
82 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation *animation, size_t *width, size_t *height);
83
84 /**
85  *  @brief Returns total animation duration of Lottie resource in second.
86  *         it uses totalFrame() and frameRate() to calculate the duration.
87  *         duration = totalFrame() / frameRate().
88  *
89  *  @param[in] animation Animation object.
90  *
91  *  @return total animation duration in second.
92  *          @c 0 if the Lottie resource has no animation.
93  *
94  *  @see lottie_animation_get_totalframe()
95  *  @see lottie_animation_get_framerate()
96  *
97  *  @ingroup Lottie_Animation
98  *  @internal
99  */
100 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation *animation);
101
102 /**
103  *  @brief Returns total number of frames present in the Lottie resource.
104  *
105  *  @param[in] animation Animation object.
106  *
107  *  @return frame count of the Lottie resource.*
108  *
109  *  @note frame number starts with 0.
110  *
111  *  @see lottie_animation_get_duration()
112  *  @see lottie_animation_get_framerate()
113  *
114  *  @ingroup Lottie_Animation
115  *  @internal
116  */
117 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation *animation);
118
119 /**
120  *  @brief Returns default framerate of the Lottie resource.
121  *
122  *  @param[in] animation Animation object.
123  *
124  *  @return framerate of the Lottie resource
125  *
126  *  @ingroup Lottie_Animation
127  *  @internal
128  *
129  */
130 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation *animation);
131
132 /**
133  *  @brief Get the render tree which contains the snapshot of the animation object
134  *         at frame = @c frame_num, the content of the animation in that frame number.
135  *
136  *  @param[in] animation Animation object.
137  *  @param[in] width requested snapshot viewport width.
138  *  @param[in] height requested snapshot viewport height.
139  *
140  *  @return Animation snapshot tree.
141  *
142  * @note: User has to traverse the tree for rendering.
143  *
144  * @see LOTLayerNode
145  * @see LOTNode
146  *
147  *  @ingroup Lottie_Animation
148  *  @internal
149  */
150 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation *animation,
151                                                              size_t frame_num,
152                                                              size_t width, size_t height);
153
154 /**
155  *  @brief Maps position to frame number and returns it.
156  *
157  *  @param[in] animation Animation object.
158  *  @param[in] pos position in the range [ 0.0 .. 1.0 ].
159  *
160  *  @return mapped frame numbe in the range [ start_frame .. end_frame ].
161  *          @c 0 if the Lottie resource has no animation.
162  *
163  *
164  *  @ingroup Lottie_Animation
165  *  @internal
166  */
167 LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
168
169 /**
170  *  @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
171  *
172  *  @param[in] animation Animation object.
173  *  @param[in] frame_num the frame number needs to be rendered.
174  *  @param[in] buffer surface buffer use for rendering.
175  *  @param[in] width width of the surface
176  *  @param[in] height height of the surface
177  *  @param[in] bytes_per_line stride of the surface in bytes.
178  *
179  *  @note user must call lottie_animation_render_flush() to make sure render is finished.
180  *
181  *  @ingroup Lottie_Animation
182  *  @internal
183  */
184 LOT_EXPORT void
185 lottie_animation_render_async(Lottie_Animation *animation,
186                               size_t frame_num,
187                               uint32_t *buffer,
188                               size_t width,
189                               size_t height,
190                               size_t bytes_per_line);
191
192 /**
193  *  @brief Request to finish the current async renderer job for this animation object.
194  *  If render is finished then this call returns immidiately.
195  *  If not, it waits till render job finish and then return.
196  *
197  *  @param[in] animation Animation object.
198  *
199  *  @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
200  *  in pair to get the benefit of async rendering.
201  *
202  *  @return the pixel buffer it finished rendering.
203  *
204  *  @ingroup Lottie_Animation
205  *  @internal
206  */
207 LOT_EXPORT uint32_t *
208 lottie_animation_render_flush(Lottie_Animation *animation);
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214 #endif //_LOTTIE_ANIMATION_CAPI_H_
215