-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw an exception in transferToImageBitmap if canvas layers are opened
This API is incompatible with how the 2D canvas is rasterized when it contains unclosed layers. Because layers can have filters that get applied on their final content, they can't be presented until they are closed. Instead, we normally keep the layer content alive after a flush, so that it can be presented in a later frame when the layer is finally closed. OffscreenCanvas.transferToImageBitmap however is supposed to release the canvas content, leaving the offscreen canvas empty. We cannot release the recording if layers are incomplete, and if we kept the layer content alive for later, we would not be leaving the canvas empty as the spec requires. This behavior is part of the current 2D Canvas Layer spec draft: Explainer: https://github.com/fserb/canvas2D/blob/master/spec/layers.md Spec draft: whatwg/html#9537 Bug: 1484741 Change-Id: Ic770b51a0343faf0b2c7477624d69f59187ce97f
- Loading branch information
1 parent
3324586
commit 1652225
Showing
8 changed files
with
156 additions
and
181 deletions.
There are no files selected for viewing
24 changes: 0 additions & 24 deletions
24
...canvas/offscreen/layers/2d.layer.render-opportunities.transferToImageBitmap-expected.html
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
html/canvas/offscreen/layers/2d.layer.render-opportunities.transferToImageBitmap.html
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
html/canvas/offscreen/layers/2d.layer.render-opportunities.transferToImageBitmap.w.html
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
html/canvas/offscreen/layers/2d.layer.transferToImageBitmap.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<!-- DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. --> | ||
<title>OffscreenCanvas test: 2d.layer.transferToImageBitmap</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/html/canvas/resources/canvas-tests.js"></script> | ||
|
||
<h1>2d.layer.transferToImageBitmap</h1> | ||
<p class="desc">Check that calling transferToImageBitmap in a layer throws an exception.</p> | ||
|
||
|
||
<script> | ||
var t = async_test("Check that calling transferToImageBitmap in a layer throws an exception."); | ||
var t_pass = t.done.bind(t); | ||
var t_fail = t.step_func(function(reason) { | ||
throw reason; | ||
}); | ||
t.step(function() { | ||
|
||
var canvas = new OffscreenCanvas(100, 50); | ||
var ctx = canvas.getContext('2d'); | ||
|
||
// `transferToImageBitmap` shouldn't throw on it's own. | ||
canvas.transferToImageBitmap(); | ||
// Make sure the exception isn't caused by calling the function twice. | ||
canvas.transferToImageBitmap(); | ||
// Calling again inside a layer should throw. | ||
ctx.beginLayer(); | ||
assert_throws_dom("InvalidStateError", | ||
() => canvas.transferToImageBitmap()); | ||
t.done(); | ||
|
||
}); | ||
</script> |
29 changes: 29 additions & 0 deletions
29
html/canvas/offscreen/layers/2d.layer.transferToImageBitmap.worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// DO NOT EDIT! This test has been generated by /html/canvas/tools/gentest.py. | ||
// OffscreenCanvas test in a worker:2d.layer.transferToImageBitmap | ||
// Description:Check that calling transferToImageBitmap in a layer throws an exception. | ||
// Note: | ||
|
||
importScripts("/resources/testharness.js"); | ||
importScripts("/html/canvas/resources/canvas-tests.js"); | ||
|
||
var t = async_test("Check that calling transferToImageBitmap in a layer throws an exception."); | ||
var t_pass = t.done.bind(t); | ||
var t_fail = t.step_func(function(reason) { | ||
throw reason; | ||
}); | ||
t.step(function() { | ||
|
||
var canvas = new OffscreenCanvas(100, 50); | ||
var ctx = canvas.getContext('2d'); | ||
|
||
// `transferToImageBitmap` shouldn't throw on it's own. | ||
canvas.transferToImageBitmap(); | ||
// Make sure the exception isn't caused by calling the function twice. | ||
canvas.transferToImageBitmap(); | ||
// Calling again inside a layer should throw. | ||
ctx.beginLayer(); | ||
assert_throws_dom("InvalidStateError", | ||
() => canvas.transferToImageBitmap()); | ||
t.done(); | ||
}); | ||
done(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters