Name Date Size #Lines LOC

..--

external_test/H25-Apr-2025-199182

fonts/H25-Apr-2025-42

future_apis/H25-Apr-2025-8157

go/gold_test_env/H25-Apr-2025-222152

htmlcanvas/H25-Apr-2025-2,2601,873

npm_build/H25-Apr-2025-13,8199,529

tests/H25-Apr-2025-8,8287,298

wasm_tools/H25-Apr-2025-555293

.gitignoreH A D25-Apr-2025131 66

BUILD.bazelH A D25-Apr-202511.9 KiB427399

BUILD.gnH A D25-Apr-20259.6 KiB391363

CHANGELOG.mdH A D25-Apr-202553.1 KiB1,156924

MakefileH A D25-Apr-20256.7 KiB198158

README.mdH A D25-Apr-20257.6 KiB170122

WasmCommon.hH A D25-Apr-20254.3 KiB13786

canvaskit.gniH A D25-Apr-20251.4 KiB3531

canvaskit_bindings.cppH A D25-Apr-2025129.9 KiB2,7062,339

catchExceptionNop.jsH A D25-Apr-2025474 146

color.jsH A D25-Apr-20256.9 KiB203148

compile.shH A D25-Apr-20257.6 KiB267222

compile_gm.shH A D25-Apr-20257.1 KiB242188

cpu.jsH A D25-Apr-20255 KiB11575

debug.jsH A D25-Apr-202579 54

debugger.jsH A D25-Apr-20251 KiB2716

debugger_bindings.cppH A D25-Apr-202522.1 KiB559387

externs.jsH A D25-Apr-202533.2 KiB1,3011,057

font.jsH A D25-Apr-202512.6 KiB333252

gm.jsH A D25-Apr-20251.5 KiB5040

gm_bindings.cppH A D25-Apr-202512.8 KiB365268

interface.jsH A D25-Apr-202552.2 KiB1,351991

karma.bazel.jsH A D25-Apr-20251.6 KiB4922

karma.conf.jsH A D25-Apr-20253.1 KiB9548

make_version.shH A D25-Apr-2025750 3015

matrix.jsH A D25-Apr-202517.4 KiB535383

memory.jsH A D25-Apr-202513.3 KiB397240

package-lock.jsonH A D25-Apr-2025154.5 KiB4,2484,247

package.jsonH A D25-Apr-2025459 2221

paragraph.jsH A D25-Apr-202516.4 KiB397318

paragraph_bindings.cppH A D25-Apr-202536.5 KiB863716

paragraph_bindings_gen.cppH A D25-Apr-20255.1 KiB10781

pathops.jsH A D25-Apr-2025439 1815

postamble.jsH A D25-Apr-2025127 31

preamble.jsH A D25-Apr-2025376 91

release.jsH A D25-Apr-2025205 63

rt_shader.jsH A D25-Apr-20253.4 KiB7142

skottie.jsH A D25-Apr-20258.1 KiB221161

skottie_bindings.cppH A D25-Apr-202534.8 KiB861708

skp.jsH A D25-Apr-2025594 1814

util.jsH A D25-Apr-2025368 1910

viewer_bindings.cppH A D25-Apr-20252.7 KiB7360

webgl.jsH A D25-Apr-202517.2 KiB399297

webgpu.jsH A D25-Apr-20255.6 KiB142107

README.md

