Commit graph

998 commits

Author SHA1 Message Date
Mira Grudzinska
f3fac71a12 sw_engine: added check whether surface width <= surface stride
In a case width > stride segf occured. Such a case should be treated
as an invalid arg.
2021-06-08 17:20:46 +09:00
Mira Grudzinska
419751c736 sw_engine: fixing the composition for canvas width != canvas stride
When canvas width was smaller than its stride and a composition is used,
the plots were drawn incorrectly. This is fixed by setting the image width
(image from a compositor) to be equal to the surface stride, instead of its width.
The image data are now allocated accordingly the fixed image width.
2021-06-08 17:19:59 +09:00
Hermet Park
f0ecc670ef common canvas: return FailedAllocation if it really failed at memory allocation.
This fixes SwCanvasBase Reservation Unit Test.
2021-06-07 20:04:39 +09:00
Hermet Park
1c53d47f81 sw_engine mempool: tiny optimization.
don't mempool anything if the option is same.
2021-06-07 19:40:56 +09:00
JunsuChoi
3c19f2aaf5 svg_loader SceneBuilder: Remove incorrect calculation for radial gradient
We are doing enough calculations in the parser if the unit is user space.
This causes the cx,cy coordinates of radial gradient to be calculated incorrectly.
So remove it.
2021-06-07 19:12:17 +09:00
JunsuChoi
bd566bdcb2 svg_loader SceneBuilder: Remove incorrect calculation for linear gradient
Calculation of objectBoundingBox case in linear gradient is incorrect code.
This causes the x,y coordinates of the linear gradient to be calculated incorrectly.
So remove it.
2021-06-07 19:12:17 +09:00
Hermet Park
50b2b1c7de sw_engine renderer: fix to success SwCanvas Unit Test.
render init count shouldn't be counted when it's in a fail-case.
2021-06-07 18:09:35 +09:00
Hermet Park
eda022365f canvas: fix for SwCanvas Unit Test
Fixed to fail canvas generation if engines are not initialized.
2021-06-07 18:01:26 +09:00
Hermet Park
314b96651b doc: correct the beginning year 2021-06-07 17:39:45 +09:00
Hermet Park
7a407eb8bb common: fix typo 2021-06-07 17:36:19 +09:00
Michal Maciola
c7ccca79b3 TVG Loader/Saver: tvg helper file ('tvgTvgHelper.h') introduced
This patch introduces tvgTvgHelper.h file that contains base definitions used
for .tvg loader and saver modules. Indicators, flags and sizes are defined
and base tvgBlock struct is declared here.
'tvgTvgHelper.h' file is essential only for .tvg loader/saver module and it
doesn't affect any other file. Loader and saver modules itself are introduced
in other, further patches.

.tvg is a binary file format designed for saving/restoring the scene content.
It allows to save scenes and reuse them in other apps or to restore state of
the application.
2021-06-07 13:02:44 +09:00
Hermet Park
9873539b04 common taskScheduler: fix wrong thread indexing due to duplicated variable names.
That mistake could invoke inproper threads....
2021-06-07 12:57:35 +09:00
Mira Grudzinska
ae5673658e svg_loader: initializing uninitialized variables
The 'loader->svgParse->global' variable was uninitialized when no viewBox attribute
was set. If gradient was applied, the division by zero occured and no gradient was drawn.
2021-06-07 12:30:56 +09:00
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