Bug 28786 - Canvas needs a well defined model for what happens when you change contexts
Summary: Canvas needs a well defined model for what happens when you change contexts
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Chris Marrin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-27 15:27 PDT by Chris Marrin
Modified: 2021-03-08 02:39 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Marrin 2009-08-27 15:27:50 PDT
When Canvas had only a 2D context, the model was simple. That 2D context lived for as long as the Canvas element. But now that you can have a 3D context, what happens when you switch between 2D and 3D? The old context can't get destroyed because there is possibly still a reference to it in JavaScript. So what happens when you call one of its rendering functions? Mixing 2D and 3D is hard, and maybe even impossible on some hardware. 

We have to decide on what the model is. Who owns the bitmap being rendered into? If it's owned by the context, how does that bitmap get associated with a Canvas? If it's the canvas, how do you know which context it is attached to? There are many ways to do it, we just need to decide which one to use. This is a discussion that has to be in the HTML5 group.

For now, the model I have implemented is that, once you have done a getContext for a 2D or 3D context, you can only use that context. Trying a getContext with any other string will return null. This is not a great solution, but it is safe and sufficient for any existing content.
Comment 1 Kimmo Kinnunen 2021-03-08 02:39:13 PST
As per https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-getcontext maybe the model originally selected was good.