1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Resizing Test for OffscreenCanvas commit()</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/canvas-tests-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("This test ensures that the OffscreenCanvas context returns the correct image size after resizing and calling commit().");
function testResizeOnNewOffscreenCanvas() {
var canvas = new OffscreenCanvas(10, 20);
canvas.getContext("webgl");
canvas.width = 30;
canvas.height = 40;
assertWidthAndHeight(canvas, "canvas", 30, 40);
var imagebitmap = canvas.transferToImageBitmap();
assertWidthAndHeight(imagebitmap, "imagebitmap", 30, 40);
}
function testResizeOnTransferredOffscreenCanvas() {
var placeholder = document.createElement("canvas");
var offscreencanvas = transferredOffscreenCanvasCreation(placeholder, 10, 20);
var ctx = offscreencanvas.getContext("webgl");
// Verify that setting the size of an OffscreenCanvas that has a placeholder works.
offscreencanvas.width = 30;
offscreencanvas.height = 40;
assertWidthAndHeight(offscreencanvas, "resized offscreencanvas", 30, 40);
var imagebitmap = offscreencanvas.transferToImageBitmap();
assertWidthAndHeight(imagebitmap, "imagebitmap transferred from resized offscreencanvas" , 30, 40);
// Verify that setting the size of an OffscreenCanvas does not directly update the size of its placeholder canvas.
assertWidthAndHeight(placeholder, "placeholder canvas", 10, 20);
var asyncStepsCompleted = 0;
ctx.commit();
createImageBitmap(placeholder).then(image => {
// Verify that the placeholder was not updated synchronously.
assertWidthAndHeight(image, "imagebitmap from placeholder canvas", 10, 20);
asyncStepsCompleted++;
if (asyncStepsCompleted == 2) {
finishTest();
}
});
// Set timeout acts as a sync barrier to allow commit to propagate
setTimeout(function() {
// Verify that commit() asynchronously updates the size of its placeholder canvas.
assertWidthAndHeight(placeholder, "placeholder canvas", 30, 40);
// Verify that width/height attributes are not settable
shouldThrow("placeholder.width = 50");
shouldThrow("placeholder.height = 60");
assertWidthAndHeight(placeholder, "placeholder canvas after size reset", 30, 40);
createImageBitmap(placeholder).then(image => {
// Verify that an image grabbed from the placeholder has the correct dimensions
assertWidthAndHeight(image, "imagebitmap from placeholder canvas", 30, 40);
asyncStepsCompleted++;
if (asyncStepsCompleted == 2) {
finishTest();
}
});
}, 0);
}
if (!window.OffscreenCanvas) {
testPassed("No OffscreenCanvas support");
finishTest();
} else if (!new OffscreenCanvas(10, 20).getContext("webgl").commit) {
testPassed("commit() not supported");
finishTest();
} else {
testResizeOnNewOffscreenCanvas();
testResizeOnTransferredOffscreenCanvas();
}
</script>
</body>
</html>
|