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

Side by Side Diff: third_party/WebKit/PerformanceTests/Canvas/draw-dynamic-canvas-2d-to-hw-accelerated-canvas-2d.html

Issue 2126013002: Fix canvas blink_perf tests to avoid GPU fallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <body> 3 <body>
4 <script src="../resources/runner.js"></script> 4 <script src="../resources/runner.js"></script>
5 <script src="resources/canvas_runner.js"></script> 5 <script src="resources/canvas_runner.js"></script>
6 <script> 6 <script>
7 var sourceCanvas2D = document.createElement("canvas"); 7 var sourceCanvas2D = document.createElement("canvas");
8 var sourceCtx2D = sourceCanvas2D.getContext("2d"); 8 var sourceCtx2D = sourceCanvas2D.getContext("2d");
9 var destCanvas2D = document.createElement("canvas"); 9 var destCanvas2D = document.createElement("canvas");
10 var destCtx2D = destCanvas2D.getContext("2d"); 10 var destCtx2D = destCanvas2D.getContext("2d");
11 11 var dummyCanvas2D = document.createElement("canvas");
12 var dummyCtx2D = dummyCanvas2D.getContext("2d");
13
14 dummyCanvas2D.width = 1;
15 dummyCanvas2D.height = 1;
16
12 function setSize(sourceWidth, sourceHeight, destWidth, destHeight) { 17 function setSize(sourceWidth, sourceHeight, destWidth, destHeight) {
13 sourceCanvas2D.width = sourceWidth; 18 sourceCanvas2D.width = sourceWidth;
14 sourceCanvas2D.height = sourceHeight; 19 sourceCanvas2D.height = sourceHeight;
15 destCanvas2D.width = destWidth; 20 destCanvas2D.width = destWidth;
16 destCanvas2D.height = destHeight; 21 destCanvas2D.height = destHeight;
17 } 22 }
18 23
19 function rand(range) { 24 function rand(range) {
20 return Math.floor(Math.random() * range); 25 return Math.floor(Math.random() * range);
21 } 26 }
22 27
23 function fillCanvas(ctx2d, canvas2d) { 28 function fillCanvas(ctx2d, canvas2d) {
24 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")"; 29 ctx2d.fillStyle = "rgba(" + rand(255) + "," + rand(255) + "," + rand(255) + "," + rand(255) + ")";
25 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height); 30 ctx2d.fillRect(0, 0, canvas2d.width, canvas2d.height);
26 } 31 }
27 32
28 function doRun() { 33 function doRun() {
29 fillCanvas(sourceCtx2D, sourceCanvas2D); 34 fillCanvas(sourceCtx2D, sourceCanvas2D);
30 // draw dynamic Canvas 35 // draw dynamic Canvas
31 destCtx2D.drawImage(sourceCanvas2D, 0, 0); 36 destCtx2D.drawImage(sourceCanvas2D, 0, 0);
32 } 37 }
33 38
34 function ensureComplete() { 39 function ensureComplete() {
35 // Calling getImageData() is just to flush out the content when 40 // Using destCanvas2D a source image is just to flush out the content when
xidachen 2016/07/06 20:16:25 nit: Using destCanvas2D *as* a source image.
36 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low. 41 // accelerated 2D canvas is in use.
37 destCtx2D.getImageData(0, 0, 1, 1); 42 dummyCtx2D.drawImage(destCanvas2D, 0, 0, 1, 1, 0, 0, 1, 1);
38 } 43 }
39 44
40 window.onload = function () { 45 window.onload = function () {
41 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size 46 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size
42 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257 47 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257
43 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024. 48 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024.
44 setSize(1024, 1024, 1024, 1024); 49 setSize(1024, 1024, 1024, 1024);
45 fillCanvas(sourceCtx2D, sourceCanvas2D); 50 fillCanvas(sourceCtx2D, sourceCanvas2D);
46 CanvasRunner.start({ 51 CanvasRunner.start({
47 description: "This bench test checks the speed on drawing dynamic 2d Can vas(1024x1024) to HW accelerated Canvas2D(1024x1024).", 52 description: "This bench test checks the speed on drawing dynamic 2d Can vas(1024x1024) to HW accelerated Canvas2D(1024x1024).",
48 doRun: doRun, 53 doRun: doRun,
49 ensureComplete: ensureComplete}); 54 ensureComplete: ensureComplete});
50 } 55 }
51 56
52 </script> 57 </script>
53 </body> 58 </body>
54 </html> 59 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698