thorvg.h
Defines
-
TVG_BUILD
-
TVG_API
-
TVG_DEPRECATED
-
_TVG_DECLARE_PRIVATE(A)
-
_TVG_DISABLE_CTOR(A)
-
_TVG_DECLARE_ACCESSOR(A)
-
namespace tvg
Enums
-
enum class Result
Enumeration specifying the result from the APIs.
All ThorVG APIs could potentially return one of the values in the list. Please note that some APIs may additionally specify the reasons that trigger their return values.
Values:
-
enumerator Success
The value returned in case of a correct request execution.
-
enumerator InvalidArguments
The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers.
-
enumerator InsufficientCondition
The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist.
-
enumerator FailedAllocation
The value returned in case of unsuccessful memory allocation.
-
enumerator MemoryCorruption
The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting.
-
enumerator NonSupport
The value returned in case of choosing unsupported engine features(options).
-
enumerator Unknown
The value returned in all other cases.
-
enumerator Success
-
enum class PathCommand
Enumeration specifying the values of the path commands accepted by TVG.
Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others). TVG interprets all of them and translates to the ones from the PathCommand values.
Values:
-
enumerator Close
Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.
-
enumerator MoveTo
Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.
-
enumerator 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.
-
enumerator 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.
-
enumerator Close
-
enum class StrokeCap
Enumeration determining the ending type of a stroke in the open sub-paths.
Values:
-
enumerator Square
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.
-
enumerator 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.
-
enumerator 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.
-
enumerator Square
-
enum class StrokeJoin
Enumeration determining the style used at the corners of joined stroked path segments.
Values:
-
enumerator Bevel
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.
-
enumerator Round
The outer corner of the joined path segments is rounded. The circular region is centered at the join point.
-
enumerator 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.
-
enumerator Bevel
-
enum class FillSpread
Enumeration specifying how to fill the area outside the gradient bounds.
Values:
-
enumerator Pad
The remaining area is filled with the closest stop color.
-
enumerator Reflect
The gradient pattern is reflected outside the gradient area until the expected region is filled.
-
enumerator Repeat
The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled.
-
enumerator Pad
-
enum class FillRule
Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape.
Values:
-
enumerator Winding
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.
-
enumerator 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.
-
enumerator Winding
-
enum class CompositeMethod
Enumeration indicating the method used in the composition of two objects - the target and the source.
Notation: S(Source), T(Target), SA(Source Alpha), TA(Target Alpha)
Values:
-
enumerator None
No composition is applied.
-
enumerator ClipPath
The intersection of the source and the target is determined and only the resulting pixels from the source are rendered. Note that ClipPath only supports the Shape type.
- Deprecated:
Use Paint::clip() instead.
-
enumerator AlphaMask
Alpha Masking using the compositing target's pixels as an alpha value.
-
enumerator InvAlphaMask
Alpha Masking using the complement to the compositing target's pixels as an alpha value.
-
enumerator LumaMask
Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the compositing target's pixels.
- Since
0.9
-
enumerator InvLumaMask
Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the complement to the compositing target's pixels.
- Since
0.11
-
enumerator AddMask
Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) (Experimental API)
-
enumerator SubtractMask
Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) (Experimental API)
-
enumerator IntersectMask
Computes the result by taking the minimum value between the target alpha and the source alpha and multiplies it with the target color. (T * min(TA, SA)) (Experimental API)
-
enumerator DifferenceMask
Calculates the absolute difference between the target color and the source color multiplied by the complement of the target alpha. abs(T - S * (255 - TA)) (Experimental API)
-
enumerator LightenMask
Where multiple masks intersect, the highest transparency value is used. (Experimental API)
-
enumerator DarkenMask
Where multiple masks intersect, the lowest transparency value is used. (Experimental API)
-
enumerator None
-
enum class BlendMethod : uint8_t
Enumeration indicates the method used for blending paint. Please refer to the respective formulas for each method.
Notation: S(source paint as the top layer), D(destination as the bottom layer), Sa(source paint alpha), Da(destination alpha)
- Since
0.15
Values:
-
enumerator Normal
Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D.
-
enumerator Multiply
Takes the RGB channel values from 0 to 255 of each pixel in the top layer and multiples them with the values for the corresponding pixel from the bottom layer. (S * D)
-
enumerator Screen
The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D)
-
enumerator Overlay
Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)
-
enumerator SrcOver
Replace the bottom layer with the top layer.
-
enumerator Darken
Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D)
-
enumerator Lighten
Only has the opposite action of Darken Only. max(S, D)
-
enumerator ColorDodge
Divides the bottom layer by the inverted top layer. D / (255 - S)
-
enumerator ColorBurn
Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S.
-
enumerator HardLight
The same as Overlay but with the color roles reversed. (2 * S * D) if (S < Sa), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)
-
enumerator SoftLight
The same as Overlay but with applying pure black or white does not result in pure black or white. (1 - 2 * S) * (D ^ 2) + (2 * S * D)
-
enumerator Difference
Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S)
-
enumerator Exclusion
The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d)
-
enumerator Hue
Reserved. Not supported.
-
enumerator Saturation
Reserved. Not supported.
-
enumerator Color
Reserved. Not supported.
-
enumerator Luminosity
Reserved. Not supported.
-
enumerator Add
Simply adds pixel values of one layer with the other. (S + D)
-
enumerator HardMix
Reserved. Not supported.
-
enum class SceneEffect : uint8_t
Enumeration that defines methods used for Scene Effects.
This enum provides options to apply various post-processing effects to a scene. Scene effects are typically applied to modify the final appearance of a rendered scene, such as blurring.
备注
Experimental API
Values:
-
enumerator ClearAll
Reset all previously applied scene effects, restoring the scene to its original state.
-
enumerator GaussianBlur
Apply a blur effect with a Gaussian filter. Param(3) = {sigma(float)[> 0], direction(int)[both: 0 / horizontal: 1 / vertical: 2], border(int)[duplicate: 0 / wrap: 1], quality(int)[0 - 100]}.
-
enumerator ClearAll
-
enum class CanvasEngine
Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed.
Values:
-
enumerator Sw
CPU rasterizer.
-
enumerator Gl
OpenGL rasterizer.
-
enumerator Wg
WebGPU rasterizer.
- Since
0.15
-
enumerator Sw
-
enum class Type : uint8_t
Enumeration specifying the ThorVG class type value.
ThorVG's drawing objects can return class type values, allowing you to identify the specific class of each object.
参见
备注
Experimental API
Values:
-
enumerator Undefined
Unkown class.
-
enumerator LinearGradient
LinearGradient class.
-
enumerator RadialGradient
RadialGradient class.
-
enumerator Undefined
Functions
-
struct Point
- #include <thorvg.h>
A data structure representing a point in two-dimensional space.
-
struct Matrix
- #include <thorvg.h>
A data structure representing a three-dimensional matrix.
The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor. The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively. The elements e31 and e32 are set to 0, e33 is set to 1.
-
class Paint
- #include <thorvg.h>
An abstract class for managing graphical elements.
A graphical element in TVG is any object composed into a Canvas. Paint represents such a graphical object and its behaviors such as duplication, transformation and composition. 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.
Subclassed by tvg::Picture, tvg::Scene, tvg::Shape, tvg::Text
Public Functions
-
virtual ~Paint()
-
Result rotate(float degree) noexcept
Sets the angle by which the object is rotated.
The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.
- 参数:
degree -- [in] The value of the angle in degrees.
- 返回值:
Result::InsufficientCondition -- in case a custom transform is applied.
-
Result scale(float factor) noexcept
Sets the scale value of the object.
- 参数:
factor -- [in] The value of the scaling factor. The default value is 1.
- 返回值:
Result::InsufficientCondition -- in case a custom transform is applied.
-
Result translate(float x, float y) noexcept
Sets the values by which the object is moved in a two-dimensional space.
The origin of the coordinate system is in the upper-left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.
- 参数:
x -- [in] The value of the horizontal shift.
y -- [in] The value of the vertical shift.
- 返回值:
Result::InsufficientCondition -- in case a custom transform is applied.
-
Result transform(const Matrix &m) noexcept
Sets the matrix of the affine transformation for the object.
The augmented matrix of the transformation is expected to be given.
- 参数:
m -- [in] The 3x3 augmented matrix.
-
Matrix transform() noexcept
Gets the matrix of the affine transformation of the object.
The values of the matrix can be set by the transform() API, as well by the translate(), scale() and rotate(). In case no transformation was applied, the identity matrix is returned.
- Since
0.4
- 返回:
The augmented transformation matrix.
-
Result opacity(uint8_t o) noexcept
Sets the opacity of the object.
备注
Setting the opacity with this API may require multiple render pass for composition. It is recommended to avoid changing the opacity if possible.
- 参数:
o -- [in] The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
-
Result composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept
Sets the composition target object and the composition method.
- 参数:
target -- [in] The paint of the target object.
method -- [in] The method used to composite the source object with the target.
-
Result clip(std::unique_ptr<Paint> clipper) noexcept
Clip the drawing region of the paint object.
This function restricts the drawing area of the paint object to the specified shape's paths.
备注
clipper
only supports the Shape type.备注
Experimental API
- 参数:
clipper -- [in] The shape object as the clipper.
- 返回值:
Result::NonSupport -- If the
clipper
type is not Shape.
-
Result blend(BlendMethod method) noexcept
Sets the blending method for the paint object.
The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. The blending operation is determined by the chosen
BlendMethod
, which specifies how the colors or images are combined.备注
Experimental API
- 参数:
method -- [in] The blending method to be set.
-
Result bounds(float *x, float *y, float *w, float *h) const noexcept
- Deprecated:
Use bounds(float* x, float* y, float* w, float* h, bool transformed) instead
-
Result bounds(float *x, float *y, float *w, float *h, bool transformed) const noexcept
Gets the axis-aligned bounding box of the paint object.
备注
This is useful when you need to figure out the bounding box of the paint in the canvas space.
备注
The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object.
备注
If
transformed
istrue
, the paint needs to be pushed into a canvas and updated before this api is called.- 参数:
x -- [out] The x-coordinate of the upper-left corner of the object.
y -- [out] The y-coordinate of the upper-left corner of the object.
w -- [out] The width of the object.
h -- [out] The height of the object.
transformed -- [in] If
true
, the paint's transformations are taken into account in the scene it belongs to. Otherwise they aren't.
-
Paint *duplicate() const noexcept
Duplicates the object.
Creates a new object and sets its all properties as in the original object.
- 返回:
The created object when succeed,
nullptr
otherwise.
-
uint8_t opacity() const noexcept
Gets the opacity value of the object.
- 返回:
The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
-
CompositeMethod composite(const Paint **target) const noexcept
Gets the composition target object and the composition method.
- Since
0.5
- 参数:
target -- [out] The paint of the target object.
- 返回:
The method used to composite the source object with the target.
-
virtual Type type() const noexcept = 0
Returns the ID value of this class.
This method can be used to check the current concrete instance type.
- Since
Experimental API
- 返回:
The class type ID of the Paint instance.
-
uint32_t identifier() const noexcept
-
virtual ~Paint()
-
class Fill
- #include <thorvg.h>
An abstract class representing the gradient fill of the Shape object.
It contains the information about the gradient colors and their arrangement inside the gradient bounds. The gradients bounds are defined in the LinearGradient or RadialGradient class, depending on the type of the gradient to be used. It specifies the gradient behavior in case the area defined by the gradient bounds is smaller than the area to be filled.
Subclassed by tvg::LinearGradient, tvg::RadialGradient
Public Functions
-
virtual ~Fill()
-
Result colorStops(const ColorStop *colorStops, uint32_t cnt) noexcept
Sets the parameters of the colors of the gradient and their position.
- 参数:
colorStops -- [in] An array of ColorStop data structure.
cnt -- [in] The count of the
colorStops
array equal to the colors number used in the gradient.
-
Result spread(FillSpread s) noexcept
Sets the FillSpread value, which specifies how to fill the area outside the gradient bounds.
- 参数:
s -- [in] The FillSpread value.
-
Result transform(const Matrix &m) noexcept
Sets the matrix of the affine transformation for the gradient fill.
The augmented matrix of the transformation is expected to be given.
- 参数:
m -- [in] The 3x3 augmented matrix.
-
uint32_t colorStops(const ColorStop **colorStops) const noexcept
Gets the parameters of the colors of the gradient, their position and number.
- 参数:
colorStops -- [out] A pointer to the memory location, where the array of the gradient's ColorStop is stored.
- 返回:
The number of colors used in the gradient. This value corresponds to the length of the
colorStops
array.
-
FillSpread spread() const noexcept
Gets the FillSpread value of the fill.
- 返回:
The FillSpread value of this Fill.
-
Matrix transform() const noexcept
Gets the matrix of the affine transformation of the gradient fill.
In case no transformation was applied, the identity matrix is returned.
- 返回:
The augmented transformation matrix.
-
Fill *duplicate() const noexcept
Creates a copy of the Fill object.
Return a newly created Fill object with the properties copied from the original.
- 返回:
A copied Fill object when succeed,
nullptr
otherwise.
-
virtual Type type() const noexcept = 0
Returns the ID value of this class.
This method can be used to check the current concrete instance type.
- Since
Experimental API
- 返回:
The class type ID of the Fill instance.
-
uint32_t identifier() const noexcept
参见
Public Members
-
Impl *pImpl
Protected Functions
-
Fill()
-
struct ColorStop
- #include <thorvg.h>
A data structure storing the information about the color and its relative position inside the gradient bounds.
Public Members
-
float offset
The relative position of the color.
-
uint8_t r
The red color channel value in the range [0 ~ 255].
-
uint8_t g
The green color channel value in the range [0 ~ 255].
-
uint8_t b
The blue color channel value in the range [0 ~ 255].
-
uint8_t a
The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
-
float offset
-
virtual ~Fill()
-
class Canvas
- #include <thorvg.h>
An abstract class for drawing graphical elements.
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.
备注
A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical.
Subclassed by tvg::GlCanvas, tvg::SwCanvas, tvg::WgCanvas
Public Functions
-
Canvas(RenderMethod*)
-
virtual ~Canvas()
-
std::list<Paint*> &paints() noexcept
Returns the list of the paints that currently held by the Canvas.
This function provides the list of paint nodes, allowing users a direct opportunity to modify the scene tree.
备注
Experimental API
-
virtual Result push(std::unique_ptr<Paint> paint) noexcept
Passes drawing elements to the Canvas using Paint objects.
Only pushed paints in the canvas will be drawing targets. They are retained by the canvas until you call Canvas::clear().
备注
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.
- 参数:
paint -- [in] A Paint object to be drawn.
- 返回值:
Result::MemoryCorruption -- In case a
nullptr
is passed as the argument.
-
virtual Result clear(bool free = true) noexcept
Clear the internal canvas resources that used for the drawing.
This API sets the total number of paints pushed into the canvas to zero. Depending on the value of the
free
argument, the paints are either freed or retained. So if you need to update paint properties while maintaining the existing scene structure, you can setfree
= false.- 参数:
free -- [in] If
true
, the memory occupied by paints is deallocated, otherwise it is not.
-
virtual Result update(Paint *paint = nullptr) noexcept
Request the canvas to update the paint objects.
If a
nullptr
is passed all paint objects retained by the Canvas are updated, otherwise only the paint to which the givenpaint
points.备注
The Update behavior can be asynchronous if the assigned thread number is greater than zero.
- 参数:
paint -- [in] A pointer to the Paint object or
nullptr
.
-
virtual Result draw() noexcept
Requests the canvas to draw the Paint objects.
备注
Drawing can be asynchronous if the assigned thread number is greater than zero. To guarantee the drawing is done, call sync() afterwards.
-
virtual Result viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept
Sets the drawing region in the canvas.
This function defines the rectangular area of the canvas that will be used for drawing operations. The specified viewport is used to clip the rendering output to the boundaries of the rectangle.
- Since
0.15
备注
When resetting the target, the viewport will also be reset to the target size.
警告
It's not allowed to change the viewport during Canvas::push() - Canvas::sync() or Canvas::update() - Canvas::sync().
- 参数:
x -- [in] The x-coordinate of the upper-left corner of the rectangle.
y -- [in] The y-coordinate of the upper-left corner of the rectangle.
w -- [in] The width of the rectangle.
h -- [in] The height of the rectangle.
-
virtual Result sync() noexcept
Guarantees that drawing task is finished.
The Canvas rendering can be performed asynchronously. To make sure that rendering is finished, the sync() must be called after the draw() regardless of threading.
- 返回值:
Result::InsufficientCondition -- The canvas is either already in sync condition or in a damaged condition (a draw is required before syncing).
Public Members
-
Impl *pImpl
-
Canvas(RenderMethod*)
-
class LinearGradient : public tvg::Fill
- #include <thorvg.h>
A class representing the linear gradient fill of the Shape object.
Besides the APIs inherited from the Fill class, it enables setting and getting the linear gradient bounds. The behavior outside the gradient bounds depends on the value specified in the spread API.
Public Functions
-
~LinearGradient()
-
Result linear(float x1, float y1, float x2, float y2) noexcept
Sets the linear gradient bounds.
The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing the given points (
x1
,y1
) and (x2
,y2
), respectively. Both lines are perpendicular to the line linking (x1
,y1
) and (x2
,y2
).备注
In case the first and the second points are equal, an object is filled with a single color using the last color specified in the colorStops().
- 参数:
x1 -- [in] The horizontal coordinate of the first point used to determine the gradient bounds.
y1 -- [in] The vertical coordinate of the first point used to determine the gradient bounds.
x2 -- [in] The horizontal coordinate of the second point used to determine the gradient bounds.
y2 -- [in] The vertical coordinate of the second point used to determine the gradient bounds.
-
Result linear(float *x1, float *y1, float *x2, float *y2) const noexcept
Gets the linear gradient bounds.
The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing the given points (
x1
,y1
) and (x2
,y2
), respectively. Both lines are perpendicular to the line linking (x1
,y1
) and (x2
,y2
).- 参数:
x1 -- [out] The horizontal coordinate of the first point used to determine the gradient bounds.
y1 -- [out] The vertical coordinate of the first point used to determine the gradient bounds.
x2 -- [out] The horizontal coordinate of the second point used to determine the gradient bounds.
y2 -- [out] The vertical coordinate of the second point used to determine the gradient bounds.
-
virtual Type type() const noexcept override
Returns the ID value of this class.
This method can be used to check the current concrete instance type.
- Since
Experimental API
- 返回:
The class type ID of the LinearGradient instance.
Public Members
-
Impl *pImpl
Public Static Functions
-
static std::unique_ptr<LinearGradient> gen() noexcept
Creates a new LinearGradient object.
- 返回:
A new LinearGradient object.
-
static uint32_t identifier() noexcept
Protected Functions
-
LinearGradient(const LinearGradient&) = delete
-
const LinearGradient &operator=(const LinearGradient&) = delete
-
LinearGradient()
-
~LinearGradient()
-
class RadialGradient : public tvg::Fill
- #include <thorvg.h>
A class representing the radial gradient fill of the Shape object.
Public Functions
-
~RadialGradient()
-
Result radial(float cx, float cy, float radius) noexcept
Sets the radial gradient bounds.
The radial gradient bounds are defined as a circle centered in a given point (
cx
,cy
) of a given radius.备注
In case the
radius
is zero, an object is filled with a single color using the last color specified in the colorStops().- 参数:
cx -- [in] The horizontal coordinate of the center of the bounding circle.
cy -- [in] The vertical coordinate of the center of the bounding circle.
radius -- [in] The radius of the bounding circle.
- 返回值:
Result::InvalidArguments -- in case the
radius
value is zero or less.
-
Result radial(float *cx, float *cy, float *radius) const noexcept
Gets the radial gradient bounds.
The radial gradient bounds are defined as a circle centered in a given point (
cx
,cy
) of a given radius.- 参数:
cx -- [out] The horizontal coordinate of the center of the bounding circle.
cy -- [out] The vertical coordinate of the center of the bounding circle.
radius -- [out] The radius of the bounding circle.
-
virtual Type type() const noexcept override
Returns the ID value of this class.
This method can be used to check the current concrete instance type.
- Since
Experimental API
- 返回:
The class type ID of the LinearGradient instance.
Public Members
-
Impl *pImpl
Public Static Functions
-
static std::unique_ptr<RadialGradient> gen() noexcept
Creates a new RadialGradient object.
- 返回:
A new RadialGradient object.
-
static uint32_t identifier() noexcept
Protected Functions
-
RadialGradient(const RadialGradient&) = delete
-
const RadialGradient &operator=(const RadialGradient&) = delete
-
RadialGradient()
-
~RadialGradient()
-
class Shape : public tvg::Paint
- #include <thorvg.h>
A class representing two-dimensional figures and their properties.
A shape has three major properties: shape outline, stroking, filling. The outline in the Shape is retained as the path. Path can be composed by accumulating primitive commands such as moveTo(), lineTo(), cubicTo(), or complete shape interfaces such as appendRect(), appendCircle(), etc. Path can consists of sub-paths. One sub-path is determined by a close command.
The stroke of Shape is an optional property in case the Shape needs to be represented with/without the outline borders. 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.
Public Functions
-
~Shape()
-
Result reset() noexcept
Resets the shape path.
The transformation matrix, color, fill, and stroke properties are retained.
备注
The memory where the path data is stored is not deallocated at this stage to allow for caching.
-
Result moveTo(float x, float y) noexcept
Sets the initial point of the sub-path.
The value of the current point is set to the given point.
- 参数:
x -- [in] The horizontal coordinate of the initial point of the sub-path.
y -- [in] The vertical coordinate of the initial point of the sub-path.
-
Result lineTo(float x, float y) noexcept
Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point.
The value of the current point is set to the given end-point.
备注
In case this is the first command in the path, it corresponds to the moveTo() call.
- 参数:
x -- [in] The horizontal coordinate of the end-point of the line.
y -- [in] The vertical coordinate of the end-point of the line.
-
Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept
Adds new points to the sub-path, which results in drawing a cubic Bezier curve starting at the current point and ending at the given end-point (
x
,y
) using the control points (cx1
,cy1
) and (cx2
,cy2
).The value of the current point is set to the given end-point.
备注
In case this is the first command in the path, no data from the path are rendered.
- 参数:
cx1 -- [in] The horizontal coordinate of the 1st control point.
cy1 -- [in] The vertical coordinate of the 1st control point.
cx2 -- [in] The horizontal coordinate of the 2nd control point.
cy2 -- [in] The vertical coordinate of the 2nd control point.
x -- [in] The horizontal coordinate of the end-point of the curve.
y -- [in] The vertical coordinate of the end-point of the curve.
-
Result close() noexcept
Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path.
The value of the current point is set to the initial point of the closed sub-path.
备注
In case the sub-path does not contain any points, this function has no effect.
-
Result appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0) noexcept
Appends a rectangle to the path.
The rectangle with rounded corners can be achieved by setting non-zero values to
rx
andry
arguments. Therx
andry
values specify the radii of the ellipse defining the rounding of the corners.The position of the rectangle is specified by the coordinates of its upper-left corner -
x
andy
arguments.The rectangle is treated as a new sub-path - it is not connected with the previous sub-path.
The value of the current point is set to (
x
+rx
,y
) - in caserx
is greater thanw/2
the current point is set to (x
+w/2
,y
)备注
For
rx
andry
greater than or equal to the half ofw
and the half ofh
, respectively, the shape become an ellipse.- 参数:
x -- [in] The horizontal coordinate of the upper-left corner of the rectangle.
y -- [in] The vertical coordinate of the upper-left corner of the rectangle.
w -- [in] The width of the rectangle.
h -- [in] The height of the rectangle.
rx -- [in] The x-axis radius of the ellipse defining the rounded corners of the rectangle.
ry -- [in] The y-axis radius of the ellipse defining the rounded corners of the rectangle.
-
Result appendCircle(float cx, float cy, float rx, float ry) noexcept
Appends an ellipse to the path.
The position of the ellipse is specified by the coordinates of its center -
cx
andcy
arguments.The ellipse is treated as a new sub-path - it is not connected with the previous sub-path.
The value of the current point is set to (
cx
,cy
-ry
).- 参数:
cx -- [in] The horizontal coordinate of the center of the ellipse.
cy -- [in] The vertical coordinate of the center of the ellipse.
rx -- [in] The x-axis radius of the ellipse.
ry -- [in] The y-axis radius of the ellipse.
-
Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept
Appends a circular arc to the path.
The arc is treated as a new sub-path - it is not connected with the previous sub-path. The current point value is set to the end-point of the arc in case
pie
isfalse
, and to the center of the arc otherwise.备注
Setting
sweep
value greater than 360 degrees, is equivalent to calling appendCircle(cx, cy, radius, radius).- 参数:
cx -- [in] The horizontal coordinate of the center of the arc.
cy -- [in] The vertical coordinate of the center of the arc.
radius -- [in] The radius of the arc.
startAngle -- [in] The start angle of the arc given in degrees, measured counter-clockwise from the horizontal line.
sweep -- [in] The central angle of the arc given in degrees, measured counter-clockwise from
startAngle
.pie -- [in] Specifies whether to draw radii from the arc's center to both of its end-point - drawn if
true
.
-
Result appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point *pts, uint32_t ptsCnt) noexcept
Appends a given sub-path to the path.
The current point value is set to the last point from the sub-path. For each command from the
cmds
array, an appropriate number of points inpts
array should be specified. If the number of points in thepts
array is different than the number required by thecmds
array, the shape with this sub-path will not be displayed on the screen.备注
The interface is designed for optimal path setting if the caller has a completed path commands already.
- 参数:
cmds -- [in] The array of the commands in the sub-path.
cmdCnt -- [in] The number of the sub-path's commands.
pts -- [in] The array of the two-dimensional points.
ptsCnt -- [in] The number of the points in the
pts
array.
-
Result stroke(float width) noexcept
Sets the stroke width for all of the figures from the path.
- 参数:
width -- [in] The width of the stroke. The default value is 0.
-
Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept
Sets the color of the stroke for all of the figures from the path.
- 参数:
r -- [in] The red color channel value in the range [0 ~ 255]. The default value is 0.
g -- [in] The green color channel value in the range [0 ~ 255]. The default value is 0.
b -- [in] The blue color channel value in the range [0 ~ 255]. The default value is 0.
a -- [in] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
-
Result stroke(std::unique_ptr<Fill> f) noexcept
Sets the gradient fill of the stroke for all of the figures from the path.
- 参数:
f -- [in] The gradient fill.
- 返回值:
Result::MemoryCorruption -- In case a
nullptr
is passed as the argument.
-
Result stroke(const float *dashPattern, uint32_t cnt) noexcept
Sets the dash pattern of the stroke.
备注
To reset the stroke dash pattern, pass
nullptr
todashPattern
and zero tocnt
.警告
cnt
must be greater than 1 if the dash pattern is valid.- 参数:
dashPattern -- [in] The array of consecutive pair values of the dash length and the gap length.
cnt -- [in] The length of the
dashPattern
array.
- 返回值:
Result::InvalidArguments -- In case
dashPattern
isnullptr
andcnt
> 0,cnt
is zero, any of the dash pattern values is zero or less.
-
Result stroke(StrokeCap cap) noexcept
Sets the cap style of the stroke in the open sub-paths.
- 参数:
cap -- [in] The cap style value. The default value is
StrokeCap::Square
.
-
Result stroke(StrokeJoin join) noexcept
Sets the join style for stroked path segments.
The join style is used for joining the two line segment while stroking the path.
- 参数:
join -- [in] The join style value. The default value is
StrokeJoin::Bevel
.
-
Result strokeMiterlimit(float miterlimit) noexcept
Sets the stroke miterlimit.
- Since
0.11
- 参数:
miterlimit -- [in] The miterlimit imposes a limit on the extent of the stroke join, when the
StrokeJoin::Miter
join style is set. The default value is 4.- 返回值:
Result::InvalidArgument -- for
miterlimit
values less than zero.
-
Result strokeTrim(float begin, float end, bool simultaneous = true) noexcept
Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible.
If the values of the arguments
begin
andend
exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular.备注
Experimental API
- 参数:
begin -- [in] Specifies the start of the segment to display along the path.
end -- [in] Specifies the end of the segment to display along the path.
simultaneous -- [in] Determines how to trim multiple paths within a single shape. If set to
true
(default), trimming is applied simultaneously to all paths; Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such.
-
Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept
Sets the solid color for all of the figures from the path.
The parts of the shape defined as inner are colored.
备注
Either a solid color or a gradient fill is applied, depending on what was set as last.
- 参数:
r -- [in] The red color channel value in the range [0 ~ 255]. The default value is 0.
g -- [in] The green color channel value in the range [0 ~ 255]. The default value is 0.
b -- [in] The blue color channel value in the range [0 ~ 255]. The default value is 0.
a -- [in] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.
-
Result fill(std::unique_ptr<Fill> f) noexcept
Sets the gradient fill for all of the figures from the path.
The parts of the shape defined as inner are filled.
备注
Either a solid color or a gradient fill is applied, depending on what was set as last.
- 参数:
f -- [in] The unique pointer to the gradient fill.
-
Result fill(FillRule r) noexcept
Sets the fill rule for the Shape object.
- 参数:
r -- [in] The fill rule value. The default value is
FillRule::Winding
.
-
Result order(bool strokeFirst) noexcept
Sets the rendering order of the stroke and the fill.
- Since
0.10
- 参数:
strokeFirst -- [in] If
true
the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option).
-
uint32_t pathCommands(const PathCommand **cmds) const noexcept
Gets the commands data of the path.
- 参数:
cmds -- [out] The pointer to the array of the commands from the path.
- 返回:
The length of the
cmds
array when succeed, zero otherwise.
-
uint32_t pathCoords(const Point **pts) const noexcept
Gets the points values of the path.
- 参数:
pts -- [out] The pointer to the array of the two-dimensional points from the path.
- 返回:
The length of the
pts
array when succeed, zero otherwise.
-
const Fill *fill() const noexcept
Gets the pointer to the gradient fill of the shape.
- 返回:
The pointer to the gradient fill of the stroke when succeed,
nullptr
in case no fill was set.
-
Result fillColor(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a = nullptr) const noexcept
Gets the solid color of the shape.
- 参数:
r -- [out] The red color channel value in the range [0 ~ 255].
g -- [out] The green color channel value in the range [0 ~ 255].
b -- [out] The blue color channel value in the range [0 ~ 255].
a -- [out] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
-
float strokeWidth() const noexcept
Gets the stroke width.
- 返回:
The stroke width value when succeed, zero if no stroke was set.
-
Result strokeColor(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a = nullptr) const noexcept
Gets the color of the shape's stroke.
- 参数:
r -- [out] The red color channel value in the range [0 ~ 255].
g -- [out] The green color channel value in the range [0 ~ 255].
b -- [out] The blue color channel value in the range [0 ~ 255].
a -- [out] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
-
const Fill *strokeFill() const noexcept
Gets the pointer to the gradient fill of the stroke.
- 返回:
The pointer to the gradient fill of the stroke when succeed,
nullptr
otherwise.
-
uint32_t strokeDash(const float **dashPattern) const noexcept
Gets the dash pattern of the stroke.
- 参数:
dashPattern -- [out] The pointer to the memory, where the dash pattern array is stored.
- 返回:
The length of the
dashPattern
array.
-
StrokeCap strokeCap() const noexcept
Gets the cap style used for stroking the path.
- 返回:
The cap style value of the stroke.
-
StrokeJoin strokeJoin() const noexcept
Gets the join style value used for stroking the path.
- 返回:
The join style value of the stroke.
-
float strokeMiterlimit() const noexcept
Gets the stroke miterlimit.
- Since
0.11
- 返回:
The stroke miterlimit value when succeed, 4 if no stroke was set.
Public Members
-
Impl *pImpl
Public Static Functions
-
static uint32_t identifier() noexcept
-
~Shape()
-
class Picture : public tvg::Paint
- #include <thorvg.h>
A class representing an image read in one of the supported formats: raw, svg, png, jpg, lottie(json) and etc. Besides the methods inherited from the Paint, it provides methods to load & draw images on the canvas.
备注
Supported formats are depended on the available TVG loaders.
备注
See Animation class if the picture data is animatable.
Public Functions
-
~Picture()
-
Result load(const std::string &path) noexcept
Loads a picture data directly from a file.
ThorVG efficiently caches the loaded data using the specified
path
as a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded picture data.备注
The Load behavior can be asynchronous if the assigned thread number is greater than zero.
- 参数:
path -- [in] A path to the picture file.
- 返回值:
Result::InvalidArguments -- In case the
path
is invalid.Result::NonSupport -- When trying to load a file with an unknown extension.
-
Result load(const char *data, uint32_t size, bool copy = false) noexcept
- Deprecated:
Use load(const char* data, uint32_t size, const std::string& mimeType, bool copy) instead.
-
Result load(const char *data, uint32_t size, const std::string &mimeType, bool copy = false) noexcept
Loads a picture data from a memory block of a given size.
ThorVG efficiently caches the loaded data using the specified
data
address as a key when thecopy
hasfalse
. This means that loading the same data again will not result in duplicate operations for the sharabledata
. Instead, ThorVG will reuse the previously loaded picture data.- Since
0.5
备注
If you are unsure about the MIME type, you can provide an empty value like
""
, and thorvg will attempt to figure it out.警告
It's the user responsibility to release the
data
memory.- 参数:
data -- [in] A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if
copy
isfalse
.size -- [in] The size in bytes of the memory occupied by the
data
.mimeType -- [in] Mimetype or extension of data such as "jpg", "jpeg", "lottie", "svg", "svg+xml", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one.
copy -- [in] If
true
the data are copied into the engine local buffer, otherwise they are not.
- 返回值:
Result::InvalidArguments -- In case no data are provided or the
size
is zero or less.Result::NonSupport -- When trying to load a file with an unknown extension.
-
Result size(float w, float h) noexcept
Resizes the picture content to the given width and height.
The picture content is resized while keeping the default size aspect ratio. The scaling factor is established for each of dimensions and the smaller value is applied to both of them.
- 参数:
w -- [in] A new width of the image in pixels.
h -- [in] A new height of the image in pixels.
-
Result size(float *w, float *h) const noexcept
Gets the size of the image.
- 参数:
w -- [out] The width of the image in pixels.
h -- [out] The height of the image in pixels.
-
Result load(uint32_t *data, uint32_t w, uint32_t h, bool copy) noexcept
Loads raw data in ARGB8888 format from a memory block of the given size.
ThorVG efficiently caches the loaded data using the specified
data
address as a key when thecopy
hasfalse
. This means that loading the same data again will not result in duplicate operations for the sharabledata
. Instead, ThorVG will reuse the previously loaded picture data.- Since
0.9
- 参数:
data -- [in] A pointer to a memory location where the content of the picture raw data is stored.
w -- [in] The width of the image
data
in pixels.h -- [in] The height of the image
data
in pixels.premultiplied -- [in] If
true
, the given image data is alpha-premultiplied.copy -- [in] If
true
the data are copied into the engine local buffer, otherwise they are not.
-
const Paint *paint(uint32_t id) noexcept
Retrieve a paint object from the Picture scene by its Unique ID.
This function searches for a paint object within the Picture scene that matches the provided
id
.备注
Experimental API
- 参数:
id -- [in] The Unique ID of the paint object.
- 返回:
A pointer to the paint object that matches the given identifier, or
nullptr
if no matching paint object is found.
-
~Picture()
-
class Scene : public tvg::Paint
- #include <thorvg.h>
A class to composite children paints.
As the traditional graphics rendering method, TVG also enables scene-graph mechanism. This feature supports an array function for managing the multiple paints as one group paint.
As a group, the scene can be transformed, made translucent and composited with other target paints, its children will be affected by the scene world.
Public Functions
-
~Scene()
-
Result push(std::unique_ptr<Paint> paint) noexcept
Passes drawing elements to the Scene using Paint objects.
Only the paints pushed into the scene will be the drawn targets. The paints are retained by the scene until Scene::clear() is called.
备注
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.
- 参数:
paint -- [in] A Paint object to be drawn.
-
std::list<Paint*> &paints() noexcept
Returns the list of the paints that currently held by the Scene.
This function provides the list of paint nodes, allowing users a direct opportunity to modify the scene tree.
备注
Experimental API
警告
Please avoid accessing the paints during Scene update/draw. You can access them after calling Canvas::sync().
-
Result clear(bool free = true) noexcept
Sets the total number of the paints pushed into the scene to be zero. Depending on the value of the
free
argument, the paints are freed or not.- Since
0.2
警告
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
free
argument only when you know how it works, otherwise it's not recommended.- 参数:
free -- [in] If
true
, the memory occupied by paints is deallocated, otherwise it is not.
-
Result push(SceneEffect effect, ...) noexcept
Apply a post-processing effect to the scene.
This function adds a specified scene effect, such as clearing all effects or applying a Gaussian blur, to the scene after it has been rendered. Multiple effects can be applied in sequence.
备注
Experimental API
- 参数:
effect -- [in] The scene effect to apply. Options are defined in the SceneEffect enum. For example, use SceneEffect::GaussianBlur to apply a blur with specific parameters.
... -- [in] Additional variadic parameters required for certain effects (e.g., sigma and direction for GaussianBlur).
Public Members
-
Impl *pImpl
Public Static Functions
-
static uint32_t identifier() noexcept
-
~Scene()
-
class Text : public tvg::Paint
- #include <thorvg.h>
A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text.
- Since
0.15
Public Functions
-
~Text()
-
Result font(const char *name, float size, const char *style = nullptr) noexcept
Sets the font properties for the text.
This function allows you to define the font characteristics used for text rendering. It sets the font name, size and optionally the style.
备注
Experimental API
- 参数:
name -- [in] The name of the font. This should correspond to a font available in the canvas.
size -- [in] The size of the font in points. This determines how large the text will appear.
style -- [in] The style of the font. It can be used to set the font to 'italic'. If not specified, the default style is used. Only 'italic' style is supported currently.
- 返回值:
Result::InsufficientCondition -- when the specified
name
cannot be found.
-
Result text(const char *text) noexcept
Assigns the given unicode text to be rendered.
This function sets the unicode string that will be displayed by the rendering system. The text is set according to the specified UTF encoding method, which defaults to UTF-8.
备注
Experimental API
- 参数:
text -- [in] The multi-byte text encoded with utf8 string to be rendered.
-
Result fill(uint8_t r, uint8_t g, uint8_t b) noexcept
Sets the text color.
参见
- Since
0.15
- 参数:
r -- [in] The red color channel value in the range [0 ~ 255]. The default value is 0.
g -- [in] The green color channel value in the range [0 ~ 255]. The default value is 0.
b -- [in] The blue color channel value in the range [0 ~ 255]. The default value is 0.
-
Result fill(std::unique_ptr<Fill> f) noexcept
Sets the gradient fill for all of the figures from the text.
The parts of the text defined as inner are filled.
参见
- Since
0.15
备注
Either a solid color or a gradient fill is applied, depending on what was set as last.
- 参数:
f -- [in] The unique pointer to the gradient fill.
Public Members
-
Impl *pImpl
Public Static Functions
-
static Result load(const std::string &path) noexcept
Loads a scalable font data (ttf) from a file.
ThorVG efficiently caches the loaded data using the specified
path
as a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded font data.- Since
0.15
- 参数:
path -- [in] The path to the font file.
- 返回值:
Result::InvalidArguments -- In case the
path
is invalid.Result::NonSupport -- When trying to load a file with an unknown extension.
-
static Result load(const char *name, const char *data, uint32_t size, const std::string &mimeType = "ttf", bool copy = false) noexcept
Loads a scalable font data (ttf) from a memory block of a given size.
ThorVG efficiently caches the loaded font data using the specified
name
as a key. This means that loading the same fonts again will not result in duplicate operations. Instead, ThorVG will reuse the previously loaded font data.备注
To unload the font data loaded using this API, pass the proper
name
andnullptr
asdata
.备注
If you are unsure about the MIME type, you can provide an empty value like
""
, and thorvg will attempt to figure it out.备注
0.15
警告
It's the user responsibility to release the
data
memory.- 参数:
name -- [in] The name under which the font will be stored and accessible (e.x. in a
font()
API).data -- [in] A pointer to a memory location where the content of the font data is stored.
size -- [in] The size in bytes of the memory occupied by the
data
.mimeType -- [in] Mimetype or extension of font data. In case an empty string is provided the loader will be determined automatically.
copy -- [in] If
true
the data are copied into the engine local buffer, otherwise they are not (default).
- 返回值:
Result::InvalidArguments -- If no name is provided or if
size
is zero whiledata
points to a valid memory location.Result::NonSupport -- When trying to load a file with an unsupported extension.
Result::InsufficientCondition -- If attempting to unload the font data that has not been previously loaded.
-
static Result unload(const std::string &path) noexcept
Unloads the specified scalable font data (TTF) that was previously loaded.
This function is used to release resources associated with a font file that has been loaded into memory.
- Since
0.15
备注
If the font data is currently in use, it will not be immediately unloaded.
- 参数:
path -- [in] The file path of the loaded font.
- 返回值:
Result::InsufficientCondition -- Fails if the loader is not initialized.
-
class SwCanvas : public tvg::Canvas
- #include <thorvg.h>
A class for the rendering graphical elements with a software raster engine.
Public Types
-
enum Colorspace
Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color.
Values:
-
enumerator ABGR8888
The channels are joined in the order: alpha, blue, green, red. Colors are alpha-premultiplied. (a << 24 | b << 16 | g << 8 | r)
-
enumerator ARGB8888
The channels are joined in the order: alpha, red, green, blue. Colors are alpha-premultiplied. (a << 24 | r << 16 | g << 8 | b)
-
enumerator ABGR8888S
The channels are joined in the order: alpha, blue, green, red. Colors are un-alpha-premultiplied.
- Since
0.12
-
enumerator ARGB8888S
The channels are joined in the order: alpha, red, green, blue. Colors are un-alpha-premultiplied.
- Since
0.12
-
enumerator ABGR8888
-
enum MempoolPolicy
Enumeration specifying the methods of Memory Pool behavior policy.
- Since
0.4
Values:
-
enumerator Default
Default behavior that ThorVG is designed to.
Memory Pool is shared among the SwCanvases.
-
enumerator Individual
Allocate designated memory pool that is only used by current instance.
Public Functions
-
~SwCanvas()
-
Result target(uint32_t *buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept
Sets the drawing target for the rasterization.
The buffer of a desirable size should be allocated and owned by the caller.
警告
Do not access
buffer
during Canvas::push() - Canvas::sync(). It should not be accessed while the engine is writing on it.- 参数:
buffer -- [in] A pointer to a memory block of the size
stride
xh
, where the raster data are stored.stride -- [in] The stride of the raster image - greater than or equal to
w
.w -- [in] The width of the raster image.
h -- [in] The height of the raster image.
cs -- [in] The value specifying the way the 32-bits colors should be read/written.
- 返回值:
Result::InvalidArguments -- In case no valid pointer is provided or the width, or the height or the stride is zero.
Result::InsufficientCondition -- if the canvas is performing rendering. Please ensure the canvas is synced.
Result::NonSupport -- In case the software engine is not supported.
-
Result mempool(MempoolPolicy policy) noexcept
Set sw engine memory pool behavior policy.
Basically ThorVG draws a lot of shapes, it allocates/deallocates a few chunk of memory while processing rendering. It internally uses one shared memory pool which can be reused among the canvases in order to avoid memory overhead.
Thus ThorVG suggests using a memory pool policy to satisfy user demands, if it needs to guarantee the thread-safety of the internal data access.
- Since
0.4
备注
When
policy
is set asMempoolPolicy::Individual
, the current instance of canvas uses its own individual memory data, which is not shared with others. This is necessary when the canvas is accessed on a worker-thread.警告
It's not allowed after pushing any paints.
- 参数:
policy -- [in] The method specifying the Memory Pool behavior. The default value is
MempoolPolicy::Default
.- 返回值:
Result::InsufficientCondition -- If the canvas contains some paints already.
Result::NonSupport -- In case the software engine is not supported.
Public Members
-
Impl *pImpl
Public Static Functions
-
enum Colorspace
-
class GlCanvas : public tvg::Canvas
- #include <thorvg.h>
A class for the rendering graphic elements with a GL raster engine.
- Since
0.14
Public Functions
-
~GlCanvas()
-
Result target(int32_t id, uint32_t w, uint32_t h) noexcept
Sets the drawing target for rasterization.
This function specifies the drawing target where the rasterization will occur. It can target a specific framebuffer object (FBO) or the main surface.
备注
Currently, this only allows the GL_RGBA8 color space format.
备注
Experimental API
- 参数:
id -- [in] The GL target ID, usually indicating the FBO ID. A value of
0
specifies the main surface.w -- [in] The width (in pixels) of the raster image.
h -- [in] The height (in pixels) of the raster image.
- 返回值:
Result::InsufficientCondition -- if the canvas is performing rendering. Please ensure the canvas is synced.
Result::NonSupport -- In case the gl engine is not supported.
Public Members
-
Impl *pImpl
Public Static Functions
-
enum class Result