-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
OffscreenCanvas and CanvasRenderingContext2D #5701
Comments
I've been eagerly awaiting canvas since I heard about Deno. |
What about using raqote for Canvas? |
I'm implementing skia-rs using NodeJS |
my alternative for now as been to use imagemagick, which requires users to install an external dependency, has no type safety, and has some very old, archaic apis |
*actually I discovered a library that has been a pretty good solution https://github.com/DjDeveloperr/deno-canvas. It provides the canvas api as a wasm binary import Canvas from 'https://deno.land/x/[email protected]/mod.ts'
const canvas = Canvas.MakeCanvas(200, 200);
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'red';
ctx.fillRect(10, 10, 200 - 20, 200 - 20);
await Deno.writeFile('image.png', canvas.toBuffer()) |
For completeness sake, I want to point out that there’s CanvasKit, which is Skia compiled to WebAssembly (Skia being the 2D graphics library that Blink uses to implement Canvas itself). |
@surma https://deno.land/x/canvas is built on CanvasKit. For native in the binary, we already include wgpu-core (the WebGPU engine for Gecko). If Skia will ever be able to use WebGPU as a rendering backend, it might make sense to include canvaskit or skia linked to wgpu-core (webgpu.h) right in the binary. |
Amazing news. Did not know about that. Thank you :) |
This is way over my head, but is https://bugs.chromium.org/p/skia/issues/detail?id=12512 progress which would allow canvas native in Deno? 🤞 |
that would be very cool indeed. Another project has popped up in the meantime though https://deno.land/x/[email protected]. SkiaCanvas backed by ffi rather than wasm |
The problem with emulated Canvas2D API of canvaskit is it doesn't support some APIs. From https://www.npmjs.com/package/canvaskit-wasm
And it has some performance issues as well. Which is why I made skia_canvas. |
I just talked with Leo about this, and we think it will be trivial to support at least OffscreenCanvas + GPURenderingContext (WebGPU) soon. This is not 2D rendering context, but it will allow rendering using WGSL shaders and exporting of the data to a blob / ImageBitmap. |
I think text measuring and rendering are very important for server side image generation... WebGPU, on the other hand, is not useful enough (for image generation, since you can only export one frame a time). |
For 2DContext, we might consider using https://github.com/linebender/vello. |
@crowlKats from their readme:
Does this mean you would require bringing webgpu support back in first? |
yes, which is coming in the upcoming release most likely. |
WebGPU is back as of 1.39, hopefully making this on track again! |
<ctx.textAlign = 'center' and ctx_full.textBaseline = 'middle' > Invalid code wait fix bug |
#1629 is about WebGL, it will likely take a lot of time to implement.
I think add OffscreenCanvas & CanvasRenderingContext2D interface at first is a good idea for now.
A lot of server-side image process like shields.io can be done in OffscreenCanvas with 2d renderer
(and it should be able to load image from disk / web / memory.)
Read from ttf directly? <- so we need a FontFace api with local file support
Use system font registry?
The text was updated successfully, but these errors were encountered: