Commit graph

83 commits

Author SHA1 Message Date
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
JunsuChoi
3c7adb0a95 common: Functions that can declare const are refactored to use const
Member functions that don't mutate their objects should be declared "const"
2021-02-19 16:51:50 +09:00
Mira Grudzinska
3dfc3c4943 sw_engine renderer: rendering optimization of shapes without strokes
The value of 'a' for shapes without a stroke could hold the fill 'a' value.
Added checking if stroke exists before calling rastering functions.
2021-02-02 11:53:58 +09:00
Hermet Park
0e9115cd00 sw_engine renderer: fix invalid rle issue.
if shape rendering is failed, all the prepared data must be reset
because those are invalid.

@Issues: 180
2021-01-10 17:39:57 +09:00
Hermet Park
736d6ee4ef
common sw_engine: revise the masking implementation.
We re-implement the masking feature with image composition method.

This patch is working only for single shape but settle up coming extensions.
2021-01-04 00:46:59 +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
c3d0a79d3e sw_engine renderer: fix a regression bug.
recover a broken shape+stroking opacity that introduced in ealier refactoring...
2020-12-29 12:07:05 +09:00
Hermet Park
7d9023ac5c common sw_engine: code refactoring
Renamed internal interfaces.

We need both blender & compositor interfaces.

Renamed SwCompositor -> SwBlender which is for pixel joining methods.

Added (SwCompositor, Compositor) which is designed for compositing images.
2020-12-25 20:54:56 +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
ac43ec591e sw_engine renderer: fix wrong conditional check.
unsigned int won't be less than 0.
2020-12-22 11:09:48 +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
abc9e89517 common log: notify opacity composition usage log.
replaced [XXX] log prefix with XXX:
2020-12-15 14:29:52 +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
e3eff97fac sw_engine renderer: optimize composition data usage.
Use cache mechanism for composition data so that we don't reallocate
composition memory several times in one frame rendering.

@Issues: 168
2020-12-10 19:55:57 +09:00
Hermet Park
1ed611386d
common sw_engine: code refactoring & stabilizing.
Apply tvg Array instead of std::vector

Also Fixed to compList in update() to passed by reference, not copying.
Also Fixed Composition Target memory leak

Here is the binary size result:

[libthorvg.so] 1785376 >> 1607416
[text] 121255 >> 118277
[data] 7792 >> 7736
[dec] 129119 >> 126085
2020-12-09 19:56:59 +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
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
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
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
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
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
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
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
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
46bd78a7c3 sw_engine renderer: fix aliasing shape outline result.
There a scenario detected that stroke 2 is not enough to cover
shape outlines. So make it bigger size.
2020-10-22 15:02:57 +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
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
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
Hermet Park
b1a91acd6a sw_engine: code refactoring.
use macro for single maintenance.
2020-09-10 15:30:38 +09:00
Mira Grudzinska
5a21b3bd68 sw_engine: the check if the stroke width > 0 after conversion its value from float to long
During stroke width interpolation, if the width value after conversion
to long was 0, the bbox size was undefined.
2020-09-10 15:23:01 +09:00
Hermet Park
4c0bce3fdc sw_engine: fix shape rendering skip issue.
tvg canvas must draw retained shapes for every draw call
even though user missed call update() for shapes.

that case canvs must draw shapes without update,
it means drawing them within previous condition.
2020-09-09 11:02:56 +09:00
Hermet Park
8685c7e0f0 common: fix context corruption among the multiple canvases.
previous implementation didn't consider multiple canvases,
multiple canvas shared one renderer engine that brought corrupted contexts.
Thus, each canvas instances should have designated renderer engine instances.

Now fixed.
2020-09-05 18:55:51 +09:00
Hermet Park
1f05c249af sw_engine: step backward optimization.
As profiled, raster parallelization is not so efficient,
we revert this behavior.

We will come again with a better fine-tuned method.
2020-09-04 12:36:19 +09:00
Hermet Park
c8bc0a91d9 sw_engine: applied async rasterizing based on task scheduler.
Now, we have 2 points for asynchronous behaviors.

1. update shapes:

Each shape update will be performed by async when you push shape to canvas.
Meaning, if you have time gap between update and rendering in process main-loop,
you can have a benefit by this.

2. rasterization by canvas:

Canvas.draw() will be performed asynchnously until you call canvas.sync();
Meaing, if you can trigger tvg rendering eariler than composition time.
You can have a benefit by this.

If these 1, 2 points might not work for your program,
You can just toggle off async by setting threads number zero at initialization.

Or if you could apply either point of them for your program,
It might be good for performance.

But the best approach is to make both async properly.
Though this might need to fine-grained tuning integration between your program & tvg,
You could achieve the best peformance by parallelzing tasks as possible without any jobs delaying.

Change-Id: I04f9a61ebb426fd897624f5b24c83841737e6b5b
2020-08-26 16:56:54 +09:00
Mira Grudzinska
42a747fa17 SwRenderer: fixing unnecessary nesting in prepare()
Validating the above by adding shape/canvas update to testCapi.cpp

Change-Id: I7db8d014f4aff7b5b2884c2dca5af119329e9d43
2020-08-25 16:50:14 +09:00
Hermet Park
04c6295974 code refactoring
remove unnecessary condition.
implementation won't be included multiple times not like headers.

Thus this condition is unnecessary.

Change-Id: Id37e675c40ce7213a06c950da8e5ca17ff7245c9
2020-08-20 16:16:46 +09:00
Hermet Park
ffa4a7248b code refactoring
Now, stabilizing is pretty enough.

Remove assert code so that we never abort process in any cases.
This also reduce the binary size.

Change-Id: Ia7d2d5c5a0757b12481eaebad7a86aade6a89c1e
2020-08-19 14:53:38 +09:00
Hermet Park
a5beca7369 sw_engine: code refactoring
introduce compositor table for runtime colorspace switching.

Change-Id: If179d1e1625f995e114d66cf1bf13742c54ed4f7
2020-08-18 20:27:23 +09:00
Hermet Park
f4d1065d52 sw_engine: convert colorspace ARGB -> RGBA in default.
We can use RGBA colorspace rather ARGB for pixel data.
This would be better for many rendering system,
since it's more widely preferred than ARGB including opengl.

Change-Id: Ibbfe6a511d77bf0ef30ce261995467c11164d306
2020-08-15 18:22:43 +09:00
Hermet Park
7289116227 remove std async usage.
we can't control any threads count that could drop the performance.

remove async() and will come back with fine-tuned threading-pool.

Change-Id: I17c39792234acfce6db334abc0ce12da23978a9a
2020-08-14 17:41:44 +09:00
Hermet Park
9893af979f replace license from Apache 2.0 to MIT
Change-Id: I61f7cb2b0e407bc035f3b2ec7da9b7f230057e24
2020-08-13 16:53:38 +09:00
Hermet Park
7214559ad9 common: fix compile warnings.
--Werror=unused-parameter

Change-Id: If4c04e3e20b67be62b50c3b1e2e909dbd848eccc
2020-08-06 16:48:26 +09:00
Hermet Park
4d72eeda15 sw_engine: revise scale transform logic.
Basically, stroke width size is linear,

engine couldn't apply scale factor from the matrix which contains 2 dimensional values.

Thus, we can apply it if the scale factor of x/y is identical.

Otherwise, we should transform every stroke points in the stroking process.
That scenario can be improved with another patch.

Change-Id: I070dcf29d2e42f21e182bdf4239781464158ef73
2020-07-22 20:59:52 +09:00