Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUESTION abou SKIA + NODE + NAPI #1652

Open
asturur opened this issue Aug 20, 2020 · 17 comments
Open

QUESTION abou SKIA + NODE + NAPI #1652

asturur opened this issue Aug 20, 2020 · 17 comments

Comments

@asturur
Copy link
Contributor

asturur commented Aug 20, 2020

@chearon @zbjornson i wanted to start a question/conversation

https://github.com/google/skia/tree/master/modules/canvaskit

This thing here is an emscripten port of skia and works as a JS + WASM replacement of canvas ( also in node )
Could the C source code, before being emscripten converted, be easily converted in a NAPI module and be as much performant as possible? would be this a even more greater node-canvas library?

@zbjornson
Copy link
Collaborator

I don't have an exact answer, but that's one possibility I've been wondering about too. Ideas on my radar:

  1. Start over based on Skia, using C++.
    Benefits: Skia has more features built-in, including webp and filters.
    Uncertainties: text shaping, as @chearon points out further down in this thread: Add support for WebP decoding #1280 (comment)
    @samizdatco has a Rust+Skia based implementation here that looks exciting: https://github.com/samizdatco/skia-canvas

  2. Skia, but using WASM build.
    Benefits: above, plus no C++ build.
    Uncertainties: performance

  3. Grab Firefox's implementation and make Node.js bindings for it.
    Uncertainties: feasibility

(I'm not letting myself start on this stuff until I finish a libuv PR I've been working on for a year. I of course won't block anyone who wants to try these things, and I'll help where I can!)

@asturur
Copy link
Contributor Author

asturur commented Sep 12, 2020

i do not have the time and the skill for a project full start. But i would love to be part of it.

I m more on the side of compatibility and feasibility rather than performances

@zbjornson
Copy link
Collaborator

If/when I start work on it, I'll keep you posted!

@kenotron
Copy link

FWIW, we tried using CavnasKit, and it was maybe 70-80% there until we realized the WASM code leaked memory like crazy and then the .js portion is missing all kinds of text alignment stubs. So, beyond pure WASM perf diffs, there is a possible problem of having to re-create instances of canvas to get around leaky memory issue.

@statm looked at this before

@asturur
Copy link
Contributor Author

asturur commented Sep 16, 2020

Well or contribute and fix them.
Alignment stubs are easily done if you have a ok way to measure font. So far the biggest thing i m looking at is consistency between browser and non browser. And the problem are always only around text and weird blending things.

@chearon
Copy link
Collaborator

chearon commented Sep 16, 2020

So far the biggest thing i m looking at is consistency between browser and non browser. And the problem are always only around text and weird blending things.

Are browsers even consistent with themselves across different hardware? I'd think not.

I don't understand much of the Skia source, but it looks like it can use HarfBuzz to shape text, so we could get consistent shaping across all platforms with it.

I also have played around with shaping/rendering in JS/WASM but we're pretty far from being able to do that I think. HarfBuzz's official WASM build is missing a lot of features that are needed for a high quality implementation, like vertical text features. I should be working on that soon for a related project though.

@asturur
Copy link
Contributor Author

asturur commented Sep 16, 2020

Browsers are consistent between themselves, with exception of old bad supported intel gpu. But otherwise i would say yes.

Is vertical text a native canvas api? i did not know.

@asturur
Copy link
Contributor Author

asturur commented Sep 16, 2020

What create inconsistencies is also sometimes font subhinting/anti aliasing settings in the SO would influence text measurements api. But all
small things very small

@danielyaa5
Copy link

Was canvaskit faster?

@satoren
Copy link

satoren commented Dec 7, 2020

I also tried canvaskit.
It took 2 minutes to load wasm on raspberrypi zero (Node.js v10.23.0).
Once loaded, it's not slow, but the native code is still faster.

The difference in performance on a PC cannot be discerned, as we have not rigorously benchmarked it.

@Brooooooklyn
Copy link

I started a new project using skia + rust + napi recently: https://github.com/Brooooooklyn/skia-rs

It's still in very early stage, and it will be my first priority side project in 2021.

For now, I have a minimal benchmark suite and it seems faster than node-canvas, the benchmark could be found at: https://github.com/Brooooooklyn/skia-rs/blob/main/benchmark/bench.ts

❯ yarn bench
yarn run v1.22.10
$ node -r @swc-node/register benchmark/bench.ts
Running "Draw house" suite...
Progress: 100%

  @napi-rs/skia:
    37 ops/s, ±0.42%   | fastest

  node-canvas:
    27 ops/s, ±1.01%   | slowest, 27.03% slower

Finished 2 cases!
  Fastest: @napi-rs/skia
  Slowest: node-canvas
✨  Done in 21.20s.

And of course it will be easy to install, no prebuild or download phases needed.

@asturur
Copy link
Contributor Author

asturur commented Dec 24, 2020

oh i ll play with it as a backend for fabricjs, does it support a bit of text yet?

@Brooooooklyn
Copy link

oh i ll play with it as a backend for fabricjs, does it support a bit of text yet?

No I haven't start text working yet, I will add a checklist in @napi-rs/skia to show features done/undo.

@Brooooooklyn
Copy link

Roadmap for @napi-rs/skia

@asturur
Copy link
Contributor Author

asturur commented Jan 7, 2021

I hope to get some time to familiarize with the codebase.

@yisibl
Copy link

yisibl commented Aug 2, 2021

@timfish
Copy link

timfish commented Feb 16, 2022

Having problems building node-canvas for recent versions of Electron. How easy would it be to swap it out for @napi-rs/canvas?

The roadmap shows that a lot is working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants