Commit graph

585 commits

Author SHA1 Message Date
Michal Szczecinski
f8b636d4d0 common gradient: Fix possible crash in color setter
Memcpy is not allowed on nullptr. If colorStops is invalid colors are
cleared.
2021-06-04 21:36:16 +09:00
Michal Maciola
718578532c capi: include <stdint.h> into thorvg_capi.h 2021-06-04 19:52:34 +09:00
Hermet Park
b299157123 capi: add tvg_paint_get_transform() api. 2021-06-04 16:48:00 +09:00
Hermet Park
efa0035fe6 common initializer: correct the result value.
When memory is not allocated successully, it must return the FailedAllocation as the return value.
Previous initializer wrongly returns the value that case, this corrects it.
2021-06-03 20:48:02 +09:00
Hermet Park
c2b2aa92c3 infra: install capi header file only its binding option is enabled.
decouple the capi header from the default headers by replacing it in capi folder.
now it's also installed optionally.
2021-06-03 20:43:39 +09:00
Hermet Park
a864a5a0ac sw_engine rle: code refactoring.
keep it neat code, --loc
2021-06-03 11:45:59 +09:00
Hermet Park
a8a120942e sw_engine: data optimization.
changed alpha channel data type to 32 bits from 8 bits,
since subsequent data operations requires 32 bits values.

this 8 bits (since channel range is up to 255) doesn't helpful
for saving memory size because it would generate additional data casting by compiler.

I compared the binary size and this patch saves about 600bytes.
2021-06-02 21:15:58 +09:00
Mira Grudzinska
6ccebb3234
sw_engine common: improving the alpha blending algorithm
Calculations accuracy in ALPHA_BLEND function has been
improved. Until now blending resulted in a slight hue change
(all color channels affected). The chosen method of calculation
is a compromise between the accuracy and the performance.
2021-06-02 21:01:12 +09:00
Hermet Park
c7a156d5a6 capi: fix usage after this - 2c37191584. 2021-06-02 20:14:10 +09:00
Mira Grudzinska
ed7d8b73b9 common: added API to get the transformation matrix of the object 2021-06-02 19:03:20 +09:00
Hermet Park
2c37191584 api: --inproper const syntax.
compoiste() requires internal data change, its api syntax should not contain "const"

though this changes the api spec, but won't affect build break
since it allows wider usage.

@API Modification

from:
Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) const noexcept

to:
Result Paint::composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept
2021-06-02 16:42:08 +09:00
Hermet Park
0394fa5ef5 common: fix a potential memory leak after clear()
Paints must clear canvas engine data if they were dismissed from the canvas,

1. Canvas::clear(free = false) must retain all the paints from the paints hierarchy
so that user keeps the all dangled paints lifecycle.
In this scenario, it could leak the engine data of paints, this patch fixes it.

2. Previously, t just keeps the immediate paints lives of canvas, but not them of children of scene nor picture.
This patch changes a policy which was not considered seriously,
Now it keeps the all paints lives through the tree-hieararchy.

3. Also changed the Scene::clear() behavior identical to Canvas::clear() for consistency.

@API Modification:

From: Result Scene::clear() noexcept;
To: Result Scene::clear(bool free = true) noexcept;
2021-05-28 16:19:01 +09:00
Mira Grudzinska
3911a252e2 svg_loader: the viewBox clipping composite layer added independently of the shapes bounds
For now the bounding box of all the shapes was established and if it was larger
than the viewBox of the SVG, the clipping layer was added. The bounds api
returns the rectangle that encloses the shapes before any transformations.
So comparing it with the viewBox doesn't make sense. The comparison is removed
and the clipping layer is always added.
2021-05-28 14:39:02 +09:00
Hermet Park
61f07677c5 sw_engine renderer: fix aliasing problem.
a corner case is detected that anti-aliasing is missing at shapes
if the shape has the dash-style stroke.

By adding the condition, it applies anti-aliasing properly.

