Commit graph

682 commits

Author SHA1 Message Date
Hermet Park
d2d93792df wg_engine: corrected ColorDodge, ColorBurn equation
issue: https://github.com/thorvg/thorvg/issues/3072
2025-01-08 13:54:09 +09:00
Hermet Park
084c7ff214 sw_engine: corrected blendings
corrected wrong ColorDodge, ColorBurn, Exclusion, SoftLight blendings

issue: https://github.com/thorvg/thorvg/issues/3072
2025-01-08 13:27:58 +09:00
Hermet Park
a12accbc93 updated copyright 2025-01-03 14:32:31 +09:00
Mira Grudzinska
acc614ab2f sw_engine: prevent warning
Remove unused version of SUBPIXELS().
2025-01-03 10:24:46 +09:00
Hermet Park
2fb925a2d7 sw_engine: corrected the rle cell building
Properly build the cell cover value
when a new cell value is just overlapped.

This fixes certain weird visual artifacts at a corner case.

issue: https://github.com/thorvg/thorvg/issues/2929
2025-01-02 17:49:28 +09:00
Hermet Park
47524300bb sw_engine: minor code clean up 2025-01-02 17:49:28 +09:00
RuiwenTang
3c6d686795 gl_engine: fix fbo and texture leak
GlRenderTarget contains framebuffer and render target objects,
these GPU resources need to be released before reusing the structure and calling init with the new size.
2024-12-31 16:25:11 +09:00
Hermet Park
76203c3dbb gl_engine: ensure the gl context switching
This only covers emscripten environment,
need to cover other system.

issue: #3023

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
2024-12-31 12:07:52 +09:00
Jinny You
596de01b12 gl_engine: revise target API for context managing
Issue: #3024
2024-12-31 12:07:52 +09:00
Hermet Park
1cbc11cadd renderer: revamped engine interfaces
Introduced updated pre/post calls
for proper preparation of the drawing process.
2024-12-31 12:07:52 +09:00
Hermet Park
ccf5a8158f gl_engine: ++binary optimization
- removed unique_ptr, shared_ptr
- replaced std::vector with tvg::Array
- reduced binary size by -10kb
2024-12-30 22:24:53 +09:00
Mira Grudzinska
82dc41479e sw_engine: fix clipping
A shape with both fill and stroke, where clipping left
only a fragment of one (either fill or stroke), was not
rendered at all. Now fixed.
2024-12-30 12:01:24 +09:00
Hermet Park
0e9bc74603 api: renamed FillRule::Winding to NonZero
aligned the name with the web standard.
2024-12-27 21:16:27 +09:00
Marcin Baszczewski
f2883a31da gl_engine: Fix for rendering short paths
Ensure they do not terminate prematurely for paths
with a step of 0 or exceptionally small values
when a valid stroke-width is present.

In my opinion, the optimal approach was to separate vertex generation
into dedicated methods: strokeRoundPoint and strokeSquarePoint.

