Commit graph

660 commits

Author SHA1 Message Date
Jinny You
bf5cea982c common: Support .lot extension
Add support for the .lot extension to recognize Lottie animation files, as this introduces an additional extension for Lottie.

issue: #3248
2025-02-27 16:46:30 +09:00
Mira Grudzinska
2c73da0e20 gl_engine: fix line join while dashing
While dashing, changing the path command each time caused
a new 'move to' command to be added, even when dash segments
across different path commands should have been connected.

@Issue: https://github.com/thorvg/thorvg/issues/3231
2025-02-27 12:23:00 +09:00
Sergii Liebodkin
9a2d1136de wg_engine: Introduce fill effect for webgpu renderer
Issue: https://github.com/thorvg/thorvg/issues/3054
2025-02-27 12:15:42 +09:00
Mira Grudzinska
2bc6cb07b4 renderer: remove unused file
Should be removed while refactoring in 127738bb1d
2025-02-25 19:42:08 +09:00
Hermet Park
eb4b286da5 renderer: migrated TrimPath as the integrated rendering method
TrimPath -> RenderTrimPath

Co-Authored-By: Mira Grudzinska <mira@lottiefiles.com>
2025-02-25 15:38:03 +09:00
Mira Grudzinska
7275b77c22 gl/wg_engine: fix differences in dashing among engines
The differences resulted from discrepancies between
the engines in applying equality or inequality signs
and in using different precision levels when determining
the dash remainder when transitioning to a new path
command.

@Issue: https://github.com/thorvg/thorvg/issues/3265
2025-02-25 12:30:26 +09:00
Sergii Liebodkin
64ed756c2c wg_engine: Introduce drop shadow effect for webgpu renderer
Issue: https://github.com/thorvg/thorvg/issues/3054
Supported color, angle, distance, sigma, quality params
2025-02-25 11:54:04 +09:00
Mira Grudzinska
8f9527ccf1 gl_engine: support trimmed fill
This commit changes the API behavior.

@Issue: https://github.com/thorvg/thorvg/issues/3118
2025-02-24 15:06:07 +09:00
Mira Grudzinska
05a5a7ea0b wg_engine: support trimmed fill
This commit changes the API behavior.

@Issue: https://github.com/thorvg/thorvg/issues/3118
2025-02-24 15:05:59 +09:00
Mira Grudzinska
c4747e6802 sw_engine: support trimmed fill
Until now, only stroke trimming was possible,
but the Lottie standard requires support for
trimming both (if present), stroke and fill.
This commit changes the API behavior.

@Issue: https://github.com/thorvg/thorvg/issues/3118
2025-02-24 15:05:49 +09:00
Mira Grudzinska
b939a60bfa api: change api name strokeTrim() -> trimpath()
No changes in behaviour so far.
2025-02-24 15:05:38 +09:00
Hermet Park
d50632d0d6 loader: fixed potential memory leaks in font handling
Simply loading a font doesn't mean it is in use.
Fixed the loader's reference count to prevent incorrect increments.
2025-02-21 00:05:36 +09:00
Hermet Park
a768276bb6 common: ++portablity
fix a error call of ambiguous overloaded ‘free(void*&)’
2025-02-20 23:16:27 +09:00
Hermet Park
75c9028c19 gl_engine: code refactoring
- introduced GlGeometryBuffer that structure ensures the pairing of vertex and index data.
- improved for clean and neat code.
2025-02-20 21:41:29 +09:00
Hermet Park
8e5ca40250 text: allow the unnamed font
If the font name is not specified,
ThorVG will select any available font candidate.

