-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
CanvasRenderingContext2D: Add getImageDataAsync method #10855
Comments
Brillant move. I like the async method, even if it presents a very slight increase in difficulty in workflows. Performance AND battery efficiency is a simultaneous win-win with this async verison of API, especially with HDR pixel formats (48-bit / 16bpp via Float16) |
Glad to see this coming back. One aspect I'm unsure about though is the timing of the API. |
I'd naturally expect that such an API always does that. Generally, this is kind of "Get this image once it's unblocked", and unblocking always happens at least once per paint cycle. It's my understanding that getImageData blocks until the framebuffer is delivered -- so naturally I'd expect a nonblocking getImageDataAsync would report a callback right at the moment of getImageData unblock. However: That being said, it would be a good idea to explicitly mention it in the specifications, to assauge fears of a multi-frame latency added. |
Minor nit: I kinda like the |
Though |
That would confusingly mean getImageDataAsyncInto() or getImageDataIntoAsync() but that becomes longwinded. The "get" prefix and "into" suffix is usually designed in APIs independently, whether you're getEncoding() or encodeInto(), rather than getEncodingInto() Either way, I'm neutral in this case. I think @ccameron-chromium is running with the getImageDataAsync() ball. |
What is the issue with the HTML Standard?
The existing
getImageData
method is synchronous.In practice, canvases are draw asynchronously (often by a GPU, but contention for the Javascript main thread can be avoided by doing CPU drawing on a non-main thread). This means that
getImageData
must stall the main thread while it reads back data. This has been slightly mitigated bywillReadFrequently
, but that's not without its own issues.A better solution would be to create an asynchronous
getImageData
function. Something to the effect ofThis will get a snapshot of the canvas at the moment that the
getImageDataAsync
call is made (it will not be affected by subsequent draw calls). TheImageData
to populate is passed as a parameter, as opposed to being allocated by the call. This allows less memory thrashing, and it also removes ambiguity about "what should the default readback pixel format or color space be", because theImageData
already answers that.The text was updated successfully, but these errors were encountered: