Commit graph

194 commits

Author SHA1 Message Date
Mira Grudzinska
f87601db58 sw_engine: fix max length of trimmed strokes
The error was visible when multiple shapes were
simultaneously trimmed. The length of a single
shape was zeroed out only in selected cases,
which caused accumulation that could lead to
incorrect extension of the variable determining
the maximum length.

@issue: https://github.com/thorvg/thorvg/issues/2173
2024-04-19 11:00:29 +09:00
Hermet Park
8502b41b99 common: code refactoring
introduced mathDeg2Rad() and mathRad2Deg() for a common implementation.
2024-04-19 11:00:29 +09:00
Hermet Park
4319d38de8 lottie: code refactoring.
keep the coding style.
2024-04-19 11:00:29 +09:00
Lucas Niu
5992a28e47 lottie: Support the Animation Segment(Marker)
A single animation might have a desinated markers with naming: 0 ~ 0.5 (sector A), 0.5 ~ 1.0  (sector B). Selecting one of them using a marker name(sector A) and could play only that part with animation controllers.

usage:
- `animation->segment("sectionA") // Named segment(Marker)`
- `auto cnt = animation->markerCnt()`
- `auto name = animation->markers(index)`
- `animation->segment(0, 0.5) // Segment`
- `animation->segment(&begin, &end)`

