OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <body> | 3 <body> |
4 <canvas id="canvas" width="3" height="2"></canvas> | 4 <canvas id="canvas" width="3" height="2"></canvas> |
5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/js-test.js"></script> |
6 <script> | 6 <script> |
7 jsTestIsAsync = true; | 7 jsTestIsAsync = true; |
8 var worker = new Worker('./resources/canvas-ImageBitmap-structured-clone.js'); | 8 var worker = new Worker('./resources/canvas-ImageBitmap-structured-clone.js'); |
9 | 9 |
10 description("Tests that ImageBitmap supports structured clone and that the pixel
data survives the trip between main <--> worker"); | 10 description("Tests that ImageBitmap supports structured clone and that the pixel
data survives the trip between main <--> worker"); |
(...skipping 20 matching lines...) Expand all Loading... |
31 } | 31 } |
32 | 32 |
33 function checkImageBitmap1() { | 33 function checkImageBitmap1() { |
34 shouldBe("bitmapWidth", "imageWidth1"); | 34 shouldBe("bitmapWidth", "imageWidth1"); |
35 shouldBe("bitmapHeight", "imageHeight1"); | 35 shouldBe("bitmapHeight", "imageHeight1"); |
36 | 36 |
37 // newImage is not necessary the same as imageData because of | 37 // newImage is not necessary the same as imageData because of |
38 // multiplying and dividing by alpha during the round trip, but | 38 // multiplying and dividing by alpha during the round trip, but |
39 // they should be close. | 39 // they should be close. |
40 // The alpha channel should be exactly the same. | 40 // The alpha channel should be exactly the same. |
41 compareImageData(newImage.data, image1.data); | 41 compareImageData(newImage.data, imageData1); |
42 } | 42 } |
43 | 43 |
44 function checkImageBitmap2() { | 44 function checkImageBitmap2() { |
45 shouldBe("bitmapWidth", "imageWidth2"); | 45 shouldBe("bitmapWidth", "imageWidth2"); |
46 shouldBe("bitmapHeight", "imageHeight2"); | 46 shouldBe("bitmapHeight", "imageHeight2"); |
47 | 47 |
48 compareImageData(newImage.data, image2.data); | 48 compareImageData(newImage.data, imageData2); |
49 } | 49 } |
50 | 50 |
51 function postToWorker(message, transferable) { | 51 function postToWorker(message, transferable) { |
52 return new Promise((resolve, reject) => { | 52 return new Promise((resolve, reject) => { |
53 function onMessage(e) { | 53 function onMessage(e) { |
54 resolve(e.data); | 54 resolve(e.data); |
55 worker.removeEventListener("message", onMessage); | 55 worker.removeEventListener("message", onMessage); |
56 } | 56 } |
57 worker.postMessage(message, transferable); | 57 worker.postMessage(message, transferable); |
58 worker.addEventListener("message", onMessage); | 58 worker.addEventListener("message", onMessage); |
59 }); | 59 }); |
60 } | 60 } |
61 | 61 |
62 function getNewImageDataFromWorkerReply(newImageBitmap) | 62 function getNewImageDataFromImageBitmap(newImageBitmap) |
63 { | 63 { |
64 bitmapWidth = newImageBitmap.width; | 64 bitmapWidth = newImageBitmap.width; |
65 bitmapHeight = newImageBitmap.height; | 65 bitmapHeight = newImageBitmap.height; |
66 context.clearRect(0, 0, imageWidth1, imageHeight1); | 66 context.clearRect(0, 0, imageWidth1, imageHeight1); |
67 context.drawImage(newImageBitmap, 0, 0, bitmapWidth, bitmapHeight); | 67 context.drawImage(newImageBitmap, 0, 0, bitmapWidth, bitmapHeight); |
68 newImage = context.getImageData(0, 0, bitmapWidth, bitmapHeight); | 68 newImage = context.getImageData(0, 0, bitmapWidth, bitmapHeight); |
69 } | 69 } |
70 | 70 |
71 var imageWidth1 = 3; | 71 var imageWidth1 = 3; |
72 var imageHeight1 = 2; | 72 var imageHeight1 = 2; |
73 var imageWidth2 = 1; | 73 var imageWidth2 = 1; |
74 var imageHeight2 = 1; | 74 var imageHeight2 = 1; |
75 var bitmapWidth; | 75 var bitmapWidth; |
76 var bitmapHeight; | 76 var bitmapHeight; |
77 var imageBitmap1; | 77 var imageBitmap1; |
78 var imageBitmap2; | 78 var imageBitmap2; |
79 var newImage; | 79 var newImage; |
| 80 var imageData1; |
| 81 var imageData2; |
80 var image1 = new ImageData(new Uint8ClampedArray( | 82 var image1 = new ImageData(new Uint8ClampedArray( |
81 [255, 0, 0, 255, | 83 [255, 0, 0, 255, |
82 0, 255, 0, 255, | 84 0, 255, 0, 255, |
83 255, 255, 255, 127, | 85 255, 255, 255, 127, |
84 0, 0, 0, 64, | 86 0, 0, 0, 64, |
85 12, 34, 56, 64, | 87 12, 34, 56, 64, |
86 12, 34, 56, 127]), | 88 12, 34, 56, 127]), |
87 imageWidth1, imageHeight1); | 89 imageWidth1, imageHeight1); |
88 var image2 = new ImageData(new Uint8ClampedArray([255, 128, 64, 127]), imageWidt
h2, imageHeight2); | 90 var image2 = new ImageData(new Uint8ClampedArray([255, 128, 64, 127]), imageWidt
h2, imageHeight2); |
89 var context = document.getElementById("canvas").getContext("2d"); | 91 var context = document.getElementById("canvas").getContext("2d"); |
90 | 92 |
91 var p1 = createImageBitmap(image1).then(function(image) {imageBitmap1 = image}); | 93 var p1 = createImageBitmap(image1).then(function(image) {imageBitmap1 = image}); |
92 var p2 = createImageBitmap(image2, {imageOrientation: "none", premultiplyAlpha:
"none"}).then(function(image) {imageBitmap2 = image}); | 94 var p2 = createImageBitmap(image2, {imageOrientation: "none", premultiplyAlpha:
"none"}).then(function(image) {imageBitmap2 = image}); |
93 Promise.all([p1, p2]).then(function() { | 95 Promise.all([p1, p2]).then(function() { |
| 96 getNewImageDataFromImageBitmap(imageBitmap1); |
| 97 imageData1 = newImage.data; |
| 98 getNewImageDataFromImageBitmap(imageBitmap2); |
| 99 imageData2 = newImage.data; |
| 100 |
94 bitmapWidth = imageBitmap1.width; | 101 bitmapWidth = imageBitmap1.width; |
95 bitmapHeight = imageBitmap1.height; | 102 bitmapHeight = imageBitmap1.height; |
96 shouldBe("bitmapWidth", "imageWidth1"); | 103 shouldBe("bitmapWidth", "imageWidth1"); |
97 shouldBe("bitmapHeight", "imageHeight1"); | 104 shouldBe("bitmapHeight", "imageHeight1"); |
98 | 105 |
99 var replyPromise = postToWorker(imageBitmap1); | 106 var replyPromise = postToWorker(imageBitmap1); |
100 | 107 |
101 // Structured cloning should not neuter the source ImageBitmap | 108 // Structured cloning should not neuter the source ImageBitmap |
102 bitmapWidth = imageBitmap1.width; | 109 bitmapWidth = imageBitmap1.width; |
103 bitmapHeight = imageBitmap1.height; | 110 bitmapHeight = imageBitmap1.height; |
104 shouldBe("bitmapWidth", "imageWidth1"); | 111 shouldBe("bitmapWidth", "imageWidth1"); |
105 shouldBe("bitmapHeight", "imageHeight1"); | 112 shouldBe("bitmapHeight", "imageHeight1"); |
106 | 113 |
107 return replyPromise.then(reply => { | 114 return replyPromise.then(reply => { |
108 getNewImageDataFromWorkerReply(reply); | 115 getNewImageDataFromImageBitmap(reply); |
109 checkImageBitmap1(); | 116 checkImageBitmap1(); |
110 }); | 117 }); |
111 }).then(function() { | 118 }).then(function() { |
112 var replyPromise = postToWorker(imageBitmap1, [imageBitmap1]); | 119 var replyPromise = postToWorker(imageBitmap1, [imageBitmap1]); |
113 | 120 |
114 // Transfer the ImageBitmap should neuter it | 121 // Transfer the ImageBitmap should neuter it |
115 bitmapWidth = imageBitmap1.width; | 122 bitmapWidth = imageBitmap1.width; |
116 bitmapHeight = imageBitmap1.height; | 123 bitmapHeight = imageBitmap1.height; |
117 shouldBe("bitmapWidth", "0"); | 124 shouldBe("bitmapWidth", "0"); |
118 shouldBe("bitmapHeight", "0"); | 125 shouldBe("bitmapHeight", "0"); |
119 | 126 |
120 return replyPromise.then(reply => { | 127 return replyPromise.then(reply => { |
121 getNewImageDataFromWorkerReply(reply); | 128 getNewImageDataFromImageBitmap(reply); |
122 checkImageBitmap1(); | 129 checkImageBitmap1(); |
123 }); | 130 }); |
124 }).then(function() { | 131 }).then(function() { |
125 var replyPromise = postToWorker(imageBitmap2); | 132 var replyPromise = postToWorker(imageBitmap2); |
126 | 133 |
127 // Structured cloning should not neuter the source ImageBitmap | 134 // Structured cloning should not neuter the source ImageBitmap |
128 bitmapWidth = imageBitmap2.width; | 135 bitmapWidth = imageBitmap2.width; |
129 bitmapHeight = imageBitmap2.height; | 136 bitmapHeight = imageBitmap2.height; |
130 shouldBe("bitmapWidth", "imageWidth2"); | 137 shouldBe("bitmapWidth", "imageWidth2"); |
131 shouldBe("bitmapHeight", "imageHeight2"); | 138 shouldBe("bitmapHeight", "imageHeight2"); |
132 | 139 |
133 return replyPromise.then(reply => { | 140 return replyPromise.then(reply => { |
134 getNewImageDataFromWorkerReply(reply); | 141 getNewImageDataFromImageBitmap(reply); |
135 checkImageBitmap2(); | 142 checkImageBitmap2(); |
136 }); | 143 }); |
137 }).then(finishJSTest, shouldNotBeCalled); | 144 }).then(finishJSTest, shouldNotBeCalled); |
138 </script> | 145 </script> |
139 </body> | 146 </body> |
140 </html> | 147 </html> |
OLD | NEW |