Commit graph

493 commits

Author SHA1 Message Date
Hermet Park
d13cd37094 fix typo 2020-12-09 15:29:22 +09:00
Hermet Park
d4515d2732 common array: Introduce Array function to common.
This Array is promoted from SvgVector to use it widely in tvg.
It's similar with std::vector, we can use it instead of it.

Also, svg_loader replaced with it subsequently.
2020-12-09 15:29:22 +09:00
Hermet Park
ca6639bb2c svg_loader: code refactoring
Use custom vector data algorithm for optimizing binary size.
Plus remove tuple usage since it leads unnecessary instance copying.

binary size comparison:

[libthorvg.so] 1811400 >> 1785448
[text] 122914 >> 121255
[data] 7824 >> 7792
[dec] 130810 >> 129119
2020-12-09 14:52:47 +09:00
Hermet Park
924490a7a5 sw_engine renderer: code refactoring.
Unify Shape+Stroke composition with CompositeCtx which is added for Scene Composition

This fixes clipping issue as well.

@Issues: 164
2020-12-09 12:54:13 +09:00
JunsuChoi
e794c678ec svg_loader SceneBuilder: No propagate opacity to child
Scene's opacity() propagates opacity value inside.
Therefore, unnecessary opacity calculation.
2020-12-08 12:32:05 +09:00
Hermet Park
af88da976d wasm: code refactoring.
Use Picture::size() method instead of scale()

Picture newly supports size() method to resize image.
It's more convenient for users in its usage.
2020-12-08 12:30:58 +09:00
Hermet Park
1e78d1f845
picture: replace size parameter to float.
Considering smooth-resizing on sub-pixeling.
2020-12-08 12:27:13 +09:00
Hermet Park
ea969ad0e2 sw_engine renderer: fix a crash issue.
This stroking composition condition must be initialized
even when exceptional cases. We moved the condition setting to
handle it always.
2020-12-07 19:52:56 +09:00
Hermet Park
77e8a195b4
sw_engine renderer: support scene opacity composition
this is an additional enhancement of af8c278c5e

Now scene opacity composition is supported.

Also, this implementaion fixes an incorrect scene bounding box computation.

Plus, adding stroking feathering to shape bounding box size.
2020-12-07 15:45:44 +09:00
Hermet Park
20de2bfc15 common picture: revise resize method.
this implementation handles the center-aligned scale.
Also removed viewbox usage since we have size() method.
2020-12-07 13:56:50 +09:00
JunsuChoi
6889f0ad1f
common Picture : Introduce Picture's size setter, getter APIs
* common Picture : Introduce Picture's size setter, getter APIs

If picture or file loaded by picture has an explicit Size(width, height),
it is transformed to fit the size.
2020-12-04 15:03:25 +09:00
Hermet Park
ceb14e73a8 sw_engine renderer: refactoring code & optimize composition.
Move the prepare stage of shape & stroking composition stage to a separate function
this returns SwImage to use in composite stage.

Also clear partial region buffer since we know composition area.
2020-12-03 18:59:42 +09:00
JunsuChoi
3881f20e9c svg_loader SceneBuilder: Use opacity() without using alpha color
If opacity value is set in node,
opacity() API is used without composing alpha color.
2020-12-03 18:50:39 +09:00
JunsuChoi
d3020b7bbe svg_loader Loader,XmlParser: String that has not been parsed returns false
Existing parser functions always return true.
Parser function's return value was not being properly used.
So, add a return to check whether it is parsed or not.
2020-12-03 18:39:47 +09:00
Hermet Park
ee1522a446 sw_engine math: fix regression bug.
There is 1 pixel misaligned issue observed.
Found out transform() increases 0.5 pt always.

This transform() logic was broken by this change - e00f948705
and now recorvered to origin.
2020-12-03 18:30:47 +09:00
Hermet Park
af8c278c5e sw_engine raster: support opacity composition.
This implementation supports shape + stroke opacity composition.

Currently, tvg shape provides individual alpha values for filling & stroking