My update supports two different stroke-cap styles.
I have also tested it with various files (JSON, SVG)
as well as a small example application similar
to the one included in the previous pull request (#3066).

issue: https://github.com/thorvg/thorvg/issues/3065
2024-12-27 21:11:38 +09:00
Hermet Park
5e102dfd25 API: enable users to use an accessor to traverse Scene
remove the restriction of targeting only Picture.
now, any kind of paints can be adaptable here.
2024-12-26 14:20:37 +09:00
Hermet Park
041ab1117b renderer: fixed a memory leak
This issue only valid on the main branch.

regression by 1806b32971

issue: https://github.com/thorvg/thorvg/issues/3070
2024-12-24 10:44:57 +09:00
Marcin Baszczewski
37c7e1efa6 Fix for Rendering Short Paths. 2024-12-23 18:56:56 +09:00
Hermet Park
285d1427ad common: refactored the scene effect tint
Pre-convert the data type from float to uint8_t
2024-12-20 12:10:11 +09:00
Hermet Park
324bff30d1 sw_engine: allow the stroke clipper
clipping with a stroke is useful for various visual effects.
TVG can support this approach as it offers better efficiency
compared to alpha masking.

If a valid stroke is defined in the clipper shape,
the renderer prioritizes clipping with the stroke over
 the shape's fill.

issue: https://github.com/thorvg/thorvg/issues/3063
2024-12-19 20:37:28 +09:00
Mira Grudzinska
0f253aac27
renderer: fix dash offset
The dash offset value was not copied while
'=' opetator was applied.

@Issue: https://github.com/thorvg/thorvg/issues/1643
2024-12-19 11:40:20 +09:00
Hermet Park
e9fb478471 renderer: support Trintone SceneEffect
The Tritone effect maps the scene's shadows, midtones, and highlights
to three specific colors, allowing for more complex and artistic color grading.

Applied Tritone Formula:
if (L < 0.5) Result = (1 - 2L) * Shadow + 2L * Midtone
else Result = (1 - 2(L - 0.5)) * Midtone + (2(L - 0.5)) * Highlight
Where the L is Luminance.

issue: https://github.com/thorvg/thorvg/issues/2718
2024-12-17 17:54:57 +09:00
Hermet Park
b778f98206 common: support Tint SceneEffect
The Tint effect in ThorVG is used to modify the overall color tone of a scene.
It works by blending a specified tint color with the existing colors of the scene.
This effect is useful for color grading, mood changes, or applying thematic filters
to vector graphics and animations.

Applied the equation is:
Result = (1 - L) * Black + L * White, where the L is Luminance.

issue: https://github.com/thorvg/thorvg/issues/2718
2024-12-17 12:16:40 +09:00
Hermet Park
1806b32971 common: optimization pImpl data structures
ThorVG pImpl idiom caused internal data to be scattered
across hierarchical classes. This refactoring consolidates
the data by inheriting pImpl internally, reducing memory
allocation counts and eliminating unnecessary strategy methods.
2024-12-14 12:24:57 +09:00
Hermet Park
01f4d6304a sw_engine: fixed a rendering bug when the invalid clipper is applied.
Shapes with boundaries outside the rendering area are ignored as non-visible.
The issue arises when such a shape serves as a clipper.
The expected behavior is for the entire clipee to be cut out,
but previously, the clipee remained fully visible as if no clip was applied.

The fix identifies these clippers and skips rendering clipees.

Please note that we can skip rendering at the Paint update stage
if the clipper's viewport is outside the canvas.
This optimization can improve performance, but only for this specific case.
The downside of the approach is that it disrupts multi-processing for clipper updates.
As a result, that approach was discarded.

issue: https://github.com/thorvg/thorvg/issues/3003
issue: https://github.com/thorvg/thorvg/issues/2684

Co-Authored-By: Mira Grudzinska <mira@lottiefiles.com>
2024-12-14 01:30:56 +09:00
Mira Grudzinska
e395961f3b sw_engine: remove redundant code
The only scenarios where 'check valid region' and
'check boundary' occur are when mathUpdateOutlineBBox()
returns true. This, in turn, happens only if mathClipBBox()
returns true. If that is the case, it means that just
before this return, exactly the same checks were performed.
2024-12-14 01:17:21 +09:00
RuiwenTang
b1b7a78dd7 gl_engine: Fix gradient color not correct when shape has opacity
When rendering gradient color, needs to take opacity value into
consider.
2024-12-13 23:44:03 +09:00
Mira Grudzinska
2e84315857 sw_engine: fix grad calculations
Added a term that was omitted during one of the refactorings.
2024-12-13 11:23:10 +09:00
Hermet Park
70fe8f2f95 sw_engine: --compiler warnings on MSYS2
comparison of integer expressions of different signedness: 'uint32_t' {aka 'unsigned int'} and 'long int' [-Wsign-compare]
2024-12-13 00:45:24 +09:00
Hermet Park
d6c80f538c renderer: add a new scene effect type - Fill
Fill is used for overriding the scene content color
with a given fill information. It's yet an Experimental API.

issue: https://github.com/thorvg/thorvg/issues/2718
2024-12-12 18:50:33 +09:00
RuiwenTang
7e7747d645 gl_engine: Fix calculation error in path triming
Basically rewrite the PathTrim code, correct the Line and Bezier split
function calling.
Also the trim situation where start is greater than end can be handled correctly.
2024-12-11 12:23:02 +09:00
Sergii Liebodkin
482bd50157 wg_engine: Improve resizing mechanics
In case of resizing recreate only render targets, but not all compositor handles
2024-12-11 12:08:47 +09:00
Hermet Park
6761c5c2a0 API: Replace the Canvas::clear() API with Canvas::remove() & draw()
Added a `clear` parameter to Canvas::draw(), allowing users to decide
whether to clear the target buffer before drawing.

To remove the paints from a canvas, please use Canvas::remove()

C++ API Removals:
- Result Canvas::clear(bool paints, bool buffer)

C++ API Modifications:
- Result Canvas::draw()
 -> Result Canvas::draw(bool clear)

C API Removals:
- Tvg_Result tvg_canvas_clear(bool paints, bool buffer)

C API Modifications:
- Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas)
 -> Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas, bool clear)

