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

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

Issue 166273018: Added showing slow scroll rectangles in Layers panel. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Final fixes. Created 6 years, 9 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
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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.Object} 33 * @extends {WebInspector.Object}
34 */ 34 */
35 WebInspector.LayerTreeModel = function() 35 WebInspector.LayerTreeModel = function()
36 { 36 {
37 WebInspector.Object.call(this); 37 WebInspector.Object.call(this);
38 this._layersById = {}; 38 this._layersById = {};
39 this._scrollRectsByLayerId = {};
39 // We fetch layer tree lazily and get paint events asynchronously, so keep t he last painted 40 // 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. 41 // rect separate from layer so we can get it after refreshing the tree.
41 this._lastPaintRectByLayerId = {}; 42 this._lastPaintRectByLayerId = {};
42 InspectorBackend.registerLayerTreeDispatcher(new WebInspector.LayerTreeDispa tcher(this)); 43 InspectorBackend.registerLayerTreeDispatcher(new WebInspector.LayerTreeDispa tcher(this));
43 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document Updated, this._onDocumentUpdated, this); 44 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document Updated, this._onDocumentUpdated, this);
44 } 45 }
45 46
46 WebInspector.LayerTreeModel.Events = { 47 WebInspector.LayerTreeModel.Events = {
47 LayerTreeChanged: "LayerTreeChanged", 48 LayerTreeChanged: "LayerTreeChanged",
48 LayerPainted: "LayerPainted", 49 LayerPainted: "LayerPainted",
49 } 50 }
50 51
52 /**
53 * @param {!LayerTreeAgent.ScrollRect} first
54 * @param {!LayerTreeAgent.ScrollRect} second
55 */
56 WebInspector.LayerTreeModel._scrollRectsEqual = function(first, second)
pfeldman 2014/02/26 11:49:40 _scrollRectsAreEqual
malch 2014/02/27 13:30:53 Done.
57 {
58 return first.x === second.x && first.y === second.y &&
59 first.width === second.width && first.height === second.height &&
60 first.layerId === second.layerId && first.type === second.type;
61 }
62
51 WebInspector.LayerTreeModel.prototype = { 63 WebInspector.LayerTreeModel.prototype = {
52 disable: function() 64 disable: function()
53 { 65 {
54 if (!this._enabled) 66 if (!this._enabled)
55 return; 67 return;
56 this._enabled = false; 68 this._enabled = false;
57 LayerTreeAgent.disable(); 69 LayerTreeAgent.disable();
58 }, 70 },
59 71
60 /** 72 /**
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 /** 125 /**
114 * @param {string} id 126 * @param {string} id
115 * @return {?WebInspector.Layer} 127 * @return {?WebInspector.Layer}
116 */ 128 */
117 layerById: function(id) 129 layerById: function(id)
118 { 130 {
119 return this._layersById[id] || null; 131 return this._layersById[id] || null;
120 }, 132 },
121 133
122 /** 134 /**
123 * @param {!Array.<!LayerTreeAgent.Layer>} payload 135 * @return {!Object}
124 */ 136 */
125 _repopulate: function(payload) 137 scrollRectsByLayerId: function()
138 {
139 return this._scrollRectsByLayerId;
140 },
141
142 /**
143 * @param {!Array.<!LayerTreeAgent.Layer>} layers
144 */
145 _repopulate: function(layers)
126 { 146 {
127 var oldLayersById = this._layersById; 147 var oldLayersById = this._layersById;
128 this._layersById = {}; 148 this._layersById = {};
129 for (var i = 0; i < payload.length; ++i) { 149 for (var i = 0; i < layers.length; ++i) {
130 var layerId = payload[i].layerId; 150 var layerId = layers[i].layerId;
131 var layer = oldLayersById[layerId]; 151 var layer = oldLayersById[layerId];
132 if (layer) 152 if (layer)
133 layer._reset(payload[i]); 153 layer._reset(layers[i]);
134 else 154 else
135 layer = new WebInspector.Layer(payload[i]); 155 layer = new WebInspector.Layer(layers[i]);
136 this._layersById[layerId] = layer; 156 this._layersById[layerId] = layer;
137 var parentId = layer.parentId(); 157 var parentId = layer.parentId();
138 if (!this._contentRoot && layer.nodeId()) 158 if (!this._contentRoot && layer.nodeId())
139 this._contentRoot = layer; 159 this._contentRoot = layer;
140 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; 160 var lastPaintRect = this._lastPaintRectByLayerId[layerId];
141 if (lastPaintRect) 161 if (lastPaintRect)
142 layer._lastPaintRect = lastPaintRect; 162 layer._lastPaintRect = lastPaintRect;
143 if (parentId) { 163 if (parentId) {
144 var parent = this._layersById[parentId]; 164 var parent = this._layersById[parentId];
145 if (!parent) 165 if (!parent)
146 console.assert(parent, "missing parent " + parentId + " for layer " + layerId); 166 console.assert(parent, "missing parent " + parentId + " for layer " + layerId);
147 parent.addChild(layer); 167 parent.addChild(layer);
148 } else { 168 } else {
149 if (this._root) 169 if (this._root)
150 console.assert(false, "Multiple root layers"); 170 console.assert(false, "Multiple root layers");
151 this._root = layer; 171 this._root = layer;
152 } 172 }
153 } 173 }
154 this._lastPaintRectByLayerId = {}; 174 this._lastPaintRectByLayerId = {};
155 }, 175 },
156 176
157 /** 177 /**
158 * @param {!Array.<!LayerTreeAgent.Layer>=} payload 178 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects
159 */ 179 */
160 _layerTreeChanged: function(payload) 180 _updateScrollRects: function(scrollRects)
181 {
182 var newScrollRectsByLayerId = {};
183 var i, layerId;
184 for (i = 0; i < scrollRects.length; ++i) {
185 var scrollRect = scrollRects[i];
186 var layer = this._layersById[scrollRect.layerId];
187 if (scrollRect.layerId in newScrollRectsByLayerId)
188 newScrollRectsByLayerId[scrollRect.layerId].push(scrollRect);
189 else
190 newScrollRectsByLayerId[scrollRect.layerId] = [scrollRect];
191 }
192 for (layerId in this._scrollRectsByLayerId) {
193 if (!newScrollRectsByLayerId[layerId])
194 delete this._scrollRectsByLayerId[layerId];
195 }
196 for (layerId in newScrollRectsByLayerId) {
197 if (!this._scrollRectsByLayerId[layerId])
198 this._scrollRectsByLayerId[layerId] = [];
199 var oldScrollRects = this._scrollRectsByLayerId[layerId];
200 for (i = 0; i < newScrollRectsByLayerId[layerId].length; ++i) {
201 if (i >= oldScrollRects.length ||
202 !WebInspector.LayerTreeModel._scrollRectsEqual(newScrollRect sByLayerId[layerId][i], oldScrollRects[i])) {
203 oldScrollRects[i] = newScrollRectsByLayerId[layerId][i];
204 }
205 }
206 oldScrollRects.splice(newScrollRectsByLayerId[layerId].length);
207 }
208 },
209
210 /**
211 * @param {!Array.<!LayerTreeAgent.Layer>=} layers
212 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects
213 */
214 _layerTreeChanged: function(layers, scrollRects)
161 { 215 {
162 this._root = null; 216 this._root = null;
163 this._contentRoot = null; 217 this._contentRoot = null;
164 // Payload will be null when not in the composited mode. 218 // Payload will be null when not in the composited mode.
165 if (payload) 219 if (layers)
166 this._repopulate(payload); 220 this._repopulate(layers);
221 this._updateScrollRects(scrollRects || []);
167 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged); 222 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged);
168 }, 223 },
169 224
170 /** 225 /**
171 * @param {!LayerTreeAgent.LayerId} layerId 226 * @param {!LayerTreeAgent.LayerId} layerId
172 * @param {!DOMAgent.Rect} clipRect 227 * @param {!DOMAgent.Rect} clipRect
173 */ 228 */
174 _layerPainted: function(layerId, clipRect) 229 _layerPainted: function(layerId, clipRect)
175 { 230 {
176 var layer = this._layersById[layerId]; 231 var layer = this._layersById[layerId];
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 * @implements {LayerTreeAgent.Dispatcher} 450 * @implements {LayerTreeAgent.Dispatcher}
396 * @param {!WebInspector.LayerTreeModel} layerTreeModel 451 * @param {!WebInspector.LayerTreeModel} layerTreeModel
397 */ 452 */
398 WebInspector.LayerTreeDispatcher = function(layerTreeModel) 453 WebInspector.LayerTreeDispatcher = function(layerTreeModel)
399 { 454 {
400 this._layerTreeModel = layerTreeModel; 455 this._layerTreeModel = layerTreeModel;
401 } 456 }
402 457
403 WebInspector.LayerTreeDispatcher.prototype = { 458 WebInspector.LayerTreeDispatcher.prototype = {
404 /** 459 /**
405 * @param {!Array.<!LayerTreeAgent.Layer>=} payload 460 * @param {!Array.<!LayerTreeAgent.Layer>=} layers
461 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects
406 */ 462 */
407 layerTreeDidChange: function(payload) 463 layerTreeDidChange: function(layers, scrollRects)
408 { 464 {
409 this._layerTreeModel._layerTreeChanged(payload); 465 this._layerTreeModel._layerTreeChanged(layers, scrollRects);
410 }, 466 },
411 467
412 /** 468 /**
413 * @param {!LayerTreeAgent.LayerId} layerId 469 * @param {!LayerTreeAgent.LayerId} layerId
414 * @param {!DOMAgent.Rect} clipRect 470 * @param {!DOMAgent.Rect} clipRect
415 */ 471 */
416 layerPainted: function(layerId, clipRect) 472 layerPainted: function(layerId, clipRect)
417 { 473 {
418 this._layerTreeModel._layerPainted(layerId, clipRect); 474 this._layerTreeModel._layerPainted(layerId, clipRect);
419 } 475 }
420 } 476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698