Commit graph

67 commits

Author SHA1 Message Date
Mira Grudzinska
0150391f03
tvg_saver: implementation of the Saver class
The Saver class enables to save any Paint object (Scene, Shape, Picture)
in a binary file. To read the file the tvg loader should be used.
To save a paint a new API was introduced - tvg::Saver::save.
2021-07-19 17:31:36 +09:00
Mira Grudzinska
f23cba89f3
common: introducing basic iterators functionality
The introduced Iterator class enables to access the children nodes
of a given Paint.
2021-07-19 17:28:14 +09:00
Hermet Park
8aa941c4ab common picture: ++exception case.
Fixed load() to return InvalidArgument if the file path is invalid.
2021-07-02 14:01:52 +09:00
Hermet Park
2fd830c940 common shape: allow to reset stroke dash.
user may need to reset stroke dash to off,
now stroke api allows it.
2021-07-02 10:35:46 +09:00
Mira Grudzinska
6eea979dae common: introducing the composite API (getter)
The new API gets the composite method and the pointer to the composite
target of the given paint object.
2021-06-25 22:16:06 +09:00
Mira Grudzinska
96d6b47a64 common: PaintType enum changed to identifier in Paint class
The PaintType enum was used to set the paint type in the internal Paint
implementation. This solution is switched to an identifier with id() getter,
so that the information about the type can be reached from outside the Paint.
2021-06-25 22:13:20 +09:00
Hermet Park
ea668eae1d fix a build break in MSVC
add missing string header, string is used for a Picture::load() parameter
2021-06-22 14:35:46 +09:00
Hermet Park
0df8c00519 loaders: revise code from cce4b443b3
use copy variable instead of additional buffer pointer.
2021-06-22 10:42:34 +09:00
Michal Maciola
cce4b443b3 loaders: added copy param for Picture::load
@API Changed:
Result Picture::load(const char* data, uint32_t size, bool copy /*=false*/) noexcept
TVG_EXPORT Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data, uint32_t size, bool copy);
2021-06-21 19:52:38 +09:00
mmaciola
16e39ee81b
TVG Loader/Saver: tvg loader introduced
This patch introduces tvg loader module for loading .tvg binary files.
This allows to load and reuse pregenerated scene.

tvg file format:
.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.

@Example:
   auto picture = tvg::Picture::gen();
   picture->load(EXAMPLE_DIR"/tvg_file.tvg");
   canvas->push(move(picture));

@API Additions:
   Result paint(std::unique_ptr<Paint> paint) noexcept;

@Issue: Issue ticket is #375.
2021-06-11 12:49:37 +09:00
Hermet Park
13009657cd common canvas: supplement corner cases.
filled up corner cases to return the result properly.

Canvas newly has a drawing condition to prevent usage-violation.
2021-06-09 20:11:57 +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
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
54fa59e7c3 docs: -- beta tag.
Scene::clear() is ready to public.
2021-05-28 16:24:48 +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
Hermet Park
af01f5b899 api doc: replace beta api desc to beta tag 2021-05-14 19:49:28 +09:00
Mira Grudzinska
dc637d0beb doc: linguistic changes in C++ API docs 2021-05-13 23:44:26 +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
28008e2f91
doc: polish up api documentation. 2021-04-30 18:53:20 +09:00
JunsuChoi
d7b3f0103e doc common: Add grouping of C++ api and C api
group ThorVG C++ APIs
group ThorVGCapi C APIs
2021-04-29 12:11:06 +09:00
Mira Grudzinska
ec1232b9b4 doc common: change of the return value in the composite API 2021-04-28 15:06:00 +02:00
Mira Grudzinska
3d5006740c doc common: adding the documentation for the C++ APIs
Added the missing descriptions for Sw/Gl/Canvas and Initializer.
@retval command applied.
2021-04-28 19:46:58 +09:00
JunsuChoi
6241fd054d doc common: Fix typo and missing parameter 2021-04-27 11:54:22 +02:00
Mira Grudzinska
7e35ec339a doc common: adding the documentation for the C++ APIs
The descriptions have been changed and new ones added.
There are still few apis for which descriptions are missing.
2021-04-25 17:16:13 -07:00
JunsuChoi
2cfc2bd241 doc common: Draft documentation for C++ header APIs
Write documentation for some of the APIs that have already been cleared up.
2021-04-21 17:57:24 +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
Patryk Kaczmarek
905fd46ccf sw_engine composition: invert alpha masking
composition invert alpha masking

@Examples: added InvMasking

