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

Side by Side Diff: Source/core/inspector/InjectedScriptCanvasModuleSource.js

Issue 315253002: DevTools: [JSDoc] Fix injected scripts JSDoc and related code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix nullabilities in the injected scripts code Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/inspector/InjectedScriptSource.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 * @param {Window} inspectedWindow 33 * @param {Window} inspectedWindow
34 * @param {number} injectedScriptId 34 * @param {number} injectedScriptId
35 * @param {!InjectedScript} injectedScript 35 * @param {!InjectedScript} injectedScript
36 */ 36 */
37 (function (InjectedScriptHost, inspectedWindow, injectedScriptId, injectedScript ) { 37 (function (InjectedScriptHost, inspectedWindow, injectedScriptId, injectedScript ) {
38 38
39 var TypeUtils = { 39 var TypeUtils = {
40 /** 40 /**
41 * http://www.khronos.org/registry/typedarray/specs/latest/#7 41 * http://www.khronos.org/registry/typedarray/specs/latest/#7
42 * @const 42 * @const
43 * @type {!Array.<function(new:ArrayBufferView, (ArrayBuffer|ArrayBufferView ), number=, number=)>} 43 * @type {!Array.<function(new:ArrayBufferView, (!ArrayBuffer|!ArrayBufferVi ew), number=, number=)>}
44 */ 44 */
45 _typedArrayClasses: (function(typeNames) { 45 _typedArrayClasses: (function(typeNames) {
46 var result = []; 46 var result = [];
47 for (var i = 0, n = typeNames.length; i < n; ++i) { 47 for (var i = 0, n = typeNames.length; i < n; ++i) {
48 if (inspectedWindow[typeNames[i]]) 48 if (inspectedWindow[typeNames[i]])
49 result.push(inspectedWindow[typeNames[i]]); 49 result.push(inspectedWindow[typeNames[i]]);
50 } 50 }
51 return result; 51 return result;
52 })(["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Arr ay", "Int32Array", "Uint32Array", "Float32Array", "Float64Array"]), 52 })(["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Arr ay", "Int32Array", "Uint32Array", "Float32Array", "Float64Array"]),
53 53
54 /** 54 /**
55 * @const 55 * @const
56 * @type {!Array.<string>} 56 * @type {!Array.<string>}
57 */ 57 */
58 _supportedPropertyPrefixes: ["webkit"], 58 _supportedPropertyPrefixes: ["webkit"],
59 59
60 /** 60 /**
61 * @param {*} array 61 * @param {*} array
62 * @return {function(new:ArrayBufferView, (ArrayBuffer|ArrayBufferView), num ber=, number=)|null} 62 * @return {function(new:ArrayBufferView, (!ArrayBuffer|!ArrayBufferView), n umber=, number=)|null}
63 */ 63 */
64 typedArrayClass: function(array) 64 typedArrayClass: function(array)
65 { 65 {
66 var classes = TypeUtils._typedArrayClasses; 66 var classes = TypeUtils._typedArrayClasses;
67 for (var i = 0, n = classes.length; i < n; ++i) { 67 for (var i = 0, n = classes.length; i < n; ++i) {
68 if (array instanceof classes[i]) 68 if (array instanceof classes[i])
69 return classes[i]; 69 return classes[i];
70 } 70 }
71 return null; 71 return null;
72 }, 72 },
(...skipping 12 matching lines...) Expand all
85 return obj; 85 return obj;
86 86
87 // Handle Array and ArrayBuffer instances. 87 // Handle Array and ArrayBuffer instances.
88 if (typeof obj.slice === "function") { 88 if (typeof obj.slice === "function") {
89 console.assert(obj instanceof Array || obj instanceof ArrayBuffer); 89 console.assert(obj instanceof Array || obj instanceof ArrayBuffer);
90 return obj.slice(0); 90 return obj.slice(0);
91 } 91 }
92 92
93 var typedArrayClass = TypeUtils.typedArrayClass(obj); 93 var typedArrayClass = TypeUtils.typedArrayClass(obj);
94 if (typedArrayClass) 94 if (typedArrayClass)
95 return new typedArrayClass(/** @type {ArrayBufferView} */ (obj)); 95 return new typedArrayClass(/** @type {!ArrayBufferView} */ (obj));
96 96
97 if (obj instanceof HTMLImageElement) { 97 if (obj instanceof HTMLImageElement) {
98 var img = /** @type {HTMLImageElement} */ (obj); 98 var img = /** @type {!HTMLImageElement} */ (obj);
99 // Special case for Images with Blob URIs: cloneNode will fail if th e Blob URI has already been revoked. 99 // Special case for Images with Blob URIs: cloneNode will fail if th e Blob URI has already been revoked.
100 // FIXME: Maybe this is a bug in WebKit core? 100 // FIXME: Maybe this is a bug in WebKit core?
101 if (/^blob:/.test(img.src)) 101 if (/^blob:/.test(img.src))
102 return TypeUtils.cloneIntoCanvas(img); 102 return TypeUtils.cloneIntoCanvas(img);
103 return img.cloneNode(true); 103 return img.cloneNode(true);
104 } 104 }
105 105
106 if (obj instanceof HTMLCanvasElement) 106 if (obj instanceof HTMLCanvasElement)
107 return TypeUtils.cloneIntoCanvas(obj); 107 return TypeUtils.cloneIntoCanvas(obj);
108 108
(...skipping 15 matching lines...) Expand all
124 var valueType = typeof value; 124 var valueType = typeof value;
125 if (valueType !== "object" && valueType !== "function") 125 if (valueType !== "object" && valueType !== "function")
126 return value; 126 return value;
127 } 127 }
128 128
129 console.error("ASSERT_NOT_REACHED: failed to clone object: ", obj); 129 console.error("ASSERT_NOT_REACHED: failed to clone object: ", obj);
130 return obj; 130 return obj;
131 }, 131 },
132 132
133 /** 133 /**
134 * @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} obj 134 * @param {!HTMLImageElement|!HTMLCanvasElement|!HTMLVideoElement} obj
135 * @param {number=} width 135 * @param {number=} width
136 * @param {number=} height 136 * @param {number=} height
137 * @return {HTMLCanvasElement} 137 * @return {!HTMLCanvasElement}
138 */ 138 */
139 cloneIntoCanvas: function(obj, width, height) 139 cloneIntoCanvas: function(obj, width, height)
140 { 140 {
141 var canvas = /** @type {HTMLCanvasElement} */ (inspectedWindow.document. createElement("canvas")); 141 var canvas = /** @type {!HTMLCanvasElement} */ (inspectedWindow.document .createElement("canvas"));
142 canvas.width = width || +obj.width; 142 canvas.width = width || +obj.width;
143 canvas.height = height || +obj.height; 143 canvas.height = height || +obj.height;
144 var context = /** @type {CanvasRenderingContext2D} */ (Resource.wrappedO bject(canvas.getContext("2d"))); 144 var context = /** @type {!CanvasRenderingContext2D} */ (Resource.wrapped Object(canvas.getContext("2d")));
145 context.drawImage(obj, 0, 0); 145 context.drawImage(obj, 0, 0);
146 return canvas; 146 return canvas;
147 }, 147 },
148 148
149 /** 149 /**
150 * @param {Object=} obj 150 * @param {?Object=} obj
151 * @return {Object} 151 * @return {?Object}
152 */ 152 */
153 cloneObject: function(obj) 153 cloneObject: function(obj)
154 { 154 {
155 if (!obj) 155 if (!obj)
156 return null; 156 return null;
157 var result = {}; 157 var result = {};
158 for (var key in obj) 158 for (var key in obj)
159 result[key] = obj[key]; 159 result[key] = obj[key];
160 return result; 160 return result;
161 }, 161 },
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 * @param {string} property 196 * @param {string} property
197 * @param {!Object} obj 197 * @param {!Object} obj
198 * @return {boolean} 198 * @return {boolean}
199 */ 199 */
200 isEnumPropertyName: function(property, obj) 200 isEnumPropertyName: function(property, obj)
201 { 201 {
202 return (/^[A-Z][A-Z0-9_]+$/.test(property) && typeof obj[property] === " number"); 202 return (/^[A-Z][A-Z0-9_]+$/.test(property) && typeof obj[property] === " number");
203 }, 203 },
204 204
205 /** 205 /**
206 * @return {CanvasRenderingContext2D} 206 * @return {!CanvasRenderingContext2D}
207 */ 207 */
208 _dummyCanvas2dContext: function() 208 _dummyCanvas2dContext: function()
209 { 209 {
210 var context = TypeUtils._dummyCanvas2dContextInstance; 210 var context = TypeUtils._dummyCanvas2dContextInstance;
211 if (!context) { 211 if (!context) {
212 var canvas = /** @type {HTMLCanvasElement} */ (inspectedWindow.docum ent.createElement("canvas")); 212 var canvas = /** @type {!HTMLCanvasElement} */ (inspectedWindow.docu ment.createElement("canvas"));
213 context = /** @type {CanvasRenderingContext2D} */ (Resource.wrappedO bject(canvas.getContext("2d"))); 213 context = /** @type {!CanvasRenderingContext2D} */ (Resource.wrapped Object(canvas.getContext("2d")));
214 TypeUtils._dummyCanvas2dContextInstance = context; 214 TypeUtils._dummyCanvas2dContextInstance = context;
215 } 215 }
216 return context; 216 return context;
217 } 217 }
218 } 218 }
219 219
220 /** @typedef {{name:string, valueIsEnum:(boolean|undefined), value:*, values:(!A rray.<TypeUtils.InternalResourceStateDescriptor>|undefined), isArray:(boolean|un defined)}} */ 220 /** @typedef {{name:string, valueIsEnum:(boolean|undefined), value:*, values:(!A rray.<!TypeUtils.InternalResourceStateDescriptor>|undefined), isArray:(boolean|u ndefined)}} */
221 TypeUtils.InternalResourceStateDescriptor; 221 TypeUtils.InternalResourceStateDescriptor;
222 222
223 /** 223 /**
224 * @interface 224 * @interface
225 */ 225 */
226 function StackTrace() 226 function StackTrace()
227 { 227 {
228 } 228 }
229 229
230 StackTrace.prototype = { 230 StackTrace.prototype = {
231 /** 231 /**
232 * @param {number} index 232 * @param {number} index
233 * @return {{sourceURL: string, lineNumber: number, columnNumber: number}|un defined} 233 * @return {{sourceURL: string, lineNumber: number, columnNumber: number}|un defined}
234 */ 234 */
235 callFrame: function(index) 235 callFrame: function(index)
236 { 236 {
237 } 237 }
238 } 238 }
239 239
240 /** 240 /**
241 * @param {number=} stackTraceLimit 241 * @param {number=} stackTraceLimit
242 * @param {Function=} topMostFunctionToIgnore 242 * @param {?Function=} topMostFunctionToIgnore
243 * @return {StackTrace} 243 * @return {?StackTrace}
244 */ 244 */
245 StackTrace.create = function(stackTraceLimit, topMostFunctionToIgnore) 245 StackTrace.create = function(stackTraceLimit, topMostFunctionToIgnore)
246 { 246 {
247 if (typeof Error.captureStackTrace === "function") 247 if (typeof Error.captureStackTrace === "function")
248 return new StackTraceV8(stackTraceLimit, topMostFunctionToIgnore || argu ments.callee); 248 return new StackTraceV8(stackTraceLimit, topMostFunctionToIgnore || argu ments.callee);
249 // FIXME: Support JSC, and maybe other browsers. 249 // FIXME: Support JSC, and maybe other browsers.
250 return null; 250 return null;
251 } 251 }
252 252
253 /** 253 /**
254 * @constructor 254 * @constructor
255 * @implements {StackTrace} 255 * @implements {StackTrace}
256 * @param {number=} stackTraceLimit 256 * @param {number=} stackTraceLimit
257 * @param {Function=} topMostFunctionToIgnore 257 * @param {?Function=} topMostFunctionToIgnore
258 * @see http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi 258 * @see http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
259 */ 259 */
260 function StackTraceV8(stackTraceLimit, topMostFunctionToIgnore) 260 function StackTraceV8(stackTraceLimit, topMostFunctionToIgnore)
261 { 261 {
262 StackTrace.call(this);
263
264 var oldPrepareStackTrace = Error.prepareStackTrace; 262 var oldPrepareStackTrace = Error.prepareStackTrace;
265 var oldStackTraceLimit = Error.stackTraceLimit; 263 var oldStackTraceLimit = Error.stackTraceLimit;
266 if (typeof stackTraceLimit === "number") 264 if (typeof stackTraceLimit === "number")
267 Error.stackTraceLimit = stackTraceLimit; 265 Error.stackTraceLimit = stackTraceLimit;
268 266
269 /** 267 /**
270 * @param {Object} error 268 * @param {!Object} error
271 * @param {!Array.<CallSite>} structuredStackTrace 269 * @param {!Array.<!CallSite>} structuredStackTrace
272 * @return {!Array.<{sourceURL: string, lineNumber: number, columnNumber: nu mber}>} 270 * @return {!Array.<{sourceURL: string, lineNumber: number, columnNumber: nu mber}>}
273 */ 271 */
274 Error.prepareStackTrace = function(error, structuredStackTrace) 272 Error.prepareStackTrace = function(error, structuredStackTrace)
275 { 273 {
276 return structuredStackTrace.map(function(callSite) { 274 return structuredStackTrace.map(function(callSite) {
277 return { 275 return {
278 sourceURL: callSite.getFileName(), 276 sourceURL: callSite.getFileName(),
279 lineNumber: callSite.getLineNumber(), 277 lineNumber: callSite.getLineNumber(),
280 columnNumber: callSite.getColumnNumber() 278 columnNumber: callSite.getColumnNumber()
281 }; 279 };
(...skipping 10 matching lines...) Expand all
292 290
293 StackTraceV8.prototype = { 291 StackTraceV8.prototype = {
294 /** 292 /**
295 * @override 293 * @override
296 * @param {number} index 294 * @param {number} index
297 * @return {{sourceURL: string, lineNumber: number, columnNumber: number}|un defined} 295 * @return {{sourceURL: string, lineNumber: number, columnNumber: number}|un defined}
298 */ 296 */
299 callFrame: function(index) 297 callFrame: function(index)
300 { 298 {
301 return this._stackTrace[index]; 299 return this._stackTrace[index];
302 }, 300 }
303
304 __proto__: StackTrace.prototype
305 } 301 }
306 302
307 /** 303 /**
308 * @constructor 304 * @constructor
309 * @template T 305 * @template T
310 */ 306 */
311 function Cache() 307 function Cache()
312 { 308 {
313 this.reset(); 309 this.reset();
314 } 310 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 put: function(key, item) 351 put: function(key, item)
356 { 352 {
357 if (!this.has(key)) 353 if (!this.has(key))
358 ++this._size; 354 ++this._size;
359 this._items[key] = item; 355 this._items[key] = item;
360 } 356 }
361 } 357 }
362 358
363 /** 359 /**
364 * @constructor 360 * @constructor
365 * @param {Resource|Object} thisObject 361 * @param {?Resource|!Object} thisObject
366 * @param {string} functionName 362 * @param {string} functionName
367 * @param {!Array|Arguments} args 363 * @param {!Array|!Arguments} args
368 * @param {Resource|*=} result 364 * @param {!Resource|*=} result
369 * @param {StackTrace=} stackTrace 365 * @param {?StackTrace=} stackTrace
370 */ 366 */
371 function Call(thisObject, functionName, args, result, stackTrace) 367 function Call(thisObject, functionName, args, result, stackTrace)
372 { 368 {
373 this._thisObject = thisObject; 369 this._thisObject = thisObject;
374 this._functionName = functionName; 370 this._functionName = functionName;
375 this._args = Array.prototype.slice.call(args, 0); 371 this._args = Array.prototype.slice.call(args, 0);
376 this._result = result; 372 this._result = result;
377 this._stackTrace = stackTrace || null; 373 this._stackTrace = stackTrace || null;
378 374
379 if (!this._functionName) 375 if (!this._functionName)
380 console.assert(this._args.length === 2 && typeof this._args[0] === "stri ng"); 376 console.assert(this._args.length === 2 && typeof this._args[0] === "stri ng");
381 } 377 }
382 378
383 Call.prototype = { 379 Call.prototype = {
384 /** 380 /**
385 * @return {Resource} 381 * @return {?Resource}
386 */ 382 */
387 resource: function() 383 resource: function()
388 { 384 {
389 return Resource.forObject(this._thisObject); 385 return Resource.forObject(this._thisObject);
390 }, 386 },
391 387
392 /** 388 /**
393 * @return {string} 389 * @return {string}
394 */ 390 */
395 functionName: function() 391 functionName: function()
(...skipping 19 matching lines...) Expand all
415 411
416 /** 412 /**
417 * @return {*} 413 * @return {*}
418 */ 414 */
419 result: function() 415 result: function()
420 { 416 {
421 return this._result; 417 return this._result;
422 }, 418 },
423 419
424 /** 420 /**
425 * @return {StackTrace} 421 * @return {?StackTrace}
426 */ 422 */
427 stackTrace: function() 423 stackTrace: function()
428 { 424 {
429 return this._stackTrace; 425 return this._stackTrace;
430 }, 426 },
431 427
432 /** 428 /**
433 * @param {StackTrace} stackTrace 429 * @param {?StackTrace} stackTrace
434 */ 430 */
435 setStackTrace: function(stackTrace) 431 setStackTrace: function(stackTrace)
436 { 432 {
437 this._stackTrace = stackTrace; 433 this._stackTrace = stackTrace;
438 }, 434 },
439 435
440 /** 436 /**
441 * @param {*} result 437 * @param {*} result
442 */ 438 */
443 setResult: function(result) 439 setResult: function(result)
444 { 440 {
445 this._result = result; 441 this._result = result;
446 }, 442 },
447 443
448 /** 444 /**
449 * @param {string} name 445 * @param {string} name
450 * @param {Object} attachment 446 * @param {?Object} attachment
451 */ 447 */
452 setAttachment: function(name, attachment) 448 setAttachment: function(name, attachment)
453 { 449 {
454 if (attachment) { 450 if (attachment) {
455 /** @type {Object.<string, Object>} */ 451 /** @type {?Object.<string, !Object>|undefined} */
456 this._attachments = this._attachments || Object.create(null); 452 this._attachments = this._attachments || Object.create(null);
457 this._attachments[name] = attachment; 453 this._attachments[name] = attachment;
458 } else if (this._attachments) 454 } else if (this._attachments) {
459 delete this._attachments[name]; 455 delete this._attachments[name];
456 }
460 }, 457 },
461 458
462 /** 459 /**
463 * @param {string} name 460 * @param {string} name
464 * @return {Object} 461 * @return {?Object}
465 */ 462 */
466 attachment: function(name) 463 attachment: function(name)
467 { 464 {
468 return this._attachments && this._attachments[name]; 465 return this._attachments ? (this._attachments[name] || null) : null;
469 }, 466 },
470 467
471 freeze: function() 468 freeze: function()
472 { 469 {
473 if (this._freezed) 470 if (this._freezed)
474 return; 471 return;
475 this._freezed = true; 472 this._freezed = true;
476 for (var i = 0, n = this._args.length; i < n; ++i) { 473 for (var i = 0, n = this._args.length; i < n; ++i) {
477 // FIXME: freeze the Resources also! 474 // FIXME: freeze the Resources also!
478 if (!Resource.forObject(this._args[i])) 475 if (!Resource.forObject(this._args[i]))
479 this._args[i] = TypeUtils.clone(this._args[i]); 476 this._args[i] = TypeUtils.clone(this._args[i]);
480 } 477 }
481 }, 478 },
482 479
483 /** 480 /**
484 * @param {!Cache.<ReplayableResource>} cache 481 * @param {!Cache.<!ReplayableResource>} cache
485 * @return {!ReplayableCall} 482 * @return {!ReplayableCall}
486 */ 483 */
487 toReplayable: function(cache) 484 toReplayable: function(cache)
488 { 485 {
489 this.freeze(); 486 this.freeze();
490 var thisObject = /** @type {ReplayableResource} */ (Resource.toReplayabl e(this._thisObject, cache)); 487 var thisObject = /** @type {!ReplayableResource} */ (Resource.toReplayab le(this._thisObject, cache));
491 var result = Resource.toReplayable(this._result, cache); 488 var result = Resource.toReplayable(this._result, cache);
492 var args = this._args.map(function(obj) { 489 var args = this._args.map(function(obj) {
493 return Resource.toReplayable(obj, cache); 490 return Resource.toReplayable(obj, cache);
494 }); 491 });
495 var attachments = TypeUtils.cloneObject(this._attachments); 492 var attachments = TypeUtils.cloneObject(this._attachments);
496 return new ReplayableCall(thisObject, this._functionName, args, result, this._stackTrace, attachments); 493 return new ReplayableCall(thisObject, this._functionName, args, result, this._stackTrace, attachments);
497 }, 494 },
498 495
499 /** 496 /**
500 * @param {!ReplayableCall} replayableCall 497 * @param {!ReplayableCall} replayableCall
501 * @param {!Cache.<Resource>} cache 498 * @param {!Cache.<!Resource>} cache
502 * @return {!Call} 499 * @return {!Call}
503 */ 500 */
504 replay: function(replayableCall, cache) 501 replay: function(replayableCall, cache)
505 { 502 {
506 var replayableResult = replayableCall.result(); 503 var replayableResult = replayableCall.result();
507 if (replayableResult instanceof ReplayableResource && !cache.has(replaya bleResult.id())) { 504 if (replayableResult instanceof ReplayableResource && !cache.has(replaya bleResult.id())) {
508 var resource = replayableResult.replay(cache); 505 var resource = replayableResult.replay(cache);
509 console.assert(resource.calls().length > 0, "Expected create* call f or the Resource"); 506 console.assert(resource.calls().length > 0, "Expected create* call f or the Resource");
510 return resource.calls()[0]; 507 return resource.calls()[0];
511 } 508 }
(...skipping 18 matching lines...) Expand all
530 } 527 }
531 } 528 }
532 529
533 this._thisObject = replayObject; 530 this._thisObject = replayObject;
534 this._functionName = replayableCall.functionName(); 531 this._functionName = replayableCall.functionName();
535 this._args = replayArgs; 532 this._args = replayArgs;
536 this._result = replayResult; 533 this._result = replayResult;
537 this._stackTrace = replayableCall.stackTrace(); 534 this._stackTrace = replayableCall.stackTrace();
538 this._freezed = true; 535 this._freezed = true;
539 var attachments = replayableCall.attachments(); 536 var attachments = replayableCall.attachments();
540 if (attachments) 537 this._attachments = attachments ? TypeUtils.cloneObject(attachments) : n ull;
541 this._attachments = TypeUtils.cloneObject(attachments);
542 return this; 538 return this;
543 } 539 }
544 } 540 }
545 541
546 /** 542 /**
547 * @constructor 543 * @constructor
548 * @param {ReplayableResource} thisObject 544 * @param {!ReplayableResource} thisObject
549 * @param {string} functionName 545 * @param {string} functionName
550 * @param {!Array.<ReplayableResource|*>} args 546 * @param {!Array.<!ReplayableResource|*>} args
551 * @param {ReplayableResource|*} result 547 * @param {!ReplayableResource|*} result
552 * @param {StackTrace} stackTrace 548 * @param {?StackTrace} stackTrace
553 * @param {Object.<string, Object>} attachments 549 * @param {?Object.<string, !Object>} attachments
554 */ 550 */
555 function ReplayableCall(thisObject, functionName, args, result, stackTrace, atta chments) 551 function ReplayableCall(thisObject, functionName, args, result, stackTrace, atta chments)
556 { 552 {
557 this._thisObject = thisObject; 553 this._thisObject = thisObject;
558 this._functionName = functionName; 554 this._functionName = functionName;
559 this._args = args; 555 this._args = args;
560 this._result = result; 556 this._result = result;
561 this._stackTrace = stackTrace; 557 this._stackTrace = stackTrace;
562 if (attachments) 558 if (attachments)
563 this._attachments = attachments; 559 this._attachments = attachments;
564 } 560 }
565 561
566 ReplayableCall.prototype = { 562 ReplayableCall.prototype = {
567 /** 563 /**
568 * @return {ReplayableResource} 564 * @return {!ReplayableResource}
569 */ 565 */
570 replayableResource: function() 566 replayableResource: function()
571 { 567 {
572 return this._thisObject; 568 return this._thisObject;
573 }, 569 },
574 570
575 /** 571 /**
576 * @return {string} 572 * @return {string}
577 */ 573 */
578 functionName: function() 574 functionName: function()
(...skipping 21 matching lines...) Expand all
600 /** 596 /**
601 * @return {*} 597 * @return {*}
602 */ 598 */
603 propertyValue: function() 599 propertyValue: function()
604 { 600 {
605 console.assert(this.isPropertySetter()); 601 console.assert(this.isPropertySetter());
606 return this._args[1]; 602 return this._args[1];
607 }, 603 },
608 604
609 /** 605 /**
610 * @return {!Array.<ReplayableResource|*>} 606 * @return {!Array.<!ReplayableResource|*>}
611 */ 607 */
612 args: function() 608 args: function()
613 { 609 {
614 return this._args; 610 return this._args;
615 }, 611 },
616 612
617 /** 613 /**
618 * @return {ReplayableResource|*} 614 * @return {!ReplayableResource|*}
619 */ 615 */
620 result: function() 616 result: function()
621 { 617 {
622 return this._result; 618 return this._result;
623 }, 619 },
624 620
625 /** 621 /**
626 * @return {StackTrace} 622 * @return {?StackTrace}
627 */ 623 */
628 stackTrace: function() 624 stackTrace: function()
629 { 625 {
630 return this._stackTrace; 626 return this._stackTrace;
631 }, 627 },
632 628
633 /** 629 /**
634 * @return {Object.<string, Object>} 630 * @return {?Object.<string, !Object>}
635 */ 631 */
636 attachments: function() 632 attachments: function()
637 { 633 {
638 return this._attachments; 634 return this._attachments;
639 }, 635 },
640 636
641 /** 637 /**
642 * @param {string} name 638 * @param {string} name
643 * @return {Object} 639 * @return {!Object}
644 */ 640 */
645 attachment: function(name) 641 attachment: function(name)
646 { 642 {
647 return this._attachments && this._attachments[name]; 643 return this._attachments && this._attachments[name];
648 }, 644 },
649 645
650 /** 646 /**
651 * @param {!Cache.<Resource>} cache 647 * @param {!Cache.<!Resource>} cache
652 * @return {!Call} 648 * @return {!Call}
653 */ 649 */
654 replay: function(cache) 650 replay: function(cache)
655 { 651 {
656 var call = /** @type {!Call} */ (Object.create(Call.prototype)); 652 var call = /** @type {!Call} */ (Object.create(Call.prototype));
657 return call.replay(this, cache); 653 return call.replay(this, cache);
658 } 654 }
659 } 655 }
660 656
661 /** 657 /**
662 * @constructor 658 * @constructor
663 * @param {!Object} wrappedObject 659 * @param {!Object} wrappedObject
664 * @param {string} name 660 * @param {string} name
665 */ 661 */
666 function Resource(wrappedObject, name) 662 function Resource(wrappedObject, name)
667 { 663 {
668 /** @type {number} */ 664 /** @type {number} */
669 this._id = ++Resource._uniqueId; 665 this._id = ++Resource._uniqueId;
670 /** @type {string} */ 666 /** @type {string} */
671 this._name = name || "Resource"; 667 this._name = name || "Resource";
672 /** @type {number} */ 668 /** @type {number} */
673 this._kindId = Resource._uniqueKindIds[this._name] = (Resource._uniqueKindId s[this._name] || 0) + 1; 669 this._kindId = Resource._uniqueKindIds[this._name] = (Resource._uniqueKindId s[this._name] || 0) + 1;
674 /** @type {ResourceTrackingManager} */ 670 /** @type {?ResourceTrackingManager} */
675 this._resourceManager = null; 671 this._resourceManager = null;
676 /** @type {!Array.<Call>} */ 672 /** @type {!Array.<!Call>} */
677 this._calls = []; 673 this._calls = [];
678 /** 674 /**
679 * This is to prevent GC from collecting associated resources. 675 * This is to prevent GC from collecting associated resources.
680 * Otherwise, for example in WebGL, subsequent calls to gl.getParameter() 676 * Otherwise, for example in WebGL, subsequent calls to gl.getParameter()
681 * may return a recently created instance that is no longer bound to a 677 * may return a recently created instance that is no longer bound to a
682 * Resource object (thus, no history to replay it later). 678 * Resource object (thus, no history to replay it later).
683 * 679 *
684 * @type {!Object.<string, Resource>} 680 * @type {!Object.<string, !Resource>}
685 */ 681 */
686 this._boundResources = Object.create(null); 682 this._boundResources = Object.create(null);
687 this.setWrappedObject(wrappedObject); 683 this.setWrappedObject(wrappedObject);
688 } 684 }
689 685
690 /** 686 /**
691 * @type {number} 687 * @type {number}
692 */ 688 */
693 Resource._uniqueId = 0; 689 Resource._uniqueId = 0;
694 690
695 /** 691 /**
696 * @type {!Object.<string, number>} 692 * @type {!Object.<string, number>}
697 */ 693 */
698 Resource._uniqueKindIds = {}; 694 Resource._uniqueKindIds = {};
699 695
700 /** 696 /**
701 * @param {*} obj 697 * @param {*} obj
702 * @return {Resource} 698 * @return {?Resource}
703 */ 699 */
704 Resource.forObject = function(obj) 700 Resource.forObject = function(obj)
705 { 701 {
706 if (!obj) 702 if (!obj)
707 return null; 703 return null;
708 if (obj instanceof Resource) 704 if (obj instanceof Resource)
709 return obj; 705 return obj;
710 if (typeof obj === "object") 706 if (typeof obj === "object")
711 return obj["__resourceObject"]; 707 return obj["__resourceObject"];
712 return null; 708 return null;
713 } 709 }
714 710
715 /** 711 /**
716 * @param {Resource|*} obj 712 * @param {!Resource|*} obj
717 * @return {*} 713 * @return {*}
718 */ 714 */
719 Resource.wrappedObject = function(obj) 715 Resource.wrappedObject = function(obj)
720 { 716 {
721 var resource = Resource.forObject(obj); 717 var resource = Resource.forObject(obj);
722 return resource ? resource.wrappedObject() : obj; 718 return resource ? resource.wrappedObject() : obj;
723 } 719 }
724 720
725 /** 721 /**
726 * @param {Resource|*} obj 722 * @param {!Resource|*} obj
727 * @param {!Cache.<ReplayableResource>} cache 723 * @param {!Cache.<!ReplayableResource>} cache
728 * @return {ReplayableResource|*} 724 * @return {!ReplayableResource|*}
729 */ 725 */
730 Resource.toReplayable = function(obj, cache) 726 Resource.toReplayable = function(obj, cache)
731 { 727 {
732 var resource = Resource.forObject(obj); 728 var resource = Resource.forObject(obj);
733 return resource ? resource.toReplayable(cache) : obj; 729 return resource ? resource.toReplayable(cache) : obj;
734 } 730 }
735 731
736 Resource.prototype = { 732 Resource.prototype = {
737 /** 733 /**
738 * @return {number} 734 * @return {number}
(...skipping 13 matching lines...) Expand all
752 748
753 /** 749 /**
754 * @return {string} 750 * @return {string}
755 */ 751 */
756 description: function() 752 description: function()
757 { 753 {
758 return this._name + "@" + this._kindId; 754 return this._name + "@" + this._kindId;
759 }, 755 },
760 756
761 /** 757 /**
762 * @return {Object} 758 * @return {!Object}
763 */ 759 */
764 wrappedObject: function() 760 wrappedObject: function()
765 { 761 {
766 return this._wrappedObject; 762 return this._wrappedObject;
767 }, 763 },
768 764
769 /** 765 /**
770 * @param {!Object} value 766 * @param {!Object} value
771 */ 767 */
772 setWrappedObject: function(value) 768 setWrappedObject: function(value)
773 { 769 {
774 console.assert(value, "wrappedObject should not be NULL"); 770 console.assert(value, "wrappedObject should not be NULL");
775 console.assert(!(value instanceof Resource), "Binding a Resource object to another Resource object?"); 771 console.assert(!(value instanceof Resource), "Binding a Resource object to another Resource object?");
776 this._wrappedObject = value; 772 this._wrappedObject = value;
777 this._bindObjectToResource(value); 773 this._bindObjectToResource(value);
778 }, 774 },
779 775
780 /** 776 /**
781 * @return {Object} 777 * @return {!Object}
782 */ 778 */
783 proxyObject: function() 779 proxyObject: function()
784 { 780 {
785 if (!this._proxyObject) 781 if (!this._proxyObject)
786 this._proxyObject = this._wrapObject(); 782 this._proxyObject = this._wrapObject();
787 return this._proxyObject; 783 return this._proxyObject;
788 }, 784 },
789 785
790 /** 786 /**
791 * @return {ResourceTrackingManager} 787 * @return {?ResourceTrackingManager}
792 */ 788 */
793 manager: function() 789 manager: function()
794 { 790 {
795 return this._resourceManager; 791 return this._resourceManager;
796 }, 792 },
797 793
798 /** 794 /**
799 * @param {ResourceTrackingManager} value 795 * @param {!ResourceTrackingManager} value
800 */ 796 */
801 setManager: function(value) 797 setManager: function(value)
802 { 798 {
803 this._resourceManager = value; 799 this._resourceManager = value;
804 }, 800 },
805 801
806 /** 802 /**
807 * @return {!Array.<!Call>} 803 * @return {!Array.<!Call>}
808 */ 804 */
809 calls: function() 805 calls: function()
810 { 806 {
811 return this._calls; 807 return this._calls;
812 }, 808 },
813 809
814 /** 810 /**
815 * @return {ContextResource} 811 * @return {?ContextResource}
816 */ 812 */
817 contextResource: function() 813 contextResource: function()
818 { 814 {
819 if (this instanceof ContextResource) 815 if (this instanceof ContextResource)
820 return /** @type {ContextResource} */ (this); 816 return /** @type {!ContextResource} */ (this);
821 817
822 if (this._calculatingContextResource) 818 if (this._calculatingContextResource)
823 return null; 819 return null;
824 820
825 this._calculatingContextResource = true; 821 this._calculatingContextResource = true;
826 var result = null; 822 var result = null;
827 for (var i = 0, n = this._calls.length; i < n; ++i) { 823 for (var i = 0, n = this._calls.length; i < n; ++i) {
828 result = this._calls[i].resource().contextResource(); 824 result = this._calls[i].resource().contextResource();
829 if (result) 825 if (result)
830 break; 826 break;
831 } 827 }
832 delete this._calculatingContextResource; 828 delete this._calculatingContextResource;
833 console.assert(result, "Failed to find context resource for " + this._na me + "@" + this._kindId); 829 console.assert(result, "Failed to find context resource for " + this._na me + "@" + this._kindId);
834 return result; 830 return result;
835 }, 831 },
836 832
837 /** 833 /**
838 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 834 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
839 */ 835 */
840 currentState: function() 836 currentState: function()
841 { 837 {
842 var result = []; 838 var result = [];
843 var proxyObject = this.proxyObject(); 839 var proxyObject = this.proxyObject();
844 if (!proxyObject) 840 if (!proxyObject)
845 return result; 841 return result;
846 var statePropertyNames = this._proxyStatePropertyNames || []; 842 var statePropertyNames = this._proxyStatePropertyNames || [];
847 for (var i = 0, n = statePropertyNames.length; i < n; ++i) { 843 for (var i = 0, n = statePropertyNames.length; i < n; ++i) {
848 var pname = statePropertyNames[i]; 844 var pname = statePropertyNames[i];
849 result.push({ name: pname, value: proxyObject[pname] }); 845 result.push({ name: pname, value: proxyObject[pname] });
850 } 846 }
851 result.push({ name: "context", value: this.contextResource() }); 847 result.push({ name: "context", value: this.contextResource() });
852 return result; 848 return result;
853 }, 849 },
854 850
855 /** 851 /**
856 * @return {string} 852 * @return {string}
857 */ 853 */
858 toDataURL: function() 854 toDataURL: function()
859 { 855 {
860 return ""; 856 return "";
861 }, 857 },
862 858
863 /** 859 /**
864 * @param {!Cache.<ReplayableResource>} cache 860 * @param {!Cache.<!ReplayableResource>} cache
865 * @return {!ReplayableResource} 861 * @return {!ReplayableResource}
866 */ 862 */
867 toReplayable: function(cache) 863 toReplayable: function(cache)
868 { 864 {
869 var result = cache.get(this._id); 865 var result = cache.get(this._id);
870 if (result) 866 if (result)
871 return result; 867 return result;
872 var data = { 868 var data = {
873 id: this._id, 869 id: this._id,
874 name: this._name, 870 name: this._name,
875 kindId: this._kindId 871 kindId: this._kindId
876 }; 872 };
877 result = new ReplayableResource(this, data); 873 result = new ReplayableResource(this, data);
878 cache.put(this._id, result); // Put into the cache early to avoid loops. 874 cache.put(this._id, result); // Put into the cache early to avoid loops.
879 data.calls = this._calls.map(function(call) { 875 data.calls = this._calls.map(function(call) {
880 return call.toReplayable(cache); 876 return call.toReplayable(cache);
881 }); 877 });
882 this._populateReplayableData(data, cache); 878 this._populateReplayableData(data, cache);
883 var contextResource = this.contextResource(); 879 var contextResource = this.contextResource();
884 if (contextResource !== this) 880 if (contextResource !== this)
885 data.contextResource = Resource.toReplayable(contextResource, cache) ; 881 data.contextResource = Resource.toReplayable(contextResource, cache) ;
886 return result; 882 return result;
887 }, 883 },
888 884
889 /** 885 /**
890 * @param {!Object} data 886 * @param {!Object} data
891 * @param {!Cache.<ReplayableResource>} cache 887 * @param {!Cache.<!ReplayableResource>} cache
892 */ 888 */
893 _populateReplayableData: function(data, cache) 889 _populateReplayableData: function(data, cache)
894 { 890 {
895 // Do nothing. Should be overridden by subclasses. 891 // Do nothing. Should be overridden by subclasses.
896 }, 892 },
897 893
898 /** 894 /**
899 * @param {!Object} data 895 * @param {!Object} data
900 * @param {!Cache.<Resource>} cache 896 * @param {!Cache.<!Resource>} cache
901 * @return {!Resource} 897 * @return {!Resource}
902 */ 898 */
903 replay: function(data, cache) 899 replay: function(data, cache)
904 { 900 {
905 var resource = cache.get(data.id); 901 var resource = cache.get(data.id);
906 if (resource) 902 if (resource)
907 return resource; 903 return resource;
908 this._id = data.id; 904 this._id = data.id;
909 this._name = data.name; 905 this._name = data.name;
910 this._kindId = data.kindId; 906 this._kindId = data.kindId;
911 this._resourceManager = null; 907 this._resourceManager = null;
912 this._calls = []; 908 this._calls = [];
913 this._boundResources = Object.create(null); 909 this._boundResources = Object.create(null);
914 this._wrappedObject = null; 910 this._wrappedObject = null;
915 cache.put(data.id, this); // Put into the cache early to avoid loops. 911 cache.put(data.id, this); // Put into the cache early to avoid loops.
916 this._doReplayCalls(data, cache); 912 this._doReplayCalls(data, cache);
917 console.assert(this._wrappedObject, "Resource should be reconstructed!") ; 913 console.assert(this._wrappedObject, "Resource should be reconstructed!") ;
918 return this; 914 return this;
919 }, 915 },
920 916
921 /** 917 /**
922 * @param {!Object} data 918 * @param {!Object} data
923 * @param {!Cache.<Resource>} cache 919 * @param {!Cache.<!Resource>} cache
924 */ 920 */
925 _doReplayCalls: function(data, cache) 921 _doReplayCalls: function(data, cache)
926 { 922 {
927 for (var i = 0, n = data.calls.length; i < n; ++i) 923 for (var i = 0, n = data.calls.length; i < n; ++i)
928 this._calls.push(data.calls[i].replay(cache)); 924 this._calls.push(data.calls[i].replay(cache));
929 }, 925 },
930 926
931 /** 927 /**
932 * @param {!Call} call 928 * @param {!Call} call
933 */ 929 */
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 _registerBoundResource: function(key, obj) 961 _registerBoundResource: function(key, obj)
966 { 962 {
967 var resource = Resource.forObject(obj); 963 var resource = Resource.forObject(obj);
968 if (resource) 964 if (resource)
969 this._boundResources[key] = resource; 965 this._boundResources[key] = resource;
970 else 966 else
971 delete this._boundResources[key]; 967 delete this._boundResources[key];
972 }, 968 },
973 969
974 /** 970 /**
975 * @return {Object} 971 * @return {?Object}
976 */ 972 */
977 _wrapObject: function() 973 _wrapObject: function()
978 { 974 {
979 var wrappedObject = this.wrappedObject(); 975 var wrappedObject = this.wrappedObject();
980 if (!wrappedObject) 976 if (!wrappedObject)
981 return null; 977 return null;
982 var proxy = Object.create(wrappedObject.__proto__); // In order to emula te "instanceof". 978 var proxy = Object.create(wrappedObject.__proto__); // In order to emula te "instanceof".
983 979
984 var customWrapFunctions = this._customWrapFunctions(); 980 var customWrapFunctions = this._customWrapFunctions();
985 /** @type {!Array.<string>} */ 981 /** @type {!Array.<string>} */
986 this._proxyStatePropertyNames = []; 982 this._proxyStatePropertyNames = [];
987 983
988 /** 984 /**
989 * @param {string} property 985 * @param {string} property
986 * @this {Resource}
990 */ 987 */
991 function processProperty(property) 988 function processProperty(property)
992 { 989 {
993 if (typeof wrappedObject[property] === "function") { 990 if (typeof wrappedObject[property] === "function") {
994 var customWrapFunction = customWrapFunctions[property]; 991 var customWrapFunction = customWrapFunctions[property];
995 if (customWrapFunction) 992 if (customWrapFunction)
996 proxy[property] = this._wrapCustomFunction(this, wrappedObje ct, wrappedObject[property], property, customWrapFunction); 993 proxy[property] = this._wrapCustomFunction(this, wrappedObje ct, wrappedObject[property], property, customWrapFunction);
997 else 994 else
998 proxy[property] = this._wrapFunction(this, wrappedObject, wr appedObject[property], property); 995 proxy[property] = this._wrapFunction(this, wrappedObject, wr appedObject[property], property);
999 } else if (TypeUtils.isEnumPropertyName(property, wrappedObject)) { 996 } else if (TypeUtils.isEnumPropertyName(property, wrappedObject)) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 var args = [propertyName, value]; 1092 var args = [propertyName, value];
1096 manager.captureArguments(resource, args); 1093 manager.captureArguments(resource, args);
1097 originalObject[propertyName] = Resource.wrappedObject(value); 1094 originalObject[propertyName] = Resource.wrappedObject(value);
1098 var stackTrace = StackTrace.create(1, arguments.callee); 1095 var stackTrace = StackTrace.create(1, arguments.callee);
1099 var call = new Call(resource, "", args, undefined, stackTrace); 1096 var call = new Call(resource, "", args, undefined, stackTrace);
1100 manager.captureCall(call); 1097 manager.captureCall(call);
1101 }; 1098 };
1102 }, 1099 },
1103 1100
1104 /** 1101 /**
1105 * @return {!Object.<string, Function>} 1102 * @return {!Object.<string, !Function>}
1106 */ 1103 */
1107 _customWrapFunctions: function() 1104 _customWrapFunctions: function()
1108 { 1105 {
1109 return Object.create(null); // May be overridden by subclasses. 1106 return Object.create(null); // May be overridden by subclasses.
1110 } 1107 }
1111 } 1108 }
1112 1109
1113 /** 1110 /**
1114 * @constructor 1111 * @constructor
1115 * @param {Object} originalObject 1112 * @param {!Object} originalObject
1116 * @param {Function} originalFunction 1113 * @param {!Function} originalFunction
1117 * @param {string} functionName 1114 * @param {string} functionName
1118 * @param {!Array|Arguments} args 1115 * @param {!Array|!Arguments} args
1119 */ 1116 */
1120 Resource.WrapFunction = function(originalObject, originalFunction, functionName, args) 1117 Resource.WrapFunction = function(originalObject, originalFunction, functionName, args)
1121 { 1118 {
1122 this._originalObject = originalObject; 1119 this._originalObject = originalObject;
1123 this._originalFunction = originalFunction; 1120 this._originalFunction = originalFunction;
1124 this._functionName = functionName; 1121 this._functionName = functionName;
1125 this._args = args; 1122 this._args = args;
1126 this._resource = Resource.forObject(originalObject); 1123 this._resource = Resource.forObject(originalObject);
1127 console.assert(this._resource, "Expected a wrapped call on a Resource object ."); 1124 console.assert(this._resource, "Expected a wrapped call on a Resource object .");
1128 } 1125 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 } 1158 }
1162 } 1159 }
1163 1160
1164 /** 1161 /**
1165 * @param {function(new:Resource, !Object, string)} resourceConstructor 1162 * @param {function(new:Resource, !Object, string)} resourceConstructor
1166 * @param {string} resourceName 1163 * @param {string} resourceName
1167 * @return {function(this:Resource.WrapFunction)} 1164 * @return {function(this:Resource.WrapFunction)}
1168 */ 1165 */
1169 Resource.WrapFunction.resourceFactoryMethod = function(resourceConstructor, reso urceName) 1166 Resource.WrapFunction.resourceFactoryMethod = function(resourceConstructor, reso urceName)
1170 { 1167 {
1171 /** @this Resource.WrapFunction */ 1168 /** @this {Resource.WrapFunction} */
1172 return function() 1169 return function()
1173 { 1170 {
1174 var wrappedObject = /** @type {Object} */ (this.result()); 1171 var wrappedObject = /** @type {?Object} */ (this.result());
1175 if (!wrappedObject) 1172 if (!wrappedObject)
1176 return; 1173 return;
1177 var resource = new resourceConstructor(wrappedObject, resourceName); 1174 var resource = new resourceConstructor(wrappedObject, resourceName);
1178 var manager = this._resource.manager(); 1175 var manager = this._resource.manager();
1179 if (manager) 1176 if (manager)
1180 manager.registerResource(resource); 1177 manager.registerResource(resource);
1181 this.overrideResult(resource.proxyObject()); 1178 this.overrideResult(resource.proxyObject());
1182 resource.pushCall(this.call()); 1179 resource.pushCall(this.call());
1183 } 1180 }
1184 } 1181 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 1218
1222 /** 1219 /**
1223 * @return {!ReplayableResource} 1220 * @return {!ReplayableResource}
1224 */ 1221 */
1225 contextResource: function() 1222 contextResource: function()
1226 { 1223 {
1227 return this._data.contextResource || this; 1224 return this._data.contextResource || this;
1228 }, 1225 },
1229 1226
1230 /** 1227 /**
1231 * @param {!Cache.<Resource>} cache 1228 * @param {!Cache.<!Resource>} cache
1232 * @return {!Resource} 1229 * @return {!Resource}
1233 */ 1230 */
1234 replay: function(cache) 1231 replay: function(cache)
1235 { 1232 {
1236 var result = /** @type {!Resource} */ (Object.create(this._proto)); 1233 var result = /** @type {!Resource} */ (Object.create(this._proto));
1237 result = result.replay(this._data, cache) 1234 result = result.replay(this._data, cache)
1238 console.assert(result.__proto__ === this._proto, "Wrong type of a replay result"); 1235 console.assert(result.__proto__ === this._proto, "Wrong type of a replay result");
1239 return result; 1236 return result;
1240 } 1237 }
1241 } 1238 }
1242 1239
1243 /** 1240 /**
1244 * @param {ReplayableResource|*} obj 1241 * @param {!ReplayableResource|*} obj
1245 * @param {!Cache.<Resource>} cache 1242 * @param {!Cache.<!Resource>} cache
1246 * @return {*} 1243 * @return {*}
1247 */ 1244 */
1248 ReplayableResource.replay = function(obj, cache) 1245 ReplayableResource.replay = function(obj, cache)
1249 { 1246 {
1250 return (obj instanceof ReplayableResource) ? obj.replay(cache).wrappedObject () : obj; 1247 return (obj instanceof ReplayableResource) ? obj.replay(cache).wrappedObject () : obj;
1251 } 1248 }
1252 1249
1253 /** 1250 /**
1254 * @constructor 1251 * @constructor
1255 * @extends {Resource} 1252 * @extends {Resource}
(...skipping 16 matching lines...) Expand all
1272 * @param {string} name 1269 * @param {string} name
1273 */ 1270 */
1274 function LogEverythingResource(wrappedObject, name) 1271 function LogEverythingResource(wrappedObject, name)
1275 { 1272 {
1276 Resource.call(this, wrappedObject, name); 1273 Resource.call(this, wrappedObject, name);
1277 } 1274 }
1278 1275
1279 LogEverythingResource.prototype = { 1276 LogEverythingResource.prototype = {
1280 /** 1277 /**
1281 * @override 1278 * @override
1282 * @return {!Object.<string, Function>} 1279 * @return {!Object.<string, !Function>}
1283 */ 1280 */
1284 _customWrapFunctions: function() 1281 _customWrapFunctions: function()
1285 { 1282 {
1286 var wrapFunctions = Object.create(null); 1283 var wrapFunctions = Object.create(null);
1287 var wrappedObject = this.wrappedObject(); 1284 var wrappedObject = this.wrappedObject();
1288 if (wrappedObject) { 1285 if (wrappedObject) {
1289 for (var property in wrappedObject) { 1286 for (var property in wrappedObject) {
1290 /** @this Resource.WrapFunction */ 1287 /** @this {Resource.WrapFunction} */
1291 wrapFunctions[property] = function() 1288 wrapFunctions[property] = function()
1292 { 1289 {
1293 this._resource.pushCall(this.call()); 1290 this._resource.pushCall(this.call());
1294 } 1291 }
1295 } 1292 }
1296 } 1293 }
1297 return wrapFunctions; 1294 return wrapFunctions;
1298 }, 1295 },
1299 1296
1300 __proto__: Resource.prototype 1297 __proto__: Resource.prototype
(...skipping 13 matching lines...) Expand all
1314 { 1311 {
1315 Resource.call(this, wrappedObject, name); 1312 Resource.call(this, wrappedObject, name);
1316 /** @type {!Object.<string, *>} */ 1313 /** @type {!Object.<string, *>} */
1317 this._state = {}; 1314 this._state = {};
1318 } 1315 }
1319 1316
1320 WebGLBoundResource.prototype = { 1317 WebGLBoundResource.prototype = {
1321 /** 1318 /**
1322 * @override 1319 * @override
1323 * @param {!Object} data 1320 * @param {!Object} data
1324 * @param {!Cache.<ReplayableResource>} cache 1321 * @param {!Cache.<!ReplayableResource>} cache
1325 */ 1322 */
1326 _populateReplayableData: function(data, cache) 1323 _populateReplayableData: function(data, cache)
1327 { 1324 {
1328 var state = this._state; 1325 var state = this._state;
1329 data.state = {}; 1326 data.state = {};
1330 Object.keys(state).forEach(function(parameter) { 1327 Object.keys(state).forEach(function(parameter) {
1331 data.state[parameter] = Resource.toReplayable(state[parameter], cach e); 1328 data.state[parameter] = Resource.toReplayable(state[parameter], cach e);
1332 }); 1329 });
1333 }, 1330 },
1334 1331
1335 /** 1332 /**
1336 * @override 1333 * @override
1337 * @param {!Object} data 1334 * @param {!Object} data
1338 * @param {!Cache.<Resource>} cache 1335 * @param {!Cache.<!Resource>} cache
1339 */ 1336 */
1340 _doReplayCalls: function(data, cache) 1337 _doReplayCalls: function(data, cache)
1341 { 1338 {
1342 var gl = this._replayContextResource(data, cache).wrappedObject(); 1339 var gl = this._replayContextResource(data, cache).wrappedObject();
1343 1340
1344 /** @type {!Object.<string, Array.<string>>} */ 1341 /** @type {!Object.<string, !Array.<string>>} */
1345 var bindingsData = { 1342 var bindingsData = {
1346 TEXTURE_2D: ["bindTexture", "TEXTURE_BINDING_2D"], 1343 TEXTURE_2D: ["bindTexture", "TEXTURE_BINDING_2D"],
1347 TEXTURE_CUBE_MAP: ["bindTexture", "TEXTURE_BINDING_CUBE_MAP"], 1344 TEXTURE_CUBE_MAP: ["bindTexture", "TEXTURE_BINDING_CUBE_MAP"],
1348 ARRAY_BUFFER: ["bindBuffer", "ARRAY_BUFFER_BINDING"], 1345 ARRAY_BUFFER: ["bindBuffer", "ARRAY_BUFFER_BINDING"],
1349 ELEMENT_ARRAY_BUFFER: ["bindBuffer", "ELEMENT_ARRAY_BUFFER_BINDING"] , 1346 ELEMENT_ARRAY_BUFFER: ["bindBuffer", "ELEMENT_ARRAY_BUFFER_BINDING"] ,
1350 FRAMEBUFFER: ["bindFramebuffer", "FRAMEBUFFER_BINDING"], 1347 FRAMEBUFFER: ["bindFramebuffer", "FRAMEBUFFER_BINDING"],
1351 RENDERBUFFER: ["bindRenderbuffer", "RENDERBUFFER_BINDING"] 1348 RENDERBUFFER: ["bindRenderbuffer", "RENDERBUFFER_BINDING"]
1352 }; 1349 };
1353 var originalBindings = {}; 1350 var originalBindings = {};
1354 Object.keys(bindingsData).forEach(function(bindingTarget) { 1351 Object.keys(bindingsData).forEach(function(bindingTarget) {
1355 var bindingParameter = bindingsData[bindingTarget][1]; 1352 var bindingParameter = bindingsData[bindingTarget][1];
1356 originalBindings[bindingTarget] = gl.getParameter(gl[bindingParamete r]); 1353 originalBindings[bindingTarget] = gl.getParameter(gl[bindingParamete r]);
1357 }); 1354 });
1358 1355
1359 var state = {}; 1356 var state = {};
1360 Object.keys(data.state).forEach(function(parameter) { 1357 Object.keys(data.state).forEach(function(parameter) {
1361 state[parameter] = ReplayableResource.replay(data.state[parameter], cache); 1358 state[parameter] = ReplayableResource.replay(data.state[parameter], cache);
1362 }); 1359 });
1363 this._state = state; 1360 this._state = state;
1364 Resource.prototype._doReplayCalls.call(this, data, cache); 1361 Resource.prototype._doReplayCalls.call(this, data, cache);
1365 1362
1366 Object.keys(bindingsData).forEach(function(bindingTarget) { 1363 Object.keys(bindingsData).forEach(function(bindingTarget) {
1367 var bindMethodName = bindingsData[bindingTarget][0]; 1364 var bindMethodName = bindingsData[bindingTarget][0];
1368 gl[bindMethodName].call(gl, gl[bindingTarget], originalBindings[bind ingTarget]); 1365 gl[bindMethodName].call(gl, gl[bindingTarget], originalBindings[bind ingTarget]);
1369 }); 1366 });
1370 }, 1367 },
1371 1368
1372 /** 1369 /**
1373 * @param {!Object} data 1370 * @param {!Object} data
1374 * @param {!Cache.<Resource>} cache 1371 * @param {!Cache.<!Resource>} cache
1375 * @return {WebGLRenderingContextResource} 1372 * @return {?WebGLRenderingContextResource}
1376 */ 1373 */
1377 _replayContextResource: function(data, cache) 1374 _replayContextResource: function(data, cache)
1378 { 1375 {
1379 var calls = /** @type {!Array.<ReplayableCall>} */ (data.calls); 1376 var calls = /** @type {!Array.<!ReplayableCall>} */ (data.calls);
1380 for (var i = 0, n = calls.length; i < n; ++i) { 1377 for (var i = 0, n = calls.length; i < n; ++i) {
1381 var resource = ReplayableResource.replay(calls[i].replayableResource (), cache); 1378 var resource = ReplayableResource.replay(calls[i].replayableResource (), cache);
1382 var contextResource = WebGLRenderingContextResource.forObject(resour ce); 1379 var contextResource = WebGLRenderingContextResource.forObject(resour ce);
1383 if (contextResource) 1380 if (contextResource)
1384 return contextResource; 1381 return contextResource;
1385 } 1382 }
1386 return null; 1383 return null;
1387 }, 1384 },
1388 1385
1389 /** 1386 /**
(...skipping 18 matching lines...) Expand all
1408 * @param {string} name 1405 * @param {string} name
1409 */ 1406 */
1410 function WebGLTextureResource(wrappedObject, name) 1407 function WebGLTextureResource(wrappedObject, name)
1411 { 1408 {
1412 WebGLBoundResource.call(this, wrappedObject, name); 1409 WebGLBoundResource.call(this, wrappedObject, name);
1413 } 1410 }
1414 1411
1415 WebGLTextureResource.prototype = { 1412 WebGLTextureResource.prototype = {
1416 /** 1413 /**
1417 * @override (overrides @return type) 1414 * @override (overrides @return type)
1418 * @return {WebGLTexture} 1415 * @return {!WebGLTexture}
1419 */ 1416 */
1420 wrappedObject: function() 1417 wrappedObject: function()
1421 { 1418 {
1422 return this._wrappedObject; 1419 return this._wrappedObject;
1423 }, 1420 },
1424 1421
1425 /** 1422 /**
1426 * @override 1423 * @override
1427 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 1424 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
1428 */ 1425 */
1429 currentState: function() 1426 currentState: function()
1430 { 1427 {
1431 var result = []; 1428 var result = [];
1432 var glResource = WebGLRenderingContextResource.forObject(this); 1429 var glResource = WebGLRenderingContextResource.forObject(this);
1433 var gl = glResource.wrappedObject(); 1430 var gl = glResource.wrappedObject();
1434 var texture = this.wrappedObject(); 1431 var texture = this.wrappedObject();
1435 if (!gl || !texture) 1432 if (!gl || !texture)
1436 return result; 1433 return result;
1437 result.push({ name: "isTexture", value: gl.isTexture(texture) }); 1434 result.push({ name: "isTexture", value: gl.isTexture(texture) });
(...skipping 10 matching lines...) Expand all
1448 break; 1445 break;
1449 case gl.TEXTURE_CUBE_MAP: 1446 case gl.TEXTURE_CUBE_MAP:
1450 bindingParameter = gl.TEXTURE_BINDING_CUBE_MAP; 1447 bindingParameter = gl.TEXTURE_BINDING_CUBE_MAP;
1451 break; 1448 break;
1452 default: 1449 default:
1453 console.error("ASSERT_NOT_REACHED: unknown texture target " + target ); 1450 console.error("ASSERT_NOT_REACHED: unknown texture target " + target );
1454 return result; 1451 return result;
1455 } 1452 }
1456 result.push({ name: "target", value: target, valueIsEnum: true }); 1453 result.push({ name: "target", value: target, valueIsEnum: true });
1457 1454
1458 var oldTexture = /** @type {WebGLTexture} */ (gl.getParameter(bindingPar ameter)); 1455 var oldTexture = /** @type {!WebGLTexture} */ (gl.getParameter(bindingPa rameter));
1459 if (oldTexture !== texture) 1456 if (oldTexture !== texture)
1460 gl.bindTexture(target, texture); 1457 gl.bindTexture(target, texture);
1461 1458
1462 var textureParameters = [ 1459 var textureParameters = [
1463 "TEXTURE_MAG_FILTER", 1460 "TEXTURE_MAG_FILTER",
1464 "TEXTURE_MIN_FILTER", 1461 "TEXTURE_MIN_FILTER",
1465 "TEXTURE_WRAP_S", 1462 "TEXTURE_WRAP_S",
1466 "TEXTURE_WRAP_T", 1463 "TEXTURE_WRAP_T",
1467 "TEXTURE_MAX_ANISOTROPY_EXT" // EXT_texture_filter_anisotropic exten sion 1464 "TEXTURE_MAX_ANISOTROPY_EXT" // EXT_texture_filter_anisotropic exten sion
1468 ]; 1465 ];
1469 glResource.queryStateValues(gl.getTexParameter, target, textureParameter s, result); 1466 glResource.queryStateValues(gl.getTexParameter, target, textureParameter s, result);
1470 1467
1471 if (oldTexture !== texture) 1468 if (oldTexture !== texture)
1472 gl.bindTexture(target, oldTexture); 1469 gl.bindTexture(target, oldTexture);
1473 return result; 1470 return result;
1474 }, 1471 },
1475 1472
1476 /** 1473 /**
1477 * @override 1474 * @override
1478 * @param {!Object} data 1475 * @param {!Object} data
1479 * @param {!Cache.<Resource>} cache 1476 * @param {!Cache.<!Resource>} cache
1480 */ 1477 */
1481 _doReplayCalls: function(data, cache) 1478 _doReplayCalls: function(data, cache)
1482 { 1479 {
1483 var gl = this._replayContextResource(data, cache).wrappedObject(); 1480 var gl = this._replayContextResource(data, cache).wrappedObject();
1484 1481
1485 var state = {}; 1482 var state = {};
1486 WebGLRenderingContextResource.PixelStoreParameters.forEach(function(para meter) { 1483 WebGLRenderingContextResource.PixelStoreParameters.forEach(function(para meter) {
1487 state[parameter] = gl.getParameter(gl[parameter]); 1484 state[parameter] = gl.getParameter(gl[parameter]);
1488 }); 1485 });
1489 1486
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 1529
1533 /** 1530 /**
1534 * Handles: copyTexImage2D, copyTexSubImage2D 1531 * Handles: copyTexImage2D, copyTexSubImage2D
1535 * copyTexImage2D and copyTexSubImage2D define a texture image with pixels f rom the current framebuffer. 1532 * copyTexImage2D and copyTexSubImage2D define a texture image with pixels f rom the current framebuffer.
1536 * @param {!Call} call 1533 * @param {!Call} call
1537 */ 1534 */
1538 pushCall_copyTexImage2D: function(call) 1535 pushCall_copyTexImage2D: function(call)
1539 { 1536 {
1540 var glResource = WebGLRenderingContextResource.forObject(call.resource() ); 1537 var glResource = WebGLRenderingContextResource.forObject(call.resource() );
1541 var gl = glResource.wrappedObject(); 1538 var gl = glResource.wrappedObject();
1542 var framebufferResource = /** @type {WebGLFramebufferResource} */ (glRes ource.currentBinding(gl.FRAMEBUFFER)); 1539 var framebufferResource = /** @type {!WebGLFramebufferResource} */ (glRe source.currentBinding(gl.FRAMEBUFFER));
1543 if (framebufferResource) 1540 if (framebufferResource)
1544 this.pushCall(new Call(glResource, "bindFramebuffer", [gl.FRAMEBUFFE R, framebufferResource])); 1541 this.pushCall(new Call(glResource, "bindFramebuffer", [gl.FRAMEBUFFE R, framebufferResource]));
1545 else { 1542 else {
1546 // FIXME: Implement this case. 1543 // FIXME: Implement this case.
1547 console.error("ASSERT_NOT_REACHED: Could not properly process a gl." + call.functionName() + " call while the DRAWING BUFFER is bound."); 1544 console.error("ASSERT_NOT_REACHED: Could not properly process a gl." + call.functionName() + " call while the DRAWING BUFFER is bound.");
1548 } 1545 }
1549 this.pushCall(call); 1546 this.pushCall(call);
1550 }, 1547 },
1551 1548
1552 __proto__: WebGLBoundResource.prototype 1549 __proto__: WebGLBoundResource.prototype
1553 } 1550 }
1554 1551
1555 /** 1552 /**
1556 * @constructor 1553 * @constructor
1557 * @extends {Resource} 1554 * @extends {Resource}
1558 * @param {!Object} wrappedObject 1555 * @param {!Object} wrappedObject
1559 * @param {string} name 1556 * @param {string} name
1560 */ 1557 */
1561 function WebGLProgramResource(wrappedObject, name) 1558 function WebGLProgramResource(wrappedObject, name)
1562 { 1559 {
1563 Resource.call(this, wrappedObject, name); 1560 Resource.call(this, wrappedObject, name);
1564 } 1561 }
1565 1562
1566 WebGLProgramResource.prototype = { 1563 WebGLProgramResource.prototype = {
1567 /** 1564 /**
1568 * @override (overrides @return type) 1565 * @override (overrides @return type)
1569 * @return {WebGLProgram} 1566 * @return {!WebGLProgram}
1570 */ 1567 */
1571 wrappedObject: function() 1568 wrappedObject: function()
1572 { 1569 {
1573 return this._wrappedObject; 1570 return this._wrappedObject;
1574 }, 1571 },
1575 1572
1576 /** 1573 /**
1577 * @override 1574 * @override
1578 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 1575 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
1579 */ 1576 */
1580 currentState: function() 1577 currentState: function()
1581 { 1578 {
1582 /** 1579 /**
1583 * @param {!Object} obj 1580 * @param {!Object} obj
1584 * @param {!Array.<TypeUtils.InternalResourceStateDescriptor>} output 1581 * @param {!Array.<!TypeUtils.InternalResourceStateDescriptor>} output
1585 */ 1582 */
1586 function convertToStateDescriptors(obj, output) 1583 function convertToStateDescriptors(obj, output)
1587 { 1584 {
1588 for (var pname in obj) 1585 for (var pname in obj)
1589 output.push({ name: pname, value: obj[pname], valueIsEnum: (pnam e === "type") }); 1586 output.push({ name: pname, value: obj[pname], valueIsEnum: (pnam e === "type") });
1590 } 1587 }
1591 1588
1592 var result = []; 1589 var result = [];
1593 var program = this.wrappedObject(); 1590 var program = this.wrappedObject();
1594 if (!program) 1591 if (!program)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 if (includeAllInfo) 1665 if (includeAllInfo)
1669 item.size = activeInfo.size; 1666 item.size = activeInfo.size;
1670 uniforms.push(item); 1667 uniforms.push(item);
1671 } 1668 }
1672 return uniforms; 1669 return uniforms;
1673 }, 1670 },
1674 1671
1675 /** 1672 /**
1676 * @override 1673 * @override
1677 * @param {!Object} data 1674 * @param {!Object} data
1678 * @param {!Cache.<ReplayableResource>} cache 1675 * @param {!Cache.<!ReplayableResource>} cache
1679 */ 1676 */
1680 _populateReplayableData: function(data, cache) 1677 _populateReplayableData: function(data, cache)
1681 { 1678 {
1682 var glResource = WebGLRenderingContextResource.forObject(this); 1679 var glResource = WebGLRenderingContextResource.forObject(this);
1683 var originalErrors = glResource.getAllErrors(); 1680 var originalErrors = glResource.getAllErrors();
1684 data.uniforms = this._activeUniforms(); 1681 data.uniforms = this._activeUniforms();
1685 glResource.restoreErrors(originalErrors); 1682 glResource.restoreErrors(originalErrors);
1686 }, 1683 },
1687 1684
1688 /** 1685 /**
1689 * @override 1686 * @override
1690 * @param {!Object} data 1687 * @param {!Object} data
1691 * @param {!Cache.<Resource>} cache 1688 * @param {!Cache.<!Resource>} cache
1692 */ 1689 */
1693 _doReplayCalls: function(data, cache) 1690 _doReplayCalls: function(data, cache)
1694 { 1691 {
1695 Resource.prototype._doReplayCalls.call(this, data, cache); 1692 Resource.prototype._doReplayCalls.call(this, data, cache);
1696 var gl = WebGLRenderingContextResource.forObject(this).wrappedObject(); 1693 var gl = WebGLRenderingContextResource.forObject(this).wrappedObject();
1697 var program = this.wrappedObject(); 1694 var program = this.wrappedObject();
1698 1695
1699 var originalProgram = /** @type {WebGLProgram} */ (gl.getParameter(gl.CU RRENT_PROGRAM)); 1696 var originalProgram = /** @type {!WebGLProgram} */ (gl.getParameter(gl.C URRENT_PROGRAM));
1700 var currentProgram = originalProgram; 1697 var currentProgram = originalProgram;
1701 1698
1702 data.uniforms.forEach(function(uniform) { 1699 data.uniforms.forEach(function(uniform) {
1703 var uniformLocation = gl.getUniformLocation(program, uniform.name); 1700 var uniformLocation = gl.getUniformLocation(program, uniform.name);
1704 if (!uniformLocation) 1701 if (!uniformLocation)
1705 return; 1702 return;
1706 if (currentProgram !== program) { 1703 if (currentProgram !== program) {
1707 currentProgram = program; 1704 currentProgram = program;
1708 gl.useProgram(program); 1705 gl.useProgram(program);
1709 } 1706 }
1710 var methodName = this._uniformMethodNameByType(gl, uniform.type); 1707 var methodName = this._uniformMethodNameByType(gl, uniform.type);
1711 if (methodName.indexOf("Matrix") === -1) 1708 if (methodName.indexOf("Matrix") === -1)
1712 gl[methodName].call(gl, uniformLocation, uniform.value); 1709 gl[methodName].call(gl, uniformLocation, uniform.value);
1713 else 1710 else
1714 gl[methodName].call(gl, uniformLocation, false, uniform.value); 1711 gl[methodName].call(gl, uniformLocation, false, uniform.value);
1715 }.bind(this)); 1712 }.bind(this));
1716 1713
1717 if (currentProgram !== originalProgram) 1714 if (currentProgram !== originalProgram)
1718 gl.useProgram(originalProgram); 1715 gl.useProgram(originalProgram);
1719 }, 1716 },
1720 1717
1721 /** 1718 /**
1722 * @param {WebGLRenderingContext} gl 1719 * @param {!WebGLRenderingContext} gl
1723 * @param {number} type 1720 * @param {number} type
1724 * @return {string} 1721 * @return {string}
1725 */ 1722 */
1726 _uniformMethodNameByType: function(gl, type) 1723 _uniformMethodNameByType: function(gl, type)
1727 { 1724 {
1728 var uniformMethodNames = WebGLProgramResource._uniformMethodNames; 1725 var uniformMethodNames = WebGLProgramResource._uniformMethodNames;
1729 if (!uniformMethodNames) { 1726 if (!uniformMethodNames) {
1730 uniformMethodNames = {}; 1727 uniformMethodNames = {};
1731 uniformMethodNames[gl.FLOAT] = "uniform1f"; 1728 uniformMethodNames[gl.FLOAT] = "uniform1f";
1732 uniformMethodNames[gl.FLOAT_VEC2] = "uniform2fv"; 1729 uniformMethodNames[gl.FLOAT_VEC2] = "uniform2fv";
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 * @param {string} name 1769 * @param {string} name
1773 */ 1770 */
1774 function WebGLShaderResource(wrappedObject, name) 1771 function WebGLShaderResource(wrappedObject, name)
1775 { 1772 {
1776 Resource.call(this, wrappedObject, name); 1773 Resource.call(this, wrappedObject, name);
1777 } 1774 }
1778 1775
1779 WebGLShaderResource.prototype = { 1776 WebGLShaderResource.prototype = {
1780 /** 1777 /**
1781 * @override (overrides @return type) 1778 * @override (overrides @return type)
1782 * @return {WebGLShader} 1779 * @return {!WebGLShader}
1783 */ 1780 */
1784 wrappedObject: function() 1781 wrappedObject: function()
1785 { 1782 {
1786 return this._wrappedObject; 1783 return this._wrappedObject;
1787 }, 1784 },
1788 1785
1789 /** 1786 /**
1790 * @return {number} 1787 * @return {number}
1791 */ 1788 */
1792 type: function() 1789 type: function()
1793 { 1790 {
1794 var call = this._calls[0]; 1791 var call = this._calls[0];
1795 if (call && call.functionName() === "createShader") 1792 if (call && call.functionName() === "createShader")
1796 return call.args()[0]; 1793 return call.args()[0];
1797 console.error("ASSERT_NOT_REACHED: Failed to restore shader type from th e log.", call); 1794 console.error("ASSERT_NOT_REACHED: Failed to restore shader type from th e log.", call);
1798 return 0; 1795 return 0;
1799 }, 1796 },
1800 1797
1801 /** 1798 /**
1802 * @override 1799 * @override
1803 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 1800 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
1804 */ 1801 */
1805 currentState: function() 1802 currentState: function()
1806 { 1803 {
1807 var result = []; 1804 var result = [];
1808 var shader = this.wrappedObject(); 1805 var shader = this.wrappedObject();
1809 if (!shader) 1806 if (!shader)
1810 return result; 1807 return result;
1811 var glResource = WebGLRenderingContextResource.forObject(this); 1808 var glResource = WebGLRenderingContextResource.forObject(this);
1812 var gl = glResource.wrappedObject(); 1809 var gl = glResource.wrappedObject();
1813 var shaderParameters = ["SHADER_TYPE", "DELETE_STATUS", "COMPILE_STATUS" ]; 1810 var shaderParameters = ["SHADER_TYPE", "DELETE_STATUS", "COMPILE_STATUS" ];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 * @param {string} name 1846 * @param {string} name
1850 */ 1847 */
1851 function WebGLBufferResource(wrappedObject, name) 1848 function WebGLBufferResource(wrappedObject, name)
1852 { 1849 {
1853 WebGLBoundResource.call(this, wrappedObject, name); 1850 WebGLBoundResource.call(this, wrappedObject, name);
1854 } 1851 }
1855 1852
1856 WebGLBufferResource.prototype = { 1853 WebGLBufferResource.prototype = {
1857 /** 1854 /**
1858 * @override (overrides @return type) 1855 * @override (overrides @return type)
1859 * @return {WebGLBuffer} 1856 * @return {!WebGLBuffer}
1860 */ 1857 */
1861 wrappedObject: function() 1858 wrappedObject: function()
1862 { 1859 {
1863 return this._wrappedObject; 1860 return this._wrappedObject;
1864 }, 1861 },
1865 1862
1866 /** 1863 /**
1867 * @return {?ArrayBufferView} 1864 * @return {?ArrayBufferView}
1868 */ 1865 */
1869 cachedBufferData: function() 1866 cachedBufferData: function()
1870 { 1867 {
1871 /** 1868 /**
1872 * Creates a view to a given buffer, does NOT copy the buffer. 1869 * Creates a view to a given buffer, does NOT copy the buffer.
1873 * @param {!ArrayBuffer|!ArrayBufferView} buffer 1870 * @param {!ArrayBuffer|!ArrayBufferView} buffer
1874 * @return {!Uint8Array} 1871 * @return {!Uint8Array}
1875 */ 1872 */
1876 function createUint8ArrayBufferView(buffer) 1873 function createUint8ArrayBufferView(buffer)
1877 { 1874 {
1878 return buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength); 1875 return buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
1879 } 1876 }
1880 1877
1881 if (!this._cachedBufferData) { 1878 if (!this._cachedBufferData) {
1882 for (var i = this._calls.length - 1; i >= 0; --i) { 1879 for (var i = this._calls.length - 1; i >= 0; --i) {
1883 var call = this._calls[i]; 1880 var call = this._calls[i];
1884 if (call.functionName() === "bufferData") { 1881 if (call.functionName() === "bufferData") {
1885 var sizeOrData = /** @type {number|ArrayBuffer|ArrayBufferVi ew} */ (call.args()[1]); 1882 var sizeOrData = /** @type {number|!ArrayBuffer|!ArrayBuffer View} */ (call.args()[1]);
1886 if (typeof sizeOrData === "number") 1883 if (typeof sizeOrData === "number")
1887 this._cachedBufferData = new ArrayBuffer(sizeOrData); 1884 this._cachedBufferData = new ArrayBuffer(sizeOrData);
1888 else 1885 else
1889 this._cachedBufferData = sizeOrData; 1886 this._cachedBufferData = sizeOrData;
1890 this._lastBufferSubDataIndex = i + 1; 1887 this._lastBufferSubDataIndex = i + 1;
1891 break; 1888 break;
1892 } 1889 }
1893 } 1890 }
1894 if (!this._cachedBufferData) 1891 if (!this._cachedBufferData)
1895 return null; 1892 return null;
(...skipping 29 matching lines...) Expand all
1925 1922
1926 if (this._cachedBufferData instanceof ArrayBuffer) { 1923 if (this._cachedBufferData instanceof ArrayBuffer) {
1927 // If we failed to guess the data type yet, use Uint8Array. 1924 // If we failed to guess the data type yet, use Uint8Array.
1928 return new Uint8Array(this._cachedBufferData); 1925 return new Uint8Array(this._cachedBufferData);
1929 } 1926 }
1930 return this._cachedBufferData; 1927 return this._cachedBufferData;
1931 }, 1928 },
1932 1929
1933 /** 1930 /**
1934 * @override 1931 * @override
1935 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 1932 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
1936 */ 1933 */
1937 currentState: function() 1934 currentState: function()
1938 { 1935 {
1939 var result = []; 1936 var result = [];
1940 var glResource = WebGLRenderingContextResource.forObject(this); 1937 var glResource = WebGLRenderingContextResource.forObject(this);
1941 var gl = glResource.wrappedObject(); 1938 var gl = glResource.wrappedObject();
1942 var buffer = this.wrappedObject(); 1939 var buffer = this.wrappedObject();
1943 if (!gl || !buffer) 1940 if (!gl || !buffer)
1944 return result; 1941 return result;
1945 result.push({ name: "isBuffer", value: gl.isBuffer(buffer) }); 1942 result.push({ name: "isBuffer", value: gl.isBuffer(buffer) });
(...skipping 10 matching lines...) Expand all
1956 break; 1953 break;
1957 case gl.ELEMENT_ARRAY_BUFFER: 1954 case gl.ELEMENT_ARRAY_BUFFER:
1958 bindingParameter = gl.ELEMENT_ARRAY_BUFFER_BINDING; 1955 bindingParameter = gl.ELEMENT_ARRAY_BUFFER_BINDING;
1959 break; 1956 break;
1960 default: 1957 default:
1961 console.error("ASSERT_NOT_REACHED: unknown buffer target " + target) ; 1958 console.error("ASSERT_NOT_REACHED: unknown buffer target " + target) ;
1962 return result; 1959 return result;
1963 } 1960 }
1964 result.push({ name: "target", value: target, valueIsEnum: true }); 1961 result.push({ name: "target", value: target, valueIsEnum: true });
1965 1962
1966 var oldBuffer = /** @type {WebGLBuffer} */ (gl.getParameter(bindingParam eter)); 1963 var oldBuffer = /** @type {!WebGLBuffer} */ (gl.getParameter(bindingPara meter));
1967 if (oldBuffer !== buffer) 1964 if (oldBuffer !== buffer)
1968 gl.bindBuffer(target, buffer); 1965 gl.bindBuffer(target, buffer);
1969 1966
1970 var bufferParameters = ["BUFFER_SIZE", "BUFFER_USAGE"]; 1967 var bufferParameters = ["BUFFER_SIZE", "BUFFER_USAGE"];
1971 glResource.queryStateValues(gl.getBufferParameter, target, bufferParamet ers, result); 1968 glResource.queryStateValues(gl.getBufferParameter, target, bufferParamet ers, result);
1972 1969
1973 if (oldBuffer !== buffer) 1970 if (oldBuffer !== buffer)
1974 gl.bindBuffer(target, oldBuffer); 1971 gl.bindBuffer(target, oldBuffer);
1975 1972
1976 try { 1973 try {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 * @param {string} name 2011 * @param {string} name
2015 */ 2012 */
2016 function WebGLFramebufferResource(wrappedObject, name) 2013 function WebGLFramebufferResource(wrappedObject, name)
2017 { 2014 {
2018 WebGLBoundResource.call(this, wrappedObject, name); 2015 WebGLBoundResource.call(this, wrappedObject, name);
2019 } 2016 }
2020 2017
2021 WebGLFramebufferResource.prototype = { 2018 WebGLFramebufferResource.prototype = {
2022 /** 2019 /**
2023 * @override (overrides @return type) 2020 * @override (overrides @return type)
2024 * @return {WebGLFramebuffer} 2021 * @return {!WebGLFramebuffer}
2025 */ 2022 */
2026 wrappedObject: function() 2023 wrappedObject: function()
2027 { 2024 {
2028 return this._wrappedObject; 2025 return this._wrappedObject;
2029 }, 2026 },
2030 2027
2031 /** 2028 /**
2032 * @override 2029 * @override
2033 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 2030 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
2034 */ 2031 */
2035 currentState: function() 2032 currentState: function()
2036 { 2033 {
2037 var result = []; 2034 var result = [];
2038 var framebuffer = this.wrappedObject(); 2035 var framebuffer = this.wrappedObject();
2039 if (!framebuffer) 2036 if (!framebuffer)
2040 return result; 2037 return result;
2041 var gl = WebGLRenderingContextResource.forObject(this).wrappedObject(); 2038 var gl = WebGLRenderingContextResource.forObject(this).wrappedObject();
2042 2039
2043 var oldFramebuffer = /** @type {WebGLFramebuffer} */ (gl.getParameter(gl .FRAMEBUFFER_BINDING)); 2040 var oldFramebuffer = /** @type {!WebGLFramebuffer} */ (gl.getParameter(g l.FRAMEBUFFER_BINDING));
2044 if (oldFramebuffer !== framebuffer) 2041 if (oldFramebuffer !== framebuffer)
2045 gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); 2042 gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
2046 2043
2047 var attachmentParameters = ["COLOR_ATTACHMENT0", "DEPTH_ATTACHMENT", "ST ENCIL_ATTACHMENT"]; 2044 var attachmentParameters = ["COLOR_ATTACHMENT0", "DEPTH_ATTACHMENT", "ST ENCIL_ATTACHMENT"];
2048 var framebufferParameters = ["FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE", "FRAM EBUFFER_ATTACHMENT_OBJECT_NAME", "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL", "FRAMEB UFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE"]; 2045 var framebufferParameters = ["FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE", "FRAM EBUFFER_ATTACHMENT_OBJECT_NAME", "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL", "FRAMEB UFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE"];
2049 for (var i = 0, attachment; attachment = attachmentParameters[i]; ++i) { 2046 for (var i = 0, attachment; attachment = attachmentParameters[i]; ++i) {
2050 var values = []; 2047 var values = [];
2051 for (var j = 0, pname; pname = framebufferParameters[j]; ++j) { 2048 for (var j = 0, pname; pname = framebufferParameters[j]; ++j) {
2052 var value = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl[attachment], gl[pname]); 2049 var value = gl.getFramebufferAttachmentParameter(gl.FRAMEBUFFER, gl[attachment], gl[pname]);
2053 value = Resource.forObject(value) || value; 2050 value = Resource.forObject(value) || value;
(...skipping 29 matching lines...) Expand all
2083 * @param {string} name 2080 * @param {string} name
2084 */ 2081 */
2085 function WebGLRenderbufferResource(wrappedObject, name) 2082 function WebGLRenderbufferResource(wrappedObject, name)
2086 { 2083 {
2087 WebGLBoundResource.call(this, wrappedObject, name); 2084 WebGLBoundResource.call(this, wrappedObject, name);
2088 } 2085 }
2089 2086
2090 WebGLRenderbufferResource.prototype = { 2087 WebGLRenderbufferResource.prototype = {
2091 /** 2088 /**
2092 * @override (overrides @return type) 2089 * @override (overrides @return type)
2093 * @return {WebGLRenderbuffer} 2090 * @return {!WebGLRenderbuffer}
2094 */ 2091 */
2095 wrappedObject: function() 2092 wrappedObject: function()
2096 { 2093 {
2097 return this._wrappedObject; 2094 return this._wrappedObject;
2098 }, 2095 },
2099 2096
2100 /** 2097 /**
2101 * @override 2098 * @override
2102 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 2099 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
2103 */ 2100 */
2104 currentState: function() 2101 currentState: function()
2105 { 2102 {
2106 var result = []; 2103 var result = [];
2107 var renderbuffer = this.wrappedObject(); 2104 var renderbuffer = this.wrappedObject();
2108 if (!renderbuffer) 2105 if (!renderbuffer)
2109 return result; 2106 return result;
2110 var glResource = WebGLRenderingContextResource.forObject(this); 2107 var glResource = WebGLRenderingContextResource.forObject(this);
2111 var gl = glResource.wrappedObject(); 2108 var gl = glResource.wrappedObject();
2112 2109
2113 var oldRenderbuffer = /** @type {WebGLRenderbuffer} */ (gl.getParameter( gl.RENDERBUFFER_BINDING)); 2110 var oldRenderbuffer = /** @type {!WebGLRenderbuffer} */ (gl.getParameter (gl.RENDERBUFFER_BINDING));
2114 if (oldRenderbuffer !== renderbuffer) 2111 if (oldRenderbuffer !== renderbuffer)
2115 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer); 2112 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbuffer);
2116 2113
2117 var renderbufferParameters = ["RENDERBUFFER_WIDTH", "RENDERBUFFER_HEIGHT ", "RENDERBUFFER_INTERNAL_FORMAT", "RENDERBUFFER_RED_SIZE", "RENDERBUFFER_GREEN_ SIZE", "RENDERBUFFER_BLUE_SIZE", "RENDERBUFFER_ALPHA_SIZE", "RENDERBUFFER_DEPTH_ SIZE", "RENDERBUFFER_STENCIL_SIZE"]; 2114 var renderbufferParameters = ["RENDERBUFFER_WIDTH", "RENDERBUFFER_HEIGHT ", "RENDERBUFFER_INTERNAL_FORMAT", "RENDERBUFFER_RED_SIZE", "RENDERBUFFER_GREEN_ SIZE", "RENDERBUFFER_BLUE_SIZE", "RENDERBUFFER_ALPHA_SIZE", "RENDERBUFFER_DEPTH_ SIZE", "RENDERBUFFER_STENCIL_SIZE"];
2118 glResource.queryStateValues(gl.getRenderbufferParameter, gl.RENDERBUFFER , renderbufferParameters, result); 2115 glResource.queryStateValues(gl.getRenderbufferParameter, gl.RENDERBUFFER , renderbufferParameters, result);
2119 result.push({ name: "isRenderbuffer", value: gl.isRenderbuffer(renderbuf fer) }); 2116 result.push({ name: "isRenderbuffer", value: gl.isRenderbuffer(renderbuf fer) });
2120 result.push({ name: "context", value: this.contextResource() }); 2117 result.push({ name: "context", value: this.contextResource() });
2121 2118
2122 if (oldRenderbuffer !== renderbuffer) 2119 if (oldRenderbuffer !== renderbuffer)
2123 gl.bindRenderbuffer(gl.RENDERBUFFER, oldRenderbuffer); 2120 gl.bindRenderbuffer(gl.RENDERBUFFER, oldRenderbuffer);
(...skipping 20 matching lines...) Expand all
2144 * @param {string} name 2141 * @param {string} name
2145 */ 2142 */
2146 function WebGLUniformLocationResource(wrappedObject, name) 2143 function WebGLUniformLocationResource(wrappedObject, name)
2147 { 2144 {
2148 Resource.call(this, wrappedObject, name); 2145 Resource.call(this, wrappedObject, name);
2149 } 2146 }
2150 2147
2151 WebGLUniformLocationResource.prototype = { 2148 WebGLUniformLocationResource.prototype = {
2152 /** 2149 /**
2153 * @override (overrides @return type) 2150 * @override (overrides @return type)
2154 * @return {WebGLUniformLocation} 2151 * @return {!WebGLUniformLocation}
2155 */ 2152 */
2156 wrappedObject: function() 2153 wrappedObject: function()
2157 { 2154 {
2158 return this._wrappedObject; 2155 return this._wrappedObject;
2159 }, 2156 },
2160 2157
2161 /** 2158 /**
2162 * @return {WebGLProgramResource} 2159 * @return {?WebGLProgramResource}
2163 */ 2160 */
2164 program: function() 2161 program: function()
2165 { 2162 {
2166 var call = this._calls[0]; 2163 var call = this._calls[0];
2167 if (call && call.functionName() === "getUniformLocation") 2164 if (call && call.functionName() === "getUniformLocation")
2168 return /** @type {WebGLProgramResource} */ (Resource.forObject(call. args()[0])); 2165 return /** @type {!WebGLProgramResource} */ (Resource.forObject(call .args()[0]));
2169 console.error("ASSERT_NOT_REACHED: Failed to restore WebGLUniformLocatio n from the log.", call); 2166 console.error("ASSERT_NOT_REACHED: Failed to restore WebGLUniformLocatio n from the log.", call);
2170 return null; 2167 return null;
2171 }, 2168 },
2172 2169
2173 /** 2170 /**
2174 * @return {string} 2171 * @return {string}
2175 */ 2172 */
2176 name: function() 2173 name: function()
2177 { 2174 {
2178 var call = this._calls[0]; 2175 var call = this._calls[0];
2179 if (call && call.functionName() === "getUniformLocation") 2176 if (call && call.functionName() === "getUniformLocation")
2180 return call.args()[1]; 2177 return call.args()[1];
2181 console.error("ASSERT_NOT_REACHED: Failed to restore WebGLUniformLocatio n from the log.", call); 2178 console.error("ASSERT_NOT_REACHED: Failed to restore WebGLUniformLocatio n from the log.", call);
2182 return ""; 2179 return "";
2183 }, 2180 },
2184 2181
2185 /** 2182 /**
2186 * @override 2183 * @override
2187 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 2184 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
2188 */ 2185 */
2189 currentState: function() 2186 currentState: function()
2190 { 2187 {
2191 var result = []; 2188 var result = [];
2192 var location = this.wrappedObject(); 2189 var location = this.wrappedObject();
2193 if (!location) 2190 if (!location)
2194 return result; 2191 return result;
2195 var programResource = this.program(); 2192 var programResource = this.program();
2196 var program = programResource && programResource.wrappedObject(); 2193 var program = programResource && programResource.wrappedObject();
2197 if (!program) 2194 if (!program)
(...skipping 25 matching lines...) Expand all
2223 result.push({ name: "type", value: this._type, valueIsEnum: true }); 2220 result.push({ name: "type", value: this._type, valueIsEnum: true });
2224 if (typeof this._size === "number") 2221 if (typeof this._size === "number")
2225 result.push({ name: "size", value: this._size }); 2222 result.push({ name: "size", value: this._size });
2226 2223
2227 return result; 2224 return result;
2228 }, 2225 },
2229 2226
2230 /** 2227 /**
2231 * @override 2228 * @override
2232 * @param {!Object} data 2229 * @param {!Object} data
2233 * @param {!Cache.<ReplayableResource>} cache 2230 * @param {!Cache.<!ReplayableResource>} cache
2234 */ 2231 */
2235 _populateReplayableData: function(data, cache) 2232 _populateReplayableData: function(data, cache)
2236 { 2233 {
2237 data.type = this._type; 2234 data.type = this._type;
2238 data.size = this._size; 2235 data.size = this._size;
2239 }, 2236 },
2240 2237
2241 /** 2238 /**
2242 * @override 2239 * @override
2243 * @param {!Object} data 2240 * @param {!Object} data
2244 * @param {!Cache.<Resource>} cache 2241 * @param {!Cache.<!Resource>} cache
2245 */ 2242 */
2246 _doReplayCalls: function(data, cache) 2243 _doReplayCalls: function(data, cache)
2247 { 2244 {
2248 this._type = data.type; 2245 this._type = data.type;
2249 this._size = data.size; 2246 this._size = data.size;
2250 Resource.prototype._doReplayCalls.call(this, data, cache); 2247 Resource.prototype._doReplayCalls.call(this, data, cache);
2251 }, 2248 },
2252 2249
2253 __proto__: Resource.prototype 2250 __proto__: Resource.prototype
2254 } 2251 }
2255 2252
2256 /** 2253 /**
2257 * @constructor 2254 * @constructor
2258 * @extends {ContextResource} 2255 * @extends {ContextResource}
2259 * @param {!WebGLRenderingContext} glContext 2256 * @param {!WebGLRenderingContext} glContext
2260 */ 2257 */
2261 function WebGLRenderingContextResource(glContext) 2258 function WebGLRenderingContextResource(glContext)
2262 { 2259 {
2263 ContextResource.call(this, glContext, "WebGLRenderingContext"); 2260 ContextResource.call(this, glContext, "WebGLRenderingContext");
2264 /** @type {Object.<number, boolean>} */ 2261 /** @type {?Object.<number, boolean>} */
2265 this._customErrors = null; 2262 this._customErrors = null;
2266 /** @type {!Object.<string, string>} */ 2263 /** @type {!Object.<string, string>} */
2267 this._extensions = {}; 2264 this._extensions = {};
2268 /** @type {!Object.<string, number>} */ 2265 /** @type {!Object.<string, number>} */
2269 this._extensionEnums = {}; 2266 this._extensionEnums = {};
2270 } 2267 }
2271 2268
2272 /** 2269 /**
2273 * @const 2270 * @const
2274 * @type {!Array.<string>} 2271 * @type {!Array.<string>}
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 * @type {!Object.<string, boolean>} 2402 * @type {!Object.<string, boolean>}
2406 */ 2403 */
2407 WebGLRenderingContextResource.DrawingMethods = TypeUtils.createPrefixedPropertyN amesSet([ 2404 WebGLRenderingContextResource.DrawingMethods = TypeUtils.createPrefixedPropertyN amesSet([
2408 "clear", 2405 "clear",
2409 "drawArrays", 2406 "drawArrays",
2410 "drawElements" 2407 "drawElements"
2411 ]); 2408 ]);
2412 2409
2413 /** 2410 /**
2414 * @param {*} obj 2411 * @param {*} obj
2415 * @return {WebGLRenderingContextResource} 2412 * @return {?WebGLRenderingContextResource}
2416 */ 2413 */
2417 WebGLRenderingContextResource.forObject = function(obj) 2414 WebGLRenderingContextResource.forObject = function(obj)
2418 { 2415 {
2419 var resource = Resource.forObject(obj); 2416 var resource = Resource.forObject(obj);
2420 if (!resource) 2417 if (!resource)
2421 return null; 2418 return null;
2422 resource = resource.contextResource(); 2419 resource = resource.contextResource();
2423 return (resource instanceof WebGLRenderingContextResource) ? resource : null ; 2420 return (resource instanceof WebGLRenderingContextResource) ? resource : null ;
2424 } 2421 }
2425 2422
2426 WebGLRenderingContextResource.prototype = { 2423 WebGLRenderingContextResource.prototype = {
2427 /** 2424 /**
2428 * @override (overrides @return type) 2425 * @override (overrides @return type)
2429 * @return {WebGLRenderingContext} 2426 * @return {!WebGLRenderingContext}
2430 */ 2427 */
2431 wrappedObject: function() 2428 wrappedObject: function()
2432 { 2429 {
2433 return this._wrappedObject; 2430 return this._wrappedObject;
2434 }, 2431 },
2435 2432
2436 /** 2433 /**
2437 * @override 2434 * @override
2438 * @return {string} 2435 * @return {string}
2439 */ 2436 */
2440 toDataURL: function() 2437 toDataURL: function()
2441 { 2438 {
2442 return this.wrappedObject().canvas.toDataURL(); 2439 return this.wrappedObject().canvas.toDataURL();
2443 }, 2440 },
2444 2441
2445 /** 2442 /**
2446 * @return {Array.<number>} 2443 * @return {!Array.<number>}
2447 */ 2444 */
2448 getAllErrors: function() 2445 getAllErrors: function()
2449 { 2446 {
2450 var errors = []; 2447 var errors = [];
2451 var gl = this.wrappedObject(); 2448 var gl = this.wrappedObject();
2452 if (gl) { 2449 if (gl) {
2453 while (true) { 2450 while (true) {
2454 var error = gl.getError(); 2451 var error = gl.getError();
2455 if (error === gl.NO_ERROR) 2452 if (error === gl.NO_ERROR)
2456 break; 2453 break;
2457 this.clearError(error); 2454 this.clearError(error);
2458 errors.push(error); 2455 errors.push(error);
2459 } 2456 }
2460 } 2457 }
2461 if (this._customErrors) { 2458 if (this._customErrors) {
2462 for (var key in this._customErrors) { 2459 for (var key in this._customErrors) {
2463 var error = Number(key); 2460 var error = Number(key);
2464 errors.push(error); 2461 errors.push(error);
2465 } 2462 }
2466 delete this._customErrors; 2463 delete this._customErrors;
2467 } 2464 }
2468 return errors; 2465 return errors;
2469 }, 2466 },
2470 2467
2471 /** 2468 /**
2472 * @param {Array.<number>} errors 2469 * @param {!Array.<number>} errors
2473 */ 2470 */
2474 restoreErrors: function(errors) 2471 restoreErrors: function(errors)
2475 { 2472 {
2476 var gl = this.wrappedObject(); 2473 var gl = this.wrappedObject();
2477 if (gl) { 2474 if (gl) {
2478 var wasError = false; 2475 var wasError = false;
2479 while (gl.getError() !== gl.NO_ERROR) 2476 while (gl.getError() !== gl.NO_ERROR)
2480 wasError = true; 2477 wasError = true;
2481 console.assert(!wasError, "Error(s) while capturing current WebGL st ate."); 2478 console.assert(!wasError, "Error(s) while capturing current WebGL st ate.");
2482 } 2479 }
(...skipping 27 matching lines...) Expand all
2510 return error; 2507 return error;
2511 } 2508 }
2512 } 2509 }
2513 delete this._customErrors; 2510 delete this._customErrors;
2514 var gl = this.wrappedObject(); 2511 var gl = this.wrappedObject();
2515 return gl ? gl.NO_ERROR : 0; 2512 return gl ? gl.NO_ERROR : 0;
2516 }, 2513 },
2517 2514
2518 /** 2515 /**
2519 * @param {string} name 2516 * @param {string} name
2520 * @param {Object} obj 2517 * @param {?Object} obj
2521 */ 2518 */
2522 registerWebGLExtension: function(name, obj) 2519 registerWebGLExtension: function(name, obj)
2523 { 2520 {
2524 // FIXME: Wrap OES_vertex_array_object extension. 2521 // FIXME: Wrap OES_vertex_array_object extension.
2525 var lowerName = name.toLowerCase(); 2522 var lowerName = name.toLowerCase();
2526 if (obj && !this._extensions[lowerName]) { 2523 if (obj && !this._extensions[lowerName]) {
2527 this._extensions[lowerName] = name; 2524 this._extensions[lowerName] = name;
2528 for (var property in obj) { 2525 for (var property in obj) {
2529 if (TypeUtils.isEnumPropertyName(property, obj)) 2526 if (TypeUtils.isEnumPropertyName(property, obj))
2530 this._extensionEnums[property] = /** @type {number} */ (obj[ property]); 2527 this._extensionEnums[property] = /** @type {number} */ (obj[ property]);
(...skipping 10 matching lines...) Expand all
2541 if (typeof this._extensionEnums[name] === "number") 2538 if (typeof this._extensionEnums[name] === "number")
2542 return this._extensionEnums[name]; 2539 return this._extensionEnums[name];
2543 var gl = this.wrappedObject(); 2540 var gl = this.wrappedObject();
2544 return (typeof gl[name] === "number" ? gl[name] : undefined); 2541 return (typeof gl[name] === "number" ? gl[name] : undefined);
2545 }, 2542 },
2546 2543
2547 /** 2544 /**
2548 * @param {function(this:WebGLRenderingContext, T, number):*} func 2545 * @param {function(this:WebGLRenderingContext, T, number):*} func
2549 * @param {T} targetOrWebGLObject 2546 * @param {T} targetOrWebGLObject
2550 * @param {!Array.<string>} pnames 2547 * @param {!Array.<string>} pnames
2551 * @param {!Array.<TypeUtils.InternalResourceStateDescriptor>} output 2548 * @param {!Array.<!TypeUtils.InternalResourceStateDescriptor>} output
2552 * @template T 2549 * @template T
2553 */ 2550 */
2554 queryStateValues: function(func, targetOrWebGLObject, pnames, output) 2551 queryStateValues: function(func, targetOrWebGLObject, pnames, output)
2555 { 2552 {
2556 var gl = this.wrappedObject(); 2553 var gl = this.wrappedObject();
2557 for (var i = 0, pname; pname = pnames[i]; ++i) { 2554 for (var i = 0, pname; pname = pnames[i]; ++i) {
2558 var enumValue = this._enumValueForName(pname); 2555 var enumValue = this._enumValueForName(pname);
2559 if (typeof enumValue !== "number") 2556 if (typeof enumValue !== "number")
2560 continue; 2557 continue;
2561 var value = func.call(gl, targetOrWebGLObject, enumValue); 2558 var value = func.call(gl, targetOrWebGLObject, enumValue);
2562 value = Resource.forObject(value) || value; 2559 value = Resource.forObject(value) || value;
2563 output.push({ name: pname, value: value, valueIsEnum: WebGLRendering ContextResource.GetResultIsEnum[pname] }); 2560 output.push({ name: pname, value: value, valueIsEnum: WebGLRendering ContextResource.GetResultIsEnum[pname] });
2564 } 2561 }
2565 }, 2562 },
2566 2563
2567 /** 2564 /**
2568 * @override 2565 * @override
2569 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 2566 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
2570 */ 2567 */
2571 currentState: function() 2568 currentState: function()
2572 { 2569 {
2573 /** 2570 /**
2574 * @param {!Object} obj 2571 * @param {!Object} obj
2575 * @param {!Array.<TypeUtils.InternalResourceStateDescriptor>} output 2572 * @param {!Array.<!TypeUtils.InternalResourceStateDescriptor>} output
2576 */ 2573 */
2577 function convertToStateDescriptors(obj, output) 2574 function convertToStateDescriptors(obj, output)
2578 { 2575 {
2579 for (var pname in obj) 2576 for (var pname in obj)
2580 output.push({ name: pname, value: obj[pname], valueIsEnum: WebGL RenderingContextResource.GetResultIsEnum[pname] }); 2577 output.push({ name: pname, value: obj[pname], valueIsEnum: WebGL RenderingContextResource.GetResultIsEnum[pname] });
2581 } 2578 }
2582 2579
2583 var gl = this.wrappedObject(); 2580 var gl = this.wrappedObject();
2584 var glState = this._internalCurrentState(null); 2581 var glState = this._internalCurrentState(null);
2585 2582
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2622 var value = gl.getExtension(pname); 2619 var value = gl.getExtension(pname);
2623 value = Resource.forObject(value) || value; 2620 value = Resource.forObject(value) || value;
2624 enabledExtensions.push({ name: pname, value: value }); 2621 enabledExtensions.push({ name: pname, value: value });
2625 } 2622 }
2626 result.push({ name: "ENABLED_EXTENSIONS", values: enabledExtensions, isA rray: true }); 2623 result.push({ name: "ENABLED_EXTENSIONS", values: enabledExtensions, isA rray: true });
2627 2624
2628 return result; 2625 return result;
2629 }, 2626 },
2630 2627
2631 /** 2628 /**
2632 * @param {?Cache.<ReplayableResource>} cache 2629 * @param {?Cache.<!ReplayableResource>} cache
2633 * @return {!Object.<string, *>} 2630 * @return {!Object.<string, *>}
2634 */ 2631 */
2635 _internalCurrentState: function(cache) 2632 _internalCurrentState: function(cache)
2636 { 2633 {
2637 /** 2634 /**
2638 * @param {Resource|*} obj 2635 * @param {!Resource|*} obj
2639 * @return {Resource|ReplayableResource|*} 2636 * @return {!Resource|!ReplayableResource|*}
2640 */ 2637 */
2641 function maybeToReplayable(obj) 2638 function maybeToReplayable(obj)
2642 { 2639 {
2643 return cache ? Resource.toReplayable(obj, cache) : (Resource.forObje ct(obj) || obj); 2640 return cache ? Resource.toReplayable(obj, cache) : (Resource.forObje ct(obj) || obj);
2644 } 2641 }
2645 2642
2646 var gl = this.wrappedObject(); 2643 var gl = this.wrappedObject();
2647 var originalErrors = this.getAllErrors(); 2644 var originalErrors = this.getAllErrors();
2648 2645
2649 // Take a full GL state snapshot. 2646 // Take a full GL state snapshot.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2696 glState.TEXTURE_UNITS = textureUnits; 2693 glState.TEXTURE_UNITS = textureUnits;
2697 gl.activeTexture(savedActiveTexture); 2694 gl.activeTexture(savedActiveTexture);
2698 2695
2699 this.restoreErrors(originalErrors); 2696 this.restoreErrors(originalErrors);
2700 return glState; 2697 return glState;
2701 }, 2698 },
2702 2699
2703 /** 2700 /**
2704 * @override 2701 * @override
2705 * @param {!Object} data 2702 * @param {!Object} data
2706 * @param {!Cache.<ReplayableResource>} cache 2703 * @param {!Cache.<!ReplayableResource>} cache
2707 */ 2704 */
2708 _populateReplayableData: function(data, cache) 2705 _populateReplayableData: function(data, cache)
2709 { 2706 {
2710 var gl = this.wrappedObject(); 2707 var gl = this.wrappedObject();
2711 data.originalCanvas = gl.canvas; 2708 data.originalCanvas = gl.canvas;
2712 data.originalContextAttributes = gl.getContextAttributes(); 2709 data.originalContextAttributes = gl.getContextAttributes();
2713 data.extensions = TypeUtils.cloneObject(this._extensions); 2710 data.extensions = TypeUtils.cloneObject(this._extensions);
2714 data.extensionEnums = TypeUtils.cloneObject(this._extensionEnums); 2711 data.extensionEnums = TypeUtils.cloneObject(this._extensionEnums);
2715 data.glState = this._internalCurrentState(cache); 2712 data.glState = this._internalCurrentState(cache);
2716 }, 2713 },
2717 2714
2718 /** 2715 /**
2719 * @override 2716 * @override
2720 * @param {!Object} data 2717 * @param {!Object} data
2721 * @param {!Cache.<Resource>} cache 2718 * @param {!Cache.<!Resource>} cache
2722 */ 2719 */
2723 _doReplayCalls: function(data, cache) 2720 _doReplayCalls: function(data, cache)
2724 { 2721 {
2725 this._customErrors = null; 2722 this._customErrors = null;
2726 this._extensions = TypeUtils.cloneObject(data.extensions) || {}; 2723 this._extensions = TypeUtils.cloneObject(data.extensions) || {};
2727 this._extensionEnums = TypeUtils.cloneObject(data.extensionEnums) || {}; 2724 this._extensionEnums = TypeUtils.cloneObject(data.extensionEnums) || {};
2728 2725
2729 var canvas = data.originalCanvas.cloneNode(true); 2726 var canvas = data.originalCanvas.cloneNode(true);
2730 var replayContext = null; 2727 var replayContext = null;
2731 var contextIds = ["experimental-webgl", "webkit-3d", "3d"]; 2728 var contextIds = ["experimental-webgl", "webkit-3d", "3d"];
2732 for (var i = 0, contextId; contextId = contextIds[i]; ++i) { 2729 for (var i = 0, contextId; contextId = contextIds[i]; ++i) {
2733 replayContext = canvas.getContext(contextId, data.originalContextAtt ributes); 2730 replayContext = canvas.getContext(contextId, data.originalContextAtt ributes);
2734 if (replayContext) 2731 if (replayContext)
2735 break; 2732 break;
2736 } 2733 }
2737 2734
2738 console.assert(replayContext, "Failed to create a WebGLRenderingContext for the replay."); 2735 console.assert(replayContext, "Failed to create a WebGLRenderingContext for the replay.");
2739 2736
2740 var gl = /** @type {!WebGLRenderingContext} */ (Resource.wrappedObject(r eplayContext)); 2737 var gl = /** @type {!WebGLRenderingContext} */ (Resource.wrappedObject(r eplayContext));
2741 this.setWrappedObject(gl); 2738 this.setWrappedObject(gl);
2742 2739
2743 // Enable corresponding WebGL extensions. 2740 // Enable corresponding WebGL extensions.
2744 for (var name in this._extensions) 2741 for (var name in this._extensions)
2745 gl.getExtension(name); 2742 gl.getExtension(name);
2746 2743
2747 var glState = data.glState; 2744 var glState = data.glState;
2748 gl.bindFramebuffer(gl.FRAMEBUFFER, /** @type {WebGLFramebuffer} */ (Repl ayableResource.replay(glState.FRAMEBUFFER_BINDING, cache))); 2745 gl.bindFramebuffer(gl.FRAMEBUFFER, /** @type {!WebGLFramebuffer} */ (Rep layableResource.replay(glState.FRAMEBUFFER_BINDING, cache)));
2749 gl.bindRenderbuffer(gl.RENDERBUFFER, /** @type {WebGLRenderbuffer} */ (R eplayableResource.replay(glState.RENDERBUFFER_BINDING, cache))); 2746 gl.bindRenderbuffer(gl.RENDERBUFFER, /** @type {!WebGLRenderbuffer} */ ( ReplayableResource.replay(glState.RENDERBUFFER_BINDING, cache)));
2750 2747
2751 // Enable or disable server-side GL capabilities. 2748 // Enable or disable server-side GL capabilities.
2752 WebGLRenderingContextResource.GLCapabilities.forEach(function(parameter) { 2749 WebGLRenderingContextResource.GLCapabilities.forEach(function(parameter) {
2753 console.assert(parameter in glState); 2750 console.assert(parameter in glState);
2754 if (glState[parameter]) 2751 if (glState[parameter])
2755 gl.enable(gl[parameter]); 2752 gl.enable(gl[parameter]);
2756 else 2753 else
2757 gl.disable(gl[parameter]); 2754 gl.disable(gl[parameter]);
2758 }); 2755 });
2759 2756
(...skipping 25 matching lines...) Expand all
2785 gl.stencilFuncSeparate(gl.FRONT, glState.STENCIL_FUNC, glState.STENCIL_R EF, glState.STENCIL_VALUE_MASK); 2782 gl.stencilFuncSeparate(gl.FRONT, glState.STENCIL_FUNC, glState.STENCIL_R EF, glState.STENCIL_VALUE_MASK);
2786 gl.stencilFuncSeparate(gl.BACK, glState.STENCIL_BACK_FUNC, glState.STENC IL_BACK_REF, glState.STENCIL_BACK_VALUE_MASK); 2783 gl.stencilFuncSeparate(gl.BACK, glState.STENCIL_BACK_FUNC, glState.STENC IL_BACK_REF, glState.STENCIL_BACK_VALUE_MASK);
2787 gl.stencilOpSeparate(gl.FRONT, glState.STENCIL_FAIL, glState.STENCIL_PAS S_DEPTH_FAIL, glState.STENCIL_PASS_DEPTH_PASS); 2784 gl.stencilOpSeparate(gl.FRONT, glState.STENCIL_FAIL, glState.STENCIL_PAS S_DEPTH_FAIL, glState.STENCIL_PASS_DEPTH_PASS);
2788 gl.stencilOpSeparate(gl.BACK, glState.STENCIL_BACK_FAIL, glState.STENCIL _BACK_PASS_DEPTH_FAIL, glState.STENCIL_BACK_PASS_DEPTH_PASS); 2785 gl.stencilOpSeparate(gl.BACK, glState.STENCIL_BACK_FAIL, glState.STENCIL _BACK_PASS_DEPTH_FAIL, glState.STENCIL_BACK_PASS_DEPTH_PASS);
2789 gl.stencilMaskSeparate(gl.FRONT, glState.STENCIL_WRITEMASK); 2786 gl.stencilMaskSeparate(gl.FRONT, glState.STENCIL_WRITEMASK);
2790 gl.stencilMaskSeparate(gl.BACK, glState.STENCIL_BACK_WRITEMASK); 2787 gl.stencilMaskSeparate(gl.BACK, glState.STENCIL_BACK_WRITEMASK);
2791 2788
2792 gl.scissor(glState.SCISSOR_BOX[0], glState.SCISSOR_BOX[1], glState.SCISS OR_BOX[2], glState.SCISSOR_BOX[3]); 2789 gl.scissor(glState.SCISSOR_BOX[0], glState.SCISSOR_BOX[1], glState.SCISS OR_BOX[2], glState.SCISSOR_BOX[3]);
2793 gl.viewport(glState.VIEWPORT[0], glState.VIEWPORT[1], glState.VIEWPORT[2 ], glState.VIEWPORT[3]); 2790 gl.viewport(glState.VIEWPORT[0], glState.VIEWPORT[1], glState.VIEWPORT[2 ], glState.VIEWPORT[3]);
2794 2791
2795 gl.useProgram(/** @type {WebGLProgram} */ (ReplayableResource.replay(glS tate.CURRENT_PROGRAM, cache))); 2792 gl.useProgram(/** @type {!WebGLProgram} */ (ReplayableResource.replay(gl State.CURRENT_PROGRAM, cache)));
2796 2793
2797 // VERTEX_ATTRIB_ARRAYS 2794 // VERTEX_ATTRIB_ARRAYS
2798 var maxVertexAttribs = /** @type {number} */ (gl.getParameter(gl.MAX_VER TEX_ATTRIBS)); 2795 var maxVertexAttribs = /** @type {number} */ (gl.getParameter(gl.MAX_VER TEX_ATTRIBS));
2799 for (var i = 0; i < maxVertexAttribs; ++i) { 2796 for (var i = 0; i < maxVertexAttribs; ++i) {
2800 var state = glState.VERTEX_ATTRIB_ARRAYS[i] || {}; 2797 var state = glState.VERTEX_ATTRIB_ARRAYS[i] || {};
2801 if (state.VERTEX_ATTRIB_ARRAY_ENABLED) 2798 if (state.VERTEX_ATTRIB_ARRAY_ENABLED)
2802 gl.enableVertexAttribArray(i); 2799 gl.enableVertexAttribArray(i);
2803 else 2800 else
2804 gl.disableVertexAttribArray(i); 2801 gl.disableVertexAttribArray(i);
2805 if (state.CURRENT_VERTEX_ATTRIB) 2802 if (state.CURRENT_VERTEX_ATTRIB)
2806 gl.vertexAttrib4fv(i, state.CURRENT_VERTEX_ATTRIB); 2803 gl.vertexAttrib4fv(i, state.CURRENT_VERTEX_ATTRIB);
2807 var buffer = /** @type {WebGLBuffer} */ (ReplayableResource.replay(s tate.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, cache)); 2804 var buffer = /** @type {!WebGLBuffer} */ (ReplayableResource.replay( state.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, cache));
2808 if (buffer) { 2805 if (buffer) {
2809 gl.bindBuffer(gl.ARRAY_BUFFER, buffer); 2806 gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
2810 gl.vertexAttribPointer(i, state.VERTEX_ATTRIB_ARRAY_SIZE, state. VERTEX_ATTRIB_ARRAY_TYPE, state.VERTEX_ATTRIB_ARRAY_NORMALIZED, state.VERTEX_ATT RIB_ARRAY_STRIDE, state.VERTEX_ATTRIB_ARRAY_POINTER); 2807 gl.vertexAttribPointer(i, state.VERTEX_ATTRIB_ARRAY_SIZE, state. VERTEX_ATTRIB_ARRAY_TYPE, state.VERTEX_ATTRIB_ARRAY_NORMALIZED, state.VERTEX_ATT RIB_ARRAY_STRIDE, state.VERTEX_ATTRIB_ARRAY_POINTER);
2811 } 2808 }
2812 } 2809 }
2813 gl.bindBuffer(gl.ARRAY_BUFFER, /** @type {WebGLBuffer} */ (ReplayableRes ource.replay(glState.ARRAY_BUFFER_BINDING, cache))); 2810 gl.bindBuffer(gl.ARRAY_BUFFER, /** @type {!WebGLBuffer} */ (ReplayableRe source.replay(glState.ARRAY_BUFFER_BINDING, cache)));
2814 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, /** @type {WebGLBuffer} */ (Repla yableResource.replay(glState.ELEMENT_ARRAY_BUFFER_BINDING, cache))); 2811 gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, /** @type {!WebGLBuffer} */ (Repl ayableResource.replay(glState.ELEMENT_ARRAY_BUFFER_BINDING, cache)));
2815 2812
2816 // TEXTURE_UNITS 2813 // TEXTURE_UNITS
2817 var maxTextureImageUnits = /** @type {number} */ (gl.getParameter(gl.MAX _TEXTURE_IMAGE_UNITS)); 2814 var maxTextureImageUnits = /** @type {number} */ (gl.getParameter(gl.MAX _TEXTURE_IMAGE_UNITS));
2818 for (var i = 0; i < maxTextureImageUnits; ++i) { 2815 for (var i = 0; i < maxTextureImageUnits; ++i) {
2819 gl.activeTexture(gl.TEXTURE0 + i); 2816 gl.activeTexture(gl.TEXTURE0 + i);
2820 var state = glState.TEXTURE_UNITS[i] || {}; 2817 var state = glState.TEXTURE_UNITS[i] || {};
2821 gl.bindTexture(gl.TEXTURE_2D, /** @type {WebGLTexture} */ (Replayabl eResource.replay(state.TEXTURE_2D, cache))); 2818 gl.bindTexture(gl.TEXTURE_2D, /** @type {!WebGLTexture} */ (Replayab leResource.replay(state.TEXTURE_2D, cache)));
2822 gl.bindTexture(gl.TEXTURE_CUBE_MAP, /** @type {WebGLTexture} */ (Rep layableResource.replay(state.TEXTURE_CUBE_MAP, cache))); 2819 gl.bindTexture(gl.TEXTURE_CUBE_MAP, /** @type {!WebGLTexture} */ (Re playableResource.replay(state.TEXTURE_CUBE_MAP, cache)));
2823 } 2820 }
2824 gl.activeTexture(glState.ACTIVE_TEXTURE); 2821 gl.activeTexture(glState.ACTIVE_TEXTURE);
2825 2822
2826 ContextResource.prototype._doReplayCalls.call(this, data, cache); 2823 ContextResource.prototype._doReplayCalls.call(this, data, cache);
2827 }, 2824 },
2828 2825
2829 /** 2826 /**
2830 * @param {Object|number} target 2827 * @param {!Object|number} target
2831 * @return {Resource} 2828 * @return {?Resource}
2832 */ 2829 */
2833 currentBinding: function(target) 2830 currentBinding: function(target)
2834 { 2831 {
2835 var resource = Resource.forObject(target); 2832 var resource = Resource.forObject(target);
2836 if (resource) 2833 if (resource)
2837 return resource; 2834 return resource;
2838 var gl = this.wrappedObject(); 2835 var gl = this.wrappedObject();
2839 var bindingParameter; 2836 var bindingParameter;
2840 var bindMethodName; 2837 var bindMethodName;
2841 target = +target; // Explicitly convert to a number. 2838 target = +target; // Explicitly convert to a number.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2894 case "bindBuffer": 2891 case "bindBuffer":
2895 case "bindFramebuffer": 2892 case "bindFramebuffer":
2896 case "bindRenderbuffer": 2893 case "bindRenderbuffer":
2897 case "bindTexture": 2894 case "bindTexture":
2898 // Update BINDING state for Resources in the replay world. 2895 // Update BINDING state for Resources in the replay world.
2899 var resource = Resource.forObject(args[1]); 2896 var resource = Resource.forObject(args[1]);
2900 if (resource) 2897 if (resource)
2901 resource.pushBinding(args[0], functionName); 2898 resource.pushBinding(args[0], functionName);
2902 break; 2899 break;
2903 case "getExtension": 2900 case "getExtension":
2904 this.registerWebGLExtension(args[0], /** @type {Object} */ (call.res ult())); 2901 this.registerWebGLExtension(args[0], /** @type {!Object} */ (call.re sult()));
2905 break; 2902 break;
2906 case "bufferData": 2903 case "bufferData":
2907 var resource = /** @type {WebGLBufferResource} */ (this.currentBindi ng(args[0])); 2904 var resource = /** @type {!WebGLBufferResource} */ (this.currentBind ing(args[0]));
2908 if (resource) 2905 if (resource)
2909 resource.pushCall_bufferData(call); 2906 resource.pushCall_bufferData(call);
2910 break; 2907 break;
2911 case "bufferSubData": 2908 case "bufferSubData":
2912 var resource = /** @type {WebGLBufferResource} */ (this.currentBindi ng(args[0])); 2909 var resource = /** @type {!WebGLBufferResource} */ (this.currentBind ing(args[0]));
2913 if (resource) 2910 if (resource)
2914 resource.pushCall_bufferSubData(call); 2911 resource.pushCall_bufferSubData(call);
2915 break; 2912 break;
2916 } 2913 }
2917 }, 2914 },
2918 2915
2919 /** 2916 /**
2920 * @override 2917 * @override
2921 * @return {!Object.<string, Function>} 2918 * @return {!Object.<string, !Function>}
2922 */ 2919 */
2923 _customWrapFunctions: function() 2920 _customWrapFunctions: function()
2924 { 2921 {
2925 var wrapFunctions = WebGLRenderingContextResource._wrapFunctions; 2922 var wrapFunctions = WebGLRenderingContextResource._wrapFunctions;
2926 if (!wrapFunctions) { 2923 if (!wrapFunctions) {
2927 wrapFunctions = Object.create(null); 2924 wrapFunctions = Object.create(null);
2928 2925
2929 wrapFunctions["createBuffer"] = Resource.WrapFunction.resourceFactor yMethod(WebGLBufferResource, "WebGLBuffer"); 2926 wrapFunctions["createBuffer"] = Resource.WrapFunction.resourceFactor yMethod(WebGLBufferResource, "WebGLBuffer");
2930 wrapFunctions["createShader"] = Resource.WrapFunction.resourceFactor yMethod(WebGLShaderResource, "WebGLShader"); 2927 wrapFunctions["createShader"] = Resource.WrapFunction.resourceFactor yMethod(WebGLShaderResource, "WebGLShader");
2931 wrapFunctions["createProgram"] = Resource.WrapFunction.resourceFacto ryMethod(WebGLProgramResource, "WebGLProgram"); 2928 wrapFunctions["createProgram"] = Resource.WrapFunction.resourceFacto ryMethod(WebGLProgramResource, "WebGLProgram");
(...skipping 13 matching lines...) Expand all
2945 stateModifyingWrapFunction("compressedTexSubImage2D"); 2942 stateModifyingWrapFunction("compressedTexSubImage2D");
2946 stateModifyingWrapFunction("copyTexImage2D", WebGLTextureResource.pr ototype.pushCall_copyTexImage2D); 2943 stateModifyingWrapFunction("copyTexImage2D", WebGLTextureResource.pr ototype.pushCall_copyTexImage2D);
2947 stateModifyingWrapFunction("copyTexSubImage2D", WebGLTextureResource .prototype.pushCall_copyTexImage2D); 2944 stateModifyingWrapFunction("copyTexSubImage2D", WebGLTextureResource .prototype.pushCall_copyTexImage2D);
2948 stateModifyingWrapFunction("generateMipmap"); 2945 stateModifyingWrapFunction("generateMipmap");
2949 stateModifyingWrapFunction("texImage2D"); 2946 stateModifyingWrapFunction("texImage2D");
2950 stateModifyingWrapFunction("texSubImage2D"); 2947 stateModifyingWrapFunction("texSubImage2D");
2951 stateModifyingWrapFunction("texParameterf", WebGLTextureResource.pro totype.pushCall_texParameter); 2948 stateModifyingWrapFunction("texParameterf", WebGLTextureResource.pro totype.pushCall_texParameter);
2952 stateModifyingWrapFunction("texParameteri", WebGLTextureResource.pro totype.pushCall_texParameter); 2949 stateModifyingWrapFunction("texParameteri", WebGLTextureResource.pro totype.pushCall_texParameter);
2953 stateModifyingWrapFunction("renderbufferStorage"); 2950 stateModifyingWrapFunction("renderbufferStorage");
2954 2951
2955 /** @this Resource.WrapFunction */ 2952 /** @this {Resource.WrapFunction} */
2956 wrapFunctions["getError"] = function() 2953 wrapFunctions["getError"] = function()
2957 { 2954 {
2958 var gl = /** @type {WebGLRenderingContext} */ (this._originalObj ect); 2955 var gl = /** @type {!WebGLRenderingContext} */ (this._originalOb ject);
2959 var error = this.result(); 2956 var error = this.result();
2960 if (error !== gl.NO_ERROR) 2957 if (error !== gl.NO_ERROR)
2961 this._resource.clearError(error); 2958 this._resource.clearError(error);
2962 else { 2959 else {
2963 error = this._resource.nextError(); 2960 error = this._resource.nextError();
2964 if (error !== gl.NO_ERROR) 2961 if (error !== gl.NO_ERROR)
2965 this.overrideResult(error); 2962 this.overrideResult(error);
2966 } 2963 }
2967 } 2964 }
2968 2965
2969 /** 2966 /**
2970 * @param {string} name 2967 * @param {string} name
2971 * @this Resource.WrapFunction 2968 * @this {Resource.WrapFunction}
2972 */ 2969 */
2973 wrapFunctions["getExtension"] = function(name) 2970 wrapFunctions["getExtension"] = function(name)
2974 { 2971 {
2975 this._resource.registerWebGLExtension(name, this.result()); 2972 this._resource.registerWebGLExtension(name, this.result());
2976 } 2973 }
2977 2974
2978 // 2975 //
2979 // Register bound WebGL resources. 2976 // Register bound WebGL resources.
2980 // 2977 //
2981 2978
2982 /** 2979 /**
2983 * @param {WebGLProgram} program 2980 * @param {!WebGLProgram} program
2984 * @param {WebGLShader} shader 2981 * @param {!WebGLShader} shader
2985 * @this Resource.WrapFunction 2982 * @this {Resource.WrapFunction}
2986 */ 2983 */
2987 wrapFunctions["attachShader"] = function(program, shader) 2984 wrapFunctions["attachShader"] = function(program, shader)
2988 { 2985 {
2989 var resource = this._resource.currentBinding(program); 2986 var resource = this._resource.currentBinding(program);
2990 if (resource) { 2987 if (resource) {
2991 resource.pushCall(this.call()); 2988 resource.pushCall(this.call());
2992 var shaderResource = /** @type {WebGLShaderResource} */ (Res ource.forObject(shader)); 2989 var shaderResource = /** @type {!WebGLShaderResource} */ (Re source.forObject(shader));
2993 if (shaderResource) { 2990 if (shaderResource) {
2994 var shaderType = shaderResource.type(); 2991 var shaderType = shaderResource.type();
2995 resource._registerBoundResource("__attachShader_" + shad erType, shaderResource); 2992 resource._registerBoundResource("__attachShader_" + shad erType, shaderResource);
2996 } 2993 }
2997 } 2994 }
2998 } 2995 }
2999 /** 2996 /**
3000 * @param {number} target 2997 * @param {number} target
3001 * @param {number} attachment 2998 * @param {number} attachment
3002 * @param {number} objectTarget 2999 * @param {number} objectTarget
3003 * @param {WebGLRenderbuffer|WebGLTexture} obj 3000 * @param {!WebGLRenderbuffer|!WebGLTexture} obj
3004 * @this Resource.WrapFunction 3001 * @this {Resource.WrapFunction}
3005 */ 3002 */
3006 wrapFunctions["framebufferRenderbuffer"] = wrapFunctions["framebuffe rTexture2D"] = function(target, attachment, objectTarget, obj) 3003 wrapFunctions["framebufferRenderbuffer"] = wrapFunctions["framebuffe rTexture2D"] = function(target, attachment, objectTarget, obj)
3007 { 3004 {
3008 var resource = this._resource.currentBinding(target); 3005 var resource = this._resource.currentBinding(target);
3009 if (resource) { 3006 if (resource) {
3010 resource.pushCall(this.call()); 3007 resource.pushCall(this.call());
3011 resource._registerBoundResource("__framebufferAttachmentObje ctName", obj); 3008 resource._registerBoundResource("__framebufferAttachmentObje ctName", obj);
3012 } 3009 }
3013 } 3010 }
3014 /** 3011 /**
3015 * @param {number} target 3012 * @param {number} target
3016 * @param {Object} obj 3013 * @param {!Object} obj
3017 * @this Resource.WrapFunction 3014 * @this {Resource.WrapFunction}
3018 */ 3015 */
3019 wrapFunctions["bindBuffer"] = wrapFunctions["bindFramebuffer"] = wra pFunctions["bindRenderbuffer"] = function(target, obj) 3016 wrapFunctions["bindBuffer"] = wrapFunctions["bindFramebuffer"] = wra pFunctions["bindRenderbuffer"] = function(target, obj)
3020 { 3017 {
3021 this._resource.currentBinding(target); // To call WebGLBoundReso urce.prototype.pushBinding(). 3018 this._resource.currentBinding(target); // To call WebGLBoundReso urce.prototype.pushBinding().
3022 this._resource._registerBoundResource("__bindBuffer_" + target, obj); 3019 this._resource._registerBoundResource("__bindBuffer_" + target, obj);
3023 } 3020 }
3024 /** 3021 /**
3025 * @param {number} target 3022 * @param {number} target
3026 * @param {WebGLTexture} obj 3023 * @param {!WebGLTexture} obj
3027 * @this Resource.WrapFunction 3024 * @this {Resource.WrapFunction}
3028 */ 3025 */
3029 wrapFunctions["bindTexture"] = function(target, obj) 3026 wrapFunctions["bindTexture"] = function(target, obj)
3030 { 3027 {
3031 this._resource.currentBinding(target); // To call WebGLBoundReso urce.prototype.pushBinding(). 3028 this._resource.currentBinding(target); // To call WebGLBoundReso urce.prototype.pushBinding().
3032 var gl = /** @type {WebGLRenderingContext} */ (this._originalObj ect); 3029 var gl = /** @type {!WebGLRenderingContext} */ (this._originalOb ject);
3033 var currentTextureBinding = /** @type {number} */ (gl.getParamet er(gl.ACTIVE_TEXTURE)); 3030 var currentTextureBinding = /** @type {number} */ (gl.getParamet er(gl.ACTIVE_TEXTURE));
3034 this._resource._registerBoundResource("__bindTexture_" + target + "_" + currentTextureBinding, obj); 3031 this._resource._registerBoundResource("__bindTexture_" + target + "_" + currentTextureBinding, obj);
3035 } 3032 }
3036 /** 3033 /**
3037 * @param {WebGLProgram} program 3034 * @param {!WebGLProgram} program
3038 * @this Resource.WrapFunction 3035 * @this {Resource.WrapFunction}
3039 */ 3036 */
3040 wrapFunctions["useProgram"] = function(program) 3037 wrapFunctions["useProgram"] = function(program)
3041 { 3038 {
3042 this._resource._registerBoundResource("__useProgram", program); 3039 this._resource._registerBoundResource("__useProgram", program);
3043 } 3040 }
3044 /** 3041 /**
3045 * @param {number} index 3042 * @param {number} index
3046 * @this Resource.WrapFunction 3043 * @this {Resource.WrapFunction}
3047 */ 3044 */
3048 wrapFunctions["vertexAttribPointer"] = function(index) 3045 wrapFunctions["vertexAttribPointer"] = function(index)
3049 { 3046 {
3050 var gl = /** @type {WebGLRenderingContext} */ (this._originalObj ect); 3047 var gl = /** @type {!WebGLRenderingContext} */ (this._originalOb ject);
3051 this._resource._registerBoundResource("__vertexAttribPointer_" + index, gl.getParameter(gl.ARRAY_BUFFER_BINDING)); 3048 this._resource._registerBoundResource("__vertexAttribPointer_" + index, gl.getParameter(gl.ARRAY_BUFFER_BINDING));
3052 } 3049 }
3053 3050
3054 WebGLRenderingContextResource._wrapFunctions = wrapFunctions; 3051 WebGLRenderingContextResource._wrapFunctions = wrapFunctions;
3055 } 3052 }
3056 3053
3057 /** 3054 /**
3058 * @param {string} methodName 3055 * @param {string} methodName
3059 * @param {function(this:Resource, !Call)=} pushCallFunc 3056 * @param {function(this:Resource, !Call)=} pushCallFunc
3060 */ 3057 */
3061 function stateModifyingWrapFunction(methodName, pushCallFunc) 3058 function stateModifyingWrapFunction(methodName, pushCallFunc)
3062 { 3059 {
3063 if (pushCallFunc) { 3060 if (pushCallFunc) {
3064 /** 3061 /**
3065 * @param {Object|number} target 3062 * @param {!Object|number} target
3066 * @this Resource.WrapFunction 3063 * @this {Resource.WrapFunction}
3067 */ 3064 */
3068 wrapFunctions[methodName] = function(target) 3065 wrapFunctions[methodName] = function(target)
3069 { 3066 {
3070 var resource = this._resource.currentBinding(target); 3067 var resource = this._resource.currentBinding(target);
3071 if (resource) 3068 if (resource)
3072 pushCallFunc.call(resource, this.call()); 3069 pushCallFunc.call(resource, this.call());
3073 } 3070 }
3074 } else { 3071 } else {
3075 /** 3072 /**
3076 * @param {Object|number} target 3073 * @param {!Object|number} target
3077 * @this Resource.WrapFunction 3074 * @this {Resource.WrapFunction}
3078 */ 3075 */
3079 wrapFunctions[methodName] = function(target) 3076 wrapFunctions[methodName] = function(target)
3080 { 3077 {
3081 var resource = this._resource.currentBinding(target); 3078 var resource = this._resource.currentBinding(target);
3082 if (resource) 3079 if (resource)
3083 resource.pushCall(this.call()); 3080 resource.pushCall(this.call());
3084 } 3081 }
3085 } 3082 }
3086 } 3083 }
3087 3084
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3175 "putImageData", 3172 "putImageData",
3176 "putImageDataHD", 3173 "putImageDataHD",
3177 "stroke", 3174 "stroke",
3178 "strokeRect", 3175 "strokeRect",
3179 "strokeText" 3176 "strokeText"
3180 ]); 3177 ]);
3181 3178
3182 CanvasRenderingContext2DResource.prototype = { 3179 CanvasRenderingContext2DResource.prototype = {
3183 /** 3180 /**
3184 * @override (overrides @return type) 3181 * @override (overrides @return type)
3185 * @return {CanvasRenderingContext2D} 3182 * @return {!CanvasRenderingContext2D}
3186 */ 3183 */
3187 wrappedObject: function() 3184 wrappedObject: function()
3188 { 3185 {
3189 return this._wrappedObject; 3186 return this._wrappedObject;
3190 }, 3187 },
3191 3188
3192 /** 3189 /**
3193 * @override 3190 * @override
3194 * @return {string} 3191 * @return {string}
3195 */ 3192 */
3196 toDataURL: function() 3193 toDataURL: function()
3197 { 3194 {
3198 return this.wrappedObject().canvas.toDataURL(); 3195 return this.wrappedObject().canvas.toDataURL();
3199 }, 3196 },
3200 3197
3201 /** 3198 /**
3202 * @override 3199 * @override
3203 * @return {!Array.<TypeUtils.InternalResourceStateDescriptor>} 3200 * @return {!Array.<!TypeUtils.InternalResourceStateDescriptor>}
3204 */ 3201 */
3205 currentState: function() 3202 currentState: function()
3206 { 3203 {
3207 var result = []; 3204 var result = [];
3208 var state = this._internalCurrentState(null); 3205 var state = this._internalCurrentState(null);
3209 for (var pname in state) 3206 for (var pname in state)
3210 result.push({ name: pname, value: state[pname] }); 3207 result.push({ name: pname, value: state[pname] });
3211 result.push({ name: "context", value: this.contextResource() }); 3208 result.push({ name: "context", value: this.contextResource() });
3212 return result; 3209 return result;
3213 }, 3210 },
3214 3211
3215 /** 3212 /**
3216 * @param {?Cache.<ReplayableResource>} cache 3213 * @param {?Cache.<!ReplayableResource>} cache
3217 * @return {!Object.<string, *>} 3214 * @return {!Object.<string, *>}
3218 */ 3215 */
3219 _internalCurrentState: function(cache) 3216 _internalCurrentState: function(cache)
3220 { 3217 {
3221 /** 3218 /**
3222 * @param {Resource|*} obj 3219 * @param {!Resource|*} obj
3223 * @return {Resource|ReplayableResource|*} 3220 * @return {!Resource|!ReplayableResource|*}
3224 */ 3221 */
3225 function maybeToReplayable(obj) 3222 function maybeToReplayable(obj)
3226 { 3223 {
3227 return cache ? Resource.toReplayable(obj, cache) : (Resource.forObje ct(obj) || obj); 3224 return cache ? Resource.toReplayable(obj, cache) : (Resource.forObje ct(obj) || obj);
3228 } 3225 }
3229 3226
3230 var ctx = this.wrappedObject(); 3227 var ctx = this.wrappedObject();
3231 var state = Object.create(null); 3228 var state = Object.create(null);
3232 CanvasRenderingContext2DResource.AttributeProperties.forEach(function(at tribute) { 3229 CanvasRenderingContext2DResource.AttributeProperties.forEach(function(at tribute) {
3233 if (attribute in ctx) 3230 if (attribute in ctx)
3234 state[attribute] = maybeToReplayable(ctx[attribute]); 3231 state[attribute] = maybeToReplayable(ctx[attribute]);
3235 }); 3232 });
3236 if (ctx.getLineDash) 3233 if (ctx.getLineDash)
3237 state.lineDash = ctx.getLineDash(); 3234 state.lineDash = ctx.getLineDash();
3238 return state; 3235 return state;
3239 }, 3236 },
3240 3237
3241 /** 3238 /**
3242 * @param {Object.<string, *>} state 3239 * @param {?Object.<string, *>} state
3243 * @param {!Cache.<Resource>} cache 3240 * @param {!Cache.<!Resource>} cache
3244 */ 3241 */
3245 _applyAttributesState: function(state, cache) 3242 _applyAttributesState: function(state, cache)
3246 { 3243 {
3247 if (!state) 3244 if (!state)
3248 return; 3245 return;
3249 var ctx = this.wrappedObject(); 3246 var ctx = this.wrappedObject();
3250 for (var attribute in state) { 3247 for (var attribute in state) {
3251 if (attribute === "lineDash") { 3248 if (attribute === "lineDash") {
3252 if (ctx.setLineDash) 3249 if (ctx.setLineDash)
3253 ctx.setLineDash(/** @type {Array.<number>} */ (state[attribu te])); 3250 ctx.setLineDash(/** @type {!Array.<number>} */ (state[attrib ute]));
3254 } else 3251 } else
3255 ctx[attribute] = ReplayableResource.replay(state[attribute], cac he); 3252 ctx[attribute] = ReplayableResource.replay(state[attribute], cac he);
3256 } 3253 }
3257 }, 3254 },
3258 3255
3259 /** 3256 /**
3260 * @override 3257 * @override
3261 * @param {!Object} data 3258 * @param {!Object} data
3262 * @param {!Cache.<ReplayableResource>} cache 3259 * @param {!Cache.<!ReplayableResource>} cache
3263 */ 3260 */
3264 _populateReplayableData: function(data, cache) 3261 _populateReplayableData: function(data, cache)
3265 { 3262 {
3266 var ctx = this.wrappedObject(); 3263 var ctx = this.wrappedObject();
3267 // FIXME: Convert resources in the state (CanvasGradient, CanvasPattern) to Replayable. 3264 // FIXME: Convert resources in the state (CanvasGradient, CanvasPattern) to Replayable.
3268 data.currentAttributes = this._internalCurrentState(null); 3265 data.currentAttributes = this._internalCurrentState(null);
3269 data.originalCanvasCloned = TypeUtils.cloneIntoCanvas(ctx.canvas); 3266 data.originalCanvasCloned = TypeUtils.cloneIntoCanvas(/** @type {!HTMLCa nvasElement} */ (ctx.canvas));
3270 if (ctx.getContextAttributes) 3267 if (ctx.getContextAttributes)
3271 data.originalContextAttributes = ctx.getContextAttributes(); 3268 data.originalContextAttributes = ctx.getContextAttributes();
3272 }, 3269 },
3273 3270
3274 /** 3271 /**
3275 * @override 3272 * @override
3276 * @param {!Object} data 3273 * @param {!Object} data
3277 * @param {!Cache.<Resource>} cache 3274 * @param {!Cache.<!Resource>} cache
3278 */ 3275 */
3279 _doReplayCalls: function(data, cache) 3276 _doReplayCalls: function(data, cache)
3280 { 3277 {
3281 var canvas = TypeUtils.cloneIntoCanvas(data.originalCanvasCloned); 3278 var canvas = TypeUtils.cloneIntoCanvas(data.originalCanvasCloned);
3282 var ctx = /** @type {!CanvasRenderingContext2D} */ (Resource.wrappedObje ct(canvas.getContext("2d", data.originalContextAttributes))); 3279 var ctx = /** @type {!CanvasRenderingContext2D} */ (Resource.wrappedObje ct(canvas.getContext("2d", data.originalContextAttributes)));
3283 this.setWrappedObject(ctx); 3280 this.setWrappedObject(ctx);
3284 3281
3285 for (var i = 0, n = data.calls.length; i < n; ++i) { 3282 for (var i = 0, n = data.calls.length; i < n; ++i) {
3286 var replayableCall = /** @type {ReplayableCall} */ (data.calls[i]); 3283 var replayableCall = /** @type {!ReplayableCall} */ (data.calls[i]);
3287 if (replayableCall.functionName() === "save") 3284 if (replayableCall.functionName() === "save")
3288 this._applyAttributesState(replayableCall.attachment("canvas2dAt tributesState"), cache); 3285 this._applyAttributesState(replayableCall.attachment("canvas2dAt tributesState"), cache);
3289 this._calls.push(replayableCall.replay(cache)); 3286 this._calls.push(replayableCall.replay(cache));
3290 } 3287 }
3291 this._applyAttributesState(data.currentAttributes, cache); 3288 this._applyAttributesState(data.currentAttributes, cache);
3292 }, 3289 },
3293 3290
3294 /** 3291 /**
3295 * @param {!Call} call 3292 * @param {!Call} call
3296 */ 3293 */
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3459 this._calls[newIndex++] = call; 3456 this._calls[newIndex++] = call;
3460 } 3457 }
3461 if (newIndex >= toIndex) 3458 if (newIndex >= toIndex)
3462 return false; 3459 return false;
3463 this._calls.splice(newIndex, toIndex - newIndex); 3460 this._calls.splice(newIndex, toIndex - newIndex);
3464 return true; 3461 return true;
3465 }, 3462 },
3466 3463
3467 /** 3464 /**
3468 * @override 3465 * @override
3469 * @return {!Object.<string, Function>} 3466 * @return {!Object.<string, !Function>}
3470 */ 3467 */
3471 _customWrapFunctions: function() 3468 _customWrapFunctions: function()
3472 { 3469 {
3473 var wrapFunctions = CanvasRenderingContext2DResource._wrapFunctions; 3470 var wrapFunctions = CanvasRenderingContext2DResource._wrapFunctions;
3474 if (!wrapFunctions) { 3471 if (!wrapFunctions) {
3475 wrapFunctions = Object.create(null); 3472 wrapFunctions = Object.create(null);
3476 3473
3477 wrapFunctions["createLinearGradient"] = Resource.WrapFunction.resour ceFactoryMethod(LogEverythingResource, "CanvasGradient"); 3474 wrapFunctions["createLinearGradient"] = Resource.WrapFunction.resour ceFactoryMethod(LogEverythingResource, "CanvasGradient");
3478 wrapFunctions["createRadialGradient"] = Resource.WrapFunction.resour ceFactoryMethod(LogEverythingResource, "CanvasGradient"); 3475 wrapFunctions["createRadialGradient"] = Resource.WrapFunction.resour ceFactoryMethod(LogEverythingResource, "CanvasGradient");
3479 wrapFunctions["createPattern"] = Resource.WrapFunction.resourceFacto ryMethod(LogEverythingResource, "CanvasPattern"); 3476 wrapFunctions["createPattern"] = Resource.WrapFunction.resourceFacto ryMethod(LogEverythingResource, "CanvasPattern");
(...skipping 10 matching lines...) Expand all
3490 CanvasRenderingContext2DResource._wrapFunctions = wrapFunctions; 3487 CanvasRenderingContext2DResource._wrapFunctions = wrapFunctions;
3491 } 3488 }
3492 3489
3493 /** 3490 /**
3494 * @param {string} methodName 3491 * @param {string} methodName
3495 * @param {function(this:Resource, !Call)=} func 3492 * @param {function(this:Resource, !Call)=} func
3496 */ 3493 */
3497 function stateModifyingWrapFunction(methodName, func) 3494 function stateModifyingWrapFunction(methodName, func)
3498 { 3495 {
3499 if (func) { 3496 if (func) {
3500 /** @this Resource.WrapFunction */ 3497 /** @this {Resource.WrapFunction} */
3501 wrapFunctions[methodName] = function() 3498 wrapFunctions[methodName] = function()
3502 { 3499 {
3503 func.call(this._resource, this.call()); 3500 func.call(this._resource, this.call());
3504 } 3501 }
3505 } else { 3502 } else {
3506 /** @this Resource.WrapFunction */ 3503 /** @this {Resource.WrapFunction} */
3507 wrapFunctions[methodName] = function() 3504 wrapFunctions[methodName] = function()
3508 { 3505 {
3509 this._resource.pushCall(this.call()); 3506 this._resource.pushCall(this.call());
3510 } 3507 }
3511 } 3508 }
3512 } 3509 }
3513 3510
3514 return wrapFunctions; 3511 return wrapFunctions;
3515 }, 3512 },
3516 3513
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3565 description: value.description(), 3562 description: value.description(),
3566 resourceId: CallFormatter.makeStringResourceId(value.id()) 3563 resourceId: CallFormatter.makeStringResourceId(value.id())
3567 }; 3564 };
3568 } 3565 }
3569 3566
3570 var remoteObject = injectedScript.wrapObject(value, objectGroup || "", t rue, false); 3567 var remoteObject = injectedScript.wrapObject(value, objectGroup || "", t rue, false);
3571 var description = remoteObject.description || ("" + value); 3568 var description = remoteObject.description || ("" + value);
3572 3569
3573 var result = { 3570 var result = {
3574 description: description, 3571 description: description,
3575 type: /** @type {CanvasAgent.CallArgumentType} */ (remoteObject.type ) 3572 type: /** @type {!CanvasAgent.CallArgumentType} */ (remoteObject.typ e)
3576 }; 3573 };
3577 if (remoteObject.subtype) 3574 if (remoteObject.subtype)
3578 result.subtype = /** @type {CanvasAgent.CallArgumentSubtype} */ (rem oteObject.subtype); 3575 result.subtype = /** @type {!CanvasAgent.CallArgumentSubtype} */ (re moteObject.subtype);
3579 if (remoteObject.objectId) { 3576 if (remoteObject.objectId) {
3580 if (objectGroup) 3577 if (objectGroup)
3581 result.remoteObject = remoteObject; 3578 result.remoteObject = remoteObject;
3582 else 3579 else
3583 injectedScript.releaseObject(remoteObject.objectId); 3580 injectedScript.releaseObject(remoteObject.objectId);
3584 } 3581 }
3585 return result; 3582 return result;
3586 }, 3583 },
3587 3584
3588 /** 3585 /**
3589 * @param {string} name 3586 * @param {string} name
3590 * @return {?string} 3587 * @return {?string}
3591 */ 3588 */
3592 enumValueForName: function(name) 3589 enumValueForName: function(name)
3593 { 3590 {
3594 return null; 3591 return null;
3595 }, 3592 },
3596 3593
3597 /** 3594 /**
3598 * @param {number} value 3595 * @param {number} value
3599 * @param {Array.<string>=} options 3596 * @param {!Array.<string>=} options
3600 * @return {?string} 3597 * @return {?string}
3601 */ 3598 */
3602 enumNameForValue: function(value, options) 3599 enumNameForValue: function(value, options)
3603 { 3600 {
3604 return null; 3601 return null;
3605 }, 3602 },
3606 3603
3607 /** 3604 /**
3608 * @param {!Array.<TypeUtils.InternalResourceStateDescriptor>} descriptors 3605 * @param {!Array.<!TypeUtils.InternalResourceStateDescriptor>} descriptors
3609 * @param {string=} objectGroup 3606 * @param {string=} objectGroup
3610 * @return {!Array.<!CanvasAgent.ResourceStateDescriptor>} 3607 * @return {!Array.<!CanvasAgent.ResourceStateDescriptor>}
3611 */ 3608 */
3612 formatResourceStateDescriptors: function(descriptors, objectGroup) 3609 formatResourceStateDescriptors: function(descriptors, objectGroup)
3613 { 3610 {
3614 var result = []; 3611 var result = [];
3615 for (var i = 0, n = descriptors.length; i < n; ++i) { 3612 for (var i = 0, n = descriptors.length; i < n; ++i) {
3616 var d = descriptors[i]; 3613 var d = descriptors[i];
3617 var item; 3614 var item;
3618 if (d.values) 3615 if (d.values)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3660 var formatter = CallFormatter._formatters[resource.name()]; 3657 var formatter = CallFormatter._formatters[resource.name()];
3661 if (!formatter) { 3658 if (!formatter) {
3662 var contextResource = resource.contextResource(); 3659 var contextResource = resource.contextResource();
3663 formatter = (contextResource && CallFormatter._formatters[contextResourc e.name()]) || new CallFormatter(); 3660 formatter = (contextResource && CallFormatter._formatters[contextResourc e.name()]) || new CallFormatter();
3664 } 3661 }
3665 return formatter; 3662 return formatter;
3666 } 3663 }
3667 3664
3668 /** 3665 /**
3669 * @param {number} resourceId 3666 * @param {number} resourceId
3670 * @return {CanvasAgent.ResourceId} 3667 * @return {!CanvasAgent.ResourceId}
3671 */ 3668 */
3672 CallFormatter.makeStringResourceId = function(resourceId) 3669 CallFormatter.makeStringResourceId = function(resourceId)
3673 { 3670 {
3674 return "{\"injectedScriptId\":" + injectedScriptId + ",\"resourceId\":" + re sourceId + "}"; 3671 return "{\"injectedScriptId\":" + injectedScriptId + ",\"resourceId\":" + re sourceId + "}";
3675 } 3672 }
3676 3673
3677 /** 3674 /**
3678 * @constructor 3675 * @constructor
3679 * @extends {CallFormatter} 3676 * @extends {CallFormatter}
3680 * @param {!Object.<string, boolean>} drawingMethodNames 3677 * @param {!Object.<string, boolean>} drawingMethodNames
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
3792 { 3789 {
3793 this._initialize(); 3790 this._initialize();
3794 if (name in this._enumNameToValue) 3791 if (name in this._enumNameToValue)
3795 return "" + this._enumNameToValue[name]; 3792 return "" + this._enumNameToValue[name];
3796 return null; 3793 return null;
3797 }, 3794 },
3798 3795
3799 /** 3796 /**
3800 * @override 3797 * @override
3801 * @param {number} value 3798 * @param {number} value
3802 * @param {Array.<string>=} options 3799 * @param {!Array.<string>=} options
3803 * @return {?string} 3800 * @return {?string}
3804 */ 3801 */
3805 enumNameForValue: function(value, options) 3802 enumNameForValue: function(value, options)
3806 { 3803 {
3807 this._initialize(); 3804 this._initialize();
3808 options = options || []; 3805 options = options || [];
3809 for (var i = 0, n = options.length; i < n; ++i) { 3806 for (var i = 0, n = options.length; i < n; ++i) {
3810 if (this._enumNameToValue[options[i]] === value) 3807 if (this._enumNameToValue[options[i]] === value)
3811 return options[i]; 3808 return options[i];
3812 } 3809 }
3813 var names = this._enumValueToNames[value]; 3810 var names = this._enumValueToNames[value];
3814 if (!names || names.length !== 1) 3811 if (!names || names.length !== 1)
3815 return null; 3812 return null;
3816 return names[0]; 3813 return names[0];
3817 }, 3814 },
3818 3815
3819 /** 3816 /**
3820 * @param {!ReplayableCall} replayableCall 3817 * @param {!ReplayableCall} replayableCall
3821 * @return {Object} 3818 * @return {?Object}
3822 */ 3819 */
3823 _findEnumsInfo: function(replayableCall) 3820 _findEnumsInfo: function(replayableCall)
3824 { 3821 {
3825 function findMaxArgumentIndex(enumsInfo) 3822 function findMaxArgumentIndex(enumsInfo)
3826 { 3823 {
3827 var result = -1; 3824 var result = -1;
3828 var enumArgsIndexes = enumsInfo["enum"] || []; 3825 var enumArgsIndexes = enumsInfo["enum"] || [];
3829 for (var i = 0, n = enumArgsIndexes.length; i < n; ++i) 3826 for (var i = 0, n = enumArgsIndexes.length; i < n; ++i)
3830 result = Math.max(result, enumArgsIndexes[i]); 3827 result = Math.max(result, enumArgsIndexes[i]);
3831 var bitfieldArgsIndexes = enumsInfo["bitfield"] || []; 3828 var bitfieldArgsIndexes = enumsInfo["bitfield"] || [];
(...skipping 12 matching lines...) Expand all
3844 continue; 3841 continue;
3845 // To resolve ambiguity (see texImage2D, texSubImage2D) choose descr iption with max argument indexes. 3842 // To resolve ambiguity (see texImage2D, texSubImage2D) choose descr iption with max argument indexes.
3846 if (!result || findMaxArgumentIndex(result) < maxArgumentIndex) 3843 if (!result || findMaxArgumentIndex(result) < maxArgumentIndex)
3847 result = enumsInfo; 3844 result = enumsInfo;
3848 } 3845 }
3849 return result; 3846 return result;
3850 }, 3847 },
3851 3848
3852 /** 3849 /**
3853 * @param {?CanvasAgent.CallArgument|undefined} callArgument 3850 * @param {?CanvasAgent.CallArgument|undefined} callArgument
3854 * @param {Array.<string>=} options 3851 * @param {!Array.<string>=} options
3855 */ 3852 */
3856 _formatEnumValue: function(callArgument, options) 3853 _formatEnumValue: function(callArgument, options)
3857 { 3854 {
3858 if (!callArgument || isNaN(callArgument.description)) 3855 if (!callArgument || isNaN(callArgument.description))
3859 return; 3856 return;
3860 this._initialize(); 3857 this._initialize();
3861 var value = +callArgument.description; 3858 var value = +callArgument.description;
3862 var enumName = this.enumNameForValue(value, options); 3859 var enumName = this.enumNameForValue(value, options);
3863 if (enumName) 3860 if (enumName)
3864 callArgument.enumName = enumName; 3861 callArgument.enumName = enumName;
3865 }, 3862 },
3866 3863
3867 /** 3864 /**
3868 * @param {?CanvasAgent.CallArgument|undefined} callArgument 3865 * @param {?CanvasAgent.CallArgument|undefined} callArgument
3869 * @param {Array.<string>=} options 3866 * @param {!Array.<string>=} options
3870 */ 3867 */
3871 _formatEnumBitmaskValue: function(callArgument, options) 3868 _formatEnumBitmaskValue: function(callArgument, options)
3872 { 3869 {
3873 if (!callArgument || isNaN(callArgument.description)) 3870 if (!callArgument || isNaN(callArgument.description))
3874 return; 3871 return;
3875 this._initialize(); 3872 this._initialize();
3876 var value = +callArgument.description; 3873 var value = +callArgument.description;
3877 options = options || []; 3874 options = options || [];
3878 /** @type {!Array.<string>} */ 3875 /** @type {!Array.<string>} */
3879 var result = []; 3876 var result = [];
(...skipping 23 matching lines...) Expand all
3903 { 3900 {
3904 if (this._enumNameToValue) 3901 if (this._enumNameToValue)
3905 return; 3902 return;
3906 3903
3907 /** @type {!Object.<string, number>} */ 3904 /** @type {!Object.<string, number>} */
3908 this._enumNameToValue = Object.create(null); 3905 this._enumNameToValue = Object.create(null);
3909 /** @type {!Object.<number, !Array.<string>>} */ 3906 /** @type {!Object.<number, !Array.<string>>} */
3910 this._enumValueToNames = Object.create(null); 3907 this._enumValueToNames = Object.create(null);
3911 3908
3912 /** 3909 /**
3913 * @param {Object} obj 3910 * @param {?Object} obj
3914 * @this WebGLCallFormatter 3911 * @this WebGLCallFormatter
3915 */ 3912 */
3916 function iterateWebGLEnums(obj) 3913 function iterateWebGLEnums(obj)
3917 { 3914 {
3918 if (!obj) 3915 if (!obj)
3919 return; 3916 return;
3920 for (var property in obj) { 3917 for (var property in obj) {
3921 if (TypeUtils.isEnumPropertyName(property, obj)) { 3918 if (TypeUtils.isEnumPropertyName(property, obj)) {
3922 var value = /** @type {number} */ (obj[property]); 3919 var value = /** @type {number} */ (obj[property]);
3923 this._enumNameToValue[property] = value; 3920 this._enumNameToValue[property] = value;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3966 var common = commonSubstring(names); 3963 var common = commonSubstring(names);
3967 if (common) 3964 if (common)
3968 this._enumValueToNames[value] = [common]; 3965 this._enumValueToNames[value] = [common];
3969 else 3966 else
3970 this._enumValueToNames[value] = names.sort(); 3967 this._enumValueToNames[value] = names.sort();
3971 } 3968 }
3972 } 3969 }
3973 }, 3970 },
3974 3971
3975 /** 3972 /**
3976 * @return {WebGLRenderingContext} 3973 * @return {?WebGLRenderingContext}
3977 */ 3974 */
3978 _createUninstrumentedWebGLRenderingContext: function() 3975 _createUninstrumentedWebGLRenderingContext: function()
3979 { 3976 {
3980 var canvas = /** @type {HTMLCanvasElement} */ (inspectedWindow.document. createElement("canvas")); 3977 var canvas = /** @type {!HTMLCanvasElement} */ (inspectedWindow.document .createElement("canvas"));
3981 var contextIds = ["experimental-webgl", "webkit-3d", "3d"]; 3978 var contextIds = ["experimental-webgl", "webkit-3d", "3d"];
3982 for (var i = 0, contextId; contextId = contextIds[i]; ++i) { 3979 for (var i = 0, contextId; contextId = contextIds[i]; ++i) {
3983 var context = canvas.getContext(contextId); 3980 var context = canvas.getContext(contextId);
3984 if (context) 3981 if (context)
3985 return /** @type {WebGLRenderingContext} */ (Resource.wrappedObj ect(context)); 3982 return /** @type {!WebGLRenderingContext} */ (Resource.wrappedOb ject(context));
3986 } 3983 }
3987 return null; 3984 return null;
3988 }, 3985 },
3989 3986
3990 __proto__: CallFormatter.prototype 3987 __proto__: CallFormatter.prototype
3991 } 3988 }
3992 3989
3993 CallFormatter.register("CanvasRenderingContext2D", new CallFormatter(CanvasRende ringContext2DResource.DrawingMethods)); 3990 CallFormatter.register("CanvasRenderingContext2D", new CallFormatter(CanvasRende ringContext2DResource.DrawingMethods));
3994 CallFormatter.register("WebGLRenderingContext", new WebGLCallFormatter(WebGLRend eringContextResource.DrawingMethods)); 3991 CallFormatter.register("WebGLRenderingContext", new WebGLCallFormatter(WebGLRend eringContextResource.DrawingMethods));
3995 3992
3996 /** 3993 /**
3997 * @constructor 3994 * @constructor
3998 */ 3995 */
3999 function TraceLog() 3996 function TraceLog()
4000 { 3997 {
4001 /** @type {!Array.<!ReplayableCall>} */ 3998 /** @type {!Array.<!ReplayableCall>} */
4002 this._replayableCalls = []; 3999 this._replayableCalls = [];
4003 /** @type {!Cache.<ReplayableResource>} */ 4000 /** @type {!Cache.<!ReplayableResource>} */
4004 this._replayablesCache = new Cache(); 4001 this._replayablesCache = new Cache();
4005 /** @type {!Object.<number, boolean>} */ 4002 /** @type {!Object.<number, boolean>} */
4006 this._frameEndCallIndexes = {}; 4003 this._frameEndCallIndexes = {};
4007 /** @type {!Object.<number, boolean>} */ 4004 /** @type {!Object.<number, boolean>} */
4008 this._resourcesCreatedInThisTraceLog = {}; 4005 this._resourcesCreatedInThisTraceLog = {};
4009 } 4006 }
4010 4007
4011 TraceLog.prototype = { 4008 TraceLog.prototype = {
4012 /** 4009 /**
4013 * @return {number} 4010 * @return {number}
4014 */ 4011 */
4015 size: function() 4012 size: function()
4016 { 4013 {
4017 return this._replayableCalls.length; 4014 return this._replayableCalls.length;
4018 }, 4015 },
4019 4016
4020 /** 4017 /**
4021 * @return {!Array.<!ReplayableCall>} 4018 * @return {!Array.<!ReplayableCall>}
4022 */ 4019 */
4023 replayableCalls: function() 4020 replayableCalls: function()
4024 { 4021 {
4025 return this._replayableCalls; 4022 return this._replayableCalls;
4026 }, 4023 },
4027 4024
4028 /** 4025 /**
4029 * @param {number} id 4026 * @param {number} id
4030 * @return {ReplayableResource|undefined} 4027 * @return {!ReplayableResource|undefined}
4031 */ 4028 */
4032 replayableResource: function(id) 4029 replayableResource: function(id)
4033 { 4030 {
4034 return this._replayablesCache.get(id); 4031 return this._replayablesCache.get(id);
4035 }, 4032 },
4036 4033
4037 /** 4034 /**
4038 * @param {number} resourceId 4035 * @param {number} resourceId
4039 * @return {boolean} 4036 * @return {boolean}
4040 */ 4037 */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
4082 /** 4079 /**
4083 * @constructor 4080 * @constructor
4084 * @param {!TraceLog} traceLog 4081 * @param {!TraceLog} traceLog
4085 */ 4082 */
4086 function TraceLogPlayer(traceLog) 4083 function TraceLogPlayer(traceLog)
4087 { 4084 {
4088 /** @type {!TraceLog} */ 4085 /** @type {!TraceLog} */
4089 this._traceLog = traceLog; 4086 this._traceLog = traceLog;
4090 /** @type {number} */ 4087 /** @type {number} */
4091 this._nextReplayStep = 0; 4088 this._nextReplayStep = 0;
4092 /** @type {!Cache.<Resource>} */ 4089 /** @type {!Cache.<!Resource>} */
4093 this._replayWorldCache = new Cache(); 4090 this._replayWorldCache = new Cache();
4094 } 4091 }
4095 4092
4096 TraceLogPlayer.prototype = { 4093 TraceLogPlayer.prototype = {
4097 /** 4094 /**
4098 * @return {!TraceLog} 4095 * @return {!TraceLog}
4099 */ 4096 */
4100 traceLog: function() 4097 traceLog: function()
4101 { 4098 {
4102 return this._traceLog; 4099 return this._traceLog;
4103 }, 4100 },
4104 4101
4105 /** 4102 /**
4106 * @param {number} id 4103 * @param {number} id
4107 * @return {Resource|undefined} 4104 * @return {!Resource|undefined}
4108 */ 4105 */
4109 replayWorldResource: function(id) 4106 replayWorldResource: function(id)
4110 { 4107 {
4111 return this._replayWorldCache.get(id); 4108 return this._replayWorldCache.get(id);
4112 }, 4109 },
4113 4110
4114 /** 4111 /**
4115 * @return {number} 4112 * @return {number}
4116 */ 4113 */
4117 nextReplayStep: function() 4114 nextReplayStep: function()
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 }; 4154 };
4158 }, 4155 },
4159 4156
4160 /** 4157 /**
4161 * @param {number} stepNum 4158 * @param {number} stepNum
4162 */ 4159 */
4163 _replayCallArguments: function(stepNum) 4160 _replayCallArguments: function(stepNum)
4164 { 4161 {
4165 /** 4162 /**
4166 * @param {*} obj 4163 * @param {*} obj
4164 * @this {TraceLogPlayer}
4167 */ 4165 */
4168 function replayIfNotCreatedInThisTraceLog(obj) 4166 function replayIfNotCreatedInThisTraceLog(obj)
4169 { 4167 {
4170 if (!(obj instanceof ReplayableResource)) 4168 if (!(obj instanceof ReplayableResource))
4171 return; 4169 return;
4172 var replayableResource = /** @type {!ReplayableResource} */ (obj); 4170 var replayableResource = /** @type {!ReplayableResource} */ (obj);
4173 if (!this._traceLog.createdInThisTraceLog(replayableResource.id())) 4171 if (!this._traceLog.createdInThisTraceLog(replayableResource.id()))
4174 replayableResource.replay(this._replayWorldCache) 4172 replayableResource.replay(this._replayWorldCache)
4175 } 4173 }
4176 var replayableCalls = this._traceLog.replayableCalls(); 4174 var replayableCalls = this._traceLog.replayableCalls();
(...skipping 18 matching lines...) Expand all
4195 ResourceTrackingManager.prototype = { 4193 ResourceTrackingManager.prototype = {
4196 /** 4194 /**
4197 * @return {boolean} 4195 * @return {boolean}
4198 */ 4196 */
4199 capturing: function() 4197 capturing: function()
4200 { 4198 {
4201 return this._capturing; 4199 return this._capturing;
4202 }, 4200 },
4203 4201
4204 /** 4202 /**
4205 * @return {TraceLog} 4203 * @return {?TraceLog}
4206 */ 4204 */
4207 lastTraceLog: function() 4205 lastTraceLog: function()
4208 { 4206 {
4209 return this._lastTraceLog; 4207 return this._lastTraceLog;
4210 }, 4208 },
4211 4209
4212 /** 4210 /**
4213 * @param {!Resource} resource 4211 * @param {!Resource} resource
4214 */ 4212 */
4215 registerResource: function(resource) 4213 registerResource: function(resource)
4216 { 4214 {
4217 resource.setManager(this); 4215 resource.setManager(this);
4218 }, 4216 },
4219 4217
4220 startCapturing: function() 4218 startCapturing: function()
4221 { 4219 {
4222 if (!this._capturing) 4220 if (!this._capturing)
4223 this._lastTraceLog = new TraceLog(); 4221 this._lastTraceLog = new TraceLog();
4224 this._capturing = true; 4222 this._capturing = true;
4225 this._stopCapturingOnFrameEnd = false; 4223 this._stopCapturingOnFrameEnd = false;
4226 }, 4224 },
4227 4225
4228 /** 4226 /**
4229 * @param {TraceLog=} traceLog 4227 * @param {!TraceLog=} traceLog
4230 */ 4228 */
4231 stopCapturing: function(traceLog) 4229 stopCapturing: function(traceLog)
4232 { 4230 {
4233 if (traceLog && this._lastTraceLog !== traceLog) 4231 if (traceLog && this._lastTraceLog !== traceLog)
4234 return; 4232 return;
4235 this._capturing = false; 4233 this._capturing = false;
4236 this._stopCapturingOnFrameEnd = false; 4234 this._stopCapturingOnFrameEnd = false;
4237 if (this._lastTraceLog) 4235 if (this._lastTraceLog)
4238 this._lastTraceLog.addFrameEndMark(); 4236 this._lastTraceLog.addFrameEndMark();
4239 }, 4237 },
(...skipping 10 matching lines...) Expand all
4250 4248
4251 captureFrame: function() 4249 captureFrame: function()
4252 { 4250 {
4253 this._lastTraceLog = new TraceLog(); 4251 this._lastTraceLog = new TraceLog();
4254 this._capturing = true; 4252 this._capturing = true;
4255 this._stopCapturingOnFrameEnd = true; 4253 this._stopCapturingOnFrameEnd = true;
4256 }, 4254 },
4257 4255
4258 /** 4256 /**
4259 * @param {!Resource} resource 4257 * @param {!Resource} resource
4260 * @param {Array|Arguments} args 4258 * @param {!Array|!Arguments} args
4261 */ 4259 */
4262 captureArguments: function(resource, args) 4260 captureArguments: function(resource, args)
4263 { 4261 {
4264 if (!this._capturing) 4262 if (!this._capturing)
4265 return; 4263 return;
4266 this._lastTraceLog.captureResource(resource); 4264 this._lastTraceLog.captureResource(resource);
4267 for (var i = 0, n = args.length; i < n; ++i) { 4265 for (var i = 0, n = args.length; i < n; ++i) {
4268 var res = Resource.forObject(args[i]); 4266 var res = Resource.forObject(args[i]);
4269 if (res) 4267 if (res)
4270 this._lastTraceLog.captureResource(res); 4268 this._lastTraceLog.captureResource(res);
(...skipping 22 matching lines...) Expand all
4293 4291
4294 /** 4292 /**
4295 * @constructor 4293 * @constructor
4296 */ 4294 */
4297 var InjectedCanvasModule = function() 4295 var InjectedCanvasModule = function()
4298 { 4296 {
4299 /** @type {!ResourceTrackingManager} */ 4297 /** @type {!ResourceTrackingManager} */
4300 this._manager = new ResourceTrackingManager(); 4298 this._manager = new ResourceTrackingManager();
4301 /** @type {number} */ 4299 /** @type {number} */
4302 this._lastTraceLogId = 0; 4300 this._lastTraceLogId = 0;
4303 /** @type {!Object.<string, TraceLog>} */ 4301 /** @type {!Object.<string, !TraceLog>} */
4304 this._traceLogs = {}; 4302 this._traceLogs = {};
4305 /** @type {!Object.<string, TraceLogPlayer>} */ 4303 /** @type {!Object.<string, !TraceLogPlayer>} */
4306 this._traceLogPlayers = {}; 4304 this._traceLogPlayers = {};
4307 } 4305 }
4308 4306
4309 InjectedCanvasModule.prototype = { 4307 InjectedCanvasModule.prototype = {
4310 /** 4308 /**
4311 * @param {!WebGLRenderingContext} glContext 4309 * @param {!WebGLRenderingContext} glContext
4312 * @return {Object} 4310 * @return {!Object}
4313 */ 4311 */
4314 wrapWebGLContext: function(glContext) 4312 wrapWebGLContext: function(glContext)
4315 { 4313 {
4316 var resource = Resource.forObject(glContext) || new WebGLRenderingContex tResource(glContext); 4314 var resource = Resource.forObject(glContext) || new WebGLRenderingContex tResource(glContext);
4317 this._manager.registerResource(resource); 4315 this._manager.registerResource(resource);
4318 return resource.proxyObject(); 4316 return resource.proxyObject();
4319 }, 4317 },
4320 4318
4321 /** 4319 /**
4322 * @param {!CanvasRenderingContext2D} context 4320 * @param {!CanvasRenderingContext2D} context
4323 * @return {Object} 4321 * @return {!Object}
4324 */ 4322 */
4325 wrapCanvas2DContext: function(context) 4323 wrapCanvas2DContext: function(context)
4326 { 4324 {
4327 var resource = Resource.forObject(context) || new CanvasRenderingContext 2DResource(context); 4325 var resource = Resource.forObject(context) || new CanvasRenderingContext 2DResource(context);
4328 this._manager.registerResource(resource); 4326 this._manager.registerResource(resource);
4329 return resource.proxyObject(); 4327 return resource.proxyObject();
4330 }, 4328 },
4331 4329
4332 /** 4330 /**
4333 * @return {CanvasAgent.TraceLogId} 4331 * @return {!CanvasAgent.TraceLogId}
4334 */ 4332 */
4335 captureFrame: function() 4333 captureFrame: function()
4336 { 4334 {
4337 return this._callStartCapturingFunction(this._manager.captureFrame); 4335 return this._callStartCapturingFunction(this._manager.captureFrame);
4338 }, 4336 },
4339 4337
4340 /** 4338 /**
4341 * @return {CanvasAgent.TraceLogId} 4339 * @return {!CanvasAgent.TraceLogId}
4342 */ 4340 */
4343 startCapturing: function() 4341 startCapturing: function()
4344 { 4342 {
4345 return this._callStartCapturingFunction(this._manager.startCapturing); 4343 return this._callStartCapturingFunction(this._manager.startCapturing);
4346 }, 4344 },
4347 4345
4348 markFrameEnd: function() 4346 markFrameEnd: function()
4349 { 4347 {
4350 this._manager.markFrameEnd(); 4348 this._manager.markFrameEnd();
4351 }, 4349 },
4352 4350
4353 /** 4351 /**
4354 * @param {function(this:ResourceTrackingManager)} func 4352 * @param {function(this:ResourceTrackingManager)} func
4355 * @return {CanvasAgent.TraceLogId} 4353 * @return {!CanvasAgent.TraceLogId}
4356 */ 4354 */
4357 _callStartCapturingFunction: function(func) 4355 _callStartCapturingFunction: function(func)
4358 { 4356 {
4359 var oldTraceLog = this._manager.lastTraceLog(); 4357 var oldTraceLog = this._manager.lastTraceLog();
4360 func.call(this._manager); 4358 func.call(this._manager);
4361 var traceLog = this._manager.lastTraceLog(); 4359 var traceLog = /** @type {!TraceLog} */ (this._manager.lastTraceLog());
4362 if (traceLog === oldTraceLog) { 4360 if (traceLog === oldTraceLog) {
4363 for (var id in this._traceLogs) { 4361 for (var id in this._traceLogs) {
4364 if (this._traceLogs[id] === traceLog) 4362 if (this._traceLogs[id] === traceLog)
4365 return id; 4363 return id;
4366 } 4364 }
4367 } 4365 }
4368 var id = this._makeTraceLogId(); 4366 var id = this._makeTraceLogId();
4369 this._traceLogs[id] = traceLog; 4367 this._traceLogs[id] = traceLog;
4370 return id; 4368 return id;
4371 }, 4369 },
4372 4370
4373 /** 4371 /**
4374 * @param {CanvasAgent.TraceLogId} id 4372 * @param {!CanvasAgent.TraceLogId} id
4375 */ 4373 */
4376 stopCapturing: function(id) 4374 stopCapturing: function(id)
4377 { 4375 {
4378 var traceLog = this._traceLogs[id]; 4376 var traceLog = this._traceLogs[id];
4379 if (traceLog) 4377 if (traceLog)
4380 this._manager.stopCapturing(traceLog); 4378 this._manager.stopCapturing(traceLog);
4381 }, 4379 },
4382 4380
4383 /** 4381 /**
4384 * @param {CanvasAgent.TraceLogId} id 4382 * @param {!CanvasAgent.TraceLogId} id
4385 */ 4383 */
4386 dropTraceLog: function(id) 4384 dropTraceLog: function(id)
4387 { 4385 {
4388 var traceLog = this._traceLogs[id]; 4386 var traceLog = this._traceLogs[id];
4389 if (traceLog) 4387 if (traceLog)
4390 this._manager.dropTraceLog(traceLog); 4388 this._manager.dropTraceLog(traceLog);
4391 delete this._traceLogs[id]; 4389 delete this._traceLogs[id];
4392 delete this._traceLogPlayers[id]; 4390 delete this._traceLogPlayers[id];
4393 injectedScript.releaseObjectGroup(id); 4391 injectedScript.releaseObjectGroup(id);
4394 }, 4392 },
4395 4393
4396 /** 4394 /**
4397 * @param {CanvasAgent.TraceLogId} id 4395 * @param {!CanvasAgent.TraceLogId} id
4398 * @param {number=} startOffset 4396 * @param {number=} startOffset
4399 * @param {number=} maxLength 4397 * @param {number=} maxLength
4400 * @return {!CanvasAgent.TraceLog|string} 4398 * @return {!CanvasAgent.TraceLog|string}
4401 */ 4399 */
4402 traceLog: function(id, startOffset, maxLength) 4400 traceLog: function(id, startOffset, maxLength)
4403 { 4401 {
4404 var traceLog = this._traceLogs[id]; 4402 var traceLog = this._traceLogs[id];
4405 if (!traceLog) 4403 if (!traceLog)
4406 return "Error: Trace log with the given ID not found."; 4404 return "Error: Trace log with the given ID not found.";
4407 4405
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4445 result.calls.push(item); 4443 result.calls.push(item);
4446 if (!contextIds[item.contextId]) { 4444 if (!contextIds[item.contextId]) {
4447 contextIds[item.contextId] = true; 4445 contextIds[item.contextId] = true;
4448 result.contexts.push(CallFormatter.forResource(resource).formatV alue(contextResource)); 4446 result.contexts.push(CallFormatter.forResource(resource).formatV alue(contextResource));
4449 } 4447 }
4450 } 4448 }
4451 return result; 4449 return result;
4452 }, 4450 },
4453 4451
4454 /** 4452 /**
4455 * @param {CanvasAgent.TraceLogId} traceLogId 4453 * @param {!CanvasAgent.TraceLogId} traceLogId
4456 * @param {number} stepNo 4454 * @param {number} stepNo
4457 * @return {{resourceState: !CanvasAgent.ResourceState, replayTime: number}| string} 4455 * @return {{resourceState: !CanvasAgent.ResourceState, replayTime: number}| string}
4458 */ 4456 */
4459 replayTraceLog: function(traceLogId, stepNo) 4457 replayTraceLog: function(traceLogId, stepNo)
4460 { 4458 {
4461 var traceLog = this._traceLogs[traceLogId]; 4459 var traceLog = this._traceLogs[traceLogId];
4462 if (!traceLog) 4460 if (!traceLog)
4463 return "Error: Trace log with the given ID not found."; 4461 return "Error: Trace log with the given ID not found.";
4464 this._traceLogPlayers[traceLogId] = this._traceLogPlayers[traceLogId] || new TraceLogPlayer(traceLog); 4462 this._traceLogPlayers[traceLogId] = this._traceLogPlayers[traceLogId] || new TraceLogPlayer(traceLog);
4465 injectedScript.releaseObjectGroup(traceLogId); 4463 injectedScript.releaseObjectGroup(traceLogId);
4466 4464
4467 var replayResult = this._traceLogPlayers[traceLogId].stepTo(stepNo); 4465 var replayResult = this._traceLogPlayers[traceLogId].stepTo(stepNo);
4468 var resource = replayResult.lastCall.resource(); 4466 var resource = replayResult.lastCall.resource();
4469 var dataURL = resource.toDataURL(); 4467 var dataURL = resource.toDataURL();
4470 if (!dataURL) { 4468 if (!dataURL) {
4471 resource = resource.contextResource(); 4469 resource = resource.contextResource();
4472 dataURL = resource.toDataURL(); 4470 dataURL = resource.toDataURL();
4473 } 4471 }
4474 return { 4472 return {
4475 resourceState: this._makeResourceState(resource.id(), traceLogId, re source, dataURL), 4473 resourceState: this._makeResourceState(resource.id(), traceLogId, re source, dataURL),
4476 replayTime: replayResult.replayTime 4474 replayTime: replayResult.replayTime
4477 }; 4475 };
4478 }, 4476 },
4479 4477
4480 /** 4478 /**
4481 * @param {CanvasAgent.TraceLogId} traceLogId 4479 * @param {!CanvasAgent.TraceLogId} traceLogId
4482 * @param {CanvasAgent.ResourceId} stringResourceId 4480 * @param {!CanvasAgent.ResourceId} stringResourceId
4483 * @return {!CanvasAgent.ResourceState|string} 4481 * @return {!CanvasAgent.ResourceState|string}
4484 */ 4482 */
4485 resourceState: function(traceLogId, stringResourceId) 4483 resourceState: function(traceLogId, stringResourceId)
4486 { 4484 {
4487 var traceLog = this._traceLogs[traceLogId]; 4485 var traceLog = this._traceLogs[traceLogId];
4488 if (!traceLog) 4486 if (!traceLog)
4489 return "Error: Trace log with the given ID not found."; 4487 return "Error: Trace log with the given ID not found.";
4490 4488
4491 var parsedStringId1 = this._parseStringId(traceLogId); 4489 var parsedStringId1 = this._parseStringId(traceLogId);
4492 var parsedStringId2 = this._parseStringId(stringResourceId); 4490 var parsedStringId2 = this._parseStringId(stringResourceId);
4493 if (parsedStringId1.injectedScriptId !== parsedStringId2.injectedScriptI d) 4491 if (parsedStringId1.injectedScriptId !== parsedStringId2.injectedScriptI d)
4494 return "Error: Both IDs must point to the same injected script."; 4492 return "Error: Both IDs must point to the same injected script.";
4495 4493
4496 var resourceId = parsedStringId2.resourceId; 4494 var resourceId = parsedStringId2.resourceId;
4497 if (!resourceId) 4495 if (!resourceId)
4498 return "Error: Wrong resource ID: " + stringResourceId; 4496 return "Error: Wrong resource ID: " + stringResourceId;
4499 4497
4500 var traceLogPlayer = this._traceLogPlayers[traceLogId]; 4498 var traceLogPlayer = this._traceLogPlayers[traceLogId];
4501 var resource = traceLogPlayer && traceLogPlayer.replayWorldResource(reso urceId); 4499 var resource = traceLogPlayer && traceLogPlayer.replayWorldResource(reso urceId);
4502 return this._makeResourceState(resourceId, traceLogId, resource); 4500 return this._makeResourceState(resourceId, traceLogId, resource);
4503 }, 4501 },
4504 4502
4505 /** 4503 /**
4506 * @param {CanvasAgent.TraceLogId} traceLogId 4504 * @param {!CanvasAgent.TraceLogId} traceLogId
4507 * @param {number} callIndex 4505 * @param {number} callIndex
4508 * @param {number} argumentIndex 4506 * @param {number} argumentIndex
4509 * @param {string} objectGroup 4507 * @param {string} objectGroup
4510 * @return {{result:(!RuntimeAgent.RemoteObject|undefined), resourceState:(! CanvasAgent.ResourceState|undefined)}|string} 4508 * @return {{result:(!RuntimeAgent.RemoteObject|undefined), resourceState:(! CanvasAgent.ResourceState|undefined)}|string}
4511 */ 4509 */
4512 evaluateTraceLogCallArgument: function(traceLogId, callIndex, argumentIndex, objectGroup) 4510 evaluateTraceLogCallArgument: function(traceLogId, callIndex, argumentIndex, objectGroup)
4513 { 4511 {
4514 var traceLog = this._traceLogs[traceLogId]; 4512 var traceLog = this._traceLogs[traceLogId];
4515 if (!traceLog) 4513 if (!traceLog)
4516 return "Error: Trace log with the given ID not found."; 4514 return "Error: Trace log with the given ID not found.";
(...skipping 19 matching lines...) Expand all
4536 var resource = traceLogPlayer && traceLogPlayer.replayWorldResource( value.id()); 4534 var resource = traceLogPlayer && traceLogPlayer.replayWorldResource( value.id());
4537 var resourceState = this._makeResourceState(value.id(), traceLogId, resource); 4535 var resourceState = this._makeResourceState(value.id(), traceLogId, resource);
4538 return { resourceState: resourceState }; 4536 return { resourceState: resourceState };
4539 } 4537 }
4540 4538
4541 var remoteObject = injectedScript.wrapObject(value, objectGroup, true, f alse); 4539 var remoteObject = injectedScript.wrapObject(value, objectGroup, true, f alse);
4542 return { result: remoteObject }; 4540 return { result: remoteObject };
4543 }, 4541 },
4544 4542
4545 /** 4543 /**
4546 * @return {CanvasAgent.TraceLogId} 4544 * @return {!CanvasAgent.TraceLogId}
4547 */ 4545 */
4548 _makeTraceLogId: function() 4546 _makeTraceLogId: function()
4549 { 4547 {
4550 return "{\"injectedScriptId\":" + injectedScriptId + ",\"traceLogId\":" + (++this._lastTraceLogId) + "}"; 4548 return "{\"injectedScriptId\":" + injectedScriptId + ",\"traceLogId\":" + (++this._lastTraceLogId) + "}";
4551 }, 4549 },
4552 4550
4553 /** 4551 /**
4554 * @param {number} resourceId 4552 * @param {number} resourceId
4555 * @param {CanvasAgent.TraceLogId} traceLogId 4553 * @param {!CanvasAgent.TraceLogId} traceLogId
4556 * @param {Resource|undefined} resource 4554 * @param {?Resource=} resource
4557 * @param {string=} overrideImageURL 4555 * @param {string=} overrideImageURL
4558 * @return {!CanvasAgent.ResourceState} 4556 * @return {!CanvasAgent.ResourceState}
4559 */ 4557 */
4560 _makeResourceState: function(resourceId, traceLogId, resource, overrideImage URL) 4558 _makeResourceState: function(resourceId, traceLogId, resource, overrideImage URL)
4561 { 4559 {
4562 var result = { 4560 var result = {
4563 id: CallFormatter.makeStringResourceId(resourceId), 4561 id: CallFormatter.makeStringResourceId(resourceId),
4564 traceLogId: traceLogId 4562 traceLogId: traceLogId
4565 }; 4563 };
4566 if (resource) { 4564 if (resource) {
(...skipping 10 matching lines...) Expand all
4577 _parseStringId: function(stringId) 4575 _parseStringId: function(stringId)
4578 { 4576 {
4579 return InjectedScriptHost.evaluate("(" + stringId + ")"); 4577 return InjectedScriptHost.evaluate("(" + stringId + ")");
4580 } 4578 }
4581 } 4579 }
4582 4580
4583 var injectedCanvasModule = new InjectedCanvasModule(); 4581 var injectedCanvasModule = new InjectedCanvasModule();
4584 return injectedCanvasModule; 4582 return injectedCanvasModule;
4585 4583
4586 }) 4584 })
OLDNEW
« no previous file with comments | « no previous file | Source/core/inspector/InjectedScriptSource.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698