Skip to content

Commit 242aa03

Browse files
akien-mgavbettaque
authored andcommitted
thorvg: Update to 0.14.7
Fixes godotengine#95861.
1 parent a866aaf commit 242aa03

37 files changed

+665
-911
lines changed

thirdparty/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ instead of `miniz.h` as an external dependency.
909909
## thorvg
910910

911911
- Upstream: https://github.com/thorvg/thorvg
912-
- Version: 0.14.2 (f6c4d8a94e0b2194fe911d6e19a550683055dd50, 2024)
912+
- Version: 0.14.7 (e3a6bf5229a9671c385ee78bc33e6e6b611a9729, 2024)
913913
- License: MIT
914914

915915
Files extracted from upstream source:

thirdparty/thorvg/inc/config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
// For internal debugging:
1616
//#define THORVG_LOG_ENABLED
1717

18-
#define THORVG_VERSION_STRING "0.14.2"
18+
#define THORVG_VERSION_STRING "0.14.7"
1919
#endif

thirdparty/thorvg/inc/thorvg.h

+72-78
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,17 @@ enum class FillRule
157157
enum class CompositeMethod
158158
{
159159
None = 0, ///< No composition is applied.
160-
ClipPath, ///< The intersection of the source and the target is determined and only the resulting pixels from the source are rendered.
160+
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.
161161
AlphaMask, ///< Alpha Masking using the compositing target's pixels as an alpha value.
162162
InvAlphaMask, ///< Alpha Masking using the complement to the compositing target's pixels as an alpha value.
163163
LumaMask, ///< Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the compositing target's pixels. @since 0.9
164164
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
165165
AddMask, ///< Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) (Experimental API)
166166
SubtractMask, ///< Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) (Experimental API)
167167
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)
168-
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)
168+
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)
169+
LightenMask, ///< Where multiple masks intersect, the highest transparency value is used. (Experimental API)
170+
DarkenMask ///< Where multiple masks intersect, the lowest transparency value is used. (Experimental API)
169171
};
170172

171173

@@ -232,34 +234,6 @@ struct Matrix
232234
};
233235

234236

235-
/**
236-
* @brief A data structure representing a texture mesh vertex
237-
*
238-
* @param pt The vertex coordinate
239-
* @param uv The normalized texture coordinate in the range (0.0..1.0, 0.0..1.0)
240-
*
241-
* @note Experimental API
242-
*/
243-
struct Vertex
244-
{
245-
Point pt;
246-
Point uv;
247-
};
248-
249-
250-
/**
251-
* @brief A data structure representing a triange in a texture mesh
252-
*
253-
* @param vertex The three vertices that make up the polygon
254-
*
255-
* @note Experimental API
256-
*/
257-
struct Polygon
258-
{
259-
Vertex vertex[3];
260-
};
261-
262-
263237
/**
264238
* @class Paint
265239
*
@@ -361,7 +335,7 @@ class TVG_API Paint
361335
*
362336
* @note Experimental API
363337
*/
364-
Result blend(BlendMethod method) const noexcept;
338+
Result blend(BlendMethod method) noexcept;
365339

366340
/**
367341
* @deprecated Use bounds(float* x, float* y, float* w, float* h, bool transformed) instead
@@ -371,15 +345,16 @@ class TVG_API Paint
371345
/**
372346
* @brief Gets the axis-aligned bounding box of the paint object.
373347
*
374-
* In case @p transform is @c true, all object's transformations are applied first, and then the bounding box is established. Otherwise, the bounding box is determined before any transformations.
375-
*
376-
* @param[out] x The x coordinate of the upper left corner of the object.
377-
* @param[out] y The y coordinate of the upper left corner of the object.
348+
* @param[out] x The x-coordinate of the upper-left corner of the object.
349+
* @param[out] y The y-coordinate of the upper-left corner of the object.
378350
* @param[out] w The width of the object.
379351
* @param[out] h The height of the object.
380-
* @param[in] transformed If @c true, the paint's transformations are taken into account, otherwise they aren't.
352+
* @param[in] transformed If @c true, the paint's transformations are taken into account in the scene it belongs to. Otherwise they aren't.
381353
*
354+
* @note This is useful when you need to figure out the bounding box of the paint in the canvas space.
382355
* @note The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object.
356+
* @note If @p transformed is @c true, the paint needs to be pushed into a canvas and updated before this api is called.
357+
* @see Canvas::update()
383358
*/
384359
Result bounds(float* x, float* y, float* w, float* h, bool transformed) const noexcept;
385360

