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:
In some test cases, I haven't noticed any performance changes in the examples here -- on a Pixel 1, all were 55+ fps. Need to make a beefier, GPU-heavy example
Will we always be a frame behind on the async createImageBitmap function? createImageBitmap(inputCanvas, ...).then(bitmap => outputCtx.transferImageToBitmap(bitmap))
This OffscreenCanvas demo has the canvas on the main thread anyway. I'm not sure how WebXR Device API handles the OC being in a worker from a MT Canvas transferring control to an OC. Is the context even still available in MT to pass into WebXR?
Are there any feature detection scenarios missing?
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:
createImageBitmap
function?createImageBitmap(inputCanvas, ...).then(bitmap => outputCtx.transferImageToBitmap(bitmap))