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

Side by Side Diff: third_party/WebKit/PerformanceTests/Canvas/draw-static-webgl-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: whoops 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 canvas2D = document.createElement("canvas"); 7 var canvas2D = document.createElement("canvas");
8 var ctx2D = canvas2D.getContext("2d"); 8 var ctx2D = canvas2D.getContext("2d");
9 var canvas3D = document.createElement('canvas'); 9 var canvas3D = document.createElement('canvas');
10 var gl = canvas3D.getContext('webgl'); 10 var gl = canvas3D.getContext('webgl');
11 if (!gl) 11 if (!gl)
12 CanvasRunner.logFatalError("WebGL is not supported or enabled on this platfo rm!"); 12 CanvasRunner.logFatalError("WebGL is not supported or enabled on this platfo rm!");
13 13
14 var dummyCanvas2D = document.createElement("canvas");
15 var dummyCtx2D = dummyCanvas2D.getContext("2d");
16
17 dummyCanvas2D.width = 1;
18 dummyCanvas2D.height = 1;
19
14 function setSize(canvas2DWidth, canvas2DHeight, webglWidth, webglHeight) { 20 function setSize(canvas2DWidth, canvas2DHeight, webglWidth, webglHeight) {
15 canvas2D.width = canvas2DWidth; 21 canvas2D.width = canvas2DWidth;
16 canvas2D.height = canvas2DHeight; 22 canvas2D.height = canvas2DHeight;
17 canvas3D.width = webglWidth; 23 canvas3D.width = webglWidth;
18 canvas3D.height = webglHeight; 24 canvas3D.height = webglHeight;
19 } 25 }
20 26
21 function rand(range) { 27 function rand(range) {
22 return Math.floor(Math.random() * range); 28 return Math.floor(Math.random() * range);
23 } 29 }
24 30
25 function renderWebGL(gl) { 31 function renderWebGL(gl) {
26 gl.disable(gl.SCISSOR_TEST); 32 gl.disable(gl.SCISSOR_TEST);
27 gl.clear(gl.COLOR_BUFER_BIT); 33 gl.clear(gl.COLOR_BUFER_BIT);
28 gl.enable(gl.SCISSOR_TEST); 34 gl.enable(gl.SCISSOR_TEST);
29 gl.scissor(rand(1024), rand(1024), rand(1024), rand(1024)); 35 gl.scissor(rand(1024), rand(1024), rand(1024), rand(1024));
30 gl.clearColor(Math.random(), Math.random(), Math.random(), 1); 36 gl.clearColor(Math.random(), Math.random(), Math.random(), 1);
31 gl.clear(gl.COLOR_BUFFER_BIT); 37 gl.clear(gl.COLOR_BUFFER_BIT);
32 } 38 }
33 39
34 function doRun() { 40 function doRun() {
35 // draw static WebGL 41 // draw static WebGL
36 ctx2D.drawImage(canvas3D, 0, 0); 42 ctx2D.drawImage(canvas3D, 0, 0);
37 } 43 }
38 44
39 function ensureComplete() { 45 function ensureComplete() {
40 // Calling getImageData() is just to flush out the content when 46 // Using destCanvas2D as a source image is just to flush out the content whe n
41 // accelerated 2D canvas is in use. The cost of reading 1x1 pixels is low. 47 // accelerated 2D canvas is in use.
42 ctx2D.getImageData(0, 0, 1, 1); 48 dummyCtx2D.drawImage(destCanvas2D, 0, 0, 1, 1, 0, 0, 1, 1);
43 } 49 }
44 50
45 window.onload = function () { 51 window.onload = function () {
46 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size 52 // It should use setMinimumAccelerated2dCanvasSize() to enable accelerated C anvas for a specified size
47 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257 53 // but this API is not available in JS or WebPage. Assume the threshold size is 256x257
48 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024. 54 // and the dest canvas is HW accelerated Canvas when setting its size to 102 4x1024.
49 setSize(1024, 1024, 1024, 1024); 55 setSize(1024, 1024, 1024, 1024);
50 renderWebGL(gl); 56 renderWebGL(gl);
51 CanvasRunner.start({ 57 CanvasRunner.start({
52 description: "This bench test checks the speed on drawing static WebGL(1 024x1024) to HW accelerated Canvas2D(1024x1024).", 58 description: "This bench test checks the speed on drawing static WebGL(1 024x1024) to HW accelerated Canvas2D(1024x1024).",
53 doRun: doRun, 59 doRun: doRun,
54 ensureComplete: ensureComplete}); 60 ensureComplete: ensureComplete});
55 } 61 }
56 62
57 </script> 63 </script>
58 </body> 64 </body>
59 </html> 65 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698