Commit graph

43 commits

Author SHA1 Message Date
Mira Grudzinska
d71e11495d api: handling values <= 0 in strokeDash() api
The API allows now values <= 0 for dashes and gaps. Negative values
are treated as zero. The exception is when all provided values
are <= 0, in which case the dash is ignored.
This fixes the issue when dash = 0 was provided for strokes with round
or butt caps - the dot was not drawn, even though it should have been.

docs: the strokeDash API behavior's clarification for odd numbers
of values in dashPattern and refinement of the accepted values.
2025-05-26 20:03:46 +02:00
Hermet Park
afd780bfa9 wg_engine: set default file permissions 644 for consistency 2025-03-27 22:19:36 +09:00
Hermet Park
f1e9ce0460 common: refactoring the dash pattern
introdced the length to avoid duplicate among engines
2025-03-17 15:28:23 +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
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
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
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
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
Sergii Liebodkin
83eb89c5c9 wg_engine: fix segmentation fault on windows with SVG examples
Some SVG files fails during tesselation on windows.
Fixed
2025-01-24 20:48:08 +09:00
Hermet Park
07e73a9e6f common: code refactoring
use ARRAY_FOREACH() for neat code and
accessing the memory efficiently than normal indexing.
2025-01-15 18:03:46 +09:00
Hermet Park
a12accbc93 updated copyright 2025-01-03 14:32:31 +09:00
Sergii Liebodkin
93ebd388c7 wg_engine: implement dash offset
Introduced dash offset param for stroke dashes
Issue https://github.com/thorvg/thorvg/issues/2592
2024-11-05 12:05:49 +09:00
Sergii Liebodkin
505ebe9fe6 wg_engine: fix close command logic
On a close path command creates a new object started form the closed point
issue: https://github.com/thorvg/thorvg/pull/2923
2024-11-05 11:55:38 +09:00
Sergii Liebodkin
8b27efc99f wg_engine: fix cubic splines and circles tesselation quality
Tesseletion factor now depends on scale matix of the shape
2024-10-31 20:24:35 +07:00
Sergii Liebodkin
1d78835609 wg_engine: fix artifacts with zero length segmants on path
Fixed cases, if path have equals neighbors points on the path
2024-10-29 11:02:09 +09:00
Sergii Liebodkin
b851d98805 wg_engine: use tvg math constants
Use tvg pi constant instead of cmath. better mingw compiler support on windows
2024-10-22 16:26:55 +03:00
Hermet Park
1e9609c6f7 wg_engine: merged math functions with common
issue: https://github.com/thorvg/thorvg/issues/2313
2024-10-17 21:08:00 +09:00
Sergii Liebodkin
adebbcd4e2 wg_engine: fix miter qdge cases math 2024-10-16 00:52:07 +09:00
Sergii Liebodkin
40cff2d6f5 wg_engine: fix long path support
created a singe shared instance of stoke generator in heap, instead of stack. No performace impact
2024-10-16 00:52:07 +09:00
Sergii Liebodkin
b4238cd647 wg_engine: fix long path decoding crash
fixed crash with shape have too big path
2024-10-07 17:00:43 +09:00
Mira Grudzinska
dc754833bc wg_engine: prevent adding duplicate points while trimming
In cases where the distance between points is 0, further
processing of the points results in division by zero.
To avoid this check, we ensure that duplicate points are
not added during trimming.
2024-09-26 16:13:05 +09:00
Mira Grudzinska
2fc0aad2d1 wg_engine: fix stroke trimming
Fix cases when begin < 0 - this require handling the stroke
in two parts: begin - 0 and 0 - end.
Improve trimming for simultaneous=true.
2024-09-26 16:13:05 +09:00
Sergii Liebodkin
ee6a7214d4 wg_engine: geometry generating optimization
Streaming model for massive vertex and index creations: minimize memory allocations, range checks and other conditions
Reduce number of segments length calculations (sqrt) and bbox (min and max).
Update distances and bboxes on a whole buffer and only if necessary. For shapes without strokes compute distances not necessary at all. bbox can be updated only on the final stage of geometry workflow, but not on the each stage.
Using stack memory instead of heap. its more cache friendly and did not fragment memory, faster memory allocations (weak place of realization)
Using cache for points distances and whole path length. Updates only if necessary
Validation of geometry consistency executes only on the final stage of path life cicle. It more friendly for data streaming: no any conditions and branches.
Using binary search for strokes trimming
Pre-cached circles geometry for caps and joints
Refactored strokes elements generation functions. Code is more readable and modifiable in general. Can be easily fixed if some geometry issues will be finded
2024-09-25 17:09:29 +09:00
Sergii Liebodkin
79d4d64e4a wg_engine: fix strokes triangulation artifacts
Fixed detection of close vertices using comparison with epsilon and related artifacts in stencil buffer as extra pixels.
Fixed incorrect tessellation of curves using scaling.
2024-09-19 16:51:41 +09:00
Sergii Liebodkin
0787e46635 wg_engine: aabb based masking optimization
* used fragment shaders for mask applience instead of compute shaders
* less render targets swithing
* shape aabb based on transformed shape bbox
2024-08-20 16:23:31 +09:00
Hermet Park
5332876fe8 common: spec out TexMap
Spec out this incomplete experimental feature,
this is a still promising one, we will reintroduce
this officially after 1.0 release

size: -2kb

issue: https://github.com/thorvg/thorvg/issues/1372
2024-08-20 11:14:54 +09:00
Sergii Liebodkin
a4bbf14371 wg_engine: composition and blend optimization
* bind groups creation in real time removed - performance boost
* blend and composition shaders decomposed - performance boost
* shader modules and pipeline layouts generalized - less memory usage
* shared single stencil buffer used - less memory usage
* bind groups usage simplified
* general context API simplified and generalized
* all rendering logic moved into new composition class
* ready for hardware MSAA (in next steps)
* ready for direct mask applience (in next steps)
2024-08-09 14:30:17 +09:00
Hermet Park
44955b704e common/math: code refactoring
Replaced the prefix "math" with "tvg" namespace.
2024-07-10 00:21:02 +09:00
Mira Grudzinska
c36bc1a7a3 wg_engine: fix shapes closing
Shapes were incorrectly closed in certain cases -
the decision to close a shape or not should be based on
path commands rather than the number of points and
their distances from each other.
2024-06-27 13:54:32 +09:00
Sergii Liebodkin
7145c66b00 wg_engine: fix stroke mitter limit
Change the appliense of stroke mitter limit as in SVG spec

Before/After
2024-06-25 21:53:42 +09:00
Sergii Liebodkin
53de5f2ff7 wg_engine: fix incorrect geomatry
Fix computation of segments count for cubic curves.
Using screen coordinates of base points, instead of world coordinates
2024-06-20 19:03:42 +09:00
Sergii Liebodkin
c778f451b1 wg_engine: update mesh generations and render mechanics
[issues 1479: lottie](#1479)

- optimaze stroking algorithm by prevent vector normalizations
- using render meshes heaps to reduce webgpu instances re-creations
- using single instance of pilylines for standard operations such as trim and split
- "on-the-fly" strokes generations with dash pattern
- "on-the-fly" mesh objects generation in a process of path decoding
- merge strokes into single mesh by each shape
2024-04-18 18:54:02 +09:00
Sergii Liebodkin
90ce9d81bc wg_engine: added math and polyline structures for geometry generating optimizations
[issues 1479: lottie](#1479)
2024-04-18 18:54:02 +09:00
Sergii Liebodkin
7a9b23fe71 wg_engine: render buffers usage refactorings
[issues 1479: strokes](#1479)

- update buffers via memory mapping
- refactoring of winding fill rule computation
2024-03-28 10:49:29 +09:00
Sergii Liebodkin
bcaa5db269 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-03-25 12:34:24 +09:00
Sergii Liebodkin
1a28f837a8 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-03-16 15:11:42 +09:00
Sergii Liebodkin
45368c319e wg_engine: introduced composition ability
[issues 1479: Masking](#1479)

Supported composition methods:

    AlphaMask
    InvAlphaMask
    LumaMask
    InvLumaMask
    AddMask
    SubtractMask
    IntersectMask
    DifferenceMask

Usage example:

    //Solid Rectangle
    auto shape = tvg::Shape::gen();
    shape->appendRect(0, 0, 400, 400);
    shape->fill(0, 0, 255);

    //Mask
    auto mask = tvg::Shape::gen();
    mask->appendCircle(200, 200, 125, 125);
    mask->fill(255, 255, 255);        //AlphaMask RGB channels are unused.

    //Nested Mask
    auto nMask = tvg::Shape::gen();
    nMask->appendCircle(220, 220, 125, 125);
    nMask->fill(255, 255, 255);       //AlphaMask RGB channels are unused.

    mask->composite(std::move(nMask), tvg::CompositeMethod::AlphaMask);
    shape->composite(std::move(mask), tvg::CompositeMethod::AlphaMask);
    canvas->push(std::move(shape));

    //Star
    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(30);
    star->strokeJoin(tvg::StrokeJoin::Miter);
    star->strokeFill(255, 255, 255);

    //Mask3
    auto mask3 = tvg::Shape::gen();
    mask3->appendCircle(600, 200, 125, 125);
    mask3->fill(255, 255, 255);       //AlphaMask RGB channels are unused.
    mask3->opacity(200);
    star->composite(std::move(mask3), tvg::CompositeMethod::AlphaMask);
    if (canvas->push(std::move(star)) != tvg::Result::Success) return;
2024-01-15 17:33:59 +09:00
Jinny You
2c6c8d3b21
updated copyright date (#1866) 2023-12-28 10:43:25 +09:00
Sergii Liebodkin
8553044875 wg_engine: shape bbox based rendering (optimization)
Before the current changes, all surfaces were painted using a full-screen overlay, no matter how large the object was rendered. This approach is redundant and required reorganization. At the moment, all objects are rendered using an overlay equal to the box of the object itself, which reduces the cost of filling the surface.
Also surfaces and images were divided into different entities, which reduces the pressure on memory.
Also geometry data for rendering and geometry data for calculations in system memory were logically separated.
2023-12-23 13:37:56 +09:00
Hermet Park
9d06308207 wg_engine: apply tvg coding style. 2023-12-18 23:34:13 +09:00
Sergii Liebodkin
a3adbef2c2 Added ability to draw solid strokes
[issues 1479: Shape](https://github.com/thorvg/thorvg/issues/1479)

In order to build you need third party libraries. Before you start please read this: [LearnWebGPU](https://eliemichel.github.io/LearnWebGPU/getting-started/hello-webgpu.html)

Usage example:

    // init glfw
    glfwInit();

    // create a windowed mode window and its opengl context
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    GLFWwindow* window = glfwCreateWindow(800, 800, "WebGPU base app", nullptr, nullptr);

    // get window size
    int width{}, height{};
    glfwGetWindowSize(window, &width, &height);

    // init engine webgpu
    tvg::Initializer::init(tvg::CanvasEngine::Wg, 0);

    // create wg canvas
    auto canvasWg = tvg::WgCanvas::gen();
    canvas_wg->target(glfwGetWin32Window(window), width, height);

    //Test for Stroke Dash for Arc, Circle, Rect
    auto shape = tvg::Shape::gen();
    shape->appendArc(70, 600, 160, 10, 30, true);
    shape->appendCircle(70, 700, 20, 60);
    shape->appendRect(130, 710, 100, 40);
    shape->strokeFill(255, 0, 0);
    shape->strokeWidth(5);
    shape->strokeJoin(tvg::StrokeJoin::Round);
    shape->strokeCap(tvg::StrokeCap::Round);
    if (canvas_wg->push(std::move(shape)) != tvg::Result::Success) return;

    while (!glfwWindowShouldClose(window)) {
        // webgpu
        canvas_wg->draw();
        canvas_wg->sync();

        // pull events
        glfwPollEvents();
    }

    // terminate engine and window
    tvg::Initializer::term(tvg::CanvasEngine::Wg);
    glfwDestroyWindow(window);
    glfwTerminate();
2023-11-06 20:35:26 +09:00