Merge "tvg: added task support that runs on a threadpool." into tizen
[platform/core/graphics/tizenvg.git] / inc / thorvg.h
1 #ifndef _THORVG_H_
2 #define _THORVG_H_
3
4 #include <memory>
5
6 #ifdef TVG_BUILD
7     #define TVG_EXPORT __attribute__ ((visibility ("default")))
8 #else
9     #define TVG_EXPORT
10 #endif
11
12 #ifdef  LOG_TAG
13 #undef  LOG_TAG
14 #endif
15 #define LOG_TAG "TVG"
16
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22
23 #define _TVG_DECLARE_PRIVATE(A) \
24 protected: \
25     struct Impl; \
26     std::unique_ptr<Impl> pImpl; \
27     A(const A&) = delete; \
28     const A& operator=(const A&) = delete; \
29     A()
30
31 #define _TVG_DISABLE_CTOR(A) \
32     A() = delete; \
33     ~A() = delete
34
35 #define _TVG_DECLARE_ACCESSOR() \
36     friend Canvas; \
37     friend Scene; \
38     friend Picture
39
40 #define _TVG_DECALRE_IDENTIFIER() \
41     auto id() const { return _id; } \
42 protected: \
43     unsigned _id
44
45 namespace tvg
46 {
47
48 class RenderMethod;
49 class Scene;
50 class Picture;
51 class Canvas;
52
53
54 enum class TVG_EXPORT Result { Success = 0, InvalidArguments, InsufficientCondition, FailedAllocation, MemoryCorruption, NonSupport, Unknown };
55 enum class TVG_EXPORT PathCommand { Close = 0, MoveTo, LineTo, CubicTo };
56 enum class TVG_EXPORT StrokeCap { Square = 0, Round, Butt };
57 enum class TVG_EXPORT StrokeJoin { Bevel = 0, Round, Miter };
58 enum class TVG_EXPORT FillSpread { Pad = 0, Reflect, Repeat };
59 enum class TVG_EXPORT CanvasEngine { Sw = 0, Gl };
60
61
62 struct Point
63 {
64     float x, y;
65 };
66
67
68 struct Matrix
69 {
70     float e11, e12, e13;
71     float e21, e22, e23;
72     float e31, e32, e33;
73 };
74
75
76 /**
77  * @class Paint
78  *
79  * @ingroup ThorVG
80  *
81  * @brief description...
82  *
83  */
84 class TVG_EXPORT Paint
85 {
86 public:
87     virtual ~Paint();
88
89     Result rotate(float degree) noexcept;
90     Result scale(float factor) noexcept;
91     Result translate(float x, float y) noexcept;
92     Result transform(const Matrix& m) noexcept;
93     Result bounds(float* x, float* y, float* w, float* h) const noexcept;
94
95     _TVG_DECLARE_ACCESSOR();
96     _TVG_DECLARE_PRIVATE(Paint);
97 };
98
99
100 /**
101  * @class Fill
102  *
103  * @ingroup ThorVG
104  *
105  * @brief description...
106  *
107  */
108 class TVG_EXPORT Fill
109 {
110 public:
111     struct ColorStop
112     {
113         float offset;
114         uint8_t r, g, b, a;
115     };
116
117     virtual ~Fill();
118
119     Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept;
120     Result spread(FillSpread s) noexcept;
121
122     uint32_t colorStops(const ColorStop** colorStops) const noexcept;
123     FillSpread spread() const noexcept;
124
125     _TVG_DECALRE_IDENTIFIER();
126     _TVG_DECLARE_PRIVATE(Fill);
127 };
128
129
130 /**
131  * @class Canvas
132  *
133  * @ingroup ThorVG
134  *
135  * @brief description...
136  *
137  */
138 class TVG_EXPORT Canvas
139 {
140 public:
141     Canvas(RenderMethod*);
142     virtual ~Canvas();
143
144     Result reserve(uint32_t n) noexcept;
145     virtual Result push(std::unique_ptr<Paint> paint) noexcept;
146     virtual Result clear() noexcept;
147     virtual Result update(Paint* paint) noexcept;
148     virtual Result draw() noexcept;
149     virtual Result sync() noexcept;
150
151     _TVG_DECLARE_PRIVATE(Canvas);
152 };
153
154
155 /**
156  * @class LinearGradient
157  *
158  * @ingroup ThorVG
159  *
160  * @brief description...
161  *
162  */
163 class TVG_EXPORT LinearGradient final : public Fill
164 {
165 public:
166     ~LinearGradient();
167
168     Result linear(float x1, float y1, float x2, float y2) noexcept;
169     Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept;
170
171     static std::unique_ptr<LinearGradient> gen() noexcept;
172
173     _TVG_DECLARE_PRIVATE(LinearGradient);
174 };
175
176
177 /**
178  * @class RadialGradient
179  *
180  * @ingroup ThorVG
181  *
182  * @brief description...
183  *
184  */
185 class TVG_EXPORT RadialGradient final : public Fill
186 {
187 public:
188     ~RadialGradient();
189
190     Result radial(float cx, float cy, float radius) noexcept;
191     Result radial(float* cx, float* cy, float* radius) const noexcept;
192
193     static std::unique_ptr<RadialGradient> gen() noexcept;
194
195     _TVG_DECLARE_PRIVATE(RadialGradient);
196 };
197
198
199
200 /**
201  * @class Shape
202  *
203  * @ingroup ThorVG
204  *
205  * @brief description...
206  *
207  */
208 class TVG_EXPORT Shape final : public Paint
209 {
210 public:
211     ~Shape();
212
213     Result reset() noexcept;
214
215     //Path
216     Result moveTo(float x, float y) noexcept;
217     Result lineTo(float x, float y) noexcept;
218     Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
219     Result close() noexcept;
220
221     //Shape
222     Result appendRect(float x, float y, float w, float h, float rx, float ry) noexcept;
223     Result appendCircle(float cx, float cy, float rx, float ry) noexcept;
224     Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept;
225     Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept;
226
227     //Stroke
228     Result stroke(float width) noexcept;
229     Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
230     Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
231     Result stroke(StrokeCap cap) noexcept;
232     Result stroke(StrokeJoin join) noexcept;
233
234     //Fill
235     Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
236     Result fill(std::unique_ptr<Fill> f) noexcept;
237
238     //Getters
239     uint32_t pathCommands(const PathCommand** cmds) const noexcept;
240     uint32_t pathCoords(const Point** pts) const noexcept;
241     Result fill(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
242     const Fill* fill() const noexcept;
243
244     float strokeWidth() const noexcept;
245     Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
246     uint32_t strokeDash(const float** dashPattern) const noexcept;
247     StrokeCap strokeCap() const noexcept;
248     StrokeJoin strokeJoin() const noexcept;
249
250     static std::unique_ptr<Shape> gen() noexcept;
251
252     _TVG_DECLARE_PRIVATE(Shape);
253 };
254
255
256 /**
257  * @class Picture
258  *
259  * @ingroup ThorVG
260  *
261  * @brief description...
262  *
263  */
264 class TVG_EXPORT Picture final : public Paint
265 {
266 public:
267     ~Picture();
268
269     Result load(const std::string& path) noexcept;
270     Result load(const char* data, uint32_t size) noexcept;
271     Result viewbox(float* x, float* y, float* w, float* h) const noexcept;
272
273     static std::unique_ptr<Picture> gen() noexcept;
274
275     _TVG_DECLARE_PRIVATE(Picture);
276 };
277
278
279 /**
280  * @class Scene
281  *
282  * @ingroup ThorVG
283  *
284  * @brief description...
285  *
286  */
287 class TVG_EXPORT Scene final : public Paint
288 {
289 public:
290     ~Scene();
291
292     Result push(std::unique_ptr<Paint> paint) noexcept;
293     Result reserve(uint32_t size) noexcept;
294
295     static std::unique_ptr<Scene> gen() noexcept;
296
297     _TVG_DECLARE_PRIVATE(Scene);
298 };
299
300
301 /**
302  * @class SwCanvas
303  *
304  * @ingroup ThorVG
305  *
306   @brief description...
307  *
308  */
309 class TVG_EXPORT SwCanvas final : public Canvas
310 {
311 public:
312     ~SwCanvas();
313
314     enum Colorspace { ABGR8888 = 0, ARGB8888 };
315
316     Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept;
317
318     static std::unique_ptr<SwCanvas> gen() noexcept;
319
320     _TVG_DECLARE_PRIVATE(SwCanvas);
321 };
322
323
324 /**
325  * @class GlCanvas
326  *
327  * @ingroup ThorVG
328  *
329  * @brief description...
330  *
331  */
332 class TVG_EXPORT GlCanvas final : public Canvas
333 {
334 public:
335     ~GlCanvas();
336
337     //TODO: Gl Specific methods. Need gl backend configuration methods as well.
338     Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
339
340     static std::unique_ptr<GlCanvas> gen() noexcept;
341
342     _TVG_DECLARE_PRIVATE(GlCanvas);
343 };
344
345
346 /**
347  * @class Engine
348  *
349  * @ingroup ThorVG
350  *
351  * @brief description...
352  *
353  */
354 class TVG_EXPORT Initializer final
355 {
356 public:
357
358     /**
359      * @brief ...
360      *
361      * @param[in] arg ...
362      *
363      * @note ...
364      *
365      * @return ...
366      *
367      * @see ...
368      */
369     static Result init(CanvasEngine engine) noexcept;
370     static Result term(CanvasEngine engine) noexcept;
371     static Result threads(uint32_t cnt) noexcept;
372     static uint32_t threads() noexcept;
373
374     _TVG_DISABLE_CTOR(Initializer);
375 };
376
377 } //namespace
378
379 #ifdef __cplusplus
380 }
381 #endif
382
383 #endif //_THORVG_H_