[whatwg] Proposal to change getContext to support unavailable context at run-time.

Hello group,

For WebGL, we need getContext to possibly fail whereas the browser
supports contextId "webgl".
Indeed it is possible the browser fails creating a new 3D context for
many different reasons at run-time, which means a given contextId
might not be available at any given time.

This is in relation to [1]
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-canvas-getcontext


We are investigating two options :

Option #1 - modify getContext specified context creation steps so that
null can be returned at a later stage than step 3.
In a nutshell, allow the contextId specification to fail new context
initialization, reorder setting primary context only after the new
context object has been successfully initialized.
For this option (which is the current behavior of WebGL 1.0 spec), I'd
like to propose [1]'s steps 4 to 6 to be replaced with :

4. If the getContext() method has already been invoked on this element
for the same contextId, return the same object as was returned that
time, and abort these steps. The additional arguments are ignored.  [!
this was step 5]
5. Attempt to create a new context object, as defined by the
specification given for contextId's entry in the WHATWG Wiki
CanvasContexts page. [WHATWGWIKI]
6. If the new context object could not be initialized successfully,
return null and abort these steps.
7. If the element does not have a primary context, let the element's
primary context be contextId. [! this was step 4]
8. Return the new context object.



Option #2 - allow getContext to throw an exception.
We still need the modification of the spec as above, with step 6 as :
"6. If the new context object could not be initialized successfully,
throw an exception and abort these steps."
We'd probably also need to specify the kind of exception object to be thrown.


Regards,

Received on Sunday, 1 May 2011 22:50:01 UTC