Changeset 140142 in webkit
- Timestamp:
- Jan 18, 2013 7:12:17 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r140140 r140142 1 2013-01-18 Andrey Adaikin <aandrey@chromium.org> 2 3 Web Inspector: [Canvas] introduce Resource.toDataURL 4 https://bugs.webkit.org/show_bug.cgi?id=107019 5 6 Reviewed by Pavel Feldman. 7 8 Resource.toDataURL will return string data url representation of a resource, if applicable. 9 For example, for a rendering context resource (2D or WebGL) it will return canvas.toDataURL(). 10 11 * inspector/InjectedScriptCanvasModuleSource.js: 12 (.): 13 1 14 2013-01-18 Csaba Osztrogonác <ossy@webkit.org> 2 15 -
trunk/Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js
r139729 r140142 93 93 // FIXME: Maybe this is a bug in WebKit core? 94 94 if (/^blob:/.test(img.src)) 95 return TypeUtils.cloneIntoCanvas(img , img.width, img.height);95 return TypeUtils.cloneIntoCanvas(img); 96 96 return img.cloneNode(true); 97 97 } 98 98 99 99 if (obj instanceof HTMLCanvasElement) 100 return TypeUtils.cloneIntoCanvas(obj , obj.width, obj.height);100 return TypeUtils.cloneIntoCanvas(obj); 101 101 102 102 if (obj instanceof HTMLVideoElement) … … 118 118 /** 119 119 * @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} obj 120 * @param {number } width121 * @param {number } height120 * @param {number=} width 121 * @param {number=} height 122 122 * @return {HTMLCanvasElement} 123 123 */ … … 125 125 { 126 126 var canvas = /** @type {HTMLCanvasElement} */ (inspectedWindow.document.createElement("canvas")); 127 canvas.width = width ;128 canvas.height = height ;127 canvas.width = width || +obj.width; 128 canvas.height = height || +obj.height; 129 129 var context = /** @type {CanvasRenderingContext2D} */ (Resource.wrappedObject(canvas.getContext("2d"))); 130 130 context.drawImage(obj, 0, 0); … … 735 735 console.assert(result, "Failed to find context resource for " + this._name + "@" + this._kindId); 736 736 return result; 737 }, 738 739 /** 740 * @return {string} 741 */ 742 toDataURL: function() 743 { 744 var contextResource = this.contextResource(); 745 return contextResource === this ? "" : contextResource.toDataURL(); 737 746 }, 738 747 … … 1600 1609 * @extends {ContextResource} 1601 1610 * @param {!WebGLRenderingContext} glContext 1602 * @param {function():WebGLRenderingContext} replayContextCallback 1603 */ 1604 function WebGLRenderingContextResource(glContext, replayContextCallback) 1611 */ 1612 function WebGLRenderingContextResource(glContext) 1605 1613 { 1606 1614 ContextResource.call(this, glContext, "WebGLRenderingContext"); 1607 this._replayContextCallback = replayContextCallback;1608 1615 /** @type {Object.<number, boolean>} */ 1609 1616 this._customErrors = null; … … 1720 1727 1721 1728 /** 1729 * @override 1730 * @return {string} 1731 */ 1732 toDataURL: function() 1733 { 1734 return this.wrappedObject().canvas.toDataURL(); 1735 }, 1736 1737 /** 1722 1738 * @return {Array.<number>} 1723 1739 */ … … 1809 1825 { 1810 1826 var gl = this.wrappedObject(); 1811 data.replayContextCallback = this._replayContextCallback; 1827 data.originalCanvas = gl.canvas; 1828 data.originalContextAttributes = gl.getContextAttributes(); 1812 1829 data.extensions = TypeUtils.cloneObject(this._extensions); 1813 1830 … … 1864 1881 _doReplayCalls: function(data, cache) 1865 1882 { 1866 this._replayContextCallback = data.replayContextCallback;1867 1883 this._customErrors = null; 1868 1884 this._extensions = TypeUtils.cloneObject(data.extensions) || {}; 1869 1885 1870 var gl = /** @type {!WebGLRenderingContext} */ (Resource.wrappedObject(this._replayContextCallback())); 1886 var canvas = data.originalCanvas.cloneNode(true); 1887 var replayContext = null; 1888 var contextIds = ["experimental-webgl", "webkit-3d", "3d"]; 1889 for (var i = 0, contextId; contextId = contextIds[i]; ++i) { 1890 replayContext = canvas.getContext(contextId, data.originalContextAttributes); 1891 if (replayContext) 1892 break; 1893 } 1894 1895 var gl = /** @type {!WebGLRenderingContext} */ (Resource.wrappedObject(replayContext)); 1871 1896 this.setWrappedObject(gl); 1872 1897 … … 2187 2212 * @extends {ContextResource} 2188 2213 * @param {!CanvasRenderingContext2D} context 2189 * @param {function():CanvasRenderingContext2D} replayContextCallback 2190 */ 2191 function CanvasRenderingContext2DResource(context, replayContextCallback) 2214 */ 2215 function CanvasRenderingContext2DResource(context) 2192 2216 { 2193 2217 ContextResource.call(this, context, "CanvasRenderingContext2D"); 2194 this._replayContextCallback = replayContextCallback;2195 2218 } 2196 2219 … … 2261 2284 /** 2262 2285 * @override 2263 * @param {!Object} data 2264 * @param {!Cache} cache 2265 */ 2266 _populateReplayableData: function(data, cache) 2267 { 2268 data.replayContextCallback = this._replayContextCallback; 2269 data.currentAttributes = this._currentAttributesState(); 2270 var ctx = this.wrappedObject(); 2271 try { 2272 data.originalImageData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height); 2273 } catch (e) { 2274 console.error("ASSERT_NOT_REACHED: getImageData failed.", e); 2275 } 2286 * @return {string} 2287 */ 2288 toDataURL: function() 2289 { 2290 return this.wrappedObject().canvas.toDataURL(); 2276 2291 }, 2277 2292 … … 2281 2296 * @param {!Cache} cache 2282 2297 */ 2298 _populateReplayableData: function(data, cache) 2299 { 2300 data.currentAttributes = this._currentAttributesState(); 2301 data.originalCanvasCloned = TypeUtils.cloneIntoCanvas(this.wrappedObject().canvas); 2302 }, 2303 2304 /** 2305 * @override 2306 * @param {!Object} data 2307 * @param {!Cache} cache 2308 */ 2283 2309 _doReplayCalls: function(data, cache) 2284 2310 { 2285 this._replayContextCallback = data.replayContextCallback; 2286 2287 var ctx = /** @type {!CanvasRenderingContext2D} */ (Resource.wrappedObject(this._replayContextCallback())); 2311 var canvas = TypeUtils.cloneIntoCanvas(data.originalCanvasCloned); 2312 var ctx = /** @type {!CanvasRenderingContext2D} */ (Resource.wrappedObject(canvas.getContext("2d"))); 2288 2313 this.setWrappedObject(ctx); 2289 2314 2290 if (data.originalImageData) {2291 try {2292 ctx.putImageData(data.originalImageData, 0, 0);2293 } catch (e) {2294 console.error("ASSERT_NOT_REACHED: putImageData failed.", e);2295 }2296 }2297 2298 2315 for (var i = 0, n = data.calls.length; i < n; ++i) { 2299 var replayableCall = data.calls[i];2316 var replayableCall = /** @type {ReplayableCall} */ (data.calls[i]); 2300 2317 if (replayableCall.functionName() === "save") 2301 2318 this._applyAttributesState(replayableCall.attachment("canvas2dAttributesState")); … … 2610 2627 * @constructor 2611 2628 * @param {!TraceLog} traceLog 2612 * @param {function()=} resetCallback 2613 */ 2614 function TraceLogPlayer(traceLog, resetCallback) 2629 */ 2630 function TraceLogPlayer(traceLog) 2615 2631 { 2616 2632 /** @type {!TraceLog} */ … … 2620 2636 /** @type {!Cache} */ 2621 2637 this._replayWorldCache = new Cache(); 2622 /** @type {function()|undefined} */2623 this._resetCallback = resetCallback;2624 2638 } 2625 2639 … … 2645 2659 this._nextReplayStep = 0; 2646 2660 this._replayWorldCache.reset(); 2647 if (this._resetCallback)2648 this._resetCallback();2649 2661 }, 2650 2662 … … 2800 2812 /** @type {!Object.<string, TraceLog>} */ 2801 2813 this._traceLogs = {}; 2802 /** @type {TraceLogPlayer} */ 2803 this._traceLogPlayer = null; 2804 /** @type {!Array.<{type: string, context: Object}>} */ 2805 this._replayContexts = []; 2814 /** @type {!Object.<string, TraceLogPlayer>} */ 2815 this._traceLogPlayers = {}; 2806 2816 } 2807 2817 … … 2813 2823 wrapWebGLContext: function(glContext) 2814 2824 { 2815 var resource = Resource.forObject(glContext) || new WebGLRenderingContextResource(glContext , this._constructWebGLReplayContext.bind(this, glContext));2825 var resource = Resource.forObject(glContext) || new WebGLRenderingContextResource(glContext); 2816 2826 this._manager.registerResource(resource); 2817 2827 return resource.proxyObject(); … … 2824 2834 wrapCanvas2DContext: function(context) 2825 2835 { 2826 var resource = Resource.forObject(context) || new CanvasRenderingContext2DResource(context , this._constructCanvas2DReplayContext.bind(this, context));2836 var resource = Resource.forObject(context) || new CanvasRenderingContext2DResource(context); 2827 2837 this._manager.registerResource(resource); 2828 2838 return resource.proxyObject(); … … 2881 2891 { 2882 2892 this.stopCapturing(id); 2883 if (this._traceLogPlayer && this._traceLogPlayer.traceLog() === this._traceLogs[id]) {2884 this._traceLogPlayer = null;2885 this._replayContexts = [];2886 }2887 2893 delete this._traceLogs[id]; 2894 delete this._traceLogPlayers[id]; 2888 2895 }, 2889 2896 … … 2955 2962 if (!traceLog) 2956 2963 return ""; 2957 if (!this._traceLogPlayer || this._traceLogPlayer.traceLog() !== traceLog) { 2958 this._replayContexts = []; 2959 this._traceLogPlayer = new TraceLogPlayer(traceLog, this._onTraceLogPlayerReset.bind(this)); 2960 } 2961 var lastCall = this._traceLogPlayer.stepTo(stepNo); 2962 if (!this._replayContexts.length) { 2963 console.error("ASSERT_NOT_REACHED: replayTraceLog failed to create a replay canvas?!"); 2964 return ""; 2965 } 2966 // FIXME: Support replaying several canvases simultaneously. 2967 var lastCallResourceContext = Resource.wrappedObject(lastCall.resource()); 2968 for (var i = 0, n = this._replayContexts.length; i < n; ++i) { 2969 var context = this._replayContexts[i].context; 2970 if (lastCallResourceContext === context) 2971 return context.canvas.toDataURL(); 2972 } 2973 console.assert("ASSERT_NOT_REACHED: replayTraceLog failed to match the replaying canvas?!"); 2974 return this._replayContexts[0].context.canvas.toDataURL(); 2964 this._traceLogPlayers[id] = this._traceLogPlayers[id] || new TraceLogPlayer(traceLog); 2965 var lastCall = this._traceLogPlayers[id].stepTo(stepNo); 2966 return lastCall.resource().toDataURL(); 2975 2967 }, 2976 2968 … … 2990 2982 { 2991 2983 return "{\"injectedScriptId\":" + injectedScriptId + ",\"canvasContextId\":" + resourceId + "}"; 2992 },2993 2994 _onTraceLogPlayerReset: function()2995 {2996 this._replayContexts = [];2997 },2998 2999 /**3000 * @param {!WebGLRenderingContext} originalGlContext3001 * @return {WebGLRenderingContext}3002 */3003 _constructWebGLReplayContext: function(originalGlContext)3004 {3005 var canvas = originalGlContext.canvas.cloneNode(true);3006 var attributes = originalGlContext.getContextAttributes();3007 var contextIds = ["experimental-webgl", "webkit-3d", "3d"];3008 for (var i = 0, contextId; contextId = contextIds[i]; ++i) {3009 var replayContext = canvas.getContext(contextId, attributes);3010 if (replayContext) {3011 replayContext = /** @type {WebGLRenderingContext} */ (Resource.wrappedObject(replayContext));3012 this._replayContexts.push({3013 type: "3d",3014 context: replayContext3015 });3016 return replayContext;3017 }3018 }3019 return null;3020 },3021 3022 /**3023 * @param {!CanvasRenderingContext2D} originalContext3024 * @return {CanvasRenderingContext2D}3025 */3026 _constructCanvas2DReplayContext: function(originalContext)3027 {3028 // Create a new 2D context each time to start with an empty context drawing state stack (managed by save() and restore() methods).3029 var canvas = originalContext.canvas.cloneNode(true);3030 var replayContext = /** @type {CanvasRenderingContext2D} */ (Resource.wrappedObject(canvas.getContext("2d")));3031 this._replayContexts.push({3032 type: "2d",3033 context: replayContext3034 });3035 return replayContext;3036 2984 } 3037 2985 }
Note: See TracChangeset
for help on using the changeset viewer.