a411e634bcf400e81d2120be7f517842fb95e569
[platform/core/graphics/tizenvg.git] / inc / thorvg.h
1 /*!
2  * @file thorvg.h
3  *
4  * The main APIs enabling the TVG initialization, preparation of the canvas and provisioning of its content:
5  * - drawing shapes such as line, curve, arc, rectangle, circle or user-defined
6  * - drawing pictures - SVG, PNG, RAW
7  * - solid or gradient filling
8  * - continuous and dashed stroking
9  * - clipping and masking
10  * and finally drawing the canvas and TVG termination.
11  */
12
13
14 #ifndef _THORVG_H_
15 #define _THORVG_H_
16
17 #include <memory>
18 #include <string>
19
20 #ifdef TVG_BUILD
21     #define TVG_EXPORT __attribute__ ((visibility ("default")))
22 #else
23     #define TVG_EXPORT
24 #endif
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30
31 #define _TVG_DECLARE_PRIVATE(A) \
32 protected: \
33     struct Impl; \
34     Impl* pImpl; \
35     A(const A&) = delete; \
36     const A& operator=(const A&) = delete; \
37     A()
38
39 #define _TVG_DISABLE_CTOR(A) \
40     A() = delete; \
41     ~A() = delete
42
43 #define _TVG_DECLARE_ACCESSOR() \
44     friend Canvas; \
45     friend Scene; \
46     friend Picture
47
48 #define _TVG_DECALRE_IDENTIFIER() \
49     auto id() const { return _id; } \
50 protected: \
51     unsigned _id
52
53 namespace tvg
54 {
55
56 class RenderMethod;
57 class Scene;
58 class Picture;
59 class Canvas;
60
61 /**
62  * @defgroup ThorVG ThorVG
63  * @brief ThorVG classes and enumerations providing C++ APIs.
64  */
65
66 /**@{*/
67
68 /**
69  * @brief Enumeration specifying the result from the APIs.
70  */
71 enum class TVG_EXPORT Result
72 {
73     Success = 0,           ///< The value returned in case of a correct request execution.
74     InvalidArguments,      ///< The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers.
75     InsufficientCondition, ///< The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist.
76     FailedAllocation,      ///< The value returned in case of unsuccessful memory allocation.
77     MemoryCorruption,      ///< The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting
78     NonSupport,            ///< The value returned in case of choosing unsupported options.
79     Unknown                ///< The value returned in all other cases.
80 };
81
82 /**
83  * @brief Enumeration specifying the values of the path commands accepted by TVG.
84  *
85  * Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others).
86  * TVG interprets all of them and translates to the ones from the PathCommand values.
87  */
88 enum class TVG_EXPORT PathCommand
89 {
90     Close = 0, ///< Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.
91     MoveTo,    ///< Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.
92     LineTo,    ///< Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line.
93     CubicTo    ///< Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve.
94 };
95
96 /**
97  * @brief Enumeration determining the ending type of a stroke in the open sub-paths.
98  */
99 enum class TVG_EXPORT StrokeCap
100 {
101     Square = 0, ///< The stroke is extended in both end-points of a sub-path by a rectangle, with the width equal to the stroke width and the length equal to the half of the stroke width. For zero length sub-paths the square is rendered with the size of the stroke width.
102     Round,      ///< The stroke is extended in both end-points of a sub-path by a half circle, with a radius equal to the half of a stroke width. For zero length sub-paths a full circle is rendered.
103     Butt        ///< The stroke ends exactly at each of the two end-points of a sub-path. For zero length sub-paths no stroke is rendered.
104 };
105
106 /**
107  * @brief Enumeration determining the style used at the corners of joined stroked path segments.
108  */
109 enum class TVG_EXPORT StrokeJoin
110 {
111     Bevel = 0, ///< The outer corner of the joined path segments is bevelled at the join point. The triangular region of the corner is enclosed by a straight line between the outer corners of each stroke.
112     Round,     ///< The outer corner of the joined path segments is rounded. The circular region is centered at the join point.
113     Miter      ///< The outer corner of the joined path segments is spiked. The spike is created by extension beyond the join point of the outer edges of the stroke until they intersect. In case the extension goes beyond the limit, the join style is converted to the Bevel style.
114 };
115
116 /**
117  * @brief Enumeration specifying how to fill the area outside the gradient bounds.
118  */
119 enum class TVG_EXPORT FillSpread
120 {
121     Pad = 0, ///< The remaining area is filled with the closest stop color.
122     Reflect, ///< The gradient pattern is reflected outside the gradient area until the expected region is filled.
123     Repeat   ///< The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled.
124 };
125
126 /**
127  * @brief Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape.
128  */
129 enum class TVG_EXPORT FillRule
130 {
131     Winding = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape.
132     EvenOdd      ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape.
133 };
134
135 /**
136  * @brief Enumeration indicating the method used in the composition of two objects - the target and the source.
137  */
138 enum class TVG_EXPORT CompositeMethod
139 {
140     None = 0,     ///< No composition is applied.
141     ClipPath,     ///< The intersection of the source and the target is determined and only the resulting pixels from the source are rendered.
142     AlphaMask,    ///< The pixels of the source and the target are alpha blended. As a result, only the part of the source, which intersects with the target is visible.
143     InvAlphaMask  ///< The pixels of the source and the complement to the target's pixels are alpha blended. As a result, only the part of the source which is not covered by the target is visible.
144 };
145
146 /**
147  * @brief Enumeration specifying the engine type used for the graphics backend. For multiple backeneds bitwise operation is allowed.
148  */
149 enum class TVG_EXPORT CanvasEngine
150 {
151     Sw = (1 << 1), ///< CPU rasterizer.
152     Gl = (1 << 2)  ///< OpenGL rasterizer.
153 };
154
155
156 /**
157  * @brief A data structure representing a point in two-dimensional space.
158  */
159 struct Point
160 {
161     float x, y;
162 };
163
164
165 /**
166  * @brief A data structure representing a three-dimensional matrix.
167  *
168  * The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor.
169  * The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively.
170  * The elements e31 and e32 are set to 0, e33 is set to 1.
171  */
172 struct Matrix
173 {
174     float e11, e12, e13;
175     float e21, e22, e23;
176     float e31, e32, e33;
177 };
178
179
180 /**
181  * @class Paint
182  *
183  * @brief An abstract class for managing graphical elements.
184  *
185  * A graphical element in TVG is any object composed into a Canvas.
186  * Paint represents such a graphical object and its behaviors such as duplication, transformation and composition.
187  * TVG recommends the user to regard a paint as a set of volatile commands. They can prepare a Paint and then request a Canvas to run them.
188  */
189 class TVG_EXPORT Paint
190 {
191 public:
192     virtual ~Paint();
193
194     /**
195      * @brief Sets the angle by which the object is rotated.
196      *
197      * The angle in measured clockwise from the horizontal axis.
198      * The rotational axis passes through the point on the object with zero coordinates.
199      *
200      * @param[in] degree The value of the angle in degrees.
201      *
202      * @return Result::Success when succeed, Result::FailedAllocation otherwise.
203      */
204     Result rotate(float degree) noexcept;
205
206     /**
207      * @brief Sets the scale value of the object.
208      *
209      * @param[in] factor The value of the scaling factor. The default value is 1.
210      *
211      * @return Result::Success when succeed, Result::FailedAllocation otherwise.
212      */
213     Result scale(float factor) noexcept;
214
215     /**
216      * @brief Sets the values by which the object is moved in a two-dimensional space.
217      *
218      * The origin of the coordinate system is in the upper left corner of the canvas.
219      * The horizontal and vertical axes point to the right and down, respectively.
220      *
221      * @param[in] x The value of the horizontal shift.
222      * @param[in] y The value of the vertical shift.
223      *
224      * @return Result::Success when succeed, Result::FailedAllocation otherwise.
225      */
226     Result translate(float x, float y) noexcept;
227
228     /**
229      * @brief Sets the matrix of the affine transformation for the object.
230      *
231      * The augmented matrix of the transformation is expected to be given.
232      *
233      * @param[in] m The 3x3 augmented matrix.
234      *
235      * @return Result::Success when succeed, Result::FailedAllocation otherwise.
236      */
237     Result transform(const Matrix& m) noexcept;
238
239     /**
240      * @brief Gets the matrix of the affine transformation of the object.
241      *
242      * The values of the matrix can be set by the transform() API, as well by the translate(),
243      * scale() and rotate(). In case no transformation was applied, the identity matrix is returned.
244      *
245      * @retval The augmented transformation matrix.
246      *
247      * @BETA_API
248      */
249     Matrix transform() noexcept;
250
251     /**
252      * @brief Sets the opacity of the object.
253      *
254      * @param[in] o The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
255      *
256      * @return Result::Success when succeed.
257      *
258      * @note Setting the opacity with this API may require multiple render pass for composition. It is recommended to avoid changing the opacity if possible.
259      */
260     Result opacity(uint8_t o) noexcept;
261
262     /**
263      * @brief Sets the composition target object and the composition method.
264      *
265      * @param[in] target The paint of the target object.
266      * @param[in] method The method used to composite the source object with the target.
267      *
268      * @return Result::Success when succeed, Result::InvalidArguments otherwise.
269      */
270     Result composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept;
271
272     /**
273      * @brief Gets the bounding box of the paint object before any transformation.
274      *
275      * @param[out] x The x coordinate of the upper left corner of the object.
276      * @param[out] y The y coordinate of the upper left corner of the object.
277      * @param[out] w The width of the object.
278      * @param[out] h The height of the object.
279      *
280      * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
281      *
282      * @note The bounding box doesn't indicate the final rendered region. It's the smallest rectangle that encloses the object.
283      */
284     Result bounds(float* x, float* y, float* w, float* h) const noexcept;
285
286     /**
287      * @brief Duplicates the object.
288      *
289      * Creates a new object and sets its all properties as in the original object.
290      *
291      * @return The created object when succeed, @c nullptr otherwise.
292      */
293     Paint* duplicate() const noexcept;
294
295     /**
296      * @brief Gets the opacity value of the object.
297      *
298      * @return The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
299      */
300     uint8_t opacity() const noexcept;
301
302     /**
303      * @brief Const forward iterator-like class enabling the iteration over the children nodes of the given paint.
304      *
305      * For the Scene-type Paint the children nodes represent the paints pushed into the Scene - the order of the children nodes is the same as the order as they were pushed. For the Picture-type Paint the child node is the read image in one of the supported formats. The Shape-type Paint doesn't have any child nodes.
306      *
307      * @BETA_API
308      */
309     class Iterator
310     {
311         const Paint* parent;
312         const Paint* child;
313
314         public:
315             Iterator (Paint* p = nullptr, Paint* c = nullptr);
316             const Paint& operator*() const;
317             Iterator& operator++();
318             Iterator operator++(int);
319             friend bool operator!=(const Iterator& it1, const Iterator& it2)
320             {
321                 return it1.child != it2.child;
322             };
323             friend bool operator==(const Iterator& it1, const Iterator& it2)
324             {
325                 return it1.child == it2.child;
326             };
327     };
328
329     /**
330      * @brief Gets the iterator to the first child node.
331      *
332      * @return The iterator pointing to the first element of the children nodes of the given paint object.
333      *
334      * @BETA_API
335      */
336     Iterator begin() const noexcept;
337
338     /**
339      * @brief Gets the iterator to the past-the end child node.
340      *
341      * @return The iterator referring to the past-the-end element of the children nodes of the given paint object.
342      *
343      * @BETA_API
344      */
345     Iterator end() const noexcept;
346
347     /**
348      * @brief Gets the composition target object and the composition method.
349      *
350      * @param[out] target The paint of the target object.
351      *
352      * @return The method used to composite the source object with the target.
353      *
354      * @BETA_API
355      */
356     CompositeMethod composite(const Paint** target) const noexcept;
357
358     _TVG_DECLARE_ACCESSOR();
359     _TVG_DECALRE_IDENTIFIER();
360     _TVG_DECLARE_PRIVATE(Paint);
361 };
362
363
364 /**
365  * @class Fill
366  *
367  * @brief An abstract class representing the gradient fill of the Shape object.
368  *
369  * It contains the information about the gradient colors and their arrangement
370  * inside the gradient bounds. The gradients bounds are defined in the LinearGradient
371  * or RadialGradient class, depending on the type of the gradient to be used.
372  * It specifies the gradient behavior in case the area defined by the gradient bounds
373  * is smaller than the area to be filled.
374  */
375 class TVG_EXPORT Fill
376 {
377 public:
378     /**
379      * @brief A data structure storing the information about the color and its relative position inside the gradient bounds.
380      */
381     struct ColorStop
382     {
383         float offset; /**< The relative position of the color. */
384         uint8_t r;    /**< The red color channel value in the range [0 ~ 255]. */
385         uint8_t g;    /**< The green color channel value in the range [0 ~ 255]. */
386         uint8_t b;    /**< The blue color channel value in the range [0 ~ 255]. */
387         uint8_t a;    /**< The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. */
388     };
389
390     virtual ~Fill();
391
392     /**
393      * @brief Sets the parameters of the colors of the gradient and their position.
394      *
395      * @param[in] colorStops An array of ColorStop data structure.
396      * @param[in] cnt The count of the @p colorStops array equal to the colors number used in the gradient.
397      *
398      * @return Result::Success when succeed.
399      */
400     Result colorStops(const ColorStop* colorStops, uint32_t cnt) noexcept;
401
402     /**
403      * @brief Sets the FillSpread value, which specifies how to fill the area outside the gradient bounds.
404      *
405      * @param[in] s The FillSpread value.
406      *
407      * @return Result::Success when succeed.
408      */
409     Result spread(FillSpread s) noexcept;
410
411     /**
412      * @brief Gets the parameters of the colors of the gradient, their position and number.
413      *
414      * @param[in] colorStops A pointer to the memory location, where the array of the gradient's ColorStop is stored.
415      *
416      * @return The number of colors used in the gradient. This value corresponds to the length of the @p colorStops array.
417      */
418     uint32_t colorStops(const ColorStop** colorStops) const noexcept;
419
420     /**
421      * @brief Gets the FillSpread value of the fill.
422      *
423      * @return The FillSpread value of this Fill.
424      */
425     FillSpread spread() const noexcept;
426
427     /**
428      * @brief Creates a copy of the Fill object.
429      *
430      * Return a newly created Fill object with the properties copied from the original.
431      *
432      * @return A copied Fill object when succeed, @c nullptr otherwise.
433      */
434     Fill* duplicate() const noexcept;
435
436     _TVG_DECALRE_IDENTIFIER();
437     _TVG_DECLARE_PRIVATE(Fill);
438 };
439
440
441 /**
442  * @class Canvas
443  *
444  * @brief An abstract class for drawing graphical elements.
445  *
446  * A canvas is an entity responsible for drawing the target. It sets up the drawing engine and the buffer, which can be drawn on the screen. It also manages given Paint objects.
447  *
448  * @note A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical.
449  * @warning The Paint objects belonging to one Canvas can't be shared among multiple Canvases.
450  */
451 class TVG_EXPORT Canvas
452 {
453 public:
454     Canvas(RenderMethod*);
455     virtual ~Canvas();
456
457     /**
458      * @brief Sets the size of the container, where all the paints pushed into the Canvas are stored.
459      *
460      * If the number of objects pushed into the Canvas is known in advance, calling the function
461      * prevents multiple memory reallocation, thus improving the performance.
462      *
463      * @param[in] n The number of objects for which the memory is to be reserved.
464      *
465      * @return Result::Success when succeed.
466      */
467     Result reserve(uint32_t n) noexcept;
468
469     /**
470      * @brief Passes drawing elements to the Canvas using Paint objects.
471      *
472      * Only pushed paints in the canvas will be drawing targets.
473      * They are retained by the canvas until you call Canvas::clear().
474      * If you know the number of the pushed objects in the advance, please call Canvas::reserve().
475      *
476      * @param[in] paint A Paint object to be drawn.
477      *
478      * @retval Result::Success When succeed.
479      * @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument.
480      * @retval Result::InsufficientCondition An internal error.
481      *
482      * @note The rendering order of the paints is the same as the order as they were pushed into the canvas. Consider sorting the paints before pushing them if you intend to use layering.
483      * @see Canvas::reserve()
484      * @see Canvas::clear()
485      */
486     virtual Result push(std::unique_ptr<Paint> paint) noexcept;
487
488     /**
489      * @brief Sets the total number of the paints pushed into the canvas to be zero.
490      * Depending on the value of the @p free argument, the paints are freed or not.
491      *
492      * @param[in] free If @c true, the memory occupied by paints is deallocated, otherwise it is not.
493      *
494      * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
495      *
496      * @warning If you don't free the paints they become dangled. They are supposed to be reused, otherwise you are responsible for their lives. Thus please use the @p free argument only when you know how it works, otherwise it's not recommended.
497      */
498     virtual Result clear(bool free = true) noexcept;
499
500     /**
501      * @brief Request the canvas to update the paint objects.
502      *
503      * If a @c nullptr is passed all paint objects retained by the Canvas are updated,
504      * otherwise only the paint to which the given @p paint points.
505      *
506      * @param[in] paint A pointer to the Paint object or @c nullptr.
507      *
508      * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
509      *
510      * @note The Update behavior can be asynchronous if the assigned thread number is greater than zero.
511      */
512     virtual Result update(Paint* paint) noexcept;
513
514     /**
515      * @brief Request the canvas to draw the Paint objects.
516      *
517      * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
518      *
519      * @note Drawing can be asynchronous if the assigned thread number is greater than zero. To guarantee the drawing is done, call sync() afterwards.
520      * @see Canvas::sync()
521      */
522     virtual Result draw() noexcept;
523
524     /**
525      * @brief Guarantees that drawing task is finished.
526      *
527      * The Canvas rendering can be performed asynchronously. To make sure that rendering is finished,
528      * the sync() must be called after the draw() regardless of threading.
529      *
530      * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
531      * @see Canvas::draw()
532      */
533     virtual Result sync() noexcept;
534
535     _TVG_DECLARE_PRIVATE(Canvas);
536 };
537
538
539 /**
540  * @class LinearGradient
541  *
542  * @brief A class representing the linear gradient fill of the Shape object.
543  *
544  * Besides the APIs inherited from the Fill class, it enables setting and getting the linear gradient bounds.
545  * The behavior outside the gradient bounds depends on the value specified in the spread API.
546  */
547 class TVG_EXPORT LinearGradient final : public Fill
548 {
549 public:
550     ~LinearGradient();
551
552     /**
553      * @brief Sets the linear gradient bounds.
554      *
555      * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing
556      * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking
557      * (@p x1, @p y1) and (@p x2, @p y2).
558      *
559      * @param[in] x1 The horizontal coordinate of the first point used to determine the gradient bounds.
560      * @param[in] y1 The vertical coordinate of the first point used to determine the gradient bounds.
561      * @param[in] x2 The horizontal coordinate of the second point used to determine the gradient bounds.
562      * @param[in] y2 The vertical coordinate of the second point used to determine the gradient bounds.
563      *
564      * @return Result::Success when succeed, Result::InvalidArguments otherwise.
565      */
566     Result linear(float x1, float y1, float x2, float y2) noexcept;
567
568     /**
569      * @brief Gets the linear gradient bounds.
570      *
571      * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing
572      * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking
573      * (@p x1, @p y1) and (@p x2, @p y2).
574      *
575      * @param[out] x1 The horizontal coordinate of the first point used to determine the gradient bounds.
576      * @param[out] y1 The vertical coordinate of the first point used to determine the gradient bounds.
577      * @param[out] x2 The horizontal coordinate of the second point used to determine the gradient bounds.
578      * @param[out] y2 The vertical coordinate of the second point used to determine the gradient bounds.
579      *
580      * @return Result::Success when succeed.
581      */
582     Result linear(float* x1, float* y1, float* x2, float* y2) const noexcept;
583
584     /**
585      * @brief Creates a new LinearGradient object.
586      *
587      * @return A new LinearGradient object.
588      */
589     static std::unique_ptr<LinearGradient> gen() noexcept;
590
591     _TVG_DECLARE_PRIVATE(LinearGradient);
592 };
593
594
595 /**
596  * @class RadialGradient
597  *
598  * @brief A class representing the radial gradient fill of the Shape object.
599  *
600  */
601 class TVG_EXPORT RadialGradient final : public Fill
602 {
603 public:
604     ~RadialGradient();
605
606     /**
607      * @brief Sets the radial gradient bounds.
608      *
609      * The radial gradient bounds are defined as a circle centered in a given point (@p cx, @p cy) of a given radius.
610      *
611      * @param[in] cx The horizontal coordinate of the center of the bounding circle.
612      * @param[in] cy The vertical coordinate of the center of the bounding circle.
613      * @param[in] radius The radius of the bounding circle.
614      *
615      * @return Result::Success when succeed, Result::InvalidArguments otherwise.
616      */
617     Result radial(float cx, float cy, float radius) noexcept;
618
619     /**
620      * @brief Gets the radial gradient bounds.
621      *
622      * The radial gradient bounds are defined as a circle centered in a given point (@p cx, @p cy) of a given radius.
623      *
624      * @param[out] cx The horizontal coordinate of the center of the bounding circle.
625      * @param[out] cy The vertical coordinate of the center of the bounding circle.
626      * @param[out] radius The radius of the bounding circle.
627      *
628      * @return Result::Success when succeed.
629      */
630     Result radial(float* cx, float* cy, float* radius) const noexcept;
631
632     /**
633      * @brief Creates a new RadialGradient object.
634      *
635      * @return A new RadialGradient object.
636      */
637     static std::unique_ptr<RadialGradient> gen() noexcept;
638
639     _TVG_DECLARE_PRIVATE(RadialGradient);
640 };
641
642
643 /**
644  * @class Shape
645  *
646  * @brief A class representing two-dimensional figures and their properties.
647  *
648  * A shape has three major properties: shape outline, stroking, filling. The outline in the Shape is retained as the path.
649  * Path can be composed by accumulating primitive commands such as moveTo(), lineTo(), cubicTo(), or complete shape interfaces such as appendRect(), appendCircle(), etc.
650  * Path can consists of sub-paths. One sub-path is determined by a close command.
651  *
652  * The stroke of Shape is an optional property in case the Shape needs to be represented with/without the outline borders.
653  * It's efficient since the shape path and the stroking path can be shared with each other. It's also convenient when controlling both in one context.
654  */
655 class TVG_EXPORT Shape final : public Paint
656 {
657 public:
658     ~Shape();
659
660     /**
661      * @brief Resets the properties of the shape path.
662      *
663      * The color, the fill and the stroke properties are retained.
664      *
665      * @return Result::Success when succeed.
666      *
667      * @note The memory, where the path data is stored, is not deallocated at this stage for caching effect.
668      */
669     Result reset() noexcept;
670
671     /**
672      * @brief Sets the initial point of the sub-path.
673      *
674      * The value of the current point is set to the given point.
675      *
676      * @param[in] x The horizontal coordinate of the initial point of the sub-path.
677      * @param[in] y The vertical coordinate of the initial point of the sub-path.
678      *
679      * @return Result::Success when succeed.
680      */
681     Result moveTo(float x, float y) noexcept;
682
683     /**
684      * @brief Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point.
685      *
686      * The value of the current point is set to the given end-point.
687      *
688      * @param[in] x The horizontal coordinate of the end-point of the line.
689      * @param[in] y The vertical coordinate of the end-point of the line.
690      *
691      * @return Result::Success when succeed.
692      *
693      * @note In case this is the first command in the path, it corresponds to the moveTo() call.
694      */
695     Result lineTo(float x, float y) noexcept;
696
697     /**
698      * @brief Adds new points to the sub-path, which results in drawing a cubic Bezier curve starting
699      * at the current point and ending at the given end-point (@p x, @p y) using the control points (@p cx1, @p cy1) and (@p cx2, @p cy2).
700      *
701      * The value of the current point is set to the given end-point.
702      *
703      * @param[in] cx1 The horizontal coordinate of the 1st control point.
704      * @param[in] cy1 The vertical coordinate of the 1st control point.
705      * @param[in] cx2 The horizontal coordinate of the 2nd control point.
706      * @param[in] cy2 The vertical coordinate of the 2nd control point.
707      * @param[in] x The horizontal coordinate of the end-point of the curve.
708      * @param[in] y The vertical coordinate of the end-point of the curve.
709      *
710      * @return Result::Success when succeed.
711      *
712      * @note In case this is the first command in the path, no data from the path are rendered.
713      */
714     Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept;
715
716     /**
717      * @brief Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path.
718      *
719      * The value of the current point is set to the initial point of the closed sub-path.
720      *
721      * @return Result::Success when succeed.
722      *
723      * @note In case the sub-path does not contain any points, this function has no effect.
724      */
725     Result close() noexcept;
726
727     /**
728      * @brief Appends a rectangle to the path.
729      *
730      * The rectangle with rounded corners can be achieved by setting non-zero values to @p rx and @p ry arguments.
731      * The @p rx and @p ry values specify the radii of the ellipse defining the rounding of the corners.
732      *
733      * The position of the rectangle is specified by the coordinates of its upper left corner - @p x and @p y arguments.
734      *
735      * The rectangle is treated as a new sub-path - it is not connected with the previous sub-path.
736      *
737      * The value of the current point is set to (@p x + @p rx, @p y) - in case @p rx is greater
738      * than @p w/2 the current point is set to (@p x + @p w/2, @p y)
739      *
740      * @param[in] x The horizontal coordinate of the upper left corner of the rectangle.
741      * @param[in] y The vertical coordinate of the upper left corner of the rectangle.
742      * @param[in] w The width of the rectangle.
743      * @param[in] h The height of the rectangle.
744      * @param[in] rx The x-axis radius of the ellipse defining the rounded corners of the rectangle.
745      * @param[in] ry The y-axis radius of the ellipse defining the rounded corners of the rectangle.
746      *
747      * @return Result::Success when succeed.
748      *
749      * @note For @p rx and @p ry greater than or equal to the half of @p w and the half of @p h, respectively, the shape become an ellipse.
750      */
751     Result appendRect(float x, float y, float w, float h, float rx, float ry) noexcept;
752
753     /**
754      * @brief Appends an ellipse to the path.
755      *
756      * The position of the ellipse is specified by the coordinates of its center - @p cx and @p cy arguments.
757      *
758      * The ellipse is treated as a new sub-path - it is not connected with the previous sub-path.
759      *
760      * The value of the current point is set to (@p cx, @p cy - @p ry).
761      *
762      * @param[in] cx The horizontal coordinate of the center of the ellipse.
763      * @param[in] cy The vertical coordinate of the center of the ellipse.
764      * @param[in] rx The x-axis radius of the ellipse.
765      * @param[in] ry The y-axis radius of the ellipse.
766      *
767      * @return Result::Success when succeed.
768      */
769     Result appendCircle(float cx, float cy, float rx, float ry) noexcept;
770
771     /**
772      * @brief Appends a circular arc to the path.
773      *
774      * The arc is treated as a new sub-path - it is not connected with the previous sub-path.
775      * The current point value is set to the end-point of the arc in case @p pie is @c false, and to the center of the arc otherwise.
776      *
777      * @param[in] cx The horizontal coordinate of the center of the arc.
778      * @param[in] cy The vertical coordinate of the center of the arc.
779      * @param[in] radius The radius of the arc.
780      * @param[in] startAngle The start angle of the arc given in degrees, measured counter-clockwise from the horizontal line.
781      * @param[in] sweep The central angle of the arc given in degrees, measured counter-clockwise from @p startAngle.
782      * @param[in] pie Specifies whether to draw radii from the arc's center to both of its end-point - drawn if @c true.
783      *
784      * @return Result::Success when succeed.
785      *
786      * @note Setting @p sweep value greater than 360 degrees, is equivalent to calling appendCircle(cx, cy, radius, radius).
787      */
788     Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept;
789
790     /**
791      * @brief Appends a given sub-path to the path.
792      *
793      * The current point value is set to the last point from the sub-path.
794      * For each command from the @p cmds array, an appropriate number of points in @p pts array should be specified.
795      *
796      * @param[in] cmds The array of the commands in the sub-path.
797      * @param[in] cmdCnt The number of the sub-path's commands.
798      * @param[in] pts The array of the two-dimensional points.
799      * @param[in] ptsCnt The number of the points in the @p pts array.
800      *
801      * @return Result::Success when succeed, Result::InvalidArguments otherwise.
802      *
803      * @note The interface is designed for optimal path setting if the caller has a completed path commands already.
804      */
805     Result appendPath(const PathCommand* cmds, uint32_t cmdCnt, const Point* pts, uint32_t ptsCnt) noexcept;
806
807     /**
808      * @brief Sets the stroke width for all of the figures from the path.
809      *
810      * @param[in] width The width of the stroke. The default value is 0.
811      *
812      * @return Result::Success when succeed, Result::FailedAllocation otherwise.
813      */
814     Result stroke(float width) noexcept;
815
816     /**
817      * @brief Sets the color of the stroke for all of the figures from the path.
818      *
819      * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0.
820      * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0.
821      * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0.
822      * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
823      *
824      * @return Result::Success when succeed, Result::FailedAllocation otherwise.
825      */
826     Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
827
828     /**
829      * @brief Sets the gradient fill of the stroke for all of the figures from the path.
830      *
831      * @param[in] f The gradient fill.
832      *
833      * @retval Result::Success When succeed.
834      * @retval Result::FailedAllocation An internal error with a memory allocation for an object to be filled.
835      * @retval Result::MemoryCorruption In case a @c nullptr is passed as the argument.
836      */
837     Result stroke(std::unique_ptr<Fill> f) noexcept;
838
839     /**
840      * @brief Sets the dash pattern of the stroke.
841      *
842      * @param[in] dashPattern The array of consecutive pair values of the dash length and the gap length.
843      * @param[in] cnt The length of the @p dashPattern array.
844      *
845      * @retval Result::Success When succeed.
846      * @retval Result::FailedAllocation An internal error with a memory allocation for an object to be dashed.
847      * @retval Result::InvalidArguments In case that either @p dashPattern is @c nullptr or @p cnt is zero.
848      *
849      * @note If any of the dash pattern values is zero, this function has no effect.
850      * @note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt.
851      * @warning @p cnt must be greater than 1 if the dash pattern is valid.
852      */
853     Result stroke(const float* dashPattern, uint32_t cnt) noexcept;
854
855     /**
856      * @brief Sets the cap style of the stroke in the open sub-paths.
857      *
858      * @param[in] cap The cap style value. The default value is @c StrokeCap::Square.
859      *
860      * @return Result::Success when succeed, Result::FailedAllocation otherwise.
861      */
862     Result stroke(StrokeCap cap) noexcept;
863
864     /**
865      * @brief Sets the join style for stroked path segments.
866      *
867      * The join style is used for joining the two line segment while stroking the path.
868      *
869      * @param[in] join The join style value. The default value is @c StrokeJoin::Bevel.
870      *
871      * @return Result::Success when succeed, Result::FailedAllocation otherwise.
872      */
873     Result stroke(StrokeJoin join) noexcept;
874
875     /**
876      * @brief Sets the solid color for all of the figures from the path.
877      *
878      * The parts of the shape defined as inner are colored.
879      *
880      * @param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0.
881      * @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0.
882      * @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0.
883      * @param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
884      *
885      * @return Result::Success when succeed.
886      *
887      * @note Either a solid color or a gradient fill is applied, depending on what was set as last.
888      */
889     Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a) noexcept;
890
891     /**
892      * @brief Sets the gradient fill for all of the figures from the path.
893      *
894      * The parts of the shape defined as inner are filled.
895      *
896      * @param[in] f The unique pointer to the gradient fill.
897      *
898      * @return Result::Success when succeed, Result::MemoryCorruption otherwise.
899      *
900      * @note Either a solid color or a gradient fill is applied, depending on what was set as last.
901      */
902     Result fill(std::unique_ptr<Fill> f) noexcept;
903
904     /**
905      * @brief Sets the fill rule for the Shape object.
906      *
907      * @param[in] r The fill rule value.
908      *
909      * @return Result::Success when succeed.
910      */
911     Result fill(FillRule r) noexcept;
912
913     /**
914      * @brief Gets the commands data of the path.
915      *
916      * @param[out] cmds The pointer to the array of the commands from the path.
917      *
918      * @return The length of the @p cmds array when succeed, zero otherwise.
919      */
920     uint32_t pathCommands(const PathCommand** cmds) const noexcept;
921
922     /**
923      * @brief Gets the points values of the path.
924      *
925      * @param[out] pts The pointer to the array of the two-dimensional points from the path.
926      *
927      * @return The length of the @p pts array when succeed, zero otherwise.
928      */
929     uint32_t pathCoords(const Point** pts) const noexcept;
930
931     /**
932      * @brief Gets the pointer to the gradient fill of the shape.
933      *
934      * @return The pointer to the gradient fill of the stroke when succeed, @c nullptr in case no fill was set.
935      */
936     const Fill* fill() const noexcept;
937
938     /**
939      * @brief Gets the solid color of the shape.
940      *
941      * @param[out] r The red color channel value in the range [0 ~ 255].
942      * @param[out] g The green color channel value in the range [0 ~ 255].
943      * @param[out] b The blue color channel value in the range [0 ~ 255].
944      * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
945      *
946      * @return Result::Success when succeed.
947      */
948     Result fillColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
949
950     /**
951      * @brief Gets the fill rule value.
952      *
953      * @return The fill rule value of the shape.
954      */
955     FillRule fillRule() const noexcept;
956
957     /**
958      * @brief Gets the stroke width.
959      *
960      * @return The stroke width value when succeed, zero if no stroke was set.
961      */
962     float strokeWidth() const noexcept;
963
964     /**
965      * @brief Gets the color of the shape's stroke.
966      *
967      * @param[out] r The red color channel value in the range [0 ~ 255].
968      * @param[out] g The green color channel value in the range [0 ~ 255].
969      * @param[out] b The blue color channel value in the range [0 ~ 255].
970      * @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
971      *
972      * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
973      */
974     Result strokeColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) const noexcept;
975
976     /**
977      * @brief Gets the pointer to the gradient fill of the stroke.
978      *
979      * @return The pointer to the gradient fill of the stroke when succeed, @c nullptr otherwise.
980      */
981     const Fill* strokeFill() const noexcept;
982
983     /**
984      * @brief Gets the dash pattern of the stroke.
985      *
986      * @param[out] dashPattern The pointer to the memory, where the dash pattern array is stored.
987      *
988      * @return The length of the @p dashPattern array.
989      */
990     uint32_t strokeDash(const float** dashPattern) const noexcept;
991
992     /**
993      * @brief Gets the cap style used for stroking the path.
994      *
995      * @return The cap style value of the stroke.
996      */
997     StrokeCap strokeCap() const noexcept;
998
999     /**
1000      * @brief Gets the join style value used for stroking the path.
1001      *
1002      * @return The join style value of the stroke.
1003      */
1004     StrokeJoin strokeJoin() const noexcept;
1005
1006     /**
1007      * @brief Creates a new Shape object.
1008      *
1009      * @return A new Shape object.
1010      */
1011     static std::unique_ptr<Shape> gen() noexcept;
1012
1013     _TVG_DECLARE_PRIVATE(Shape);
1014 };
1015
1016
1017 /**
1018  * @class Picture
1019  *
1020  * @brief A class representing an image read in one of the supported formats: raw, svg, png and etc.
1021  * Besides the methods inherited from the Paint, it provides methods to load & draw images on the canvas.
1022  *
1023  * @note Supported formats are depended on the available TVG loaders.
1024  */
1025 class TVG_EXPORT Picture final : public Paint
1026 {
1027 public:
1028     ~Picture();
1029
1030     /**
1031      * @brief Loads a picture data directly from a file.
1032      *
1033      * @param[in] path A path to the picture file.
1034      *
1035      * @retval Result::Success When succeed.
1036      * @retval Result::InvalidArguments In case the @p path is invalid.
1037      * @retval Result::NonSupport When trying to load a file with an unknown extension.
1038      * @retval Result::Unknown If an error occurs at a later stage.
1039      *
1040      * @note The Load behavior can be asynchronous if the assigned thread number is greater than zero.
1041      * @see Initializer::init()
1042      */
1043     Result load(const std::string& path) noexcept;
1044
1045     /**
1046      * @brief Loads a picture data from a memory block of a given size.
1047      *
1048      * @param[in] data A pointer to a memory location where the content of the picture file is stored.
1049      * @param[in] size The size in bytes of the memory occupied by the @p data.
1050      * @param[in] copy Decides whether the data should be copied into the engine local buffer.
1051      *
1052      * @retval Result::Success When succeed.
1053      * @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less.
1054      * @retval Result::NonSupport When trying to load a file with an unknown extension.
1055      * @retval Result::Unknown If an error occurs at a later stage.
1056      *
1057      * @note: This api supports only SVG format
1058      *
1059      * @warning: you have responsibility to release the @p data memory if the @p copy is true
1060      */
1061     Result load(const char* data, uint32_t size, bool copy) noexcept;
1062     Result load(const char* data, uint32_t size) noexcept;
1063
1064     /**
1065      * @brief Resize the picture content with the given width and height.
1066      *
1067      * Resize the picture content while keeping the default size aspect ratio.
1068      * The scaling factor is established for each of dimensions and the smaller value is applied to both of them.
1069      *
1070      * @param[in] w A new width of the image in pixels.
1071      * @param[in] h A new height of the image in pixels.
1072      *
1073      * @return Result::Success when succeed, Result::InsufficientCondition otherwise.
1074      */
1075     Result size(float w, float h) noexcept;
1076
1077     /**
1078      * @brief Gets the size of the image.
1079      *
1080      * @param[out] w The width of the image in pixels.
1081      * @param[out] h The height of the image in pixels.
1082      *
1083      * @return Result::Success when succeed.
1084      */
1085     Result size(float* w, float* h) const noexcept;
1086
1087     /**
1088      * @brief Gets the pixels information of the picture.
1089      *
1090      * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1091      *
1092      * @BETA_API
1093      */
1094     const uint32_t* data() const noexcept;
1095
1096     /**
1097      * @brief Set paint for the picture.
1098      *
1099      * @param[in] paint A Paint object to be drawn.
1100      *
1101      * @return Result::Success when succeed.
1102      * @return Result::InsufficientCondition if paint already set.
1103      * @return Result::MemoryCorruption when bad memory handling.
1104      *
1105      * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1106      *
1107      * @BETA_API
1108      */
1109     Result paint(std::unique_ptr<Paint> paint) noexcept;
1110
1111     /**
1112      * @brief Loads a raw data from a memory block with a given size.
1113      *
1114      * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1115      *
1116      * @BETA_API
1117      */
1118     Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy) noexcept;
1119
1120     /**
1121      * @brief Gets the position and the size of the loaded picture.
1122      *
1123      * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1124      *
1125      * @BETA_API
1126      */
1127     Result viewbox(float* x, float* y, float* w, float* h) const noexcept;
1128
1129     /**
1130      * @brief Creates a new Picture object.
1131      *
1132      * @return A new Picture object.
1133      */
1134     static std::unique_ptr<Picture> gen() noexcept;
1135
1136     _TVG_DECLARE_PRIVATE(Picture);
1137 };
1138
1139
1140 /**
1141  * @class Scene
1142  *
1143  * @brief A class to composite children paints.
1144  *
1145  * As the traditional graphics rendering method, TVG also enables scene-graph mechanism.
1146  * This feature supports an array function for managing the multiple paints as one group paint.
1147  *
1148  * As a group, the scene can be transformed, made translucent and composited with other target paints,
1149  * its children will be affected by the scene world.
1150  */
1151 class TVG_EXPORT Scene final : public Paint
1152 {
1153 public:
1154     ~Scene();
1155
1156     /**
1157      * @brief Passes drawing elements to the Scene using Paint objects.
1158      *
1159      * Only pushed paints in the scene will be drawing targets.
1160      * They are retained by the scene until you call Scene::clear().
1161      * If you know the number of the pushed objects in the advance, please call Scene::reserve().
1162      *
1163      * @param[in] paint A Paint object to be drawn.
1164      *
1165      * @return Result::Success when succeed, Result::MemoryCorruption otherwise.
1166      *
1167      * @note The rendering order of the paints is the same as the order as they were pushed. Consider sorting the paints before pushing them if you intend to use layering.
1168      * @see Scene::reserve()
1169      */
1170     Result push(std::unique_ptr<Paint> paint) noexcept;
1171
1172     /**
1173      * @brief Sets the size of the container, where all the paints pushed into the Scene are stored.
1174      *
1175      * If the number of objects pushed into the scene is known in advance, calling the function
1176      * prevents multiple memory reallocation, thus improving the performance.
1177      *
1178      * @param[in] size The number of objects for which the memory is to be reserved.
1179      *
1180      * @return Result::Success when succeed.
1181      */
1182     Result reserve(uint32_t size) noexcept;
1183
1184     /**
1185      * @brief Sets the total number of the paints pushed into the scene to be zero.
1186      * Depending on the value of the @p free argument, the paints are freed or not.
1187      *
1188      * @param[in] free If @c true, the memory occupied by paints is deallocated, otherwise it is not.
1189      *
1190      * @return Result::Success when succeed
1191      *
1192      * @warning If you don't free the paints they become dangled. They are supposed to be reused, otherwise you are responsible for their lives. Thus please use the @p free argument only when you know how it works, otherwise it's not recommended.
1193      * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1194      *
1195      * @since 0.2
1196      */
1197     Result clear(bool free = true) noexcept;
1198
1199     /**
1200      * @brief Creates a new Scene object.
1201      *
1202      * @return A new Scene object.
1203      */
1204     static std::unique_ptr<Scene> gen() noexcept;
1205
1206     _TVG_DECLARE_PRIVATE(Scene);
1207 };
1208
1209
1210 /**
1211  * @class SwCanvas
1212  *
1213  * @brief A class for the rendering graphical elements with a software raster engine.
1214  */
1215 class TVG_EXPORT SwCanvas final : public Canvas
1216 {
1217 public:
1218     ~SwCanvas();
1219
1220     /**
1221      * @brief Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color.
1222      */
1223     enum Colorspace
1224     {
1225         ABGR8888 = 0, ///< The channels are joined in the order: alpha, blue, green, red.
1226         ARGB8888      ///< The channels are joined in the order: alpha, red, green, blue.
1227     };
1228
1229     /**
1230      * @brief Enumeration specifying the methods of Memory Pool behavior policy.
1231      *
1232      * @BETA_API
1233      */
1234     enum MempoolPolicy
1235     {
1236         Default = 0, ///< Default behavior that ThorVG is designed to.
1237         Shareable,   ///< Memory Pool is shared among the SwCanvases.
1238         Individual   ///< Allocate designated memory pool that is only used by current instance.
1239     };
1240
1241     /**
1242      * @brief Sets the target buffer for the rasterization.
1243      *
1244      * The buffer of a desirable size should be allocated and owned by the caller.
1245      *
1246      * @param[in] buffer A pointer to a memory block of the size @p stride x @p h, where the raster data are stored.
1247      * @param[in] stride The stride of the raster image - greater than or equal to @p w.
1248      * @param[in] w The width of the raster image.
1249      * @param[in] h The height of the raster image.
1250      * @param[in] cs The value specifying the way the 32-bits colors should be read/written.
1251      *
1252      * @retval Result::Success When succeed.
1253      * @retval Result::MemoryCorruption When casting in the internal function implementation failed.
1254      * @retval Result::InvalidArguments In case no valid pointer is provided or the width, or the height or the stride is zero.
1255      * @retval Result::NonSupport In case the software engine is not supported.
1256      *
1257      * @warning Do not access @p buffer during Canvas::draw() - Canvas::sync(). It should not be accessed while TVG is writing on it.
1258     */
1259     Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept;
1260
1261     /**
1262      * @brief Set sw engine memory pool behavior policy.
1263      *
1264      * Basically ThorVG draws a lot of shapes, it allocates/deallocates a few chunk of memory
1265      * while processing rendering. It internally uses one shared memory pool
1266      * which can be reused among the canvases in order to avoid memory overhead.
1267      *
1268      * Thus ThorVG suggests memory pool policy to satisfy user demands,
1269      * if it needs to guarantee the thread-safety of the internal data access.
1270      *
1271      * @param[in] policy Use the shared cache memory. The default value is @c true
1272      *
1273      * @retval Result::Success When succeed.
1274      * @retval Result::InsufficientCondition If the canvas has any paints.
1275      * @retval Result::NonSupport In case the software engine is not supported.
1276      *
1277      * @note When @c policy is set as @c MempoolPolicy::Individual, current instance of canvas uses its own individual
1278      *       memory data that is not shared with others. This is necessary when the canvas is accessed on a worker-thread.
1279      *
1280      * @warning It's not allowed after pushing any paints.
1281      *
1282      * @BETA_API
1283     */
1284     Result mempool(MempoolPolicy policy) noexcept;
1285
1286     /**
1287      * @brief Creates a new SwCanvas object.
1288      * @return A new SwCanvas object.
1289      */
1290     static std::unique_ptr<SwCanvas> gen() noexcept;
1291
1292     _TVG_DECLARE_PRIVATE(SwCanvas);
1293 };
1294
1295
1296 /**
1297  * @class GlCanvas
1298  *
1299  * @brief A class for the rendering graphic elements with a GL raster engine.
1300  *
1301  * @warning Please do not use it. This class is not fully supported yet.
1302  *
1303  * @BETA_API
1304  */
1305 class TVG_EXPORT GlCanvas final : public Canvas
1306 {
1307 public:
1308     ~GlCanvas();
1309
1310     /**
1311      * @brief Sets the target buffer for the rasterization.
1312      *
1313      * @warning Please do not use it, this API is not official one. It could be modified in the next version.
1314      *
1315      * @BETA_API
1316      */
1317     Result target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h) noexcept;
1318
1319     /**
1320      * @brief Creates a new GlCanvas object.
1321      *
1322      * @return A new GlCanvas object.
1323      *
1324      * @BETA_API
1325      */
1326     static std::unique_ptr<GlCanvas> gen() noexcept;
1327
1328     _TVG_DECLARE_PRIVATE(GlCanvas);
1329 };
1330
1331
1332 /**
1333  * @class Initializer
1334  *
1335  * @brief A class that enables initialization and termination of the TVG engines.
1336  */
1337 class TVG_EXPORT Initializer final
1338 {
1339 public:
1340     /**
1341      * @brief Initializes TVG engines.
1342      *
1343      * TVG requires the running-engine environment.
1344      * TVG runs its own task-scheduler for parallelizing rendering tasks efficiently.
1345      * You can indicate the number of threads, the count of which is designated @p threads.
1346      * In the initialization step, TVG will generate/spawn the threads as set by @p threads count.
1347      *
1348      * @param[in] engine The engine types to initialize. This is relative to the Canvas types, in which it will be used. For multiple backeneds bitwise operation is allowed.
1349      * @param[in] threads The number of additional threads. Zero indicates only the main thread is to be used.
1350      *
1351      * @retval Result::Success When succeed.
1352      * @retval Result::FailedAllocation An internal error possibly with memory allocation.
1353      * @retval Result::InvalidArguments If unknown engine type chosen.
1354      * @retval Result::NonSupport In case the engine type is not supported on the system.
1355      * @retval Result::Unknown Others.
1356      *
1357      * @note The Initializer keeps track of the number of times it was called. Threads count is fixed at the first init() call.
1358      * @see Initializer::term()
1359      */
1360     static Result init(CanvasEngine engine, uint32_t threads) noexcept;
1361
1362     /**
1363      * @brief Terminates TVG engines.
1364      *
1365      * @param[in] engine The engine types to terminate. This is relative to the Canvas types, in which it will be used. For multiple backeneds bitwise operation is allowed
1366      *
1367      * @retval Result::Success When succeed.
1368      * @retval Result::InsufficientCondition In case there is nothing to be terminated.
1369      * @retval Result::InvalidArguments If unknown engine type chosen.
1370      * @retval Result::NonSupport In case the engine type is not supported on the system.
1371      * @retval Result::Unknown Others.
1372      *
1373      * @note Initializer does own reference counting for multiple calls.
1374      * @see Initializer::init()
1375      */
1376     static Result term(CanvasEngine engine) noexcept;
1377
1378     _TVG_DISABLE_CTOR(Initializer);
1379 };
1380
1381
1382 /**
1383  * @class Saver
1384  *
1385  * @brief A class enabling saving a paint in a binary format.
1386  *
1387  * @BETA_API
1388  */
1389 class TVG_EXPORT Saver
1390 {
1391 public:
1392     ~Saver();
1393
1394     /**
1395      * @brief Saves all the paints from the tree in a binary format.
1396      *
1397      * @param[in] paint The root paint to be saved with all its nodes.
1398      * @param[in] path A path to the file, in which the data is to be saved.
1399      *
1400      * @retval Result::Success When succeed.
1401      * @retval Result::InvalidArguments the @p path is invalid.
1402      * @retval Result::FailedAllocation An internal error with a memory allocation for the Saver object.
1403      * @retval Result::MemoryCorruption When casting in the internal function implementation failed.
1404      * @retval Result::Unknown Others.
1405      *
1406      */
1407     Result save(std::unique_ptr<Paint> paint, const std::string& path) noexcept;
1408     Result sync() noexcept;
1409
1410     static std::unique_ptr<Saver> gen() noexcept;
1411
1412     _TVG_DECLARE_PRIVATE(Saver);
1413 };
1414
1415
1416 /** @}*/
1417
1418 } //namespace
1419
1420 #ifdef __cplusplus
1421 }
1422 #endif
1423
1424 #endif //_THORVG_H_