Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-toBlob-toDataURL-race-imageEncoder-webp.html

Issue 1355333005: Implement Asynchronous image encoding for Canvas.toBlob (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Static Variables! Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <script src = "../../resources/js-test.js"></script>
2 <script type = 'text/javascript'>
3 description("Verifies if WEBP image encoding on main thread (toDataURL) conflict s with image encoding on async thread (toBlob)");
4 if (window.testRunner) {
5 testRunner.dumpAsText();
6 testRunner.waitUntilDone();
7 }
8
9 var numToBlobCalls = 9; // number of toBlob calls on the original canvas
10 var numToDataURLCalls = 3; // number of toDataURL calls
11 var testImages = [];
12 var canvasCtxs = [];
13
14 // Create an original canvas with content
15 var canvas = document.createElement("canvas");
16 var ctx = canvas.getContext("2d");
17 ctx.fillStyle = "#EE21AF";
18 ctx.fillRect(0, 0, 2500, 1750);
19
20 function testIfAllImagesAreCorrect()
21 {
22 // Because the color filled is not black, we should not have a pixel having zero as value
23 shouldBeNonZero('canvasCtxs[0].getImageData(0, 0, 2500, 1750).data[25]');
24
25 // All resultant images should be the same because both async and main threa ds use the same image encoder
26 // We pick a pixel at position 25 to check whether they match
27 for (var i = 0; i < (numToBlobCalls + numToDataURLCalls - 1); i++)
28 {
29 shouldBe('canvasCtxs[' + i + '].getImageData(0, 0, 2500, 1750).data[25]' , 'canvasCtxs[' + (i+1) + '].getImageData(0, 0, 2500, 1750).data[25]');
30 }
31 }
32
33 var counter = numToBlobCalls + numToDataURLCalls;
34 function onCanvasDrawCompleted(ctx_test, i)
35 {
36 counter = counter - 1;
37 if (counter == 0) {
38 testIfAllImagesAreCorrect();
39 if (window.testRunner)
40 testRunner.notifyDone();
41 }
42 }
43
44 function createTestCase(i)
45 {
46 var canvas_test = document.createElement("canvas");
47 var ctx_test = canvas_test.getContext("2d");
48 canvasCtxs[i] = ctx_test;
49
50 var newImg = new Image();
51 newImg.onload = function() {
52 ctx_test.drawImage(newImg, 0, 0, 2500, 1750);
53 onCanvasDrawCompleted(ctx_test, i);
54 }
55 testImages[i] = newImg;
56 }
57
58 // Start creating test cases
59 for (var i = 0; i < (numToBlobCalls + numToDataURLCalls); i++)
60 {
61 createTestCase(i);
62 }
63
64 //Fire a bunch of toBlob operations of canvas to keep the async thread busy
65 var j = 0; // due to async nature of toBlob we need a separate counter
66 for (var i = 0; i < numToBlobCalls; i++)
67 {
68 canvas.toBlob(function(blob) {
69 url = URL.createObjectURL(blob);
70 testImages[j++].src = url;
71 }, "image/webp", 1.0);
72 }
73
74 //Then file a bunch of toDataURL operation on main thread, so both threads now c ompete for image encoding
75 for (var i = numToBlobCalls; i < (numToDataURLCalls + numToBlobCalls); i++)
76 {
77 testImages[i].src = canvas.toDataURL("image/webp", 1.0);
78 }
79 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698