These alpha values are working individually, meaning that if stroking is half translucent,
user can see that translucent stroking is crossed the shape outlines.

Sometimes this result can be expected but user also expects the shape filling is invisible
behind of translucent stroking.

For this reason, Paint provides an additional api opacity()
that applies opacity value to whole paint attributes.

This is a little expensive job, please consider if you can possibly avoid that usage.

See Opacity example.

@Issues: 94
2020-12-03 13:07:17 +09:00
Hermet Park
1743db705b
sw_engine raster: code refactoring & optimize code.
* sw_engine raster: code refactoring & optimize code.

1. move the computation out of rolling if possible.
2. renamed internal variables & function prototypes.
2020-12-02 16:49:53 +09:00
Hermet Park
2c78945483 gl_engine renderer: fix build break.
interface has been changed. make it up-to-date
2020-12-01 16:13:51 +09:00
Michal Szczecinski
a36e25e178 common capi: Added scene clear API
Scene::clear() API allows users to remove shapes on their own, without
a crash in paint->dispose() or tvg_paint_del() methods. This case is
needed especially when thorvg is used to draw frames, when in one frame
we have scene with shape, and in next frames (future time stamps) user
deletes shapes

@API additions
Result Scene::clear();
Tvg_Result tvg_scene_clear(Tvg_Paint *scene);

Example:
```c
Tvg_Paint *scene = tvg_scene_new();
Tvg_Paint *shape = tvg_shape_new();

tvg_scene_push(scene, shape);
tvg_scene_clear();
//Now we can safelly free resources manually
tvg_paint_del(scene);
//Without tvg_scene_clear() memory allocatad for shape was double released
tvg_paint_del(shape);
```
2020-12-01 15:39:08 +09:00
JunsuChoi
676e824719 common Scene: Fix validation check for child's bounds
Fix typo. and Change return to continue.
Even if the child's boundary calculation is wrong,
other child's boundary should be calculated.
2020-11-30 15:36:36 +09:00
JunsuChoi
1bdf1c72a4 common Test: Add Paint.bounds unit test 2020-11-30 15:36:36 +09:00
JunsuChoi
d8d754e969 sw_engine Raster: Add null check for transform
If transform is null, identify matrix is used.
2020-11-30 15:32:30 +09:00
Michal Maciola
7ec52e6c9e Picture capi binding 2020-11-30 13:16:20 +09:00
Michal Szczecinski
01aef488f0
capi: Added fill rule API.
Added capi binding for fill rule setter and getter.

@API changes:

enum Tvg_Fill_Rule {
  TVG_FILL_RULE_WINDING = 0,
  TVG_FILL_RULE_EVEN_ODD,
}

Tvg_Result     tvg_shape_set_fill_rule(Tvg_Paint* paint, Tvg_Fill_Rule rule)
Tvg_Fill_Rule  tvg_shape_get_fill_rule(Tvg_Paint* paint, Tvg_Fill_Rule* rule)
2020-11-30 13:08:24 +09:00
Hermet Park
b125a7ea2e examples: ignore loading raw image file.
in the last commit, it added a raw image file in the images folder.
It breaks Multicanvas, Svg which try to load all kinds of files in it.

We don't need to load all files by figuring out file extension name.
2020-11-23 18:56:23 +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
Michal Szczecinski
e259213b44 capi: Added free flag to clear API.
Cpp implementaiton of library has free flag which was not used in
capi bindings.

@API changes
from: tvg_canvas_clear(Tvg_Canvas *canvas);
to: tvg_canvas_clear(Tvg_Canvas *canvas, bool free);
2020-11-20 12:04:22 +09:00
Hermet Park
a71773f98d
common taskScheduler: code refactoring
removed unnecessary code.
2020-11-11 13:55:46 +09:00
Subhransu Mohanty
c2e1583e94 common taskScheduler: fix a synchronization data race.
std mutex shouldn't be used among threads. behavior is unexpected by implmentation.