issue: https://github.com/thorvg/thorvg/issues/1372
2024-12-10 11:59:46 +09:00
Hermet Park
445000ba66 common: improve the rendering pipeline
enhanced the rendering composition target to better support features such as
alpha blending, blending, masking, post effects, and more.
This allows rasterizers to prepare the composition context with more precise control.

Additionally, resolved a crash in the software engine's post-effect process
caused by a buffer size mismatch during XY buffer flipping.

issue: https://github.com/thorvg/thorvg/issues/3009
issue: https://github.com/thorvg/thorvg/issues/2984
2024-12-04 22:31:37 +09:00
Hermet Park
0ebbc614be api: 1.0 specification revision
- Enhanced Scene management to provide users with more control.
- Scenes now support adding specific scenes at defined positions and removing them as needed.
- Ensure safe access to Canvas, Scene paints() by adding const specifiers.
- Removed virtual specifier for the canvas primitive apis.
- Introduced a nested scene in the canvas to remove logic duplication.

C++ API Modification:
- Result Scene::push(Paint* paint)
 -> Result Scene::push(Paint* target, Paint* at = nullptr)
- Result Scene::clear(bool free = true)
 -> Result Scene::remove(Paint* paint = nullptr)
- Result Canvas::push(Paint* paint)
 -> Result Canvas::push(Paint* target, Paint* at = nullptr)
- list<Paint*>& Scene::paints()
 -> const list<Paint*>& Scene::paints() const
- list<Paint*>& Canvas::paints()
 -> const list<Paint*>& Canvas::paints() const

C++ API Addition:
- Result Canvas::remove(Paint* paint = nullptr);

C API Modifications:
- Tvg_Result tvg_scene_clear(Tvg_Paint* scene, bool free)
 -> Tvg_Result tvg_scene_remove(Tvg_Paint* scene, Tvg_Paint* paint)

C API Addition:
- Tvg_Result tvg_scene_push_at(Tvg_Paint* scene, Tvg_Paint* target, Tvg_Paint* at)
- Tvg_Result tvg_canvas_push_at(Tvg_Canvas* canvas, Tvg_Paint* target, Tvg_Paint* at)
- Tvg_Result tvg_canvas_remove(Tvg_Canvas* canvas, Tvg_Paint* paint)

issue: https://github.com/thorvg/thorvg/issues/2957
issue: https://github.com/thorvg/thorvg/issues/1372
2024-12-04 11:44:58 +09:00
Sergii Liebodkin
07fbe56162 wg_engine: fixed scene blending equation and clear color rule
Issue: https://github.com/thorvg/thorvg/issues/2998
2024-12-04 11:39:57 +09:00
Dragoș Tiselice
8a5710b3c5 sw_engine: replaced longjmp with returns
Since longjmp is not yet fully supported on Wasm (emscripten uses
JS to make the jumps and requires slow jumps), but also because
longjmp is hard to reason about, this patch replaces it with
return values. The logic stays exactly the same.
2024-12-03 20:27:41 +09:00
Hermet Park
f33b63abad common: inlist code refactoring
introduced INLIST_FOREACH() / INLIST_SAFE_FOREACH()
for common implementation
2024-12-02 15:15:35 +09:00
Hermet Park
1422c4ca5f renderer: make the file io configurable
certain systems, may not support file I/O operations.
ThorVG should provide users with an option to configure
builds according to their requirements.

This ensures that file I/O calls are avoided,
preventing potential crashes.

Please use the meson '-Dfile=true/false' option for this.

Please note that "THORVG_FILE_IO_SUPPORT" might be expected
for your thorvg manual build.

issue: https://github.com/thorvg/thorvg/issues/3008
2024-12-02 11:50:59 +09:00
RuiwenTang
08e88c8df1 gl_engine: Fix the wrong bounds cause composition not correct
The bounds should allow negative origins, only zero width or height bounds needs discard.
2024-11-29 19:32:15 +09:00
Sergii Liebodkin
18db3ab1fd wg_engine: refactor pipeline creation
Pipeline creation workflow redesigned. Make code more compact
No any public interfaces changed
2024-11-29 19:08:28 +09:00
Sergii Liebodkin
4a38a4d360 wg_engine: simplify shader types
Use universal vec4f type for blend settings and color to pass data as shader parameter
2024-11-29 19:01:47 +09:00
Sergii Liebodkin
163640b3e5 wg_engine: apply texture formats on creation (refactoring)
Apply texture color space on texture creation, instead of shader side
2024-11-29 18:57:57 +09:00
Sergii Liebodkin
13b976ee80 wg_engine: support resizing
Added abillity to resize target (surface)
In case of resizing only render targets handles recreated
Issue: https://github.com/thorvg/thorvg/issues/2985
2024-11-29 18:48:01 +09:00
Sergii Liebodkin
cf05128a96 wg_engine: revision of device creation policy
make valid device and instance as mandatory paramter for webgpu renderer
2024-11-29 18:48:01 +09:00
Sergii Liebodkin
77201546dd wg_engine: separate pipelines ans bind group layouts (refactoring)
The main reason of refactoring is to separate bind group sets and pipelines, and change owning of pipelines to compositor
2024-11-27 11:31:35 +02:00
RuiwenTang
1a766ec00e gl_engine: correct the stroke alpha calculation
The wrong matrix scale factor value caused the stroke alpha to be zero
when the matrix contains rotation.
2024-11-27 12:37:47 +09:00
Hermet Park
968e438d25 portability: fixed a compile error on msys2 2024-11-26 22:00:08 +09:00
RuiwenTang
af5e0e3ef9 gl_engine: support cross compile GL backend into WASM
Support cross compile the GL backend code into WASM.
The code needs WebGL 2.0 API so, the compile flags contains `MAX_WEBGL_VERSION` and `FULL_ES3`
Also add binding code to initialize the WebGL context and GLCanvas.
2024-11-26 17:12:49 +09:00
Hermet Park
0f409a654a renderer: reserved colorspace option in target api
API Modification:
- Result WgCanvas::target(void* device, void* instance, void* target, uint32_t w, uint32_t h, int type = 0)
 -> Result WgCanvas::target(void* device, void* instance, void* target, uint32_t w, uint32_t h, ColorSpace cs, int type = 0)
- Tvg_Result tvg_wgcanvas_set_target(Tvg_Canvas* canvas, void* device, void* instance, void* target, uint32_t w, uint32_t h, int type)
 -> Tvg_Result tvg_wgcanvas_set_target(Tvg_Canvas* canvas, void* device, void* instance, void* target, uint32_t w, uint32_t h, Tvg_Colorspace cs, int type)
2024-11-26 12:04:30 +09:00
Sergii Liebodkin
6c452c1fd3 wg_engine: fix resources disposing on context destroy
We must to dispose all paints render handles before the context will be destroyed to prevent handles leak
2024-11-26 11:34:42 +09:00