@@ -411,9 +386,9 @@ class TVG_API Paint
411386
CompositeMethod composite(const Paint** target) const noexcept;
412387

413388
/**
414-
* @brief Gets the blending method of the object.
389+
* @brief Retrieves the current blending method applied to the paint object.
415390
*
416-
* @return The blending method
391+
* @return The currently set blending method.
417392
*
418393
* @note Experimental API
419394
*/
@@ -428,6 +403,15 @@ class TVG_API Paint
428403
*/
429404
uint32_t identifier() const noexcept;
430405

406+
/**
407+
* @brief Unique ID of this instance.
408+
*
409+
* This is reserved to specify an paint instance in a scene.
410+
*
411+
* @since Experimental API
412+
*/
413+
uint32_t id = 0;
414+
431415
_TVG_DECLARE_PRIVATE(Paint);
432416
};
433417

@@ -675,7 +659,8 @@ class TVG_API LinearGradient final : public Fill
675659
* @param[in] x2 The horizontal coordinate of the second point used to determine the gradient bounds.
676660
* @param[in] y2 The vertical coordinate of the second point used to determine the gradient bounds.
677661
*
678-
* @note In case the first and the second points are equal, an object filled with such a gradient fill is not rendered.
662+
* @note 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().
663+
* @see Fill::colorStops()
679664
*/
680665
Result linear(float x1, float y1, float x2, float y2) noexcept;
681666

@@ -734,6 +719,8 @@ class TVG_API RadialGradient final : public Fill
734719
* @param[in] radius The radius of the bounding circle.
735720
*
736721
* @retval Result::InvalidArguments in case the @p radius value is zero or less.
722+
*
723+
* @note In case the @p radius is zero, an object is filled with a single color using the last color specified in the colorStops().
737724
*/
738725
Result radial(float cx, float cy, float radius) noexcept;
739726

@@ -990,7 +977,7 @@ class TVG_API Shape final : public Paint
990977
/**
991978
* @brief Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible.
992979
*
993-
* The values of the arguments @p begin, @p end, and @p offset are in the range of 0.0 to 1.0, representing the beginning of the path and the end, respectively.
980+
* If the values of the arguments @p begin and @p end exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular.
994981
*
995982
* @param[in] begin Specifies the start of the segment to display along the path.
996983
* @param[in] end Specifies the end of the segment to display along the path.
@@ -1076,7 +1063,6 @@ class TVG_API Shape final : public Paint
10761063
* @param[out] b The blue color channel value in the range [0 ~ 255].
10771064
* @param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
10781065
*
1079-
* @return Result::Success when succeed.
10801066
*/
10811067
Result fillColor(uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a = nullptr) const noexcept;
10821068

@@ -1219,7 +1205,7 @@ class TVG_API Picture final : public Paint
12191205
* when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations
12201206
* for the sharable @p data. Instead, ThorVG will reuse the previously loaded picture data.
12211207
*
1222-
* @param[in] data A pointer to a memory location where the content of the picture file is stored.
1208+
* @param[in] data 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 @p copy is @c false.
12231209
* @param[in] size The size in bytes of the memory occupied by the @p data.
12241210
* @param[in] mimeType 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.
12251211
* @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not.
@@ -1256,7 +1242,7 @@ class TVG_API Picture final : public Paint
12561242
Result size(float* w, float* h) const noexcept;
12571243