This resolves it by introducing conditional value.
2020-11-10 16:45:52 +09:00
Michal Szczecinski
d1d54e8b8f
capi examples: Added scene API C bindings.
Scene CAPI allows to use scene functionaliy in C applications such as
set opacity to few shapes at one time or implement transparent layers.

@API Additions:
```c
Tvg_Paint* tvg_scene_new();
Tvg_Result tvg_scene_reserve(Tvg_Paint* scene, uint32_t size);
Tvg_Result tvg_scene_push(Tvg_Paint* scene, Tvg_Paint *paint);
```

Examples:
```c
Tvg_Paint *scene = tvg_scene_new();

Tvg_Paint *shape1 = tvg_shape_new();
tvg_shape_append_rect(shape1, 10, 10, 100, 100, 0, 0);
tvg_shape_set_fill_color(shape1, 255, 0, 0, 255);

Tvg_Paint *shape2 = tvg_shape_new();
tvg_shape_append_rect(shape2, 120, 10, 100, 100, 0, 0);
tvg_shape_set_fill_color(shape2, 255, 0, 0, 255);

tvg_scene_push(scene, shape1);
tvg_scene_push(scene, shape2);

tvg_paint_set_opacity(scene, 100);

tvg_canvas_push(canvas, scene);
```

Co-authored-by: Michal Szczecinski <m.szczecinsk@partner.samsung.com>
2020-11-10 12:13:48 +09:00
Hermet Park
3fabd604bf examples capi: removed printf()
there is no point to print information.
2020-11-09 14:43:15 +09:00
Hermet Park
9872cf066d
common taskScheduler: thread sync optmization
replaced future/promise with mutex since they use a lot of memory allocation number.

plus, binary size is reduced from 2094896 -> 1746864
2020-11-09 14:36:22 +09:00
Hermet Park
e445b7f579 Revert "examples: revise example code."
This broke gl_engine rendering, revert it.

This reverts commit 9bb1972ef9.
2020-11-06 15:37:17 +09:00
Hermet Park
bb4c6b299f common renderer: code refactoring.
renamed internal methods from flush() to sync()
since flush() is reserved for caching flush.
2020-11-06 15:26:47 +09:00
Hermet Park
9718c6aa5b gl_engine renderer: fix build break.
just found a missing change for the fillColor api.
2020-11-06 15:25:11 +09:00
Hermet Park
5751fd13cc sw_engine mempool: ++optimization
These memory pools requires very simple mechanism.

Remove stl vector but use direct memory for less binary size.(2127696 -> 2094094)

@Issues: 75
2020-11-06 13:54:53 +09:00
Hermet Park
c6013536ec common shape: memory optimization
All shapes will have path data,
avoid unnecesary dynamic memory allocation internally.

@Issues: 75
2020-11-06 11:47:51 +09:00
Hermet Park
8d03f131a3 updated AUTHORS 2020-11-06 11:33:09 +09:00
Vincent Torri
5a85b40f6c fix compilation on Windows 2020-11-06 11:28:54 +09:00
Vincent Torri
8243b3a1f5 fix compilation on Windows 2020-11-06 11:28:54 +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
2b762f00e2
Update README.md 2020-11-05 14:44:43 +09:00
Hermet Park
39ea685edb
Update README.md 2020-11-05 14:43:32 +09:00
Hermet Park
ad9460444a
Update CONTRIBUTING.md 2020-11-05 13:57:21 +09:00
Hermet Park
5fbc446455
Update README.md 2020-11-04 21:01:22 +09:00
Hermet Park
9ba5f740d5 res: updated thorvg card images. 2020-11-04 20:59:19 +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
410fa6c115 sw_engine mempool: changed caching policy.
for smart usage, clear memory only when engine is terminated.
2020-11-04 19:20:29 +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
9bb1972ef9 examples: revise example code.
Move the Clear call to the end of drawing those scenarios doesn't need to retain paints resources.

We should show the examples as the best usage.

@Issues: 75
2020-11-04 19:05:11 +09:00