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

[Public WebGL] webglcontextrestored, WEBKIT_lose_context



A problem with webglcontextrestored: "The system only restores the context if a handler for the webglcontextrestored event is installed on the HTMLCanvasElement associated with the context."

Registering DOM event listeners doesn't have side-effects. Calling object.addEventListener("string", function(e) { }, false); should never have any perceivable side-effect. I don't know of any API on the platform where this isn't the case.

I recommend: "The system only restores the context if the default behavior for the webglcontextlost event is prevented." (Note: webglcontextlost here, not webglcontextrestored.)

In other words, the default behavior of webglcontextlost is to prevent restoration of the context. This is much more consistent with how DOM events work. (I'll suggest a more precise spec wording later after some other discussions move forward, if there's interest in making this change.) To enable context restoration,

canvas.addEventListener("webglcontextlost", function(e) { e.preventDefault(); }, false);



A related issue (maybe some WebKit list is a closer fit for this, but it seems appropriate here):

WEBKIT_lose_context exposes one function: loseContext. It causes the context to be lost, and then restored a moment later. This allows testing context loss, but it's incomplete: it's not possible to cause the context stay lost. This is needed to test script behavior during an extended or permanent context loss; for example, when manipulating UI controls while the context is still lost.

I'd suggest adding a "force" parameter to loseContext; if true, an internal flag is set, persistently preventing the context from being restored. Second, add a restoreContext() method, which unset the flag, allowing the context to be restored at next appropriate time in the event loop. If the "force" flag wasn't already set, restoreContext() triggers INVALID_OPERATION.

I think this it's important to make it as easy as possible to test context loss, or else nobody is going to handle it correctly.

--
Glenn Maynard