diff options
author | xidachen <xidachen@chromium.org> | 2016-01-23 15:27:32 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-23 23:28:27 +0000 |
commit | 5d34a13da920a09a36b94127cac1872384b34df6 (patch) | |
tree | 006bec02d344c9bd749f84b345af456cb35aaaa4 /third_party/WebKit/LayoutTests | |
parent | e496c18243b150962bd7c9c707126da555a8b2b0 (diff) | |
download | chromium_src-5d34a13da920a09a36b94127cac1872384b34df6.zip chromium_src-5d34a13da920a09a36b94127cac1872384b34df6.tar.gz chromium_src-5d34a13da920a09a36b94127cac1872384b34df6.tar.bz2 |
Make ImageBitmap support structured clone
ImageBitmap is already transferable, but at this moment we cannot use
postMessage(ImageBitmap) via structured clone. This CL will enable it.
This CL also includes a layout test and sends an ImageBitmap to a
worker, the worker sends the ImageBitmap back to main, and does check
that the underline pixel data survives the round trip.
BUG=579539
Review URL: https://codereview.chromium.org/1616213003
Cr-Commit-Position: refs/heads/master@{#371155}
Diffstat (limited to 'third_party/WebKit/LayoutTests')
3 files changed, 182 insertions, 0 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-ImageBitmap-structured-clone-expected.txt b/third_party/WebKit/LayoutTests/fast/canvas/canvas-ImageBitmap-structured-clone-expected.txt new file mode 100644 index 0000000..683319c --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-ImageBitmap-structured-clone-expected.txt @@ -0,0 +1,49 @@ +Tests that ImageBitmap supports structured clone and that the pixel data survives the trip between main <--> worker + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS bitmapWidth is imageWidth1 +PASS bitmapHeight is imageHeight1 +PASS bitmapWidth is imageWidth1 +PASS bitmapHeight is imageHeight1 +PASS bitmapWidth is imageWidth1 +PASS bitmapHeight is imageHeight1 +PASS newImage.data[0] is within 5 of image1.data[0] +PASS newImage.data[1] is within 5 of image1.data[1] +PASS newImage.data[2] is within 5 of image1.data[2] +PASS newImage.data[3] is image1.data[3] +PASS newImage.data[4] is within 5 of image1.data[4] +PASS newImage.data[5] is within 5 of image1.data[5] +PASS newImage.data[6] is within 5 of image1.data[6] +PASS newImage.data[7] is image1.data[7] +PASS newImage.data[8] is within 5 of image1.data[8] +PASS newImage.data[9] is within 5 of image1.data[9] +PASS newImage.data[10] is within 5 of image1.data[10] +PASS newImage.data[11] is image1.data[11] +PASS newImage.data[12] is within 5 of image1.data[12] +PASS newImage.data[13] is within 5 of image1.data[13] +PASS newImage.data[14] is within 5 of image1.data[14] +PASS newImage.data[15] is image1.data[15] +PASS newImage.data[16] is within 5 of image1.data[16] +PASS newImage.data[17] is within 5 of image1.data[17] +PASS newImage.data[18] is within 5 of image1.data[18] +PASS newImage.data[19] is image1.data[19] +PASS newImage.data[20] is within 5 of image1.data[20] +PASS newImage.data[21] is within 5 of image1.data[21] +PASS newImage.data[22] is within 5 of image1.data[22] +PASS newImage.data[23] is image1.data[23] +PASS bitmapWidth is imageWidth2 +PASS bitmapHeight is imageHeight2 +PASS bitmapWidth is imageWidth2 +PASS bitmapHeight is imageHeight2 +PASS bitmapWidth is imageWidth2 +PASS bitmapHeight is imageHeight2 +PASS newImage.data[0] is within 5 of image2.data[0] +PASS newImage.data[1] is within 5 of image2.data[1] +PASS newImage.data[2] is within 5 of image2.data[2] +PASS newImage.data[3] is image2.data[3] +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-ImageBitmap-structured-clone.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-ImageBitmap-structured-clone.html new file mode 100644 index 0000000..c85a11cb --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-ImageBitmap-structured-clone.html @@ -0,0 +1,130 @@ +<!DOCTYPE html> +<html> +<body> +<canvas id="canvas" width="3" height="2"></canvas> +<script src="../../resources/js-test.js"></script> +<script> +jsTestIsAsync = true; +var worker = new Worker('./resources/canvas-ImageBitmap-structured-clone.js'); + +description("Tests that ImageBitmap supports structured clone and that the pixel data survives the trip between main <--> worker"); + +function shouldNotBeCalled() { + testFailed("createImageBitmap promise rejected."); + finishJSTest(); +} + +var imageWidth1 = 3; +var imageHeight1 = 2; +var imageWidth2 = 1; +var imageHeight2 = 1; +var bitmapWidth; +var bitmapHeight; +var newImage1; +var newImage2; +var imageBitmap1; +var imageBitmap2; +var newImageBitmap; +var image1 = new ImageData(new Uint8ClampedArray( + [255, 0, 0, 255, + 0, 255, 0, 255, + 255, 255, 255, 127, + 0, 0, 0, 64, + 12, 34, 56, 64, + 12, 34, 56, 127]), + imageWidth1, imageHeight1); +var image2 = new ImageData(new Uint8ClampedArray([255, 128, 64, 127]), imageWidth2, imageHeight2); +var context = document.getElementById("canvas").getContext("2d"); + +var p1 = createImageBitmap(image1).then(function(image) {imageBitmap1 = image}); +var p2 = createImageBitmap(image2).then(function(image) {imageBitmap2 = image}); +Promise.all([p1, p2]).then(function() { + bitmapWidth = imageBitmap1.width; + bitmapHeight = imageBitmap1.height; + shouldBe("bitmapWidth", "imageWidth1"); + shouldBe("bitmapHeight", "imageHeight1"); + + worker.postMessage({label:'bitmap1', data:imageBitmap1}); + + // Structured cloning should not neuter the source ImageBitmap + bitmapWidth = imageBitmap1.width; + bitmapHeight = imageBitmap1.height; + shouldBe("bitmapWidth", "imageWidth1"); + shouldBe("bitmapHeight", "imageHeight1"); +}, shouldNotBeCalled); + +worker.onmessage = function(e) { + newImageBitmap = e.data.data; + bitmapWidth = newImageBitmap.width; + bitmapHeight = newImageBitmap.height; + context.clearRect(0, 0, imageWidth1, imageHeight1); + context.drawImage(newImageBitmap, 0, 0, bitmapWidth, bitmapHeight); + newImage = context.getImageData(0, 0, bitmapWidth, bitmapHeight); + + switch (e.data.label) { + case 'bitmap1': + shouldBe("bitmapWidth", "imageWidth1"); + shouldBe("bitmapHeight", "imageHeight1"); + + // newImage is not necessary the same as imageData because of + // multiplying and dividing by alpha during the round trip, but + // they should be close. + // The alpha channel should be exactly the same. + shouldBeCloseTo("newImage.data[0]", "image1.data[0]", 5); + shouldBeCloseTo("newImage.data[1]", "image1.data[1]", 5); + shouldBeCloseTo("newImage.data[2]", "image1.data[2]", 5); + shouldBe("newImage.data[3]", "image1.data[3]"); + + shouldBeCloseTo("newImage.data[4]", "image1.data[4]", 5); + shouldBeCloseTo("newImage.data[5]", "image1.data[5]", 5); + shouldBeCloseTo("newImage.data[6]", "image1.data[6]", 5); + shouldBe("newImage.data[7]", "image1.data[7]"); + + shouldBeCloseTo("newImage.data[8]", "image1.data[8]", 5); + shouldBeCloseTo("newImage.data[9]", "image1.data[9]", 5); + shouldBeCloseTo("newImage.data[10]", "image1.data[10]", 5); + shouldBe("newImage.data[11]", "image1.data[11]"); + + shouldBeCloseTo("newImage.data[12]", "image1.data[12]", 5); + shouldBeCloseTo("newImage.data[13]", "image1.data[13]", 5); + shouldBeCloseTo("newImage.data[14]", "image1.data[14]", 5); + shouldBe("newImage.data[15]", "image1.data[15]"); + + shouldBeCloseTo("newImage.data[16]", "image1.data[16]", 5); + shouldBeCloseTo("newImage.data[17]", "image1.data[17]", 5); + shouldBeCloseTo("newImage.data[18]", "image1.data[18]", 5); + shouldBe("newImage.data[19]", "image1.data[19]"); + + shouldBeCloseTo("newImage.data[20]", "image1.data[20]", 5); + shouldBeCloseTo("newImage.data[21]", "image1.data[21]", 5); + shouldBeCloseTo("newImage.data[22]", "image1.data[22]", 5); + shouldBe("newImage.data[23]", "image1.data[23]"); + + bitmapWidth = imageBitmap2.width; + bitmapHeight = imageBitmap2.height; + shouldBe("bitmapWidth", "imageWidth2"); + shouldBe("bitmapHeight", "imageHeight2"); + + worker.postMessage({label:'bitmap2', data:imageBitmap2}); + + // Structured cloning should not neuter the source ImageBitmap + bitmapWidth = imageBitmap2.width; + bitmapHeight = imageBitmap2.height; + shouldBe("bitmapWidth", "imageWidth2"); + shouldBe("bitmapHeight", "imageHeight2"); + break; + case 'bitmap2': + shouldBe("bitmapWidth", "imageWidth2"); + shouldBe("bitmapHeight", "imageHeight2"); + + shouldBeCloseTo("newImage.data[0]", "image2.data[0]", 5); + shouldBeCloseTo("newImage.data[1]", "image2.data[1]", 5); + shouldBeCloseTo("newImage.data[2]", "image2.data[2]", 5); + shouldBe("newImage.data[3]", "image2.data[3]"); + finishJSTest(); + break; + } +} +</script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/fast/canvas/resources/canvas-ImageBitmap-structured-clone.js b/third_party/WebKit/LayoutTests/fast/canvas/resources/canvas-ImageBitmap-structured-clone.js new file mode 100644 index 0000000..50205fe --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/canvas/resources/canvas-ImageBitmap-structured-clone.js @@ -0,0 +1,3 @@ +self.onmessage = function(e) { + postMessage({label:e.data.label, data:e.data.data}); +}; |