- From: Dean Jackson <dino@apple.com>
- Date: Mon, 10 Sep 2012 12:32:26 -0700
- To: Tobie Langel <tobie.langel@gmail.com>
- Cc: "whatwg@lists.whatwg.org" <whatwg@lists.whatwg.org>
On Sep 10, 2012, at 12:28 PM, Tobie Langel <tobie.langel@gmail.com> wrote: > On Sep 10, 2012, at 8:14 PM, Dean Jackson <dino@apple.com> wrote: > >> I propose adding a new method to HTMLCanvasElement: >> >> interface HTMLCanvasElement : HTMLElement { >> boolean supportsContext(DOMString contextId, any... arguments); >> }; >> >> supportsContext takes the same parameters as getContext, and simply returns >> true if the corresponding call to getContext would have returned a valid >> context, false otherwise. > > What about enabling feature detection by providing a method per context? > > interface HTMLCanvasElement : HTMLElement { > object get2DContext(); > object getWebGLContext(any... args); > }; > > That way, developers can use idiomatic JS for feature testing like > pretty much everywhere else on the Web platform: > > if (canvas.get2DContext) { > // do stuff with 2D canvas > } This doesn't address the problem we are hitting, which is that it is expensive to create a context. It's also a big change to an existing operational API. I'm looking for some way an implementation can suggest that it supports a particular context without the user having to create one. As James Robinson pointed out in the WebKit IRC channel, even the implementation might not know for sure it can create the context, but I think that's ok. The important thing is that returning false from supportsContext means that a corresponding call to getContext would fail. Dean
Received on Monday, 10 September 2012 19:32:53 UTC