lottie: refactor lottie interface
[platform/core/uifw/lottie-player.git] / inc / lottieanimation.h
1 #ifndef _LOTTIE_ANIMATION_H_
2 #define _LOTTIE_ANIMATION_H_
3
4 #include <future>
5 #include <vector>
6 #include <memory>
7
8 #ifdef _WIN32
9 #ifdef LOT_BUILD
10 #ifdef DLL_EXPORT
11 #define LOT_EXPORT __declspec(dllexport)
12 #else
13 #define LOT_EXPORT
14 #endif
15 #else
16 #define LOT_EXPORT __declspec(dllimport)
17 #endif
18 #else
19 #ifdef __GNUC__
20 #if __GNUC__ >= 4
21 #define LOT_EXPORT __attribute__((visibility("default")))
22 #else
23 #define LOT_EXPORT
24 #endif
25 #else
26 #define LOT_EXPORT
27 #endif
28 #endif
29
30 class AnimationImpl;
31 class LOTNode;
32
33 namespace lottie {
34
35 class LOT_EXPORT Surface {
36 public:
37     Surface() = default;
38     Surface(uint32_t *buffer, size_t width, size_t height, size_t bytesPerLine);
39     size_t width() const {return mWidth;}
40     size_t height() const {return mHeight;}
41     size_t  bytesPerLine() const {return mBytesPerLine;}
42     uint32_t *buffer() const {return mBuffer;}
43
44 private:
45     uint32_t    *mBuffer;
46     size_t       mWidth;
47     size_t       mHeight;
48     size_t       mBytesPerLine;
49 };
50
51 class LOT_EXPORT Animation {
52 public:
53
54     static std::unique_ptr<Animation>
55     loadFromFile(const std::string &path);
56
57     static std::unique_ptr<Animation>
58     loadFromData(const char *jsonData, const char *key);
59
60     double frameRate() const;
61     size_t totalFrame() const;
62     void   size(size_t &width, size_t &height) const;
63     double duration() const;
64     size_t frameAtPos(double pos);
65
66     std::future<Surface> render(size_t frameNo, Surface surface);
67     void              renderSync(size_t frameNo, Surface surface);
68
69     ~Animation();
70     Animation();
71
72     const std::vector<LOTNode *> &renderList(size_t frameNo, size_t width, size_t height) const;
73 private:
74     std::unique_ptr<AnimationImpl> d;
75 };
76 }  // namespace lotplayer
77
78 #endif  // _LOTTIE_ANIMATION_H_