Search code examples
htmlwebhtml5-canvaswebgl

What's the state of OffscreenCanvas's support for 2d context?


I'm new to web development, so this might be a dumb question. Please let me know if it's already answered:)

According to MDN web docs' page for OffscreenCanvas, currently, the API only supports WebGL context only. (Maybe it just means the worker support for OffscreenCanvas' 2d context is not implemented, but we can still use it on the main thread?)

Note: This API is currently implemented for WebGL1 and WebGL2 contexts only. See bug 801176 for Canvas 2D API support from workers.

But when I read the HTML Specs for OffscreenCanvas, the 2d context is supported.

enum OffscreenRenderingContextType { "2d", "webgl" };

I suspect the second one is only a proposal for what OffscreenCanvas should support, and the first is what is actually supported. Is my understanding correct? If so, how could I know whether a specific browser supports the 2d context for OffscreenCanvas, like Chromium?

What makes me even more confused is people called the regular canvas an offscreenCanvas, and get a 2d context from it (example1, example2). But I think in this case, they are just referring a regular canvas which is not attached to DOM, other than the OffscreenCanvas I like to research on.


Solution

  • I suspect the second one is only a proposal for what OffscreenCanvas should support, and the first is what is actually supported. Is my understanding correct?

    Correct, the WHATWG spec is the standard that browsers should support. The reason Firefox's bug #801176 exists is because Firefox falls short of the requirements of the WHATWG specification in this area.

    What makes me even more confused is people called the regular canvas an offscreenCanvas

    These are simply variables called offscreenCanvas which hold a normal canvas. You can name your variables anything; these authors chose a descriptive name for a canvas that is not currently rendered on the screen.