immersive-web / webxr-polyfill

Use the WebXR Device API today, providing fallbacks to native WebVR 1.1 and Cardboard
Apache License 2.0
382 stars 85 forks source link

Implement support for OffscreenCanvas, as well as use ImageBitmapRenderingContext #35

Closed jsantell closed 5 years ago

jsantell commented 6 years ago

With OffscreenCanvas in Chrome 69, I wanted to explore using ImageBitmaps to reduce the canvas copying from input context to XRPresentationContext via CanvasRenderingContext2D's drawImage.

In this PR, if ImageBitmapRenderingContext is available (same spec as OffscreenCanvas, practically speaking will probably exist if OffscreenCanvas does?), the XRPresentationContext will be created using that instead. This means if using a non-OffscreenCanvas, we'll asynchronously create a bitmap via createImageBtimap; if using an OffscreenCanvas, this just directly calls OffscreenCanvas#transferImageToBitmap, which is the most ideal case, I think.

If using OffscreenCanvas without ImageBitmapRenderingContext support, CanvasRenderingContext2D's drawImage is still used. I'm not sure if this scenario will occur practically.

Questions/Comments: