Skip to content

OffscreenCanvas support? #2

@mmocny

Description

@mmocny

Is there any plan to support OffscrenCanvas with these new apis?

My read is that the element being placed has to be a "direct child of the canvas element". I think this does limit the api to the main thread, since you cannot pass a reference to an element across to workers, and the OffscreenCanvas, although transferable, is not an element that would have access to the actual <canvas> children.

Is that correct?


I think it would be interesting to support some sort of (even limited) use case for Web workers, such as just supplying dynamic data for an html template / Web Component / DOM Parts, etc.

One of the uses cases I have could be summarized as:

  • I have a web component that supplies UI. It could be instantiated on the main thread and attached to the canvas as a child.
  • This component is completely isolated from the rest of the page, can be in a shadow root.
  • Component adjusts itself visually based on custom props passed to it.
  • The values of these props are dynamically computed and updated by a web worker.
  • All the features the component needs are already supported by web workers-- except for the ability to render a DOM element.

Besides just moving the cost of the compute for props off the main thread, a requirement is to asynchronously display visual updates decoupled from the main thread animation frame rate. So just a convenience wrapper around postMessage is not sufficient for this use case.

Is it viable to consider something like this in the future? Or does it fundamentally require main thread?

Cheers.


(Apologies, I know I asked this question elsewhere but am failing to find the source now...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions