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

Side by Side Diff: Source/devtools/front_end/LayerTreeModel.js

Issue 224843014: DevTools: support importing layer tree from trace snapshots. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased, removed redundant transform handling code Created 6 years, 8 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/devtools/front_end/LayersPanel.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 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** @typedef {!{
32 bounds: {height: number, width: number},
33 children: Array.<!WebInspector.TracingLayerPayload>,
34 layer_id: number,
35 position: Array.<number>,
36 scroll_offset: Array.<number>,
37 layer_quad: Array.<number>,
38 draws_content: number,
39 transform: Array.<number>
40 }}
41 */
42 WebInspector.TracingLayerPayload;
43
31 /** 44 /**
32 * @constructor 45 * @constructor
33 * @extends {WebInspector.TargetAwareObject} 46 * @extends {WebInspector.TargetAwareObject}
34 */ 47 */
35 WebInspector.LayerTreeModel = function(target) 48 WebInspector.LayerTreeModel = function(target)
36 { 49 {
37 WebInspector.TargetAwareObject.call(this, target); 50 WebInspector.TargetAwareObject.call(this, target);
38 this._layersById = {}; 51 this._layersById = {};
39 // We fetch layer tree lazily and get paint events asynchronously, so keep t he last painted 52 // We fetch layer tree lazily and get paint events asynchronously, so keep t he last painted
40 // rect separate from layer so we can get it after refreshing the tree. 53 // rect separate from layer so we can get it after refreshing the tree.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 /** 86 /**
74 * @param {!WebInspector.LayerTreeSnapshot} snapshot 87 * @param {!WebInspector.LayerTreeSnapshot} snapshot
75 */ 88 */
76 setSnapshot: function(snapshot) 89 setSnapshot: function(snapshot)
77 { 90 {
78 this.disable(); 91 this.disable();
79 this._resolveNodesAndRepopulate(snapshot.layers); 92 this._resolveNodesAndRepopulate(snapshot.layers);
80 }, 93 },
81 94
82 /** 95 /**
96 * @param {!WebInspector.TracingLayerSnapshot} snapshot
97 */
98 setTracingSnapshot: function(snapshot)
99 {
100 this.disable();
101 this._importTracingLayers(snapshot.root);
102 },
103
104 /**
83 * @return {?WebInspector.Layer} 105 * @return {?WebInspector.Layer}
84 */ 106 */
85 root: function() 107 root: function()
86 { 108 {
87 return this._root; 109 return this._root;
88 }, 110 },
89 111
90 /** 112 /**
91 * @return {?WebInspector.Layer} 113 * @return {?WebInspector.Layer}
92 */ 114 */
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (!layers) 171 if (!layers)
150 return; 172 return;
151 var oldLayersById = this._layersById; 173 var oldLayersById = this._layersById;
152 this._layersById = {}; 174 this._layersById = {};
153 for (var i = 0; i < layers.length; ++i) { 175 for (var i = 0; i < layers.length; ++i) {
154 var layerId = layers[i].layerId; 176 var layerId = layers[i].layerId;
155 var layer = oldLayersById[layerId]; 177 var layer = oldLayersById[layerId];
156 if (layer) 178 if (layer)
157 layer._reset(layers[i]); 179 layer._reset(layers[i]);
158 else 180 else
159 layer = new WebInspector.Layer(layers[i]); 181 layer = new WebInspector.AgentLayer(layers[i]);
160 this._layersById[layerId] = layer; 182 this._layersById[layerId] = layer;
161 if (layers[i].backendNodeId) { 183 if (layers[i].backendNodeId) {
162 layer._setNode(this._target.domModel.nodeForId(this._backendNode IdToNodeId[layers[i].backendNodeId])); 184 layer._setNode(this._target.domModel.nodeForId(this._backendNode IdToNodeId[layers[i].backendNodeId]));
163 if (!this._contentRoot) 185 if (!this._contentRoot)
164 this._contentRoot = layer; 186 this._contentRoot = layer;
165 } 187 }
166 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; 188 var lastPaintRect = this._lastPaintRectByLayerId[layerId];
167 if (lastPaintRect) 189 if (lastPaintRect)
168 layer._lastPaintRect = lastPaintRect; 190 layer._lastPaintRect = lastPaintRect;
169 var parentId = layer.parentId(); 191 var parentId = layer.parentId();
170 if (parentId) { 192 if (parentId) {
171 var parent = this._layersById[parentId]; 193 var parent = this._layersById[parentId];
172 if (!parent) 194 if (!parent)
173 console.assert(parent, "missing parent " + parentId + " for layer " + layerId); 195 console.assert(parent, "missing parent " + parentId + " for layer " + layerId);
174 parent.addChild(layer); 196 parent.addChild(layer);
175 } else { 197 } else {
176 if (this._root) 198 if (this._root)
177 console.assert(false, "Multiple root layers"); 199 console.assert(false, "Multiple root layers");
178 this._root = layer; 200 this._root = layer;
179 } 201 }
180 } 202 }
181 this._root._calculateQuad(new WebKitCSSMatrix()); 203 this._root._calculateQuad(new WebKitCSSMatrix());
182 this._lastPaintRectByLayerId = {}; 204 this._lastPaintRectByLayerId = {};
183 }, 205 },
184 206
185 /** 207 /**
208 * @param {!WebInspector.TracingLayerPayload} root
209 */
210 _importTracingLayers: function(root)
211 {
212 this._layersById = {};
213 this._contentRoot = null;
214 this._root = this._innerImportTracingLayers(root);
215 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged);
216 },
217
218 /**
219 * @param {!WebInspector.TracingLayerPayload} payload
220 * @return {!WebInspector.TracingLayer}
221 */
222 _innerImportTracingLayers: function(payload)
223 {
224 var layer = new WebInspector.TracingLayer(payload);
225 if (!this._contentRoot && payload.draws_content)
226 this._contentRoot = layer;
227 for (var i = 0; i < payload.children.length; ++i)
228 layer.addChild(this._innerImportTracingLayers(payload.children[i]));
229 return layer;
230 },
231
232 /**
186 * @param {!Array.<!LayerTreeAgent.Layer>=} layers 233 * @param {!Array.<!LayerTreeAgent.Layer>=} layers
187 */ 234 */
188 _layerTreeChanged: function(layers) 235 _layerTreeChanged: function(layers)
189 { 236 {
190 if (!this._enabled) 237 if (!this._enabled)
191 return; 238 return;
192 this._resolveNodesAndRepopulate(layers); 239 this._resolveNodesAndRepopulate(layers);
193 }, 240 },
194 241
195 /** 242 /**
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 _onDocumentUpdated: function() 297 _onDocumentUpdated: function()
251 { 298 {
252 this.disable(); 299 this.disable();
253 this.enable(); 300 this.enable();
254 }, 301 },
255 302
256 __proto__: WebInspector.TargetAwareObject.prototype 303 __proto__: WebInspector.TargetAwareObject.prototype
257 } 304 }
258 305
259 /** 306 /**
260 * @constructor 307 * @interface
261 * @param {!LayerTreeAgent.Layer} layerPayload
262 */ 308 */
263 WebInspector.Layer = function(layerPayload) 309 WebInspector.Layer = function()
264 { 310 {
265 this._scrollRects = [];
266 this._reset(layerPayload);
267 } 311 }
268 312
269 WebInspector.Layer.prototype = { 313 WebInspector.Layer.prototype = {
270 /** 314 /**
271 * @return {string} 315 * @return {string}
272 */ 316 */
317 id: function() { },
318
319 /**
320 * @return {?string}
321 */
322 parentId: function() { },
323
324 /**
325 * @return {?WebInspector.Layer}
326 */
327 parent: function() { },
328
329 /**
330 * @return {boolean}
331 */
332 isRoot: function() { },
333
334 /**
335 * @return {!Array.<!WebInspector.Layer>}
336 */
337 children: function() { },
338
339 /**
340 * @param {!WebInspector.Layer} child
341 */
342 addChild: function(child) { },
343
344 /**
345 * @return {?WebInspector.DOMNode}
346 */
347 node: function() { },
348
349 /**
350 * @return {?WebInspector.DOMNode}
351 */
352 nodeForSelfOrAncestor: function() { },
353
354 /**
355 * @return {number}
356 */
357 offsetX: function() { },
358
359 /**
360 * @return {number}
361 */
362 offsetY: function() { },
363
364 /**
365 * @return {number}
366 */
367 width: function() { },
368
369 /**
370 * @return {number}
371 */
372 height: function() { },
373
374 /**
375 * @return {?Array.<number>}
376 */
377 transform: function() { },
378
379 /**
380 * @return {?Array.<number>}
381 */
382 quad: function() { },
383
384 /**
385 * @return {!Array.<number>}
386 */
387 anchorPoint: function() { },
388
389 /**
390 * @return {boolean}
391 */
392 invisible: function() { },
393
394 /**
395 * @return {number}
396 */
397 paintCount: function() { },
398
399 /**
400 * @return {?DOMAgent.Rect}
401 */
402 lastPaintRect: function() { },
403
404 /**
405 * @return {!Array.<!LayerTreeAgent.ScrollRect>}
406 */
407 scrollRects: function() { },
408
409 /**
410 * @param {function(!Array.<string>)} callback
411 */
412 requestCompositingReasons: function(callback) { },
413
414 /**
415 * @param {function(!WebInspector.PaintProfilerSnapshot=)} callback
416 */
417 requestSnapshot: function(callback) { },
418 }
419
420 /**
421 * @constructor
422 * @implements {WebInspector.Layer}
423 * @param {!LayerTreeAgent.Layer} layerPayload
424 */
425 WebInspector.AgentLayer = function(layerPayload)
426 {
427 this._scrollRects = [];
428 this._reset(layerPayload);
429 }
430
431 WebInspector.AgentLayer.prototype = {
432 /**
433 * @return {string}
434 */
273 id: function() 435 id: function()
274 { 436 {
275 return this._layerPayload.layerId; 437 return this._layerPayload.layerId;
276 }, 438 },
277 439
278 /** 440 /**
279 * @return {string} 441 * @return {?string}
280 */ 442 */
281 parentId: function() 443 parentId: function()
282 { 444 {
283 return this._layerPayload.parentLayerId; 445 return this._layerPayload.parentLayerId;
284 }, 446 },
285 447
286 /** 448 /**
287 * @return {!WebInspector.Layer} 449 * @return {?WebInspector.Layer}
288 */ 450 */
289 parent: function() 451 parent: function()
290 { 452 {
291 return this._parent; 453 return this._parent;
292 }, 454 },
293 455
294 /** 456 /**
295 * @return {boolean} 457 * @return {boolean}
296 */ 458 */
297 isRoot: function() 459 isRoot: function()
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 534
373 /** 535 /**
374 * @return {number} 536 * @return {number}
375 */ 537 */
376 height: function() 538 height: function()
377 { 539 {
378 return this._layerPayload.height; 540 return this._layerPayload.height;
379 }, 541 },
380 542
381 /** 543 /**
382 * @return {!Array.<number>} 544 * @return {?Array.<number>}
383 */ 545 */
384 transform: function() 546 transform: function()
385 { 547 {
386 return this._layerPayload.transform; 548 return this._layerPayload.transform;
387 }, 549 },
388 550
389 /** 551 /**
552 * @return {?Array.<number>}
553 */
554 quad: function()
555 {
556 return this._quad;
557 },
558
559 /**
390 * @return {!Array.<number>} 560 * @return {!Array.<number>}
391 */ 561 */
392 anchorPoint: function() 562 anchorPoint: function()
393 { 563 {
394 return [ 564 return [
395 this._layerPayload.anchorX || 0, 565 this._layerPayload.anchorX || 0,
396 this._layerPayload.anchorY || 0, 566 this._layerPayload.anchorY || 0,
397 this._layerPayload.anchorZ || 0, 567 this._layerPayload.anchorZ || 0,
398 ]; 568 ];
399 }, 569 },
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 this._quad.push(point.x, point.y); 695 this._quad.push(point.x, point.y);
526 } 696 }
527 697
528 function calculateQuadForLayer(layer) 698 function calculateQuadForLayer(layer)
529 { 699 {
530 layer._calculateQuad(matrix); 700 layer._calculateQuad(matrix);
531 } 701 }
532 702
533 this._children.forEach(calculateQuadForLayer); 703 this._children.forEach(calculateQuadForLayer);
534 }, 704 },
705 }
706
707 /**
708 * @constructor
709 * @param {!WebInspector.TracingLayerPayload} payload
710 * @implements {WebInspector.Layer}
711 */
712 WebInspector.TracingLayer = function(payload)
713 {
714 this._layerId = String(payload.layer_id);
715 this._offsetX = payload.position[0];
716 this._offsetY = payload.position[1];
717 this._width = payload.bounds.width;
718 this._height = payload.bounds.height;
719 this._children = [];
720 this._parentLayerId = null;
721 this._parent = null;
722 this._quad = payload.layer_quad;
723 }
724
725 WebInspector.TracingLayer.prototype = {
726 /**
727 * @return {string}
728 */
729 id: function()
730 {
731 return this._layerId;
732 },
733
734 /**
735 * @return {?string}
736 */
737 parentId: function()
738 {
739 return this._parentLayerId;
740 },
741
742 /**
743 * @return {?WebInspector.Layer}
744 */
745 parent: function()
746 {
747 return this._parent;
748 },
749
750 /**
751 * @return {boolean}
752 */
753 isRoot: function()
754 {
755 return !this.parentId();
756 },
757
758 /**
759 * @return {!Array.<!WebInspector.Layer>}
760 */
761 children: function()
762 {
763 return this._children;
764 },
765
766 /**
767 * @param {!WebInspector.Layer} child
768 */
769 addChild: function(child)
770 {
771 if (child._parent)
772 console.assert(false, "Child already has a parent");
773 this._children.push(child);
774 child._parent = this;
775 child._parentLayerId = this._layerId;
776 },
777
778 /**
779 * @return {?WebInspector.DOMNode}
780 */
781 node: function()
782 {
783 return null;
784 },
785
786 /**
787 * @return {?WebInspector.DOMNode}
788 */
789 nodeForSelfOrAncestor: function()
790 {
791 return null;
792 },
793
794 /**
795 * @return {number}
796 */
797 offsetX: function()
798 {
799 return this._offsetX;
800 },
801
802 /**
803 * @return {number}
804 */
805 offsetY: function()
806 {
807 return this._offsetY;
808 },
809
810 /**
811 * @return {number}
812 */
813 width: function()
814 {
815 return this._width;
816 },
817
818 /**
819 * @return {number}
820 */
821 height: function()
822 {
823 return this._height;
824 },
825
826 /**
827 * @return {?Array.<number>}
828 */
829 transform: function()
830 {
831 return null;
832 },
833
834 /**
835 * @return {?Array.<number>}
836 */
837 quad: function()
838 {
839 return this._quad;
840 },
535 841
536 /** 842 /**
537 * @return {!Array.<number>} 843 * @return {!Array.<number>}
538 */ 844 */
539 quad: function() 845 anchorPoint: function()
540 { 846 {
541 return this._quad; 847 return [0.5, 0.5, 0];
848 },
849
850 /**
851 * @return {boolean}
852 */
853 invisible: function()
854 {
855 return false;
856 },
857
858 /**
859 * @return {number}
860 */
861 paintCount: function()
862 {
863 return 0;
864 },
865
866 /**
867 * @return {?DOMAgent.Rect}
868 */
869 lastPaintRect: function()
870 {
871 return null;
872 },
873
874 /**
875 * @return {!Array.<!LayerTreeAgent.ScrollRect>}
876 */
877 scrollRects: function()
878 {
879 return [];
880 },
881
882 /**
883 * @param {function(!Array.<string>)} callback
884 */
885 requestCompositingReasons: function(callback)
886 {
887 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "Lay erTreeAgent.reasonsForCompositingLayer(): ", undefined, []);
888 LayerTreeAgent.compositingReasons(this.id(), wrappedCallback);
889 },
890
891 /**
892 * @param {function(!WebInspector.PaintProfilerSnapshot=)} callback
893 */
894 requestSnapshot: function(callback)
895 {
896 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "Lay erTreeAgent.makeSnapshot(): ", WebInspector.PaintProfilerSnapshot);
897 LayerTreeAgent.makeSnapshot(this.id(), wrappedCallback);
542 } 898 }
543 } 899 }
544 900
545 /** 901 /**
546 * @constructor 902 * @constructor
547 * @param {!Array.<!LayerTreeAgent.Layer>} layers 903 * @param {!Array.<!LayerTreeAgent.Layer>} layers
548 */ 904 */
549 WebInspector.LayerTreeSnapshot = function(layers) 905 WebInspector.LayerTreeSnapshot = function(layers)
550 { 906 {
551 this.layers = layers; 907 this.layers = layers;
552 } 908 }
553 909
554 /** 910 /**
555 * @constructor 911 * @constructor
912 * @param {!WebInspector.TracingLayerPayload} root
913 */
914 WebInspector.TracingLayerSnapshot = function(root)
915 {
916 this.root = root;
917 }
918
919 /**
920 * @constructor
556 * @implements {LayerTreeAgent.Dispatcher} 921 * @implements {LayerTreeAgent.Dispatcher}
557 * @param {!WebInspector.LayerTreeModel} layerTreeModel 922 * @param {!WebInspector.LayerTreeModel} layerTreeModel
558 */ 923 */
559 WebInspector.LayerTreeDispatcher = function(layerTreeModel) 924 WebInspector.LayerTreeDispatcher = function(layerTreeModel)
560 { 925 {
561 this._layerTreeModel = layerTreeModel; 926 this._layerTreeModel = layerTreeModel;
562 } 927 }
563 928
564 WebInspector.LayerTreeDispatcher.prototype = { 929 WebInspector.LayerTreeDispatcher.prototype = {
565 /** 930 /**
566 * @param {!Array.<!LayerTreeAgent.Layer>=} layers 931 * @param {!Array.<!LayerTreeAgent.Layer>=} layers
567 */ 932 */
568 layerTreeDidChange: function(layers) 933 layerTreeDidChange: function(layers)
569 { 934 {
570 this._layerTreeModel._layerTreeChanged(layers); 935 this._layerTreeModel._layerTreeChanged(layers);
571 }, 936 },
572 937
573 /** 938 /**
574 * @param {!LayerTreeAgent.LayerId} layerId 939 * @param {!LayerTreeAgent.LayerId} layerId
575 * @param {!DOMAgent.Rect} clipRect 940 * @param {!DOMAgent.Rect} clipRect
576 */ 941 */
577 layerPainted: function(layerId, clipRect) 942 layerPainted: function(layerId, clipRect)
578 { 943 {
579 this._layerTreeModel._layerPainted(layerId, clipRect); 944 this._layerTreeModel._layerPainted(layerId, clipRect);
580 } 945 }
581 } 946 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/LayersPanel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698