2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
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
8 * http://floralicense.org/license/
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.
17 #ifndef _LOTTIE_ANIMATION_H_
18 #define _LOTTIE_ANIMATION_H_
27 #define LOT_EXPORT __declspec(dllexport)
32 #define LOT_EXPORT __declspec(dllimport)
37 #define LOT_EXPORT __attribute__((visibility("default")))
52 class LOT_EXPORT Surface {
55 * @brief Surface object constructor.
57 * @param[in] buffer surface buffer.
58 * @param[in] width surface width.
59 * @param[in] height surface height.
60 * @param[in] bytesPerLine number of bytes in a surface scanline.
62 * @note Default surface format is ARGB32_Premultiplied.
66 Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine);
69 * @brief Returns width of the surface.
71 * @return surface width
76 size_t width() const {return mWidth;}
79 * @brief Returns height of the surface.
81 * @return surface height
85 size_t height() const {return mHeight;}
88 * @brief Returns number of bytes in the surface scanline.
90 * @return number of bytes in scanline.
94 size_t bytesPerLine() const {return mBytesPerLine;}
97 * @brief Returns buffer attached tp the surface.
99 * @return buffer attaced to the Surface.
103 uint32_t *buffer() const {return mBuffer;}
106 * @brief Default constructor.
110 uint32_t *mBuffer{nullptr};
113 size_t mBytesPerLine{0};
116 class LOT_EXPORT Animation {
120 * @brief Constructs an animation object from file path.
122 * @param[in] path Lottie resource file path
124 * @return Animation object that can render the contents of the
125 * Lottie resource represented by file path.
129 static std::unique_ptr<Animation>
130 loadFromFile(const std::string &path);
133 * @brief Constructs an animation object from JSON string data.
135 * @param[in] jsonData The JSON string data.
136 * @param[in] key the string that will be used to cache the JSON string data.
138 * @return Animation object that can render the contents of the
139 * Lottie resource represented by JSON string data.
143 static std::unique_ptr<Animation>
144 loadFromData(std::string jsonData, const std::string &key);
147 * @brief Returns default framerate of the Lottie resource.
149 * @return framerate of the Lottie resource
154 double frameRate() const;
157 * @brief Returns total number of frames present in the Lottie resource.
159 * @return frame count of the Lottie resource.
161 * @note frame number starts with 0.
165 size_t totalFrame() const;
168 * @brief Returns default viewport size of the Lottie resource.
170 * @param[out] width default width of the viewport.
171 * @param[out] height default height of the viewport.
176 void size(size_t &width, size_t &height) const;
179 * @brief Returns total animation duration of Lottie resource in second.
180 * it uses totalFrame() and frameRate() to calculate the duration.
181 * duration = totalFrame() / frameRate().
183 * @return total animation duration in second.
184 * @retval 0 if the Lottie resource has no animation.
191 double duration() const;
194 * @brief Returns frame number for a given position.
195 * this function helps to map the position value retuned
196 * by the animator to a frame number in side the Lottie resource.
197 * frame_number = lerp(start_frame, endframe, pos);
199 * @param[in] pos normalized position value [0 ... 1]
201 * @return frame numer maps to the position value [startFrame .... endFrame]
205 size_t frameAtPos(double pos);
208 * @brief Renders the content to surface Asynchronously.
209 * it gives a future in return to get the result of the
210 * rendering at a future point.
211 * To get best performance user has to start rendering as soon as
212 * it finds that content at {frameNo} has to be rendered and get the
213 * result from the future at the last moment when the surface is needed
214 * to draw into the screen.
217 * @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
218 * @param[in] surface Surface in which content will be drawn
220 * @return future that will hold the result when rendering finished.
222 * for Synchronus rendering @see renderSync
227 std::future<Surface> render(size_t frameNo, Surface surface);
230 * @brief Renders the content to surface synchronously.
231 * for performance use the async rendering @see render
233 * @param[in] frameNo Content corresponds to the @p frameNo needs to be drawn
234 * @param[in] surface Surface in which content will be drawn
238 void renderSync(size_t frameNo, Surface surface);
241 * @brief Returns root layer of the composition updated with
242 * content of the Lottie resource at frame number @p frameNo.
244 * @param[in] frameNo Content corresponds to the @p frameNo needs to be extracted.
245 * @param[in] width content viewbox width
246 * @param[in] height content viewbox height
248 * @return Root layer node.
252 const LOTLayerNode * renderTree(size_t frameNo, size_t width, size_t height) const;
255 * @brief default destructor
263 * @brief default constructor
269 std::unique_ptr<AnimationImpl> d;
272 } // namespace lotplayer
274 #endif // _LOTTIE_ANIMATION_H_