Co-authored-by: Jinny You <jinny@lottiefiles.com>
2024-04-19 11:00:29 +09:00
150c2c35a8 sw_engine : type cast compile error 2024-04-19 11:00:29 +09:00
7af258ddb7 sw_engine: Implement AVX and NEON optimizations for RasterGrayscale 2024-04-19 11:00:29 +09:00
EunSik Jeong
6d3ea78d96 sw_engine/neon : Fix compilation error 2024-04-07 15:15:59 +09:00
Hermet Park
710d1f99ae renderer/loader: fix a font loader memory leak 2024-04-07 15:15:59 +09:00
Sergii Liebodkin
366c1be6bd wg_engine: vertex, index and unifroms buffers, render objects caching
[issues 1479: lottie](#1479)

Vertex, Index and uniform buffers now updates instead of recreate.
Implemented pools form mesh objects and render shapes data

it increase performance in 30-40% in massive animations scenes
2024-04-07 15:15:59 +09:00
Hermet Park
4746b2cf7b gl_engine: hotfix for the main surface drawing issue.
GL might need to generate a default target FBO
when the given target ID indicates the main surface.

However, users may want to draw visuals directly onto the main surface.

This policy must be reviewed thoroughly.
2024-04-07 15:15:59 +09:00
RuiwenTang
cde17a4fc6 gl_engine: change all shader output premultiplied alpha color 2024-04-07 15:15:59 +09:00
Hermet Park
efc7199e51 renderer/loader: ensure unique scene instances for each Lottie loader
The Lottie loader now utilizes an individual scene instance per loader.
This guarantees that each instance retains a unique frame number,
essential for maintaining the integrity of animation states.

As a result, sharing loaders between Lottie animations is prohibited
to uphold frame context isolation.

This may be subject to optimization review in the future.
2024-04-06 12:48:30 +09:00
Hermet Park
34bb27bfc9 renderer/saver: enhanced safety
enhanced safety by taking into account the object reference counting.
2024-04-06 12:48:30 +09:00
Hermet Park
1632ad9ee5 lottie: removed unused code.
Currently, thorvg has no plan to support dotlottie format.
2024-04-06 12:48:30 +09:00
Sergii Liebodkin
7d8a261a83 wg_engine: Blending optimization
[issues 1479: lottie](#1479)

To optimize bled operations hardware pipeline blend stage are used for some blend methods:
	BlendMethod::SrcOver
    BlendMethod::Normal
    BlendMethod::Add
    BlendMethod::Multiply
    BlendMethod::Darken
    BlendMethod::Lighten

Other types compute shaders used
2024-04-06 12:48:30 +09:00
Hermet Park
043b14d681 sw_engine/stroke: hotfix the memory access violation
ensure that the number of contour/close data is properly paired.

issue: https://github.com/thorvg/thorvg/issues/2129
2024-04-06 12:48:30 +09:00
Hermet Park
6688f03396 sw_engine: revised the trimpath dash line logic
Support the TrimPath modes (individual/simultaneous)
internally in the engine to handle them efficiently.
2024-04-06 12:48:30 +09:00
Sergii Liebodkin
4f204b5e13 wg_engine: Lottie extensions
[issues 1479: LottieExtensions](#1479)

LottieExtensions example supports
Supports multiple color stops for gradient fill (redial and linear)
2024-04-06 12:48:30 +09:00
Hermet Park
e4f7fffacc sw_engine: hotfix a regression bug of line drawing.
fixed one more corner case problem, just observed.
it's a side effect by 925009c4a5
2024-04-06 12:48:30 +09:00
Sergii Liebodkin
fafec9fa46 wg_engine: render buffers usage refactorings
[issues 1479: strokes](#1479)

- update buffers via memory mapping
- refactoring of winding fill rule computation
2024-04-06 12:08:23 +09:00
Hermet Park
68e4d35f7b sw_engine: stabilize the contour composition logic.
there has been a logical error that breaks the contour
composition context. This fixes it.

issue: https://github.com/thorvg/thorvg/issues/2093
2024-04-06 12:08:23 +09:00
Hermet Park
051969c61c sw_engine: rectify consecutive line drawings.
There are differences in behavior compared to the SVG spec,
especially when consecutive line drawings occur without a moveTo command
following a closePath command.

Actually, thorvg didn't care the behavior in that scenario,
this update ensures the scenario is handled correctly
to align with the SVG specification.

issue: https://github.com/thorvg/thorvg/issues/1487
2024-04-06 12:08:23 +09:00
Hermet Park
2b2d41221f renderer: Fix a crash issue related to the clipper
Fixed a crash that occurred when a given clipper had no data.
Properly handle this exceptional case to prevent the crash.

issue: https://github.com/thorvg/thorvg/issues/2083
2024-04-06 12:08:23 +09:00
Sergii Liebodkin
98b30c72ef wg_engine: stroke trim
[issues 1479: strokes](#1479)

Introduced stroke trim setting

left: (0, 0.95)
middle: (0.15, 1)
right: (0.15, 0.95)
2024-04-06 12:08:23 +09:00
Vincent Torri
2f196b514f [common] code clean up
use fmodf() instead of fmod()
2024-04-06 12:08:23 +09:00
vtorri
3640724b99 [common] code clean up
use MATH_PI and MATH_PI2 instead of M_PI and M_PI_2
2024-04-06 12:08:23 +09:00
RuiwenTang
ed146ed162 gl_engine: make stencil task support other advance logical
* Support rendering Gradient in path Stroke mode
* Fix GlStencilCoverTask not support even-odd fill rule
* Make GlStencilCoverTask can discard overlapped area during stroke
  rendering
2024-04-06 12:08:22 +09:00
Sergii Liebodkin
4d2440cc70 wg_engine: stroke first
[issues 1479: strokes](#1479)

Introduced order setting

    auto star = tvg::Shape::gen();
    star->fill(80, 80, 80);
    star->moveTo(599, 34);
    star->lineTo(653, 143);
    star->lineTo(774, 160);
    star->lineTo(687, 244);
    star->lineTo(707, 365);
    star->lineTo(599, 309);
    star->lineTo(497, 365);
    star->lineTo(512, 245);
    star->lineTo(426, 161);
    star->lineTo(546, 143);
    star->close();
    star->strokeWidth(10);
    star->strokeJoin(tvg::StrokeJoin::Round);
    star->strokeFill(255, 255, 255);
    star->order(true); // stroke first
    if (canvas->push(std::move(star)) != tvg::Result::Success) return;
2024-04-06 12:08:22 +09:00
Hermet Park
25645e087a renderer: ensure paints retain composition context
This commit addresses an issue where paints lost their
composition context when drawings occurred without any updates.

Now, paints will consistently retain the composition context,
ensuring accurate rendering.

Issue: https://github.com/thorvg/thorvg/issues/2058
2024-04-06 12:08:22 +09:00
Sergii Liebodkin
203cd4cd60 wg_engine: winding fill rule
[issues 1479: FillRule](#1479)

Introduced fill rule winding
This rule makes sense only if path have some self intersections.
In all other cases shapes are filled by even-odd behavor.
2024-04-06 12:08:21 +09:00
Hermet Park
5d10e514d7 renderer/gl_engine: Refine GlCanvas Interface
Refactor the GlCanvas::target() interface to allow
passing the drawing target ID from the user side.

Previously, it performed the drawing on the currently set FBO target.

Beta API change:

Result GlCanvas::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h)
-> Result GlCanvas::target(int32_t id, uint32_t w, uint32_t h)
2024-04-06 12:08:21 +09:00
RuiwenTang
faff16e7d4 gl_engine: enable msaa resolve in GLRenderPass
* use GLRenderBuffer in color and stencil attachment, also use x4 sample
  count by default.
* add msaa resolve logical at the end of a ComposeTask, so the normal
  color texture can get the final rendering result.
2024-04-06 12:08:21 +09:00
Hermet Park
946d934827 png: corrected a wrong premultiplied option.
this is a regresion bug by 886b6b365b
2024-04-06 12:08:21 +09:00
Lorcán Mc Donagh
612b52a3e3 sw_engine: fix radial gradient when focal point is outside circle on ARM/Apple Silicon
sw_engine: radial gradient
[issues 2014: radial gradient](#2014)

Radial gradient results in a corrupted image when the focal point is outside the circle on Apple Silicon.
This happens because some compilers use FMA to optimize the a = dr² - dx² - dy² calculation,
which cause loss of precision.

We rely on temporary variables to prevent FMA.
We could also use compiler specific float contraction control pragmas to avoid this if this doesn't work in the future
2024-04-06 12:08:21 +09:00
Sergii Liebodkin
80d454e2d6 wg_engine: fill spread
[issues 1479: LinearGradient, RadialGradient](#1479)

Introduced fill spreads: Pad, Reflect, Repeat

Pad:

Reflect:

Repeat:
2024-04-06 12:08:21 +09:00
RuiwenTang
5bf82bf142 gl_engine: remove unused alpha attribute
Since we choose MSAA, no need to calculate edge alpha during fragment
stage. So this commit removed the alpha attribute and related code:

* Remove the alpha attribute in vertex data.
* Change position type from `vec3` to `vec2` in all shader code.
* Remove alhpa multiplication in all fragment shaders
2024-04-06 12:08:21 +09:00
Hermet Park
fa393f1c52 renderer/loader: revamping the caching mechanism.
The previous loader cache mechanism encountered a problem
when the user changed the content of the cached data.

In such cases, a new request would not be processed
because the renderer would use the previously cached content.

So far, the TVG cache mechanism utilizes a pointer hash key
for the fastest hashing mechanism available.
One limitation is that it assumes the address is unique for the data.

To resolve this, we modified the caching policy.
Now, the renderer will not cache copied data;
it will only cache the given data when it is deemed shareable.

issue: https://github.com/thorvg/thorvg/issues/2020
2024-04-06 12:08:21 +09:00
Sergii Liebodkin
850e6ef466 wg_engine: antialiasing
[issues 1479: antialiasing](#1479)

Anti-aliasing implementation
Implements antialiasing as a post process on cimpute shaders and original render target with scale of 2x.
Can be modified as an external settings
2024-04-06 12:08:21 +09:00
RuiwenTang
4459d23f28 gl_engine: use stencil and cover tessellator by default
Since we choose multisample antialiasing, use stencil then cover to
render polygon can get better performance.
Also the code is much easier to understand.
2024-04-06 12:08:21 +09:00
Mira Grudzinska
203d892cbd sw_engine: fix a regression bug
After introducing the length measurement
of approximate and exact Bezier curves in
a8c0030d80
the calculation of the outline length still
used the approximate functions, while further
calculations took the exact value into account.
This discrepancy led to the creation of artifacts.

@Issue: https://github.com/thorvg/thorvg/issues/2021
2024-04-06 12:08:21 +09:00
Hermet Park
604c4dc0b0 sw_engine: fix a regression bug.
stroke line drawing has been broken at a certain case,
this reverts a part of change from the old optimization:

d81f5d29fb

note that this change wouldn't affect any performance.

issue: https://github.com/thorvg/thorvg/issues/2015
2024-04-06 12:08:21 +09:00
Hermet Park
3ed8309a11 lottie: code refactoring.
Maintains compact lines of code and functions without altering logic,
consistently prioritizing simplicity in software complexity metrics.
2024-04-06 12:08:21 +09:00
Hermet Park
56c4859138 saver: ++robustness
do not delete the given picture if the reference counting is
more than 0.
2024-04-06 12:08:21 +09:00
Mira Grudzinska
115c0242c3 common: Changing the rounded rect starting point
According to the SVG standard, drawing a rectangle
starts at (x+rx, y) point. Till now it was (x+w, y+ry).
The difference was visible only for dashed strokes.
2024-04-06 12:08:21 +09:00
Mira Grudzinska
1b3505e74f common: Changing the circle/ellipse starting point
According to the SVG standard, drawing a circle/ellipse
should start at the '3 o'clock' position and proceed
in a clock-wise direction. Until now, this point was
set at '12 o'clock'.
The differences in the outcome were visible for dashed
strokes.

issue: https://github.com/thorvg/thorvg/issues/1686
2024-04-06 12:08:21 +09:00
Jinny You
c8a7e5b02e lottie: Introduce the LottieAnimation class
This class extends the Animation and serves advanced Lottie features.
It's designed to separately have Lottie Animation's unique specs.

For now, this will have Slot overriding feature,
you can include <thorvg_lottie.h> for its extensive features.

@APIs:
- Result LottieAnimation::override(const char* slotJson) noexcept;
- static std::unique_ptr<LottieAnimation> LottieAnimation::gen() noexcept;

@Issue: https://github.com/thorvg/thorvg/issues/1808
2024-04-06 12:08:21 +09:00
Hermet Park
2087db7ebf gl_engine: fix a compile warnings, errors.
../src/renderer/gl_engine/tvgGlRenderPass.cpp:35:34: warning: macro expands to multiple statements [-Wmultistatement-macros]
   35 |     if (mColorTex != 0) GL_CHECK(glDeleteTextures(1, &mColorTex));
      |                                  ^~~~~~~~~~~~~~~~
../src/renderer/gl_engine/tvgGlCommon.h:33:9: note: in definition of macro ‘GL_CHECK’
   33 |         x; \
      |         ^
2024-04-06 12:08:21 +09:00
Hermet Park
c08c11db7d common: code refactoring
refactor common code to consolidate Bezier and line
function implementations into a single location.
2024-04-06 12:08:21 +09:00
Hermet Park
71c636e33c Revert "Revert "sw_engine: Increasing accuracy for dashed curves""
This reverts commit e49f9125b2.
2024-04-06 12:08:21 +09:00
Hermet Park
c01c8338d7 Revert "sw_engine: Increasing accuracy for dashed curves"
This reverts commit a8c0030d80.
2024-04-06 12:08:21 +09:00