Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
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

Web Assembly port #155

Open
pcwalton opened this issue May 22, 2019 · 17 comments
Open

Web Assembly port #155

pcwalton opened this issue May 22, 2019 · 17 comments

Comments

@pcwalton
Copy link
Collaborator

@pcwalton pcwalton commented May 22, 2019

It would be nice to have a Web Assembly port, like Google's CanvasKit for Skia.

@asajeffrey

This comment has been minimized.

Copy link
Member

@asajeffrey asajeffrey commented May 22, 2019

Yes please!

@asajeffrey

This comment has been minimized.

Copy link
Member

@asajeffrey asajeffrey commented May 22, 2019

There might be a bit of work getting the multithreaded story sorted out, it would be nice if we could use post message rather than SharedArrayBuffer for communication.

@pcwalton

This comment has been minimized.

Copy link
Collaborator Author

@pcwalton pcwalton commented May 22, 2019

Web Assembly is one of the reasons behind the Executor and RenderCommandListener abstractions. (The other one is WebRender, which is hesitant to add any more threads, at least in Gecko.) Core Pathfinder no longer spawns any threads. For a single-threaded workload you would buffer RenderCommands into a vector, then send them to a Renderer all at once instead of using a SceneProxy. This is likely what a Web Assembly port will want to do.

@est31

This comment has been minimized.

Copy link
Contributor

@est31 est31 commented Jun 1, 2019

I'd love to help with this. I need some project to find out how ready the wasm ecosystem is and this seems like it could be that project. @pcwalton do you have a list of items to work on?

@pcwalton

This comment has been minimized.

Copy link
Collaborator Author

@pcwalton pcwalton commented Jun 1, 2019

@est31 Here are the remaining blockers:

  • HarfBuzz needs to compile with wasm
  • FreeType needs to compile with wasm
  • Check skribo to make sure it compiles
  • Check Pathfinder to make sure it compiles
  • The pathfinder_gl crate needs a WebGL implementation
  • Canvas C API needs to be finished
  • JavaScript bindings need to be written
@est31

This comment has been minimized.

Copy link
Contributor

@est31 est31 commented Jun 1, 2019

@pcwalton thanks for the list.

I'm not sure I want to do the HarfBuzz/Freetype parts because I don't want to attempt installing emscripten again. It's very tedious to install and set up. The js embedding for wasi right now seems to build on emscripten itself :/. So maybe I should work on #164 first?

Canvas C API needs to be finished

Instead of the C API, I'd have used wasm-bindgen instead. It allows you to expose rust-y APIs to javascript.

@pcwalton

This comment has been minimized.

Copy link
Collaborator Author

@pcwalton pcwalton commented Jun 1, 2019

Any and all help is appreciated! I'll probably get to FreeType and HB if someone else doesn't do it first.

As for the C API, we need it for other reasons, for example @toolness' Unity plugin, so I figured we might as well use it for the wasm port as well. But I don't feel strongly about it either way.

@est31

This comment has been minimized.

Copy link
Contributor

@est31 est31 commented Jun 1, 2019

Hmm yeah I just realized that #164 is larger than I thought. It requires changes in font-kit as well as skribo or requires replacing skribo use entirely both of which is probably involved and it's probably easier for you given you know both much better than me.

I'd love to help though after #164 is resolved! Of course, only if you haven't done WASM support by then already :).

@jrowny

This comment has been minimized.

Copy link

@jrowny jrowny commented Jul 10, 2019

FreeType and Harfbuzz compile without any modification via emscripten. We'd have to compile the whole thing via wasm32-unknown-emscripten then right? I'm a bit new to Rust, but I'd love to help with this as well if I can.

@jrowny

This comment has been minimized.

Copy link

@jrowny jrowny commented Jul 10, 2019

Also, won't SIMD be a problem?

@est31

This comment has been minimized.

Copy link
Contributor

@est31 est31 commented Jul 10, 2019

@jrowny feel free to take this issue :)

@jnetterf

This comment has been minimized.

Copy link

@jnetterf jnetterf commented Nov 30, 2019

I have a PR which adds a glow implementation of the device abstraction: #243

This allows parts of pathfinder to target WebGL 2 on wasm32-unknown-unknown. I'd appreciate feedback.

If this works, I think this leaves getting FreeType and Harfbuzz to compile without emscripten as the main challenge.

@s3bk

This comment has been minimized.

Copy link
Contributor

@s3bk s3bk commented Jan 27, 2020

I would like to report success!
DEMO

Modified pathfinder repo: https://github.com/s3bk/pathfinder
Grafeia repo: https://github.com/grafeia/grafeia

I am using vector to draw things and font to parse fonts and draw text.

@pcwalton

This comment has been minimized.

Copy link
Collaborator Author

@pcwalton pcwalton commented Jan 28, 2020

Wow!

@boulabiar

This comment has been minimized.

Copy link

@boulabiar boulabiar commented Jan 28, 2020

Excellent !
Does it work with complex languages like Arabic?

@s3bk

This comment has been minimized.

Copy link
Contributor

@s3bk s3bk commented Jan 28, 2020

@boulabiar I plan to support right to left scripts eventually. The pdf viewer using the font crate renders Arabic text correct.
What I may not implement for a while is embeddings, and instead require a new paragraph when the direction is switched.

@s3bk

This comment has been minimized.

Copy link
Contributor

@s3bk s3bk commented Jan 28, 2020

Upon request from #rust-offtopic, here is the PDF viewer running in wasm:

https://pdf-rs.github.io/view-wasm/

(use ◁ and ▷ keys to navigate)

I moved the code to display a scene here: https://github.com/s3bk/pathfinder_view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.