Changeset 120421 in webkit
- Timestamp:
- Jun 15, 2012 1:15:43 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r120414 r120421 1 2012-06-15 Andrey Adaikin <aandrey@chromium.org> 2 3 Web Inspector: [WebGL] Simple implementation of the InjectedWebGLScriptSource to support capturing WebGL calls for a frame 4 https://bugs.webkit.org/show_bug.cgi?id=89088 5 6 Simple experimental implementation of the InjectedWebGLScriptSource.js that allows to wrap 7 a WebGL context and capture names (for now) of the WebGL function calls for a frame being captured. 8 9 Reviewed by Vsevolod Vlasov. 10 11 * inspector/InjectedWebGLScriptSource.js: 12 (.): 13 1 14 2012-06-15 Silvia Pfeiffer <silviapf@chromium.org> 2 15 -
trunk/Source/WebCore/inspector/InjectedWebGLScriptSource.js
r119572 r120421 29 29 */ 30 30 31 (function(glContext) { 31 /** 32 * @param {InjectedScriptHost} InjectedScriptHost 33 */ 34 (function (InjectedScriptHost, inspectedWindow, injectedScriptId) { 32 35 33 // FIXME: Wrap WebGL context for instrumentation. 34 return glContext; 36 /** 37 * @constructor 38 */ 39 var InjectedScript = function() 40 { 41 this._lastBoundObjectId = 0; 42 this._idToWrapperProxy = {}; 43 this._idToRealWebGLContext = {}; 44 this._capturingFrameInfo = null; 45 } 46 47 InjectedScript.prototype = { 48 wrapWebGLContext: function(glContext) 49 { 50 for (var id in this._idToRealWebGLContext) { 51 if (this._idToRealWebGLContext[id] === glContext) 52 return this._idToWrapperProxy[id]; 53 } 54 55 var proxy = {}; 56 var nameProcessed = {}; 57 nameProcessed.__proto__ = null; 58 nameProcessed.constructor = true; 59 60 function processName(name) { 61 if (nameProcessed[name]) 62 return; 63 nameProcessed[name] = true; 64 if (typeof glContext[name] === "function") 65 proxy[name] = injectedScript._wrappedFunction.bind(injectedScript, glContext, name); 66 else 67 Object.defineProperty(proxy, name, { 68 get: function() 69 { 70 return glContext[name]; 71 }, 72 set: function(value) 73 { 74 glContext[name] = value; 75 } 76 }); 77 } 78 79 for (var o = glContext; o; o = o.__proto__) 80 Object.getOwnPropertyNames(o).forEach(processName); 81 82 // In order to emulate "instanceof". 83 proxy.__proto__ = glContext.__proto__; 84 proxy.constructor = glContext.constructor; 85 86 var contextId = this._generateObjectId(); 87 this._idToWrapperProxy[contextId] = proxy; 88 this._idToRealWebGLContext[contextId] = glContext; 89 InjectedScriptHost.webGLContextCreated(contextId); 90 91 return proxy; 92 }, 93 94 _generateObjectId: function() 95 { 96 var id = ++this._lastBoundObjectId; 97 var objectId = "{\"injectedScriptId\":" + injectedScriptId + ",\"webGLId\":" + id + "}"; 98 return objectId; 99 }, 100 101 captureFrame: function(contextId) 102 { 103 this._capturingFrameInfo = { 104 contextId: contextId, 105 capturedCallsNum: 0 106 }; 107 }, 108 109 _stopCapturing: function(info) 110 { 111 if (this._capturingFrameInfo === info) 112 this._capturingFrameInfo = null; 113 }, 114 115 _wrappedFunction: function(glContext, functionName) 116 { 117 // Call real WebGL function. 118 var args = Array.prototype.slice.call(arguments, 2); 119 var result = glContext[functionName].apply(glContext, args); 120 121 if (this._capturingFrameInfo && this._idToRealWebGLContext[this._capturingFrameInfo.contextId] === glContext) { 122 var capturedCallsNum = ++this._capturingFrameInfo.capturedCallsNum; 123 if (capturedCallsNum === 1) 124 this._setZeroTimeouts(this._stopCapturing.bind(this, this._capturingFrameInfo)); 125 InjectedScriptHost.webGLReportFunctionCall(this._capturingFrameInfo.contextId, functionName, "[" + args.join(", ") + "]", result + ""); 126 } 127 128 return result; 129 }, 130 131 _setZeroTimeouts: function(callback) 132 { 133 // We need a fastest async callback, whatever fires first. 134 // Usually a postMessage should be faster than a setTimeout(0). 135 var channel = new MessageChannel(); 136 channel.port1.onmessage = callback; 137 channel.port2.postMessage(""); 138 inspectedWindow.setTimeout(callback, 0); 139 } 140 }; 141 142 var injectedScript = new InjectedScript(); 143 return injectedScript; 35 144 36 145 })
Note: See TracChangeset
for help on using the changeset viewer.