[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] getContext multiple context language




On Jan 22, 2010, at 5:45 PM, Vladimir Vukicevic wrote:

Here's the language for getContext() -- let me know of any suggestions before I send it off to hixie:

object getContext(in DOMString contextId, in optional object attributes)

'contextId' must be a string naming a canvas rendering context to be returned.  This specification only defines one context, with the name "2d".  If getContext() is called with that exact string for its 'contextId' argument, then the UA must return a reference to an object implementing CanvasRenderingContext2D.  Other specifications may define their own contexts, which would return different objects.

The optional 'attributes' parameter must be either null, or an object specific to the context being requested.  A null or unspecified value for the 'attributes' parameter is equivalent to requesting default attributes for the given context.

If getContext() is called multiple times on the same canvas with the same context ID, it must return the same resulting context object provided that the attributes are identical to all previous requests for that context ID.  If the attributes are not identical, getContext() must raise an INVALID_STATE_ERR exception.  (XXX is INVALID_STATE the right thing here? or is SYNTAX_ERR better?)

If getContext() is called with a context ID different from the context IDs given to any previous successful calls to getContext(), it may either return a new canvas context that can be used simultaneously with all previously obtained contexts, or return null to indicate that the newly requested context cannot be used with the previously obtained contexts.

If multiple rendering contexts are active, they all render to the same canvas; they are not layered or otherwise isolated.  Changes made to the canvas with one context must be immediately visible to any other active contexts on the canvas.  It is up to the implementation to manage synchronization issues associated with rendering with different contexts to the same canvas.
I  think I get why you pass the attrs as 'object' rather than WebGLContextAttributes, but I wonder if it would be better to have a common subclass (ContextAttributes?) that we derive WebGLContextAttributes from and is the type of the 'attributes' param. I'm not sure it makes much difference, but I think we should use strong typing unless there's a reason not to.

-----
~Chris