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

Make 2D contexts discardable with OffscreenCanvas #2303

Closed
junov opened this issue Jan 27, 2017 · 3 comments
Closed

Make 2D contexts discardable with OffscreenCanvas #2303

junov opened this issue Jan 27, 2017 · 3 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest normative change topic: canvas

Comments

@junov
Copy link
Member

junov commented Jan 27, 2017

WebGL has a reasonable model that allows for contexts to be released and rebuilt, which allows, among other things, for GPU resources to be released when a page is in the background. This is implemented via the webglcontextlost and webglcontextrestored events.

The issue has been raised in the past that 2D contexts should have the same feature. However, it is not clear how this could be achieved in a backwards-compatible way. One suggestion was to make 2D contexts discardable only if an event listener is registered on the contextLost event. That idea was discarded because the registration of an event listener is not allowed to have side-effects.

With OffscreenCanvas, we have a clean slate. There is no legacy content to break. Therefore, we could use this opportunity to add the contextLost/restored events to OffscreenCanvases with 2D contexts.

@annevk
Copy link
Member

annevk commented Jan 26, 2018

Is @whatwg/canvas still interested in this or can this be closed?

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Jan 26, 2018
@junov
Copy link
Member Author

junov commented Jan 26, 2018

Not sure. In Blink, we've explored alternative mitigations, such as using a background task to swap buffers out of GPU memory for browser tabs that are not in the foreground, we're thinking of also png-compressing them. This works kind of okay for preemptively freeing resources. That said, there is still no good solution for detecting and recovering from an unforeseen GPU reset. These GPU resets are not as frequent as they used to be thanks to huge improvements to display drivers and OSes.

@annevk
Copy link
Member

annevk commented Jan 26, 2018

I guess we can still consider this a while longer given that only Safari is shipping OffscreenCanvas and only for "webgl".

mfreed7 pushed a commit to mfreed7/html that referenced this issue Jun 3, 2022
This adds a cancelable contextlost event, a contextrestored event, and an isContextLost() method.

Closes whatwg#4809. Closes whatwg#2303.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest normative change topic: canvas
Development

No branches or pull requests

2 participants