This could be useful for font fallback mechanism.
2025-02-20 18:47:01 +09:00
pharuxtan
049f19313d sw_engine: fix internal types of rasterXYFlip
Before the C++ compiler couldn't decide the template of std::min (that happen if `int` type is not an `int32_t`), so explicitly changing all types to int32_t fixes this.
2025-02-19 11:00:58 +09:00
Mira Grudzinska
4e98f12743 wg_engine: fix stroke update
The stroke was not updated because the update function
handled flags related to the color/gradient only.
2025-02-18 21:10:10 +09:00
Jinny You
6c4a74e7f1 wg_engine: Fix undefined error in task scheduler usage 2025-02-18 19:16:37 +09:00
Hermet Park
b77f3ca024 common: introduced designated memory allocators
Support the bindings to be more integrable with a system's coherent memory management.

Pleaes note that thorvg now only allow the desinated memory allocators here:
malloc -> tvg::malloc
calloc -> tvg::calloc
realloc -> tvg::realloc
free -> tvg::free

issue: https://github.com/thorvg/thorvg/issues/2652
2025-02-18 17:20:31 +09:00
Mira Grudzinska
96be683460 wg/gl_engine: standardize shapes closing precision
The sw_engine, when determining the outline, converts
floats to ints by multiplying them x64, resulting in
a comparison precision of 1/64 = 0.015625.
Both gl_engine and wg_engine operate on floats. Before
adding a closing point to a shape, they performed a comparison
to check if the point differed from the starting point:
- wg: with a precision of 1e-3 (using length2, i.e., eps = 1e-6
- gl: used direct == comparison.
Now, consistency has been ensured by introducing a comparison
precision of 1/64 in both wg_engine and gl_engine.

@issue: https://github.com/thorvg/thorvg/issues/2799
@issue: https://github.com/thorvg/thorvg/issues/3235
2025-02-18 11:26:30 +09:00
Hermet Park
65306d9b66 wg_engine: fix a memory violation by a mistake
regresion by ac08a9d6e7

issue: https://github.com/thorvg/thorvg/issues/3241
2025-02-18 00:52:32 +09:00
Hermet Park
457c44c922 gl_engine: fix a compiler warning
- comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’
2025-02-17 23:31:59 +09:00
Mira Grudzinska
acbc3b3ba9 gl_engine: add offset support in dashed strokes
Offset is correctly applied to dashed strokes,
properly shifting the dash pattern.

@Issue: https://github.com/thorvg/thorvg/issues/3217
@Issue: https://github.com/thorvg/thorvg/issues/3223
@Issue: https://github.com/thorvg/thorvg/issues/3191
2025-02-17 22:30:01 +09:00
Mira Grudzinska
95cd0863eb gl_engine: fix dashing
Incorrect condition for drawing segments in cubics;
missing checks.

@Issue: https://github.com/thorvg/thorvg/issues/2729
@Issue: https://github.com/thorvg/thorvg/issues/3222
2025-02-17 19:01:41 +09:00
Hermet Park
ac08a9d6e7 wg_engine: introduced global vertexbuffer mempool & ++thread safety
Manage the global buffer memory for vertex and indexed vertex buffers,
increase the memory size incrementally twice by default and reduce
the default buffer size, which is not suitable for typical scenarios.

This could reduce the a bit stack memory usage and improve
the portability across systems where has the stack memory
limitation and potentially gaining performance enhancement
by avoiding brutal stack memory usage at the many function calls.

added the internal functions:

- WgVertexBuffer* mpoolReqVertexBuffer(float scale = 1.0f);
- WgIndexedVertexBuffer* mpoolReqIndexedVertexBuffer(float scale = 1.0f);
- void mpoolRetVertexBuffer(WgVertexBuffer* buffer);
- void mpoolRetIndexedVertexBuffer(WgIndexedVertexBuffer* buffer);

issue: https://github.com/thorvg/thorvg/issues/3159
2025-02-17 18:56:31 +09:00
Hermet Park
bdb71f18db sw_engine: properly set shared pool and don't flush memory pool 2025-02-17 15:05:57 +09:00
Mira Grudzinska
259e380733 sw_engine: fix update issue
In cases where the fill was changed while the stroke existed
but remained unchanged, the stroke would disappear because it
was being reset during the shape preparing (shapeReset).
Fixed by disabling the reset of stroke rle from shape reseting.

Also the shape should be prepared not only when the RenderUpdateFlag
is set to Color, but also when it is set to Gradient.

@Issue: https://github.com/thorvg/thorvg/issues/3237
2025-02-17 12:19:46 +09:00
Mira Grudzinska
f4c2d116d9 wg_engine: fix dash offset behavior
For an odd number of dash/gap segments, the offset was
handled incorrectly because the non-doubled count of
dashes and gaps was used.
Additionally, in ddcbbf7, an error was introduced by
overlooking the fact that the offset can shift the dash
pattern in such a way that the first segment of the dashed
line becomes a gap.
2025-02-13 19:48:25 +02:00
Mira Grudzinska
ddcbbf771f wg_engine: handle properly odd numbers of dashes/gaps
If the provided list has an odd number of values, then it
should be repeated to yield an even number of values.

@Issue: https://github.com/thorvg/thorvg/issues/3205
2025-02-13 17:23:56 +02:00
Hermet Park
a933465430 sw_engine: ++clean code 2025-02-13 12:53:44 +09:00
Sergii Liebodkin
37992b52c9 webgpu_gaussian_optimization
wg_engine: optimize gaussian blur effect for webgpu renderer

Issue: https://github.com/thorvg/thorvg/issues/3054
2025-02-13 12:52:40 +09:00
Fabian Blatz
71bb4163ed common: fixed double-precision promotion compilation warnings
Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2025-02-12 20:23:34 +09:00
Hermet Park
eab9d68e67 api: remove SwCanvas::mempool()
We have improved the functionality to manage the memory pool safely,
by figuring out the current working threads. Users no longer need to
manually configure memory pool management, and the related APIs
have been removed.

API Removals:
- Result SwCanvas::mempool(MempoolPolicy policy)
- enum SwCanvas::MempoolPolicy

- Tvg_Result tvg_swcanvas_set_mempool(Tvg_Canvas* canvas,  Tvg_Mempool_Policy policy)
- enum Tvg_Mempool_Policy

issue: https://github.com/thorvg/thorvg/issues/3116
2025-02-12 13:19:12 +09:00
Mira Grudzinska
3ed357e17a renderer: fix trimmed stroke blinking
Bug introduced as part of a7e7bbc.
After recalculating begin and end to the 0-1 range, an extra
check was added to handle cases when begin is very close to end.
However, this was a bad approach since, even for very close values,
their relationship remains important. What should have been
done in the mentioned commit is properly handling  the case
begin == end, which was incorrectly treated as trimming from begin
to end. Instead, it should be handled as trimming from begin to
1.0 and from 0.0 to end.

@Issue: https://github.com/thorvg/thorvg/issues/3204
2025-02-12 11:36:57 +09:00
Hermet Park
cc4c18d6c6 renderer: revise the Shape rect/circle features
The path direction of shapes is now functional for path trimming.
Replace the main logic with Lottie's by default
to align the spec, migrate the original logic to svg loader side.

This revision helps to reduce the binary size by 2–3 KB for lottie loader.

API Modifications:

- Result Shape::appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0)
 -> Result Shape::appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0, bool cw = true)
- Result Shape::appendCircle(float cx, float cy, float rx, float ry)
 -> Result Shape::appendCircle(float cx, float cy, float rx, float ry, bool cw = true)
- TVG_API Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry)
 -> TVG_API Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry, bool cw)
- Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry)
 -> Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry, bool cw)

issue: https://github.com/thorvg/thorvg/issues/3179
2025-02-12 01:41:02 +09:00
Mira Grudzinska
5c950b783c renderer: handle edge cases for trimming with dashing
- In cases where the begin and end values of trimming did not
result in trimming (end - begin > 1), trimming was ignored.
However, when the stroke is also dashed, this case affects
the shift of the point where the first dash becomes visible.

- Trimming that passes through the curve's start point (like -0.1:0.1)
requires passing through the curve twice. The points obtained from
both passes must be joined - visible when dashing
Cases for simultaneous = true have been handled.

@Issue: https://github.com/thorvg/thorvg/issues/3192
2025-02-11 19:46:13 +09:00
Hermet Park
3c25623ee9 sw/gl/wg: ++threads safety
Considered global engine initialization and termination.
Engines could be used among multiple worker threads.
2025-02-11 19:03:50 +09:00
Hermet Park
ab950b6321 sw_engine: fixed a broken dropshadow
corrected a mismatched stride value of the
direct drawing target buffer.

