It should be usable in both Document and Worker context. To start with only 2D will be supported. (This is the umbrella bug for the feature -- where I'll mention the general approach, etc. I'll file other bugs for each step.)
Created attachment 49243 [details] Proposed fix.
Here's a basic outline of the work: 1. make HTMLCanvasElement derive from CanvsaSurface. 2. make CanvasRenderingContext2D only depend on CanvasSurface (in a future change) a. Move methods that CanvasRenderingContext2D depends on from HTMLCanvasElement to CanvasSurface. b. Change CanvasRenderingContext2D to only use CanvasSurface. 3. Create an OffscreenCanvas which derives from CanvasSurface. 4. Expose OffscreenCanvas for document context (with layout tests). 5. Expose OffscreenCanvas for the worker context (fix threadsafety issues, idl changes, layout tests, etc.). This result in allowing CanvasRenderingContext2D to be used with either HTMLCanvasElement or OffscreenCanvas.
This work has been suspended for now (after various bits of feedback on whatwg regarding our target scenario of image resizing). Note that https://bugs.webkit.org/show_bug.cgi?id=41032 wasn't landed but may help in this effort if anyone pursues it.