@Issues: 394
2021-05-28 14:24:37 +09:00
Mira Grudzinska
f1d5571aad Revert "svg_loader: clipping composite layer is added independently on the bounds of the shapes"
This reverts commit c38e4e40a7.
It was pushed by mistake. The same changes are currently under rev in PR #399
2021-05-28 04:30:09 +02:00
Mira Grudzinska
c38e4e40a7 svg_loader: clipping composite layer is added independently on the bounds of the shapes 2021-05-27 12:54:08 +02:00
JunsuChoi
ed8dfbc529 common Initializer: Fix init count
Calling init repeatedly doesn't increment count.
This leads to unwanted termination due to mismatch of the pair.
2021-05-27 17:03:38 +09:00
Mira Grudzinska
fbd24c3c93 common scene: fixing the initial values of variables in the bounds getter
The values of the most bottom right corner of the scene bounding box
should be initialized with the biggest negative values.
Also an empty line removed.
2021-05-27 13:33:03 +09:00
Mira Grudzinska
aeb10fafec sw_engine: refactoring of the radial gradient rle rastering function
The translucent rastering function is split into 3 other (instead of if/else statement).
An additional function is introduced to decide which one of the 3 should be called.
This refactoring is done to preserve the convention used for all other rastering functs.
2021-05-26 12:47:47 +09:00
Mira Grudzinska
c2d6fc4fdd sw_engine: refactoring of the radial gradient rect rastering function
The translucent rastering function is split into 3 other (instead of if/else statement).
An additional function is introduced to decide which one of the 3 should be called.
This refactoring is done to preserve the convention used for all other rastering functs.
2021-05-26 12:47:47 +09:00
Mira Grudzinska
7cb08bebe6 sw_engine: refactoring of the linear gradient rect rastering function
The translucent rastering function is split into 3 other (instead of if/else statement).
An additional function is introduced to decide which one of the 3 should be called.
This refactoring is done to preserve the convention used for all other rastering functs.
2021-05-26 12:47:47 +09:00
Mira Grudzinska
7b931b5e32 sw_engine: refactoring the linear gradient rle rastering function
The translucent rastering function is split into 3 other (instead of if/else statement).
An additional function is introduced to decide which one of the 3 should be called.
This refactoring is done to preserve the convention used for all other rastering functs.
2021-05-25 13:00:59 +09:00
Mira Grudzinska
f18fca5173 sw_engine: gradient shapes with opacity < 255 rastered properly
The cases with gradient shapes with composition are handled
in the same function as gradint shapes with opacity < 255.
Parts of the code from _rasterOpaque... grad functions moved to
_rasterTranslucent... grad functions.
2021-05-24 11:17:44 +02:00
Hermet Park
d49e91f683 sw_engine rle: ++ precise alpha in anti-aliasing
could loss 1 pixel since it divides 255 values by 256.
2021-05-21 19:56:39 +09:00
Mira Grudzinska
edaafd99b3 sw_engine: fixing wrong 'if else' statement handling when gradient shapes rastered
The cases when composition was applied were handled only for AlphaMask and
InvAlphaMask. When opacity value was to be < 255, there was no code
to handle this.
2021-05-21 18:18:21 +09:00
Mira Grudzinska
d999a05750 sw_engine: 'inv2a' variable from the SwRadial struct replaced by 'inva'
This change reduces the number of multiplications in the fillFetchRadal function.
2021-05-18 11:38:57 +09:00
JunsuChoi
f8f90f3f34 log SvgLoader: Enhance log message
- Change tag name "Doc" to "Svg"
- Fix "Mask" tag name.
- Add element to skip output
 - title
- Add attribute to skip output
 - id, data-name, version, overflow=visible, xmlns*, xml:space
2021-05-13 23:46:17 +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
Mira Grudzinska
924ea15cfa capi: added check against null pointer before dereferencing
TVG_RESULT_INVALID_ARGUMENT returned in case a nullptr passed as an argument
(does not apply to color getters).
The change is addressed in the docs file.
2021-05-11 12:09:23 +02:00
JunsuChoi
475fc22f6d loader SvgLoader: Fix memory leak
Add memory release for style->comp.url, which is the leaking memory.

