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

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: Created 6 years, 10 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",
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 /** 114 /**
114 * @param {string} id 115 * @param {string} id
115 * @return {?WebInspector.Layer} 116 * @return {?WebInspector.Layer}
116 */ 117 */
117 layerById: function(id) 118 layerById: function(id)
118 { 119 {
119 return this._layersById[id] || null; 120 return this._layersById[id] || null;
120 }, 121 },
121 122
122 /** 123 /**
123 * @param {!Array.<!LayerTreeAgent.Layer>} payload 124 * @param {!Array.<!LayerTreeAgent.Layer>} layers
124 */ 125 */
125 _repopulate: function(payload) 126 _repopulate: function(layers)
126 { 127 {
127 var oldLayersById = this._layersById; 128 var oldLayersById = this._layersById;
128 this._layersById = {}; 129 this._layersById = {};
129 for (var i = 0; i < payload.length; ++i) { 130 for (var i = 0; i < layers.length; ++i) {
130 var layerId = payload[i].layerId; 131 var layerId = layers[i].layerId;
131 var layer = oldLayersById[layerId]; 132 var layer = oldLayersById[layerId];
132 if (layer) 133 if (layer)
133 layer._reset(payload[i]); 134 layer._reset(layers[i]);
134 else 135 else
135 layer = new WebInspector.Layer(payload[i]); 136 layer = new WebInspector.Layer(layers[i]);
136 this._layersById[layerId] = layer; 137 this._layersById[layerId] = layer;
137 var parentId = layer.parentId(); 138 var parentId = layer.parentId();
138 if (!this._contentRoot && layer.nodeId()) 139 if (!this._contentRoot && layer.nodeId())
139 this._contentRoot = layer; 140 this._contentRoot = layer;
140 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; 141 var lastPaintRect = this._lastPaintRectByLayerId[layerId];
141 if (lastPaintRect) 142 if (lastPaintRect)
142 layer._lastPaintRect = lastPaintRect; 143 layer._lastPaintRect = lastPaintRect;
143 if (parentId) { 144 if (parentId) {
144 var parent = this._layersById[parentId]; 145 var parent = this._layersById[parentId];
145 if (!parent) 146 if (!parent)
146 console.assert(parent, "missing parent " + parentId + " for layer " + layerId); 147 console.assert(parent, "missing parent " + parentId + " for layer " + layerId);
147 parent.addChild(layer); 148 parent.addChild(layer);
148 } else { 149 } else {
149 if (this._root) 150 if (this._root)
150 console.assert(false, "Multiple root layers"); 151 console.assert(false, "Multiple root layers");
151 this._root = layer; 152 this._root = layer;
152 } 153 }
153 } 154 }
154 this._lastPaintRectByLayerId = {}; 155 this._lastPaintRectByLayerId = {};
155 }, 156 },
156 157
157 /** 158 /**
158 * @param {!Array.<!LayerTreeAgent.Layer>=} payload 159 * @param {!LayerTreeAgent.ScrollRect} first
160 * @param {!LayerTreeAgent.ScrollRect} second
159 */ 161 */
160 _layerTreeChanged: function(payload) 162 _areScrollRectsEqual:function (first, second) {
caseq 2014/02/20 07:29:18 Mind the style please: { => next line, function(ar
163 return (first.x === second.x) && (first.y === second.y) &&
164 (first.width === second.width) && (first.height === second.height) & &
165 (first.layerId === second.layerId) && (first.type === second.type);
166 },
167
168 /**
169 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects
170 */
171 _updateScrollRects: function(scrollRects)
172 {
173 var scrollRectsByLayerId = {};
caseq 2014/02/20 07:29:18 newScollRectsByLayerId so we can better distinguis
174 var i, layerId;
175 for (i = 0; i < scrollRects.length; ++i) {
176 var scrollRect = scrollRects[i];
177 var layer = this._layersById[scrollRect.layerId];
178 if ((layer.width() !== 0 && layer.height() !== 0) &&
179 (scrollRect.width > layer.width() || scrollRect.height > layer.h eight()) &&
180 !layer.parent().parent())
181 continue;
182 if (scrollRect.layerId in scrollRectsByLayerId) {
caseq 2014/02/20 07:29:18 style: no need for { } here
183 scrollRectsByLayerId[scrollRect.layerId].push(scrollRect);
184 } else {
185 scrollRectsByLayerId[scrollRect.layerId] = [scrollRect];
186 }
187 }
188 for (layerId in this._scrollRectsByLayerId) {
189 if (scrollRectsByLayerId[layerId])
190 continue;
191 delete this._scrollRectsByLayerId[layerId];
192 }
193 for (layerId in scrollRectsByLayerId) {
194 if (!this._scrollRectsByLayerId[layerId])
195 this._scrollRectsByLayerId[layerId] = [];
196 for (i = 0; i < scrollRectsByLayerId[layerId].length; ++i) {
197 if (i >= this._scrollRectsByLayerId[layerId].length) {
198 this._scrollRectsByLayerId[layerId].push(scrollRectsByLayerI d[layerId][i]);
199 this._scrollRectsByLayerId[layerId][i].needsUpdate = true;
caseq 2014/02/20 07:29:18 extract something like var rect = this._scrollRect
caseq 2014/02/20 07:29:18 I don't like needsUpdate
200 } else if (this._areScrollRectsEqual(scrollRectsByLayerId[layerI d][i], this._scrollRectsByLayerId[layerId][i])) {
201 this._scrollRectsByLayerId[layerId][i].needsUpdate = false;
202 } else {
203 this._scrollRectsByLayerId[layerId][i] = scrollRectsByLayerI d[layerId][i];
204 this._scrollRectsByLayerId[layerId][i].needsUpdate = true;
205 }
206 }
207 if (this._scrollRectsByLayerId[layerId].length > scrollRectsByLayerI d[layerId].length) {
208 this._scrollRectsByLayerId[layerId].splice(scrollRectsByLayerId[ layerId].length,
209 this._scrollRectsByLayerId[layerId].length - scrollRectsByLa yerId[layerId].length);
210 }
211 }
212 },
213
214 /**
215 * @param {!Array.<!LayerTreeAgent.Layer>=} layers
216 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects
217 */
218 _layerTreeChanged: function(layers, scrollRects)
161 { 219 {
162 this._root = null; 220 this._root = null;
163 this._contentRoot = null; 221 this._contentRoot = null;
164 // Payload will be null when not in the composited mode. 222 // Payload will be null when not in the composited mode.
165 if (payload) 223 if (layers)
166 this._repopulate(payload); 224 this._repopulate(layers);
225 if (scrollRects)
226 this._updateScrollRects(scrollRects);
167 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged); 227 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr eeChanged);
168 }, 228 },
169 229
170 /** 230 /**
171 * @param {!LayerTreeAgent.LayerId} layerId 231 * @param {!LayerTreeAgent.LayerId} layerId
172 * @param {!DOMAgent.Rect} clipRect 232 * @param {!DOMAgent.Rect} clipRect
173 */ 233 */
174 _layerPainted: function(layerId, clipRect) 234 _layerPainted: function(layerId, clipRect)
175 { 235 {
176 var layer = this._layersById[layerId]; 236 var layer = this._layersById[layerId];
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 * @implements {LayerTreeAgent.Dispatcher} 455 * @implements {LayerTreeAgent.Dispatcher}
396 * @param {!WebInspector.LayerTreeModel} layerTreeModel 456 * @param {!WebInspector.LayerTreeModel} layerTreeModel
397 */ 457 */
398 WebInspector.LayerTreeDispatcher = function(layerTreeModel) 458 WebInspector.LayerTreeDispatcher = function(layerTreeModel)
399 { 459 {
400 this._layerTreeModel = layerTreeModel; 460 this._layerTreeModel = layerTreeModel;
401 } 461 }
402 462
403 WebInspector.LayerTreeDispatcher.prototype = { 463 WebInspector.LayerTreeDispatcher.prototype = {
404 /** 464 /**
405 * @param {!Array.<!LayerTreeAgent.Layer>=} payload 465 * @param {!Array.<!LayerTreeAgent.Layer>=} layers
466 * @param {!Array.<!LayerTreeAgent.ScrollRect>=} scrollRects
406 */ 467 */
407 layerTreeDidChange: function(payload) 468 layerTreeDidChange: function(layers, scrollRects)
408 { 469 {
409 this._layerTreeModel._layerTreeChanged(payload); 470 this._layerTreeModel._layerTreeChanged(layers, scrollRects);
410 }, 471 },
411 472
412 /** 473 /**
413 * @param {!LayerTreeAgent.LayerId} layerId 474 * @param {!LayerTreeAgent.LayerId} layerId
414 * @param {!DOMAgent.Rect} clipRect 475 * @param {!DOMAgent.Rect} clipRect
415 */ 476 */
416 layerPainted: function(layerId, clipRect) 477 layerPainted: function(layerId, clipRect)
417 { 478 {
418 this._layerTreeModel._layerPainted(layerId, clipRect); 479 this._layerTreeModel._layerPainted(layerId, clipRect);
419 } 480 }
420 } 481 }
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorLayerTreeAgent.cpp ('k') | Source/devtools/front_end/Layers3DView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698