Skia WebAssembly

1,542 views
Skip to first unread message

sha...@infograph.com

unread,
Oct 1, 2018, 1:42:16 PM10/1/18
to skia-discuss
In an earlier thread, it was pointed out that the Skia team had setup a continuous build bot that compiled Skia to WASM, though nobody used it or tests it.Ā  I don't see anything in Skia's source that looks like a ninja script for building such a thing.Ā  Could the scripts or makefiles for compiling to WebAssembly be external to the Skia git repository?Ā Ā 

Mike Klein

unread,
Oct 1, 2018, 1:50:46 PM10/1/18
to skia-d...@googlegroups.com
I think `git grep -i wasm` is the way to what you're looking for?Ā  The most developed parts of Skia targeting WASM are the bits you see labeled Pathkit, a subset of Skia that's able to do logical operations on vector paths.

On Mon, Oct 1, 2018 at 1:42 PM <sha...@infograph.com> wrote:
In an earlier thread, it was pointed out that the Skia team had setup a continuous build bot that compiled Skia to WASM, though nobody used it or tests it.Ā  I don't see anything in Skia's source that looks like a ninja script for building such a thing.Ā  Could the scripts or makefiles for compiling to WebAssembly be external to the Skia git repository?Ā Ā 

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

sha...@infograph.com

unread,
Oct 1, 2018, 2:01:02 PM10/1/18
to skia-discuss
Ah. The results of that command revealed:
BUILD.gn:Ā  if (target_cpu != "wasm")
So, the idea is to run the existing ninja scripts but set the target cpu to wasm, instead of x64 or whatever.Ā  That is how you build webassmbly?
Will that also create some kind of HelloWorld.js / .html file(s) that show how to use it?

Mike Klein

unread,
Oct 1, 2018, 2:15:56 PM10/1/18
to skia-d...@googlegroups.com
No, wasm is not really well integrated at all with GN.Ā  At the moment we have a ton of side scripts to handle those builds.

sha...@infograph.com

unread,
Oct 1, 2018, 2:19:17 PM10/1/18
to skia-discuss
Ok.Ā  Is there a way to see what those scripts do?Ā  Do they call Emscripten?Ā  Which Skia source files do they compile? Do they reference backend source files defined outside skia?Ā  etc...

Mike Klein

unread,
Oct 1, 2018, 2:22:08 PM10/1/18
to skia-d...@googlegroups.com
Yes, they're checked into the Skia repo, and you should be able to find them by looking for those files with "wasm" in them.

sha...@infograph.com

unread,
Oct 1, 2018, 6:58:21 PM10/1/18
to skia-discuss
So, the automated build bots are only making pathOps into a wasm module?
Not all of Skia.Ā  Just pathOps?

Mike Reed

unread,
Oct 1, 2018, 8:22:53 PM10/1/18
to skia-d...@googlegroups.com
We have a separate experiment to put all of skia into wasm -- called canvaskit

sha...@infograph.com

unread,
Oct 1, 2018, 9:47:55 PM10/1/18
to skia-discuss
Any chance of seeing that project?

Florin Malita

unread,
Oct 1, 2018, 10:26:51 PM10/1/18
to skia-d...@googlegroups.com

Kevin Lubick

unread,
Oct 2, 2018, 9:36:41 AM10/2/18
to skia-discuss
If you check out Skia at ToT, you'll find $SKIA_ROOT/experimental/canvaskit

Assuming you have followed theĀ emscripten getting startedĀ guide and set that install location to the environment variable $EMSDK, you should be able to run

make release && make local-example

and then navigate toĀ http://localhost:8000/canvas-kit/example.html to see it in action.

You can also check outĀ https://jsfiddle.skia.org/canvaskit for a live-editor of the CanvasKit library (you'll want to look experimental/canvaskit/canvaskit_bindings.cpp and experimental/canvaskit/interface.js to see what's been exposed thus far.Ā  It's still very new, so we haven't exposed everything we want to yet, nor documented it sufficiently).

sha...@infograph.com

unread,
Oct 2, 2018, 3:30:03 PM10/2/18
to skia-discuss
Great!Ā  Ā Was canvaskit added to experimental after m70?
Because it isn't in my copy.

Heather Miller

unread,
Oct 2, 2018, 4:03:01 PM10/2/18
to skia-d...@googlegroups.com
Correct, it landed it a couple weeks after M70 cut.

sha...@infograph.com

unread,
Oct 4, 2018, 2:04:06 PM10/4/18
to skia-discuss
Does the build process need clang?Ā  compile.sh gives me this error:

