common initializer: introduce thread count api.
[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 viewbox(float* x, float* y, float* w, float* h) const noexcept;
271
272     static std::unique_ptr<Picture> gen() noexcept;
273
274     _TVG_DECLARE_PRIVATE(Picture);
275 };
276
277
278 /**
279  * @class Scene
280  *
281  * @ingroup ThorVG
282  *
283  * @brief description...
284  *
285  */
286 class TVG_EXPORT Scene final : public Paint
287 {
288 public:
289     ~Scene();
290
291     Result push(std::unique_ptr<Paint> paint) noexcept;
292     Result reserve(uint32_t size) noexcept;
293
294     static std::unique_ptr<Scene> gen() noexcept;
295
296     _TVG_DECLARE_PRIVATE(Scene);
297 };
298
299
300 /**
301  * @class SwCanvas
302  *
303  * @ingroup ThorVG
304  *
305   @brief description...
306  *
307  */
308 class TVG_EXPORT SwCanvas final : public Canvas
309 {
310 public:
311     ~SwCanvas();
312
313     Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
314
315     static std::unique_ptr<SwCanvas> gen() noexcept;
316
317     _TVG_DECLARE_PRIVATE(SwCanvas);
318 };
319
320
321 /**
322  * @class GlCanvas
323  *
324  * @ingroup ThorVG
325  *
326  * @brief description...
327  *
328  */
329 class TVG_EXPORT GlCanvas final : public Canvas
330 {
331 public:
332     ~GlCanvas();
333
334     //TODO: Gl Specific methods. Need gl backend configuration methods as well.
335     Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
336
337     static std::unique_ptr<GlCanvas> gen() noexcept;
338
339     _TVG_DECLARE_PRIVATE(GlCanvas);
340 };
341
342
343 /**
344  * @class Engine
345  *
346  * @ingroup ThorVG
347  *
348  * @brief description...
349  *
350  */
351 class TVG_EXPORT Initializer final
352 {
353 public:
354
355     /**
356      * @brief ...
357      *
358      * @param[in] arg ...
359      *
360      * @note ...
361      *
362      * @return ...
363      *
364      * @see ...
365      */
366     static Result init(CanvasEngine engine) noexcept;
367     static Result term(CanvasEngine engine) noexcept;
368     static Result threads(uint32_t cnt) noexcept;
369     static uint32_t threads() noexcept;
370
371     _TVG_DISABLE_CTOR(Initializer);
372 };
373
374 } //namespace
375
376 #ifdef __cplusplus
377 }
378 #endif
379
380 #endif //_THORVG_H_