[Valgrind Test Result]
==21595== 32 bytes in 1 blocks are definitely lost in loss record 29 of 152
==21595==    at 0x4C3217F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==21595==    by 0x5C248C6: _idFromUrl(char const*) (tvgSvgLoader.cpp:272)
==21595==    by 0x5C24DE1: _handleClipPathAttr(SvgLoaderData*, SvgNode*, char const*) (tvgSvgLoader.cpp:860)
==21595==    by 0x5C260CC: _attrParseGNode(void*, char const*, char const*) (tvgSvgLoader.cpp:953)
==21595==    by 0x5C2ABA9: simpleXmlParseAttributes(char const*, unsigned int, bool (*)(void*, char const*, char const*), void const*) (tvgXmlParser.cpp:272)
==21595==    by 0x5C26F6E: _createGNode(SvgLoaderData*, SvgNode*, char const*, unsigned int) (tvgSvgLoader.cpp:1063)
==21595==    by 0x5C27A04: _svgLoaderParserXmlOpen(SvgLoaderData*, char const*, unsigned int, bool) (tvgSvgLoader.cpp:2168)
==21595==    by 0x5C27CE9: _svgLoaderParser(void*, SimpleXMLType, char const*, unsigned int) (tvgSvgLoader.cpp:2226)
==21595==    by 0x5C2AC8C: simpleXmlParse(char const*, unsigned int, bool, bool (*)(void*, SimpleXMLType, char const*, unsigned int), void const*) (tvgXmlParser.cpp:378)
==21595==    by 0x5C27E09: SvgLoader::run(unsigned int) (tvgSvgLoader.cpp:2571)
==21595==    by 0x5C1A7C1: operator() (tvgTaskScheduler.h:68)
==21595==    by 0x5C1A7C1: tvg::TaskSchedulerImpl::run(unsigned int) (tvgTaskScheduler.cpp:138)
==21595==    by 0x5EED6DE: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
2021-05-03 16:29:30 +09:00
Hermet Park
6fce96a124 examples: fix wrong data size conversion.
pointer size becomes 32 to 64 bits up to machines.
it has to be 32 bits.
2021-05-01 12:56:49 +09:00
Hermet Park
2bd07c050c examples: fix wrong data size conversion.
pointer size becomes 32 to 64 bits up to machines.
it has to be 32 bits.
2021-05-01 12:49:23 +09:00
Hermet Park
1d923a8632 loader svg: fix build break due to typo 2021-05-01 12:37:45 +09:00
Michal Szczecinski
2f334f50c5 sw_engine: Added sanity checks.
This commit fixes crash when update target surface is not created yet.
2021-05-01 12:34:30 +09:00
Hermet Park
3a538340aa infra: disable capi in default.
capi is not mandatory option in v0.1.

we can manually toggle it on when it's necessary.
2021-04-30 19:15:05 +09:00
Mira Grudzinska
6601c93899 sw_engine: fixing overlapping masks
The buffer to which the mask is rastered is only partially cleared.
If the object to which the mask is applied overlaps an area where
another mask was used, an erroneous image is generated. The buffer
clearing area has been increased to the size of the object to which
the mask is applied.
2021-04-29 12:13:38 +09:00
Mira Grudzinska
d0dc9142ec common paint: changed result in composite API
A possible error is due to erroneous arguments, so
InvalidArgument is return instead of InsufficientCondition
2021-04-28 20:02:22 +09:00
Hermet Park
e1ebcf6153 loaders svg: code refactoring
split functions as its purpose.
2021-04-21 11:12:22 +09:00
JunsuChoi
51e4757a3b loader SvgLoader: Fix wrong debug log
1.
Modify that attribute information used for use type
looks like it was used for g type.

2.
Fix clippath node looking like setting "none"
(clippath's display = false is intentional)
2021-04-21 11:11:37 +09:00
JunsuChoi
8b54b6768a loader SvgLoader: add locale-independent strtof function
strtof's behavior is changed by system locale.
https://linux.die.net/man/3/strtof

Because of this, strtof(10.0000) returns 0.0 in some locales.
When a given value string is locale-independent, strtof has to be
replaced to custom function.
2021-04-20 19:44:04 +09:00
Hermet Park
b541a0654c loaders svg: ++safety
prevent buffer overflow just in case.
2021-04-20 17:49:48 +09:00
Mira Grudzinska
332012dd6b loader svg: displaying SVG images without the specified viewBox attribute
If no viewBox attribute is given, the height and width attributes are used
to establish the viewBox size. However, this information was not available
inside the scene builder, even though it was needed.
2021-04-15 04:34:44 -07:00
Hermet Park
f1feebf047 common: code refactoring.
renamed internal function, no logical changes.
2021-04-15 18:26:11 +09:00
Mira Grudzinska
a13561e9c5 sw_engine: adding a check before stroke fill dereference
The crash was observed for empty shapes.
2021-04-15 13:33:58 +09:00
Hermet Park
6276e209a7 common initializer: counting engine init count properly.
Manage the reference count in common so that
all common resources can be initialized/terminated identically.
2021-04-14 20:18:06 +09:00
Mira Grudzinska
0f9d3ff6e9 examples: ignoring pictures other than svgs in Stress.cpp
The picture->size() function does not work for raw/png pictures.
As a consequence enabling both, the svg and png file loaders,
resulted in the unintended behavior of the example.
2021-04-14 17:17:10 +09:00
JunsuChoi
5d81fe2446 loader SvgLoader: Fix for coding convention 2021-04-13 19:01:19 +09:00
JunsuChoi
b75e7ea91a loader SvgLoader: return null if transform attribute invalid
In transform matrix parsing, null is returned if any of the matrices are invalid.
2021-04-13 19:01:19 +09:00
Hermet Park
d3a73f7ee9 loaders svg: fix a wrongly handles the corner case.
Stop the internel loop quick as possible, and state must be reset.
2021-04-13 17:49:29 +09:00
Hermet Park
b3559ecf56 loaders svg: code refactoring.
keep it clean & neat within tvg coding convention.
2021-04-13 17:16:38 +09:00