| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../../http/tests/inspector/inspector-test.js"></script> | |
| 4 <script src="../canvas-profiler-test.js"></script> | |
| 5 <script> | |
| 6 if (window.internals) | |
| 7 window.internals.settings.setWebGLErrorsToConsoleEnabled(false); | |
| 8 | |
| 9 var gl; | |
| 10 var ctx; | |
| 11 | |
| 12 function createCanvasContext() | |
| 13 { | |
| 14 ctx = createCanvas2DContext(); | |
| 15 ctx.canvas.width = 32; | |
| 16 ctx.canvas.height = 32; | |
| 17 | |
| 18 gl = createWebGLContext(document.getElementById("canvas")); | |
| 19 console.assert(gl, "Failed to create a WebGL context"); | |
| 20 } | |
| 21 | |
| 22 function doCanvasCalls() | |
| 23 { | |
| 24 gl.getError(); | |
| 25 | |
| 26 var texture = gl.createTexture(); | |
| 27 gl.bindTexture(gl.TEXTURE_2D, texture); | |
| 28 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, ctx.canv
as); | |
| 29 | |
| 30 gl.activeTexture(gl.TEXTURE2); | |
| 31 gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()); | |
| 32 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0,0,0, 1,1,1]), gl.STATIC_D
RAW); | |
| 33 | |
| 34 gl.bindFramebuffer(gl.FRAMEBUFFER, gl.createFramebuffer()); | |
| 35 | |
| 36 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true); | |
| 37 var texture = gl.createTexture(); | |
| 38 gl.bindTexture(gl.TEXTURE_2D, texture); | |
| 39 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); | |
| 40 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAR
EST); | |
| 41 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 512, 512, 0, gl.RGBA, gl.UNSIGNED_B
YTE, null); | |
| 42 | |
| 43 var renderbuffer = gl.createRenderbuffer(); | |
| 44 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); | |
| 45 gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, 512, 512); | |
| 46 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
texture, 0); | |
| 47 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUF
FER, renderbuffer); | |
| 48 | |
| 49 gl.blendEquation(gl.FUNC_SUBTRACT); | |
| 50 gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_REVERSE_SUBTRACT); | |
| 51 gl.blendFunc(gl.ONE_MINUS_SRC_COLOR, gl.ONE_MINUS_DST_COLOR); | |
| 52 gl.blendFuncSeparate(gl.ZERO, gl.ONE, gl.ONE, gl.ZERO); | |
| 53 | |
| 54 gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT); | |
| 55 | |
| 56 gl.cullFace(gl.FRONT_AND_BACK); | |
| 57 gl.depthFunc(gl.NOTEQUAL); | |
| 58 | |
| 59 gl.disable(gl.DITHER); | |
| 60 gl.enable(gl.POLYGON_OFFSET_FILL); | |
| 61 | |
| 62 var vs = gl.createShader(gl.VERTEX_SHADER); | |
| 63 gl.shaderSource(vs, "attribute vec4 aVertex; attribute vec4 aColor; varying
vec4 vColor; void main() { vColor = aColor; gl_Position = aVertex; }"); | |
| 64 gl.compileShader(vs); | |
| 65 | |
| 66 var fs = gl.createShader(gl.FRAGMENT_SHADER); | |
| 67 gl.shaderSource(fs, "precision mediump float; uniform vec4 uColor; void main
() { gl_FragColor = uColor; }"); | |
| 68 gl.compileShader(fs); | |
| 69 | |
| 70 var program = gl.createProgram(); | |
| 71 gl.attachShader(program, vs); | |
| 72 gl.attachShader(program, fs); | |
| 73 gl.bindAttribLocation(program, 0, "aVertex"); | |
| 74 gl.bindAttribLocation(program, 1, "aColor"); | |
| 75 gl.linkProgram(program); | |
| 76 gl.useProgram(program); | |
| 77 | |
| 78 var location = gl.getUniformLocation(program, "uColor"); | |
| 79 | |
| 80 var extensions = [ | |
| 81 "OES_standard_derivatives", | |
| 82 "OES_vertex_array_object", | |
| 83 "EXT_texture_filter_anisotropic", | |
| 84 ]; | |
| 85 for (var i = 0, extension; extension = extensions[i]; ++i) { | |
| 86 var result1 = gl.getExtension(extension); | |
| 87 var result2 = gl.getExtension("WEBKIT_" + extension); | |
| 88 console.assert(result1 || result2, "Expected WebGL extension \"" + exten
sion + "\" to be supported."); | |
| 89 } | |
| 90 | |
| 91 var err = gl.getError(); | |
| 92 console.assert(err === gl.NO_ERROR, "Should be no GL errors, but was: " + er
r); | |
| 93 } | |
| 94 | |
| 95 function test() | |
| 96 { | |
| 97 var traceLogId; | |
| 98 var resourceIds; | |
| 99 InspectorTest.enableCanvasAgent(step1); | |
| 100 function step1() | |
| 101 { | |
| 102 InspectorTest.evaluateInPage("createCanvasContext()", step2); | |
| 103 } | |
| 104 function step2() | |
| 105 { | |
| 106 InspectorTest.CanvasAgent.startCapturing(didStartCapturing); | |
| 107 } | |
| 108 function didStartCapturing(error, id) | |
| 109 { | |
| 110 InspectorTest.assertTrue(!error && !!id, "Unexpected error: " + error); | |
| 111 InspectorTest.addResult("\nStarted capturing."); | |
| 112 traceLogId = id; | |
| 113 InspectorTest.evaluateInPage("doCanvasCalls()", didCanvasCalls); | |
| 114 } | |
| 115 function didCanvasCalls() | |
| 116 { | |
| 117 InspectorTest.CanvasAgent.stopCapturing(traceLogId, didStopCapturing); | |
| 118 } | |
| 119 function didStopCapturing() | |
| 120 { | |
| 121 InspectorTest.addResult("Stopped capturing."); | |
| 122 InspectorTest.CanvasAgent.getTraceLog(traceLogId, 0, undefined, didRecei
veTraceLog); | |
| 123 } | |
| 124 function didReceiveTraceLog(error, traceLog) | |
| 125 { | |
| 126 InspectorTest.assertTrue(!error && !!traceLog, "Unexpected error: " + er
ror); | |
| 127 var traceLogCallsNumber = traceLog.calls.length; | |
| 128 InspectorTest.assertTrue(traceLogCallsNumber > 0, "Expected not empty tr
ace log calls array"); | |
| 129 resourceIds = InspectorTest.collectResourceIdsFromTraceLog(traceLog); | |
| 130 InspectorTest.CanvasAgent.replayTraceLog(traceLogId, traceLogCallsNumber
- 1, didReplayTraceLog); | |
| 131 } | |
| 132 function didReplayTraceLog(error, resourceState) | |
| 133 { | |
| 134 InspectorTest.assertTrue(!error && !!resourceState, "Unexpected error: "
+ error); | |
| 135 InspectorTest.addResult("\n--- WebGLRenderingContext state ---"); | |
| 136 InspectorTest.dumpResourceState(resourceState); | |
| 137 InspectorTest.CanvasAgent.getResourceState(traceLogId, resourceIds["WebG
LBuffer@1"], didGetWebGLBufferState); | |
| 138 } | |
| 139 function didGetWebGLBufferState(error, resourceState) | |
| 140 { | |
| 141 InspectorTest.assertTrue(!error && !!resourceState, "Unexpected error: "
+ error); | |
| 142 InspectorTest.addResult("\n--- WebGLBuffer state ---"); | |
| 143 InspectorTest.dumpResourceState(resourceState); | |
| 144 InspectorTest.CanvasAgent.getResourceState(traceLogId, resourceIds["WebG
LTexture@1"], didGetWebGLTextureState); | |
| 145 } | |
| 146 function didGetWebGLTextureState(error, resourceState) | |
| 147 { | |
| 148 InspectorTest.assertTrue(!error && !!resourceState, "Unexpected error: "
+ error); | |
| 149 InspectorTest.addResult("\n--- WebGLTexture state ---"); | |
| 150 InspectorTest.dumpResourceState(resourceState); | |
| 151 InspectorTest.CanvasAgent.getResourceState(traceLogId, resourceIds["WebG
LProgram@1"], didGetWebGLProgramState); | |
| 152 } | |
| 153 function didGetWebGLProgramState(error, resourceState) | |
| 154 { | |
| 155 InspectorTest.assertTrue(!error && !!resourceState, "Unexpected error: "
+ error); | |
| 156 InspectorTest.addResult("\n--- WebGLProgram state ---"); | |
| 157 InspectorTest.dumpResourceState(resourceState); | |
| 158 InspectorTest.CanvasAgent.getResourceState(traceLogId, resourceIds["WebG
LShader@1"], didGetWebGLShaderState); | |
| 159 } | |
| 160 function didGetWebGLShaderState(error, resourceState) | |
| 161 { | |
| 162 InspectorTest.assertTrue(!error && !!resourceState, "Unexpected error: "
+ error); | |
| 163 InspectorTest.addResult("\n--- WebGLShader state ---"); | |
| 164 InspectorTest.dumpResourceState(resourceState); | |
| 165 InspectorTest.CanvasAgent.getResourceState(traceLogId, resourceIds["WebG
LFramebuffer@1"], didGetWebGLFramebufferState); | |
| 166 } | |
| 167 function didGetWebGLFramebufferState(error, resourceState) | |
| 168 { | |
| 169 InspectorTest.assertTrue(!error && !!resourceState, "Unexpected error: "
+ error); | |
| 170 InspectorTest.addResult("\n--- WebGLFramebuffer state ---"); | |
| 171 InspectorTest.dumpResourceState(resourceState); | |
| 172 InspectorTest.CanvasAgent.getResourceState(traceLogId, resourceIds["WebG
LRenderbuffer@1"], didGetWebGLRenderbufferState); | |
| 173 } | |
| 174 function didGetWebGLRenderbufferState(error, resourceState) | |
| 175 { | |
| 176 InspectorTest.assertTrue(!error && !!resourceState, "Unexpected error: "
+ error); | |
| 177 InspectorTest.addResult("\n--- WebGLRenderbuffer state ---"); | |
| 178 InspectorTest.dumpResourceState(resourceState); | |
| 179 InspectorTest.CanvasAgent.getResourceState(traceLogId, resourceIds["WebG
LUniformLocation@1"], didGetWebGLUniformLocationState); | |
| 180 } | |
| 181 function didGetWebGLUniformLocationState(error, resourceState) | |
| 182 { | |
| 183 InspectorTest.assertTrue(!error && !!resourceState, "Unexpected error: "
+ error); | |
| 184 InspectorTest.addResult("\n--- WebGLUniformLocation state ---"); | |
| 185 InspectorTest.dumpResourceState(resourceState); | |
| 186 InspectorTest.completeTest(); | |
| 187 } | |
| 188 } | |
| 189 | |
| 190 </script> | |
| 191 </head> | |
| 192 <body onload="runTest()"> | |
| 193 <p> | |
| 194 Tests canvas WebGL ResourceState during the replay. | |
| 195 </p> | |
| 196 <canvas id="canvas"></canvas> | |
| 197 </body> | |
| 198 </html> | |
| OLD | NEW |