12581244
/**
1259-
* @brief Loads a raw data from a memory block with a given size.
1245+
* @brief Loads raw data in ARGB8888 format from a memory block of the given size.
12601246
*
12611247
* ThorVG efficiently caches the loaded data using the specified @p data address as a key
12621248
* when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations
@@ -1265,47 +1251,27 @@ class TVG_API Picture final : public Paint
12651251
* @param[in] data A pointer to a memory location where the content of the picture raw data is stored.
12661252
* @param[in] w The width of the image @p data in pixels.
12671253
* @param[in] h The height of the image @p data in pixels.
1268-
* @param[in] premultiplied If @c true, the given image data is alpha-premultiplied.
12691254
* @param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not.
12701255
*
1256+
* @note It expects premultiplied alpha data.
12711257
* @since 0.9
12721258
*/
12731259
Result load(uint32_t* data, uint32_t w, uint32_t h, bool copy) noexcept;
12741260

12751261
/**
1276-
* @brief Sets or removes the triangle mesh to deform the image.
1277-
*
1278-
* If a mesh is provided, the transform property of the Picture will apply to the triangle mesh, and the
1279-
* image data will be used as the texture.
1280-
*
1281-
* If @p triangles is @c nullptr, or @p triangleCnt is 0, the mesh will be removed.
1282-
*
1283-
* Only raster image types are supported at this time (png, jpg). Vector types like svg and tvg do not support.
1284-
* mesh deformation. However, if required you should be able to render a vector image to a raster image and then apply a mesh.
1262+
* @brief Retrieve a paint object from the Picture scene by its Unique ID.
12851263
*
1286-
* @param[in] triangles An array of Polygons(triangles) that make up the mesh, or null to remove the mesh.
1287-
* @param[in] triangleCnt The number of Polygons(triangles) provided, or 0 to remove the mesh.
1264+
* This function searches for a paint object within the Picture scene that matches the provided @p id.
12881265
*
1289-
* @note The Polygons are copied internally, so modifying them after calling Mesh::mesh has no affect.
1290-
* @warning Please do not use it, this API is not official one. It could be modified in the next version.
1266+
* @param[in] id The Unique ID of the paint object.
12911267
*
1292-
* @note Experimental API
1293-
*/
1294-
Result mesh(const Polygon* triangles, uint32_t triangleCnt) noexcept;
1295-
1296-
/**
1297-
* @brief Return the number of triangles in the mesh, and optionally get a pointer to the array of triangles in the mesh.
1268+
* @return A pointer to the paint object that matches the given identifier, or @c nullptr if no matching paint object is found.
12981269
*
1299-
* @param[out] triangles Optional. A pointer to the array of Polygons used by this mesh.
1300-
*
1301-
* @return The number of polygons in the array.
1302-
*
1303-
* @note Modifying the triangles returned by this method will modify them directly within the mesh.
1304-
* @warning Please do not use it, this API is not official one. It could be modified in the next version.
1270+
* @see Accessor::id()
13051271
*
13061272
* @note Experimental API
13071273
*/
1308-
uint32_t mesh(const Polygon** triangles) const noexcept;
1274+
const Paint* paint(uint32_t id) noexcept;
13091275

13101276
/**
13111277
* @brief Creates a new Picture object.
@@ -1454,8 +1420,6 @@ class TVG_API Text final : public Paint
14541420
* @param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0.
14551421
* @param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0.
14561422
*
1457-
* @retval Result::InsufficientCondition when the font has not been set up prior to this operation.
1458-
*
14591423
* @see Text::font()
14601424
*
14611425
* @note Experimental API
@@ -1469,8 +1433,6 @@ class TVG_API Text final : public Paint
14691433
*
14701434
* @param[in] f The unique pointer to the gradient fill.
14711435
*
1472-
* @retval Result::InsufficientCondition when the font has not been set up prior to this operation.
1473-
*
14741436
* @note Either a solid color or a gradient fill is applied, depending on what was set as last.
14751437
* @note Experimental API
14761438
*
@@ -1781,6 +1743,19 @@ class TVG_API Initializer final
17811743
*/
17821744
static Result term(CanvasEngine engine) noexcept;
17831745

1746+
/**
1747+
* @brief Retrieves the version of the TVG engine.
1748+
*
1749+
* @param[out] major A major version number.
1750+
* @param[out] minor A minor version number.
1751+
* @param[out] micro A micro version number.
1752+
*
1753+
* @return The version of the engine in the format major.minor.micro, or a @p nullptr in case of an internal error.
1754+
*
1755+
* @note Experimental API
1756+
*/
1757+
static const char* version(uint32_t* major, uint32_t* minor, uint32_t* micro) noexcept;
1758+
17841759
_TVG_DISABLE_CTOR(Initializer);
17851760
};
17861761

