Commit graph

96 commits

Author SHA1 Message Date
Hermet Park
24711e485c infra: renames the source folders
lib -> renderer
bin -> tools
utils -> common
2023-08-28 13:11:24 +09:00
Hermet Park
f2e755cdd5 sw_engine: fix dash offset bug.
The latest offset feature has a missing starting point of the cubic bezier.
This fix addresses the issue.
2023-08-24 00:57:26 +09:00
Hermet Park
001c1c06fc sw_engine: --compiler warning
../src/lib/sw_engine/tvgSwShape.cpp:232:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  232 |         for (auto i = 0; i < dash.cnt; ++i) patternLength += pattern[i];
      |                          ~~^~~~~~~~~~
../src/lib/sw_engine/tvgSwShape.cpp:239:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘uint32_t’ {aka ‘unsigned int’} [-Wsign-compare]
  239 |         for (auto i = 0; i < dash.cnt * (1 + isOdd); ++i, ++offIdx) {
2023-08-23 12:47:10 +09:00
Mira Grudzinska
478e45f9f3 common: stroke dash offset support added
The feature is supported also in the svg loader.

@Issue: https://github.com/thorvg/thorvg/issues/1591
2023-08-23 12:40:27 +09:00
Hermet Park
a1f0b06f41 common array: revise code.
maintain code with an optimial size.
2023-07-25 19:57:12 +09:00
Hermet Park
cf09ba5abd common sw_engine: code refactoring
Even though this enlarges the binary size by 300bytes,
use the array instead of individual implementations for better maintenance.
2023-07-17 20:14:58 +09:00
Hermet Park
1c824ed191 common: code refactoring
Replace individual array implementation with a common feature.
2023-07-03 14:20:05 +09:00
Hermet Park
814d87626c common engines: optimizing data packing for compactness.
Standardized the opacity data type to use 1 byte
across all instances to maintain consistency and reduce scattered usage.
2023-06-15 10:35:34 +09:00
Hermet Park
919c90a97e common shape: code refactoring & data optimization.
re-design the shape data structure so that render backends
are able to access them directly.

This also let us remove tvgShape member data from the Shape::Impl.

To achieve this, migrate shape/stroke/path
from the canvas interface to the render interface.
2023-02-05 12:06:09 +09:00
Hermet Park
9b3c34c3b1 updated copyright. 2023-01-14 13:48:11 +09:00
mgrudzinska
0925aa84a5 sw_engine: fixing oveflow
An overflow occurred for big shapes with a dashed stroke,
since a contour end points were stored as the uint16 type
(instead of the uint32 type).
2022-03-23 16:14:51 +09:00
Hermet Park
f0141e63de updated copyright date. 2022-01-12 14:08:48 +09:00
JunsuChoi
791275c30a sw_engine SwShape: Fix coding style 2021-12-15 15:19:19 +09:00
JunsuChoi
c326b6ac3e sw_engine SwShape: Prevent null access
strokeOutline returned strokeExportOutline() is the address of mpool->strokeOutline[idx].
Assuming this value is null, mpoolRetStrokeOutline on line 617 will access mpool->strokeOutline[idx].
Logically, the logic of the mpool* functions does not occur in this case.
2021-12-15 15:19:19 +09:00
Mira Grudzinska
abc3b40a37 sw_engine: var/funct renaming
Changed names:
shape->rect -> shape->fastTrack
_factTrack -> _axisAlignedRect
2021-11-02 11:41:14 +09:00
Mira Grudzinska
26f99372b0 sw_engine: fastTrack with clips
After 362d2df the fastTrack cases were applied even for shapes with clips.
These changes fixed this - the check whether a shape is a rect should be done
only if it has no clips.
2021-11-01 22:21:17 +09:00
Mira Grudzinska
362d2dfd0f sw_engine: refactoring
The rasterization region was rearranged in the case of fastTrack,
but its validation and boundaries weren't check, causing segf in some
cases. Fixed.
2021-10-29 10:52:29 +09:00
Hermet Park
370b9b08ec sw_engine shape: code refactoring.
move the exceptional code for the coherency,
and ++ more history of the description.
2021-10-28 13:53:49 +09:00
Mira Grudzinska
babb10b7f3 sw_engine: rasterization region edited in the case of fast tracking
Since no antialiasing is applied for the fastTracking cases,
the shape's rasterization region needs to be edited. To establish
the rastered bbox, the rounding is performed before the bbox corners
are casted to the SwCoords.
2021-10-27 12:42:27 +09:00
Mira Grudzinska
ae6d574466 sw_engine: overlaping stroke cap
A square or a round cap was mistakenly added to the parts
of the dashed lines that should be continuous. Fixed

@Issues: https://github.com/Samsung/thorvg/issues/777
2021-09-08 11:17:42 +09:00
Hermet Park
f2252787ee sw_engine shape: prevent crash when wrong pair of commands & points.
add an exception handling,
if the given points count is not matched with expected points count from commands.

@Issue: https://github.com/Samsung/thorvg/issues/735
2021-08-28 15:59:29 +09:00
Hermet Park
e1d5ade705 sw_engine: memory optimization.
Save the size of the Countour array,
16 bits is large enough to count the points number in one Shape.
2021-08-12 20:13:58 +09:00
Hermet Park
2280bb9ce7 sw_engine shape: fix a corner case that close tag is overwritten with a wrong value.
if the last contour dispatching is dealt with closed command but actual command
is not the closed, the close tag is written with the opened

In this case, stroking rendering is buggy.
2021-08-12 19:40:59 +09:00
Hermet Park
e15b1dbc5f sw_engine: allow sharing shapes & connected strokes all in one.
This patch enhanced the sw raster engine to allow the both closed & open pathes
in one shape rendering.

@Issue: https://github.com/Samsung/thorvg/issues/266
2021-08-12 18:39:46 +09:00
Hermet Park
6dd414ee3b sw_engine: fix invalid data sharing at multi-threading.
We have encountered that multi-threading usage that user creates,
multiple canvases owned by multiple user threads.

Current sw_engine memory pool has been considered only for multi-threads,
spawned by tvg task scheduler.

In this case it's safe but when user threads introduced, it can occur race-condition.

Thus, Here is a renewal policy that non-threading tvg(initialized threads with zero),
takes care of multiple user threads bu changing its policy,
each of canvases should have individual memory pool to guarantee mutual-exclusion.

@API additions

enum MempoolPolicy
{
    Default = 0, ///< Default behavior that ThorVG is designed to.
    Shareable,   ///< Memory Pool is shared among the SwCanvases.
    Individual   ///< Allocate designated memory pool that is only used by current instance.
};

Result SwCanvas::mempool(MempoolPolicy policy) noexcept;

All in all, if user calls multiple threads, set memory pool policy to Individual.
2021-05-12 10:59:50 +09:00
Hermet Park
4a19e5b9f6 common: fix wrong viewport region.
in the clip rect, viewport must be accumulated to the smaller one.
this patch improves that corner-case.
2021-03-26 17:24:43 +09:00
Hermet Park
f1fe36d8f6 common sw_engine: optimize single rectangle ClipPath.
If ClipPath is a singular rectangle,
we don't need to apply this to all children nodes to adjust rle span regions.

Rather than its regular sequence,
we can adjust render region as merging viewport that is introduced internally,

All in all,
If a Paint has a single ClipPath that is Rectangle,
it sets viewport with Rectangle area that viewport is applied to
raster engine to cut off the rendering boundary.

In the normal case it brings trivial effects.
but when use SVGs which has a viewbox, it could increase the performance
up to 10% (profiled with 200 svgs rendering at the same time)

Note that, this won't be applied if the Paint has affine or rotation transform.

@Issues: 294
2021-03-26 17:10:35 +09:00
Hermet Park
4a8f45577a
sw_engine: code refactoring
1. unified clip & bounding box in rle processing
2. unified outline boundingbox functions between shape & image.
2021-03-24 18:48:39 +09:00
Hermet Park
1a7d41ce71 updated copyright 2021-03-23 14:31:58 +09:00
Hermet Park
5e01fd8b4b Revert "sw_engine shape/image: substituting logical 'and' with 'or'"
This reverts commit 74b27c74af.

This patch breaks Stroke example. 1 line drawings...

There is a possibility that less 1 (i.e: 0.5) width axis-aligned line drawings...

So logically "&&" is correct.
2021-03-09 20:13:44 +09:00
Mira Grudzinska
74b27c74af sw_engine shape/image: substituting logical 'and' with 'or'
In the case when the height or width of the bounding box is 0
it is not necessary to calculate Rle.
2021-03-09 19:44:29 +09:00
Mira Grudzinska
d86032df36
sw_engine: adding a gradient as a stroke feature
* sw_engine: adding a gradient as a stroke feature

Similarly as a shape may have a gradient fill so can the stroke.

* Capi: adding APIs for a gradient stroke

Co-authored-by: Hermet Park <hermetpark@gmail.com>
2021-02-19 17:16:10 +09:00
JunsuChoi
08c37978a9 common: Pointer that can declare const are refactored to use const
Pointer and reference parameters should be "const" if the corresponding object is not modified
2021-02-19 16:51:50 +09:00
Michal Szczecinski
ba2bd2383d shape: Fixed reset api.
Added stroke's RLE reset in shape reset function.
2021-02-03 11:23:21 +09:00
Hermet Park
cfa2d187bf
sw_engine: apply opacity to graident fill case.
previously, opacity value is ignored to gradient fill.

This patch implements that case.
2020-12-30 12:38:32 +09:00
Hermet Park
64d3897816
common sw_engine: apply partial composition.
Introduce RendererMethod::renderRegion() to return acutal drawing region info.

That is used by scene composition to composite actual partial drawing region

for better performance.

@Issues: 173
2020-12-14 12:29:37 +09:00
Hermet Park
393be38f2a sw_engine stroke: fix memory leak.
Properly free data after use.

@Issues: 178
2020-12-10 11:48:08 +09:00
JunsuChoi
e00f948705
raw_loader Loader: Introduce Raw image loader
Add RawLoader class that loads and display raw images,
and adds a Rasterizer for image data.
Image data can be loaded via picture.
Loaded image supports Composition, Transformation and Alpha blending.

New API
Result load(uint32_t* data, uint32_t width, uint32_t height, bool isCopy) noexcept;
2020-11-23 18:12:36 +09:00
Hermet Park
006e6e0920 sw_engine rle: performance optimization.
Tis is a subsequential trial of 1b8188ee67
for opimizing memory alloc count.

In this time, it concentrates on rle span.

@Issues: 75
2020-11-05 17:32:42 +09:00
Hermet Park
1d3c56e487 sw_engine mempool: performance optimization.
This is a subsequential trial of 1b8188ee67
for opimizing memory alloc count.

In this time, it concentrates on stroke outline.

@Issues: 75
2020-11-04 20:42:01 +09:00
Hermet Park
3ab1194773 common sw_engine: code refactoring
replaced names and fixed out of coding convention.
2020-11-04 19:18:59 +09:00
Hermet Park
1b8188ee67
sw_engine shape: performance optimization.
we introduced shared memory pool for avoiding reallocate memory
while it process the stroke outlines, It experimentally increase
the outline data if we use the allocated memory for multiples shape strokes,
we don't need to alloc/free memory during the process.

This shared outline memory is allocated for threads count
so that we don't interrupt memory access during the tasks.

@Issues: 75
2020-11-04 16:28:47 +09:00
Hermet Park
627579522d sw_engine shape: code refactoring.
thorvg always prefer simpler code, less LOC.
2020-11-02 19:25:36 +09:00
Mira Grudzinska
a96037cd57 sw_engine shape: change of the rectangle fast tracking algorithm
The algorithm erroneously treated some shapes (like isosceles trapezoids
and specifically arranged zero width parallelograms) as rectangles,
which causes the whole bbox to be filled.
2020-11-02 19:23:44 +09:00
Mira Grudzinska
34a832d033 sw_engine shape: adding a dash pattern switch condition
Preventing switching to the next dash pattern for a line with a length of zero.
2020-10-26 16:40:42 +09:00
Mira Grudzinska
4b58c5a5de common shape: handling dash patterns < 1
For the dash pattern values (both, length and gap) < 1 the program crashed.
curLen - variable type changed from int to float.
2020-10-23 17:42:13 +09:00
Hermet Park
65cbbcf724 sw_engine shape: support fillRule method
this change supports EvenOdd fillrule in shape rendering

@Examples: examples/FillRule.cpp

@Isuses: 97
2020-10-22 17:29:39 +09:00
Hermet Park
2a239714af sw_engine: fix missing shape update issue.
It missed to update shape data if visilibity is changed from false to true by alpha.

Also, it needs to update engine shape data for every requests.

There scenario can be allowed,

1. update shape
2. change shape property
3. update shape
4. draw

previously engine could skip step 3, its result was not properly expected.

@fix #84
2020-10-13 17:07:54 +09:00
JunsuChoi
c70d1b1e45
SwRender & tvgPaint: Implement ClipPath feature (#68)
common sw_engine: Implement ClipPath feature

Paint object can composite by using composite API.
ClipPath composite is clipping by path unit of paint.
The following cases are supported.

Shape->composite(Shape);
Scene->composite(Shape);
Picture->composite(Shape);

Add enum
  enum CompMethod { None = 0, ClipPath };

Add APIs
  Result composite(std::unique_ptr<Paint> comp, CompMethod method) const noexcept;

* Example: Added testClipPath
2020-10-07 11:21:23 +09:00
Hermet Park
6365d02a96 optimization: cut off file dependencies.
we should avoid code insertion during file dependencies,
such as #include "xxx.h" which has implementations.

This could increase binary size, we can avoid it as possible.

Current patch improves binary size like this:

From: file(2059008) = text(120360) data(8096) bss(80) dec(128536)
To  : file(1921832) = text(118429) data(7872) bss(56) dec(126357)

More additional patches will come in to optmize binary size.
2020-09-23 20:57:30 +09:00