@Issues: 31

Change-Id: I2ee9d428d5749240ddf2e6adbb7677dccbe1926f
2021-02-02 11:47:30 +09:00
Hermet Park
4767f83b99
common composite: code refactoring
Splited out ClipPath routine from other pixel compositions'
since yet it's unlikely compatible...

Also revise internal engine interfaces to be simpler.

This is a step forward to enhance masking feature.
2020-12-25 19:47:01 +09:00
Hermet Park
1e02d62d01 inc header: remove unnecessary declaration.
This log tag is not used. We can introduce it when it's necessary.
2020-12-18 19:25:24 +09:00
Hermet Park
82e3553b56 common sw_engine: fix build break.
some wrong merge conflicts left. resolve them.
2020-12-18 17:44:59 +09:00
Patryk Kaczmarek
4dbdcbd057
common composition: support Masking method
New feature - CompositeMethod::MaskAlpha

Newly Support AlphaMask. but it's unstable.

@Issues: 31
2020-12-18 17:40:54 +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
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
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
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
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
0399d84478 common paint: introduce opacity() method.
We introduced separate opacity interface to adjust alpha value by paint.
This opacity will affect to whole paint image if paint is a group of paints.

Also, this opacity is to multipy with fill/stroke alpha values.
This means if the opacity is valid, the paint might deal with a composition step,
which is very expensive due to additional rendering step.

One tip is, if you want to toggle on/off for a certian paint,
you can set opacity to 255 or 0.

@API Additions:

Result Paint::opacity(uint8_t o) noexcept;
uint8_t Paint::opacity() const noexcept;

@Examples: examples/Opacity

@Issues: 94
2020-10-26 19:23:54 +09:00
Hermet Park
0b767750e6 common api: interface refactoring
returning color fill() method renamed to fillColor() as like others-strokeXXX, fillRule- do.

This change is for naming consistency.
2020-10-23 12:23:59 +09:00
Hermet Park
c807010554 examples FillRule: added shape::fillRule() example
one shape shows Winding, the other one shows EvenOdd.
2020-10-22 13:50:04 +09:00
Hermet Park
04aa038339 common fill: add fill-rule interface.
Fill rule is used to select how paths are filled.

For both fill rules, wheter or not a point is included in the fill is determined by taking a ray
from that point to infinity and looking at intersections with the path. The ray can be in any
direction, as long as it doens't pass through the end point of a segment or have a tricky
intersection such as intersecting tangent to the path.

@API Addtions:

enum class TVG_EXPORT FillRule { Winding = 0, EvenOdd };
Result Fill::rule(FillRule r) noexcept;
FillRule Fill::rule() const noexcept;

@Examples:

shape->rule(FillRule::EvenOdd);

@issue: 97
2020-10-20 20:10:59 +09:00
Hermet Park
8422e8c62b common canvas: revise clear method.
Canvas::clear() introduces a new argument "free" that deterimes freeing the retained paints.

If free is true, Canvas won't delete the retained paints so that user keep paints valid.

In this scenario, user must have paints pointers, free them manually or push them again to the canvas.

This scenario is useful if user wants to re-organize paints order in the list or reuse them.
2020-10-08 12:07:27 +09:00
Hermet Park
a200c6d4e2
common: code refactoring
renamed the enum CompMethod -> CompositionMethod

added FIXME comment
also clean up internals for less code.
2020-10-07 16:25:09 +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
d601021b8f common fill: code refactoring
removed unique_ptr in the interface because it's hard to get polymorphism benefits in programming perspective.
2020-09-22 11:00:33 +09:00
Hermet Park
12cd858d72
common fill: implement duplicate() method. 2020-09-21 19:20:51 +09:00
Hermet Park
eef7620bc8
common: binary optimization. (#65)
removed unique_ptr usages from pImpl pattern.
that increased binary size.

2204082 -> 2045672
2020-09-18 16:34:12 +09:00
Hermet Park
87fbff63cb common: code refactoring.
revise duplicate() approach with stategy pattern.
2020-09-18 12:22:28 +09:00
Michal Szczecinski
538db6e881 shape: added duplicate api.
Changes:
1. New shape->duplicate(Shape) api.
2. New example: testDuplicate
3. Added capi binding for duploicate api
4. Added capi duplication test in testCapi.c

Description:

Added implementation of duplicate api. For now it supports stroke
properties and shape properties (fill color, path) duplication.

TODO:
Implement gradient properties duplication
2020-09-17 11:01:52 +09:00