@@ -1879,7 +1854,7 @@ class TVG_API Animation
18791854
* @retval Result::InsufficientCondition In case the animation is not loaded.
18801855
* @retval Result::NonSupport When it's not animatable.
18811856
*
1882-
* @note Range from 0.0~1.0
1857+
* @note Animation allows a range from 0.0 to 1.0. @p end should not be higher than @p begin.
18831858
* @note If a marker has been specified, its range will be disregarded.
18841859
* @see LottieAnimation::segment(const char* marker)
18851860
* @note Experimental API
@@ -2030,17 +2005,36 @@ class TVG_API Accessor final
20302005
public:
20312006
~Accessor();
20322007

2008+
TVG_DEPRECATED std::unique_ptr<Picture> set(std::unique_ptr<Picture> picture, std::function<bool(const Paint* paint)> func) noexcept;
2009+
20332010
/**
20342011
* @brief Set the access function for traversing the Picture scene tree nodes.
20352012
*
20362013
* @param[in] picture The picture node to traverse the internal scene-tree.
20372014
* @param[in] func The callback function calling for every paint nodes of the Picture.
2038-
*
2039-
* @return Return the given @p picture instance.
2015+
* @param[in] data Data passed to the @p func as its argument.
20402016
*
20412017
* @note The bitmap based picture might not have the scene-tree.
2018+
*
2019+
* @note Experimental API
2020+
*/
2021+
Result set(const Picture* picture, std::function<bool(const Paint* paint, void* data)> func, void* data) noexcept;
2022+
2023+
/**
2024+
* @brief Generate a unique ID (hash key) from a given name.
2025+
*
2026+
* This function computes a unique identifier value based on the provided string.
2027+
* You can use this to assign a unique ID to the Paint object.
2028+
*
2029+
* @param[in] name The input string to generate the unique identifier from.
2030+
*
2031+
* @return The generated unique identifier value.
2032+
*
2033+
* @see Paint::id
2034+
*
2035+
* @note Experimental API
20422036
*/
2043-
std::unique_ptr<Picture> set(std::unique_ptr<Picture> picture, std::function<bool(const Paint* paint)> func) noexcept;
2037+
static uint32_t id(const char* name) noexcept;
20442038

20452039
/**
20462040
* @brief Creates a new Accessor object.

thirdparty/thorvg/src/common/tvgArray.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct Array
5959
data[count++] = element;
6060
}
6161

62-
void push(Array<T>& rhs)
62+
void push(const Array<T>& rhs)
6363
{
6464
if (rhs.count == 0) return;
6565
grow(rhs.count);

thirdparty/thorvg/src/common/tvgCompressor.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ size_t b64Decode(const char* encoded, const size_t len, char** decoded)
478478

479479
unsigned long djb2Encode(const char* str)
480480
{
481+
if (!str) return 0;
482+
481483
unsigned long hash = 5381;
482484
int c;
483485

thirdparty/thorvg/src/common/tvgInlist.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct Inlist
100100
if (element == tail) tail = element->prev;
101101
}
102102

103-
bool empty()
103+
bool empty() const
104104
{
105105
return head ? false : true;
106106
}

thirdparty/thorvg/src/common/tvgLines.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ float _bezAt(const Bezier& bz, float at, float length, LengthFunc lineLengthFunc
7979
Bezier left;
8080
bezSplitLeft(right, t, left);
8181
length = _bezLength(left, lineLengthFunc);
82-
if (fabsf(length - at) < BEZIER_EPSILON || fabsf(smallest - biggest) < BEZIER_EPSILON) {
82+
if (fabsf(length - at) < BEZIER_EPSILON || fabsf(smallest - biggest) < 1e-3f) {
8383
break;
8484
}
8585
if (length < at) {

thirdparty/thorvg/src/common/tvgLock.h

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
#ifdef THORVG_THREAD_SUPPORT
2727

28-
#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
29-
3028
#include <mutex>
3129
#include "tvgTaskScheduler.h"
3230

0 commit comments

Comments
 (0)