Skip to content

QUESTION abou SKIA + NODE + NAPI #1652

Description

@asturur

@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?

Activity

  1. zbjornson commented on Sep 12, 2020

    @zbjornson
    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!)

  2. asturur commented on Sep 12, 2020

    @asturur
    ContributorAuthor

    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

  3. zbjornson commented on Sep 12, 2020

    @zbjornson
    Collaborator

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

  4. kenotron commented on Sep 16, 2020

    @kenotron

    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

  5. asturur commented on Sep 16, 2020

    @asturur
    ContributorAuthor

    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.

  6. chearon commented on Sep 16, 2020

    @chearon
    Collaborator

    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.

  7. asturur commented on Sep 16, 2020

    @asturur
    ContributorAuthor

    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.

  8. asturur commented on Sep 16, 2020

    @asturur
    ContributorAuthor

    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

  9. danielyaa5 commented on Nov 2, 2020

    @danielyaa5

    Was canvaskit faster?

  10. satoren commented on Dec 7, 2020

    @satoren

    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.

  11. Brooooooklyn commented on Dec 24, 2020

    @Brooooooklyn

    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.

  12. asturur commented on Dec 24, 2020

    @asturur
    ContributorAuthor

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

  13. Brooooooklyn commented on Dec 24, 2020

    @Brooooooklyn

    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.

  14. Brooooooklyn commented on Jan 7, 2021

    @Brooooooklyn

    Roadmap for @napi-rs/skia

  15. asturur commented on Jan 7, 2021

    @asturur
    ContributorAuthor

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

  16. yisibl commented on Aug 2, 2021

    @yisibl
  17. timfish commented on Feb 16, 2022

    @timfish

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions