Skip to content
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

Offscreen canvas support #25

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Conversation

SlicedSilver
Copy link

Add offscreen canvas support.

  • Adds allowOffscreenCanvas option, which tells the library to try use OffscreenCanvas if available.
  • Adds methods for getting the OffscreenCanvas instance so it can be transferred to a worker thread, if required.

@SlicedSilver SlicedSilver self-assigned this May 2, 2024
}

class DevicePixelContentBoxBinding implements Binding, Disposable {
class DevicePixelContentBoxBinding<OffscreenAllowed extends boolean> implements Binding<OffscreenAllowed>, Disposable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to decouple OffscreenCanvas size control logic from the DevicePixelContentBoxBinding.
In fact, only HTMLCanvasElement cares about its content box and occupied space on the screen to sync the bitmap size with content box. OffscreenCanvas bitmap could have any size, for example two times larger or smaller than the target canvas' bitmap.

I think it's more flexible to sync OffscreenCanvas bitmap size with HTMLCanvasElement bitmap size in a separate binding. It should be something like a CHAIN of bindings: HTMLCanvasElement bitmap size is bound with his own content box by DevicePixelContentBoxBinding, and OffscreenCanvas bitmap size is bound with target HTMLCanvasElement bitmap size by another binding, what we are going to implement in this PR)

So the size change propagation chain should look like: CanvasElement's device-pixel-content-box ==> CanvasElement's bitmap size ==> OffscreenCanvas bitmap size. And here enters the flexibility: we could subscribe MULTIPLE OffscreenCanvases to the same CanvasElement, we could introduce some size transform in-between Element and Offscreen (to perform super- or subsampling) and so on.

I'll come back later with some suggestions on naming and module structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants