canvas: Make OffscreenCanvas transferable (without placeholder) (#37872)

Follow the specification and make OffscreenCanvas objects are
transferable,
but not in case if there are a weak reference to placeholder canvas
element.
To handle it properly need to implement dedicated frame
provider/dispatcher
between canvas element (script thread) and offscreen canvas (dedicated
worker thread).

https://html.spec.whatwg.org/multipage/#the-offscreencanvas-interface:transferable-objects

Testing: Improvements in the following tests
-
html/canvas/element/drawing-images-to-the-canvas/2d.drawImage.detachedcanvas.html
-
html/canvas/offscreen/manual/convert-to-blob/offscreencanvas.convert.to.blob*
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer*
-
html/infrastructure/safe-passing-of-structured-data/transfer-errors.window.js

Part of #24276

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This commit is contained in:
Andrei Volykhin 2025-07-08 17:47:29 +03:00 committed by GitHub
parent c3f441d7ab
commit 4054f9a5a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 159 additions and 60 deletions

View file

@ -1,3 +0,0 @@
[2d.drawImage.detachedcanvas.html]
[drawImage with detached OffscreenCanvas as the source should throw exception]
expected: FAIL

View file

@ -1,3 +0,0 @@
[offscreencanvas.convert.to.blob.html]
[Test that call convertToBlob on a detached OffscreenCanvas throws exception]
expected: FAIL

View file

@ -1,4 +0,0 @@
[offscreencanvas.convert.to.blob.w.html]
expected: ERROR
[Test that call convertToBlob on a detached OffscreenCanvas throws exception in a worker]
expected: FAIL

View file

@ -4,6 +4,3 @@
[Test that transferToImageBitmap returns an ImageBitmap with correct width and height]
expected: FAIL
[Test that call transferToImageBitmap on a detached OffscreenCanvas throws an exception]
expected: FAIL

View file

@ -3,8 +3,5 @@
[Test that transferToImageBitmap returns an ImageBitmap with correct width and height in a worker]
expected: FAIL
[Test that call transferToImageBitmap on a detached OffscreenCanvas throws an exception in a worker]
expected: FAIL
[Test that call transferToImageBitmap twice on a alpha-disabled context returns an ImageBitmap with correct color in a worker]
expected: FAIL

View file

@ -1,18 +1,3 @@
[offscreencanvas.transferrable.html]
[Test that offscreenCanvas's size is correct after being transferred to a worker.]
expected: FAIL
[Test that calling getContext('webgl') on a detached OffscreenCanvas throws exception.]
expected: FAIL
[Test that transfer an OffscreenCanvas that has a context throws exception.]
expected: FAIL
[Test that transfer an OffscreenCanvas twice throws exception.]
expected: FAIL
[Test that calling getContext('2d') on a detached OffscreenCanvas throws exception.]
expected: FAIL
[Test that transfer an OffscreenCanvas that already have a 2d context throws exception.]
expected: FAIL

View file

@ -1,20 +1,10 @@
[offscreencanvas.transferrable.w.html]
expected: ERROR
[Test that calling getContext('webgl') on a detached OffscreenCanvas throws exception in a worker.]
expected: FAIL
[Test that transfer an OffscreenCanvas that has a webgl context throws exception in a worker.]
expected: FAIL
[Test that transfer an OffscreenCanvas twice throws exception in a worker.]
expected: FAIL
[Test that calling getContext('2d') on a detached OffscreenCanvas throws exception in a worker.]
expected: FAIL
[Test that OffscreenCanvas's size is correct after being transferred from a worker.]
expected: FAIL
[Test that transfer an OffscreenCanvas that has a 2d context throws exception in a worker.]
expected: FAIL
[Test that transfer an OffscreenCanvas twice throws exception in a worker.]
expected: FAIL

View file

@ -8,11 +8,5 @@
[Serialize should throw before a detached ImageBitmap is found]
expected: FAIL
[Serialize should make the OffscreenCanvas detached, so it cannot be transferred again]
expected: FAIL
[Serialize should throw before a detached OffscreenCanvas is found]
expected: FAIL
[Cannot transfer OffscreenCanvas detached while the message was serialized]
expected: FAIL