dd125b521be68489a957fbc9efd376d53a3d385f
[platform/core/graphics/tizenvg.git] / inc / tizenvg.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 _TIZENVG_H_
18 #define _TIZENVG_H_
19
20 #include <memory>
21
22 #ifdef TIZENVG_BUILD
23     #define TIZENVG_EXPORT __attribute__ ((visibility ("default")))
24 #else
25     #define TIZENVG_EXPORT
26 #endif
27
28 #ifdef  LOG_TAG
29 #undef  LOG_TAG
30 #endif
31 #define LOG_TAG "TIZENVG"
32
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #define _TIZENVG_DECLARE_PRIVATE(A) \
39 private: \
40     struct Impl; \
41     std::unique_ptr<Impl> pImpl; \
42     A(const A&) = delete; \
43     const A& operator=(const A&) = delete; \
44     A()
45
46 #define _TIZENVG_DISABLE_CTOR(A) \
47     A() = delete; \
48     ~A() = delete
49
50 namespace tvg
51 {
52
53 enum class TIZENVG_EXPORT PathCommand { Close, MoveTo, LineTo, CubicTo };
54
55 class RenderMethod;
56
57 struct Point
58 {
59     float x;
60     float y;
61 };
62
63
64 /**
65  * @class PaintNode
66  *
67  * @ingroup TizenVG
68  *
69  * @brief description...
70  *
71  */
72 class TIZENVG_EXPORT PaintNode
73 {
74 public:
75     virtual ~PaintNode() {}
76     virtual int dispose(RenderMethod* engine) = 0;
77     virtual int update(RenderMethod* engine) = 0;
78 };
79
80
81 /**
82  * @class ShapeNode
83  *
84  * @ingroup TizenVG
85  *
86  * @brief description...
87  *
88  */
89 class TIZENVG_EXPORT ShapeNode final : public PaintNode
90 {
91 public:
92     ~ShapeNode();
93
94     int dispose(RenderMethod* engine) noexcept override;
95     int update(RenderMethod* engine) noexcept override;
96     int clear() noexcept;
97
98     int appendRect(float x, float y, float w, float h, float radius) noexcept;
99     int appendCircle(float cx, float cy, float radius) noexcept;
100
101     int fill(size_t r, size_t g, size_t b, size_t a) noexcept;
102
103     int pathCommands(const PathCommand** cmds) const noexcept;
104     int pathCoords(const Point** pts) const noexcept;
105     int fill(size_t* r, size_t* g, size_t* b, size_t* a) const noexcept;
106
107     static std::unique_ptr<ShapeNode> gen() noexcept;
108
109     _TIZENVG_DECLARE_PRIVATE(ShapeNode);
110 };
111
112
113 /**
114  * @class SceneNode
115  *
116  * @ingroup TizenVG
117  *
118  * @brief description...
119  *
120  */
121 class TIZENVG_EXPORT SceneNode final : public PaintNode
122 {
123 public:
124     ~SceneNode();
125
126     int dispose(RenderMethod* engine) noexcept override;
127     int update(RenderMethod* engine) noexcept override;
128
129     int push(std::unique_ptr<ShapeNode> shape) noexcept;
130
131     static std::unique_ptr<SceneNode> gen() noexcept;
132
133     _TIZENVG_DECLARE_PRIVATE(SceneNode);
134 };
135
136
137 /**
138  * @class SwCanvas
139  *
140  * @ingroup TizenVG
141  *
142   @brief description...
143  *
144  */
145 class TIZENVG_EXPORT SwCanvas final
146 {
147 public:
148     ~SwCanvas();
149
150     int push(std::unique_ptr<PaintNode> paint) noexcept;
151     int clear() noexcept;
152
153     int update() noexcept;
154     int draw(bool async = true) noexcept;
155     int sync() noexcept;
156     RenderMethod* engine() noexcept;
157
158     int target(uint32_t* buffer, size_t stride, size_t height) noexcept;
159
160     static std::unique_ptr<SwCanvas> gen(uint32_t* buffer = nullptr, size_t stride = 0, size_t height = 0) noexcept;
161
162     _TIZENVG_DECLARE_PRIVATE(SwCanvas);
163 };
164
165
166 /**
167  * @class GlCanvas
168  *
169  * @ingroup TizenVG
170  *
171  * @brief description...
172  *
173  */
174 class TIZENVG_EXPORT GlCanvas final
175 {
176 public:
177     ~GlCanvas();
178
179     int push(std::unique_ptr<PaintNode> paint) noexcept;
180     int clear() noexcept;
181
182     //TODO: Gl Specific methods. Need gl backend configuration methods as well.
183     int update() noexcept;
184     int draw(bool async = true) noexcept { return 0; }
185     int sync() noexcept { return 0; }
186     RenderMethod* engine() noexcept;
187
188     static std::unique_ptr<GlCanvas> gen() noexcept;
189
190     _TIZENVG_DECLARE_PRIVATE(GlCanvas);
191 };
192
193
194 /**
195  * @class Engine
196  *
197  * @ingroup TizenVG
198  *
199  * @brief description...
200  *
201  */
202 class TIZENVG_EXPORT Engine final
203 {
204 public:
205     /**
206      * @brief ...
207      *
208      * @param[in] arg ...
209      *
210      * @note ...
211      *
212      * @return ...
213      *
214      * @see ...
215      */
216     static int init() noexcept;
217     static int term() noexcept;
218
219     _TIZENVG_DISABLE_CTOR(Engine);
220 };
221
222 } //namespace
223
224 #ifdef __cplusplus
225 }
226 #endif
227
228 #endif //_TIZENVG_H_