issue: https://github.com/thorvg/thorvg/issues/3146
2025-02-07 23:46:40 +09:00
Mira Grudzinska
d5125bd839 common: add missing condition while trimming
The idea of introducing epsilon during trimming was to
eliminate the occurrence of short segments whose length
would be zero when higher computational accuracy was used.
By mistake, during the refactor of 8ed4c2f302,
one of the conditions was lost. Fixed.

@Issue: https://github.com/thorvg/thorvg/issues/3053
2025-02-07 12:43:38 +09:00
Mira Grudzinska
3a0e1eadae gl_engine: apply common trimming logic
The trim-related implementation has been removed
and replaced with the one available in common.
The trimPath get() fun changed to be internal.

@Issue: https://github.com/thorvg/thorvg/issues/2854
@Issue: https://github.com/thorvg/thorvg/issues/3053
2025-02-06 22:39:11 +09:00
Mira Grudzinska
cb8cadfbba wg_engine: apply common trimming logic
The trim-related implementation has been removed
and replaced with the one available in common.

@Issue: https://github.com/thorvg/thorvg/issues/2854
2025-02-06 22:39:11 +09:00
Mira Grudzinska
8ed4c2f302 sw_engine: move trimming logic to TrimPath
The trim handling from sw_engine has been removed.
Instead the common logic from the TrimPath structure
is used.
On the sw_engine side, the dashed outline is now
used for both: dashed and/or trimmed strokes.

@Issue: https://github.com/thorvg/thorvg/issues/2854
2025-02-06 22:39:11 +09:00
Mira Grudzinska
669d6dc580 common: introduce TrimPath struct
The first step towards unifying trimming across engines.

@Issue: https://github.com/thorvg/thorvg/issues/2854
2025-02-06 22:39:11 +09:00
Hermet Park
0dd0a3b45c common: neat code++
introduced common BBox structure
2025-02-06 15:40:32 +09:00
Sergii Liebodkin
857f1404e1 wg_engine: gaussian blur basic implementation
Introduce blur effect for webgpu renderer
Issue: https://github.com/thorvg/thorvg/issues/3054
2025-02-06 14:44:08 +09:00
Hermet Park
f4a2c922be lottie: minor optimization
use a reusable buffer for intermediate path generation.
2025-02-06 12:21:16 +09:00
Hermet Park
4edaf311c6 lottie: ++compact & neat code
introduced RenderPath to minimize the path parameters.
2025-02-05 19:55:12 +09:00
Mira Grudzinska
580019b64b gl_engine: fix color burn/dodge edge cases
Aligned with sw_engine implementation.
2025-02-03 15:06:39 +09:00
Mira Grudzinska
e7e168a28b wg_engine: fix color burn/dodge edge cases
Aligned with sw_engine implementation.
2025-02-03 15:06:39 +09:00
Mira Grudzinska
41f10b9702 sw_engine: fix color burn/dodge edge cases
Dodge d / (1 - s):
- handle d = 0 first to avoid 0/0 when s = 1
- for d != 0 and s = 1, the formula results in d/0 (infinity),
  which maps to 1 in the 0-1 range (or 255 in the 0-255 range)

Burn 1 - (1 - d) / s:
- handle d = 1 first to avoid 0/0 when s = 0
- for d != 1 and s = 0, the formula results in  1 - 0/0 -> 1 - inf = -inf
  Negative infinity in the 0-1 range corresponds to the minimum possible
  value, which is 0 (255 if we operate in 0-255 range).
2025-02-03 15:06:39 +09:00