1# Prerequisites
2
3Node v14 or later is required to run tests. We use npm (the Node Package Manager) to install
4test dependencies. Recent installations of Node have npm as well.
5CanvasKit has no other external source dependencies.
6
7## Compiling with GN
8To build with GN, you need to have followed the instructions to download Skia and its deps
9<https://skia.org/docs/user/download>.
10
11To compile CanvasKit, you will first need to [download and activate `emscripten`][1] using the
12script in `//bin/activate-emsdk` (or `//tools/git-sync-deps` which also calls activate-emsdk).
13This places the associated files in `//third_party/externals/emsdk` and the GN[2] build scripts
14will use those by default.
15The compile.sh script automates the default GN settings; users are free to set their own. If users
16want to use their own version of emscripten, they should set the `skia_emsdk_dir` argument
17(see `//skia/gn/toolchain/wasm.gni`). For other available arguments, see
18`//modules/canvaskit/BUILD.gn`.
19
20[1]: https://emscripten.org/
21[2]: https://chromium.googlesource.com/chromium/src/tools/gn/+/48062805e19b4697c5fbd926dc649c78b6aaa138/README.md
22
23### MacOS specific notes
24Make sure you have Python3 installed, otherwise the downloading emscripten toolchain
25can fail with errors about SSL certificates. <https://github.com/emscripten-core/emsdk/pull/273>
26
27See also <https://github.com/emscripten-core/emscripten/issues/9036#issuecomment-532092743>
28for a solution to Python3 using the wrong certificates.
29
30# Compile and Run Local Example
31
32```
33# The following installs all npm dependencies and only needs to be when setting up
34# or if our npm dependencies have changed (rarely).
35npm ci
36
37make release  # make debug is much faster and has better error messages
38make local-example
39```
40
41This will print a local endpoint for viewing the example.  You can experiment
42with the CanvasKit API by modifying `./npm_build/example.html` and refreshing
43the page. For some more experimental APIs, there's also `./npm_build/extra.html`.
44
45For other available build targets, see `Makefile` and `compile.sh`.
46For example, building a stripped-down version of CanvasKit with no text support or
47any of the "extras", one might run:
48
49    ./compile.sh no_skottie no_font
50
51Such a stripped-down version is about half the size of the default release build.
52
53If CanvasKit fails to build and you are getting compile errors that don't look like Skia code,
54you may need to do a fresh install of the npm modules. You can do this by finding the .dts file
55mentioned in the error message, deleting it, and rerunning `npm ci`.
56
57If you're using the correct modules plus the latest supported typescript and it still fails,
58the module versions listed in package.json may need to be updated as well.
59
60# Unit tests, performance tests, and coverage.
61
62To run unit tests and compute test coverage on a debug gpu build
63
64```
65make debug
66make test-continuous
67```
68
69This reads karma.conf.js, and opens a Chrome browser and begins running all the test
70in `test/` it will detect changes to the tests in that directory and automatically
71run again, however it will automatically rebuild and reload CanvasKit. Closing the
72chrome window will just cause it to re-opened. Kill the karma process to stop continuous
73monitoring for changes.
74
75The tests are run with whichever build of CanvasKit you last made. be sure to also
76test with `release`, `debug_cpu`, and `release_cpu`. testing with release builds will
77expose problems in closure compilation and usually forgotten externs.
78
79## Coverage
80
81Coverage will be automatically computed when running test-continuous locally. Note that
82the results will only be useful when testing a debug build. Open
83`coverage/<browser version>/index.html` For a summary and detailed line-by-line result.
84
85## Measuring Performance
86
87We use puppeteer to run a Chrome browser to gather performance data in a consistent way.
88See `//tools/perf-canvaskit-puppeteer` for more.
89
90## Adding tests
91
92The tests in `tests/` are grouped into files by topic.
93Within each file there are `describe` blocks further organizing the tests, and within those
94`it()` functions which test particular behaviors. `describe` and `it` are jasmine methods
95which can both be temporarily renamed `fdescribe` and `fit`. Which causes jasmine to only those.
96
97We have also defined `gm` which is a method for defining a test which draws something to a canvas
98that is shapshotted and reported to gold.skia.org, where you can compare it with the snapshot at
99head.
100
101## Testing from Gerrit
102
103When submitting a CL in gerrit, click "choose tryjobs" and type CanvasKit to filter them.
104select all of them, which at the time of this writing is four jobs, for each combination
105of perf/test gpu/cpu.
106
107The performance results are reported to [perf.skia.org] and correctness results are reported to
108[gold.skia.org].
109
110Coverage is not measured while running tests this way.
111
112# Inspecting output WASM
113
114The `wasm2wat` tool from [the WebAssembly Binary Toolkit](https://github.com/WebAssembly/wabt)
115can be used to produce a human-readable text version of a `.wasm` file.
116
117The output of `wasm2wat --version` should be `1.0.13 (1.0.17)`. This version has been checked to
118work with the tools in `wasm_tools/SIMD/`. These tools programmatically inspect the `.wasm` output
119of a CanvasKit build to detect the presence of [wasm SIMD](https://github.com/WebAssembly/simd)
120operations.
121
122# Infrastructure Playbook
123
124When dealing with CanvasKit (or PathKit) on our bots, we use Docker. Check out
125$SKIA_ROOT/infra/wasm-common/docker/README.md for more on building/editing the
126images used for building and testing.
127
128## Updating the version of Emscripten we build/test with
129
130This presumes you have updated emscripten locally to a newer version of the
131sdk and verified/fixed any build issues that have arisen.
132
133  1. Edit `//bin/activate-emsdk` to install and activate the desired version of Emscripten.
134  2. Upload a CL with all the changes. Run all Test.+CanvasKit, Perf.+Puppeteer,
135      Test.+PathKit, Perf.+PathKit jobs to make sure the new builds pass all
136      tests and don't crash the perf harnesses.
137  3. Send out CL for review. Feel free to point the reviewer at these steps.
138
139## Running Skia's GMs and Unit Tests against wasm+WebGL ##
140
141General Tips:
142 - Make use of the skip lists and start indexes in the run-wasm-gm-tests.html to focus in on
143   problematic tests.
144 - `Uncaught (in promise) RuntimeError: function signature mismatch` tends to mean null was
145   dereferenced somewhere. Add SkASSERT to verify.
146
147### Debugging some GMs / Unit Tests
148For faster cycle time, it is recommended to focus on specific GMs instead of re-compiling all
149of them. This can be done by modifying the `compile_gm.sh` script (but not checking this in)
150to set `GMS_TO_BUILD` and/or `TESTS_TO_BUILD` to a minimal set of files. There's an `if false`
151that can be commented out to assist with this.
152
153Run `make gm_tests` or `make_gm_tests_debug` from this folder. This will produce a .js and .wasm
154in a (not checked in) `build` subfolder.
155
156Run `make single-gm` and navigate to <http://localhost:8000/wasm_tools/gms.html>. This will load
157that html file and the freshly built wasm_gm_tests binary and run a single GM and unit test that
158was compiled in. Feel free to modify //modules/canvaskit/wasm_tools/gms.html to run the specific
159GM/unit test or tests that you care about.
160
161### Testing all GMs / Unit Tests
162With the current GN build, this can take quite a while to compile and re-compile (the upcoming
163Bazel build should alleviate this).
164
165Run `make gm_tests` or `make_gm_tests_debug` from this folder. This will produce a .js and .wasm
166in a (not checked in) `build` subfolder.
167
168Change directory to `//tools/run-wasm-gm-tests`. Run `make run_local`, which will put all PNGs
169produced by GMs into `/tmp/wasm-gmtests` and run all unit tests.
170