-
Notifications
You must be signed in to change notification settings - Fork 7
Initial support for CanvasKit / JavaScript version #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manuhornung Some comments or questions for you 😄 From my side, this is ready to merge, and I can keep adding more bindings + examples in other PRs, unless you think we should change anything :)
@@ -9,35 +9,35 @@ let imageInfo = Sk.ImageInfo.make(800, 600, N32, Premul, None); | |||
let surface = Sk.Surface.makeRaster(imageInfo, None); | |||
let canvas = Sk.Surface.getCanvas(surface); | |||
|
|||
let bgColor = Sk.Color.make(255, 100, 0, 200); | |||
let bgColor = Sk.Color.makeARGB(255, 100, 0, 200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manuhornung Changed this naming to make more clear which param is what (as CanvasKit has different ordering, I was going crazy 😄 )
"devDependencies": { "ocaml": "~4.7.0" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a more recent version of OCaml (same as Revery).
src/skia.cpp
Outdated
CAMLprim value | ||
caml_SkPath_create() | ||
{ | ||
throw "caml_SkPath_create not implemented yet"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manuhornung Left these functions as todos. I couldn't compile without at least defining them in cpp too.
@@ -289,7 +301,10 @@ module Sk = { | |||
|
|||
external getCanvas: t => Canvas.t = "caml_SkSurface_getCanvas"; | |||
|
|||
external makeCanvasSurface: string => t = | |||
"caml_CanvasKit_MakeCanvasSurface"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this should belong to CanvasKit
or Surface
🤔
CAMLprim value | ||
caml_CanvasKit_currentContext(value vCanvasId) | ||
{ | ||
throw "caml_CanvasKit_MakeCanvasSurface is only available in CanvasKit / JavaScript bindings"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manuhornung Is there a better way to solve this?
This adds some support for the JavaScript / CanvasKit version of SKIA.
Some notes / discoveries:
CanvasKitInit
function, exposed in the JS filebin/canvaskit.js
, and then passing the path to the wasm file as the params to this function, which returns a promise. This means that any code relying on CanvasKit needs to wait until these two files are loaded.The way the jsoo bindings are being designed right now is assuming that
CanvasKit
exists already in the global namespace (i.e. bothbin/canvaskit.js
andbin/canvaskit.wasm
have loaded). This makes the code in this repo much simpler but forces the consumers to load these two files manually on their own.To test it:
Screenshot from the example 😄