/c/CDL_Development/ThirdPartyLibs/skia_master /c/CDL_Development/ThirdPartyLibs/skia_master/experimental/canvaskit
Compiling bitcode
ERROR at //gn/BUILDCONFIG.gn:85:14: Script returned non-zero exit code.
Ā  is_clang = exec_script("gn/is_clang.py",
Ā  Ā  Ā  Ā  Ā  Ā  Ā ^----------
Current dir: C:/CDL_Development/ThirdPartyLibs/skia_master/out/canvaskit_wasm/
Command: C:/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/python.exe -- C:/CDL_Development/ThirdPartyLibs/skia_master/gn/is_clang.py /c/emsdk/emscripten/1.38.12/emcc /c/emsdk/emscripten/1.38.12/em++
Returned 1.



On Tuesday, October 2, 2018 at 6:36:41 AM UTC-7, Kevin Lubick wrote:

Mike Klein

unread,
Oct 4, 2018, 2:15:53 PM10/4/18
to skia-d...@googlegroups.com
Can you run gn/is_clang.py yourself?

sha...@infograph.com

unread,
Oct 4, 2018, 2:32:11 PM10/4/18
to skia-discuss
Yeah.Ā Ā 

C:/emsdk/python/2.7.13.1_64bit/python-2.7.13.amd64/python.exe -- C:/CDL_Development/ThirdPartyLibs/skia_master/gn/is_clang.py /c/emsdk/emscripten/1.38.12/emcc /c/emsdk/emscripten/1.38.12/em++

puts "true" out to the concole.

Mike Klein

unread,
Oct 4, 2018, 2:34:31 PM10/4/18
to skia-d...@googlegroups.com
Weird!Ā  Can you try replacing is_clang.py's contents with

Ā  Ā print 'true'

and see how that goes?Ā  Worst case, you can always just remove that call to is_clang.py entirely.Ā  One of either false or true ought to work for you there with emcc.

sha...@infograph.com

unread,
Oct 4, 2018, 2:45:21 PM10/4/18
to skia-discuss
I hard-coded is_clang = true in BUILDCONFIG.gn

Now it errors when it tries to compile each file.Ā  In this pattern:

[1/666] compile ../../src/effects/SkOverdrawColorFilter.cpp
FAILED: obj/src/effects/effects.SkOverdrawColorFilter.oĀ 
/c/emsdk/emscripten/1.38.12/em++ -MMD -MF obj/src/effects/effects.SkOverdrawColorFilter.o.d -DNDEBUG -DSK_GAMMA_APPLY_TO_A8 -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0 -DSK_ENABLE_DISCRETE_GPU -DSKIA_IMPLEMENTATION=1 -I../../include/android -I../../include/c -I../../include/codec -I../../include/config -I../../include/core -I../../include/docs -I../../include/effects -I../../include/encode -I../../include/gpu -I../../include/atlastext -I../../include/pathops -I../../include/ports -I../../include/svg -I../../include/utils -I../../include/utils/mac -I../../include/private -I../../src/c -I../../src/codec -I../../src/core -I../../src/effects -I../../src/fonts -I../../src/image -I../../src/images -I../../src/lazy -I../../src/opts -I../../src/pathops -I../../src/pdf -I../../src/ports -I../../src/sfnt -I../../src/shaders -I../../src/shaders/gradients -I../../src/sksl -I../../src/utils -I../../src/utils/win -I../../src/xml -I../../third_party/gif -I../../src/gpu -fstrict-aliasing -fPIC -O3 -fdata-sections -ffunction-sections -Wno-unused-parameter -s USE_FREETYPE=1 -s USE_LIBPNG=1 -DIS_WEBGL=1 -DSK_RELEASE -std=c++14 -fno-exceptions -fno-rtti -frtti -c ../../src/effects/SkOverdrawColorFilter.cpp -o obj/src/effects/effects.SkOverdrawColorFilter.o
CreateProcess failed: The system cannot find the file specified.

Mike Klein

unread,
Oct 4, 2018, 3:03:45 PM10/4/18
to skia-d...@googlegroups.com
That's weird.Ā  Try again?Ā  Is your disk ok?

sha...@infograph.com

unread,
Oct 4, 2018, 3:13:24 PM10/4/18
to skia-discuss
Yeah. Results don't change.
I am running the compile.sh from Git Bash.
Since it is the only shell console I have on Windows.
Is there a way to run a shell file from the a developers console?

Should I try cygwin?Ā  I hear it is expensive.

Mike Klein

unread,
Oct 4, 2018, 3:18:24 PM10/4/18
to skia-d...@googlegroups.com
Does the compile command work if you run it yourself?Ā  Any idea what file "The system cannot find the file specified." is referring to?

You should keep in mind you're probably the first person to attempt to build like this on Windows.

sha...@infograph.com

unread,
Oct 4, 2018, 3:30:14 PM10/4/18
to skia-discuss
When I run the em++ command myself, it says:

error: unable to open output file 'obj/src/effects/effects.SkColorMatrix.o': 'no such file or directory'

Should I give up and go try to make a linux vm?

Mike Klein

unread,
Oct 4, 2018, 3:31:57 PM10/4/18
to skia-d...@googlegroups.com
Possibly, yeah.Ā  Do all those directories exist?Ā  Do you have space on your disk?

sha...@infograph.com

unread,
Oct 4, 2018, 3:46:07 PM10/4/18
to skia-discuss
There is no obj directory under canvaskit.Ā  Disk has plenty of space.

Mike Klein

unread,
Oct 4, 2018, 3:54:34 PM10/4/18
to skia-d...@googlegroups.com
maybe try making one?

sha...@infograph.com

unread,
Oct 4, 2018, 3:58:00 PM10/4/18
to skia-discuss
Yeah, if I make the obj/src/effecrts/ folders, and run the compiler manually it works.
When I run the shell script, it still fails.
I am going to stop and switch to linux.Ā  Cent OS

Matthew Leibowitz

unread,
Oct 4, 2018, 4:06:13 PM10/4/18
to skia-discuss
It will be interesting to see what you had to do to get skia working nicely.
I am working on SkiaSharp and I would really like to get that working in the browser as well.

Jesse Luo

unread,
Oct 8, 2018, 7:46:42 PM10/8/18
to skia-discuss
I was using this project today but I could not get the text to render in the examples i.e "Try moving your mouse" does not show up. Any advice?

Jesse

unread,
Oct 9, 2018, 1:34:03 PM10/9/18
to skia-discuss
Ah, my mistake, noticed in commit log that drawtext has issues, will try checking out a more recent commit.
maybe try making one?

<div class=
maybe try making one?

<div class=
maybe try making one?

<div class=

sha...@infograph.com

unread,
Oct 14, 2018, 7:34:45 PM10/14/18
to skia-discuss
The interface.js and externs.js seem to pay special attention to SkPath, but not to canvas, image or any other types.
Is that because they were important for the example?Ā  Or is that to fix an issue with path?


On Tuesday, October 2, 2018 at 6:36:41 AM UTC-7, Kevin Lubick wrote:

Shawn Riordan

unread,
Oct 16, 2018, 12:46:43 AM10/16/18
to skia-discuss
Also, consider the following:

I am working on a project where the WASM interface isn't Skia's interface. Instead, the interface is a wrapper.Ā  I am looking at exposing a more simple interface.Ā  Where the javascript doesn't need to know about things like SkPath, SkCanvas, SkBlendMode or SkImage.Ā  I have a C++ library that will understand all those things, but the javascript layer doesn't need to know about them.

I know that this sort of interface is not what you are targeting.Ā  Your goal of exposing all the primary components of Skia makes sense and should not stop, by any means.Ā Ā 

Maybe it would help if I explained my use case in more detail.

The company I work for has a universal viewer application.Ā  It can view (almost) any file format type.Ā  From office documents to CAD drawings and raster blueprints.Ā  Almost anything... In our current situation, we have native applications that use Skia for the task of rendering to the screen.Ā  For our HTML client, we convert to SVG.Ā  (not using your code, but ours)Ā Ā 

We have found SVG to suck.Ā  There are a lot of things it cannot do. And even more things it cannot do well. We spend an unreasonable amount of time trying to get SVG to do what we want it to.Ā Ā 

Then came the question:Ā  What if the HTML client could use the same rendering code base as the native clients?

Which lead to this foray into Skia-WASM town.Ā  Our native applications have multiple layers.Ā  The GUI layer has no knowledge of the rendering layer that uses Skia.Ā  Because that isn't his job.Ā  A lower "draw()" layer knows about that sort of stuff.Ā  We are trying to come up with a similar set of layers in our WASM implementation. Where the javascript layer doesn't need to understand things like Skia.Ā  Or file format reading.Ā  Or whatever. It only knows the minimalist interface we expose to native clients.


On Tuesday, October 2, 2018 at 6:36:41 AM UTC-7, Kevin Lubick wrote:

Kevin Lubick

unread,
Oct 16, 2018, 11:14:22 AM10/16/18
to skia-discuss
The reason for that is because this is new and we haven't really had time to do it for other types (yet).Ā  Much of the SkPath things came fromĀ https://skia.org/user/modules/pathkit and was more or less copy-paste, to allow for chaining w/o leaking of SkPath objects.

sha...@infograph.com

unread,
Oct 22, 2018, 8:42:11 PM10/22/18
to skia-discuss
Does CanvasKit not support blendmodes?

Kevin Lubick

unread,
Oct 23, 2018, 7:52:19 AM10/23/18
to skia-discuss
Not yet, but it's on the roadmap.Ā Ā 

sha...@infograph.com

unread,
Oct 23, 2018, 12:59:40 PM10/23/18
to skia-discuss
Even the CPU renderer?

sha...@infograph.com

unread,
Oct 30, 2018, 1:21:35 AM10/30/18
to skia-discuss
When I use the standard canvaskit.js and canvaskit.wasm in the example.html, everything is fine.
But I was given a React-flavor of node.js and used:

const CKInit = require('../bin/canvaskit.js')

In the example, everything worked fine.
In the React / Node case, I got hundreds of error messages, when parsing the canvaskit.js file.Ā  Things like:

'read' is not defined
'readbuffer' is not defined
'scriptArgs' is not definedĀ 
'quit' is not defined
'printErr' is not defined
'tempI64' is not defined
'tempDouble' is not defined

Is there some aspect of js that I need to include, before canvaskit.js?Ā  There is nothing in my example.html case.Ā  He has no troubles.

I don't know left from right, when it comes to javascript.Ā  let alone node.js or react.

Kevin Lubick

unread,
Oct 31, 2018, 9:45:36 AM10/31/18
to skia-discuss
We have an example that works for me on Node 8.9+Ā https://github.com/google/skia/blob/master/experimental/canvaskit/canvaskit/node.example.js

One small thing, I have to tell node that it is dealing with WebAssembly:

node ./canvaskit/node.example.js --expose-wasm

JongChan Choi

unread,
Sep 12, 2020, 12:21:36 PM9/12/20
to skia-discuss
Hello, is there any plans for pdf backend support on canvaskit?

Mike Reed

unread,
Sep 14, 2020, 10:29:19 AM9/14/20
to skia-d...@googlegroups.com
Should be very easy -- just grows the code-size.


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.

JongChan Choi

unread,
Sep 15, 2020, 1:06:44 AM9/15/20
to skia-d...@googlegroups.com
Then how about creating a separate package? (e.g. canvaskit-with-pdf-wasm)

I want to make custom builds for personal use, but I don't have much knowledge in c++ and skia codebase. 😭
Can you please guide me how to fix it if I want to add a pdf support?

Peter Verswyvelen

unread,
Sep 15, 2020, 3:07:44 AM9/15/20
to skia-d...@googlegroups.com
I think you just need to enable use_skia_pdf inĀ 


Are you able to run this script on your machine? First follow the instructions on the skia.org website on how to build the standard packages.

PS: One thing that would be really handy is a cloud build system, with a web front end where you can tick use_skia_xxx checkboxes, and select targets, and have a custom version of Skia build in the cloud. It could do caching to avoid rebuilding common configs. It could require you to login with your GCP account :-)



JongChan Choi

unread,
Sep 15, 2020, 9:21:58 PM9/15/20
to skia-d...@googlegroups.com
I've already just turned on that flag and built it, but the size of the wasm and js files did not change.
Probably it seems that the canvaskit_bindings.cpp file should be fixed as well. (maybe adding some js runtime code too)
The code to write the binding looks like DSL. I think I'll need somebody's mentoring to fix this. šŸ™

Nathaniel Nifong

unread,
Sep 16, 2020, 10:12:48 AM9/16/20
to skia-d...@googlegroups.com
How are you planning to use the PDF support? There's currently no PDF related javascript bindings in canvaskit_bindings.cpp, you can't just turn it on with a flag. Are you asking for some?Ā 

JongChan Choi

unread,
Sep 16, 2020, 11:09:00 AM9/16/20
to skia-d...@googlegroups.com
I want to write a Hangul document pdf converter usingĀ hwp.js.
I looked for a few javascript pdf writers, but couldn't find an implementation that could embed fonts, expressive and freely compose the layout.
Skia is suitable because it provides a pdf backend while providing a low level api similar to canvas.

Nathaniel Nifong

unread,
Sep 16, 2020, 1:33:55 PM9/16/20
to skia-d...@googlegroups.com
I'll work on adding some paragraph bindings. (basically to create a PDF surface, add pages, draw to them with ordinary SkCanvas methods, and save off the PDF file)
This is somethingĀ that would be turned on at compile time, when theĀ canvaskit wasm binary is built.
I do have some other tasks on my plate, but it shouldn't be too long.

JongChan Choi

unread,
Sep 17, 2020, 5:50:18 AM9/17/20
to skia-d...@googlegroups.com
Oh that's good news. I'll look forward to it. 😊


Reply all
Reply to author
Forward
0 new messages