| OLD | NEW |
| 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 30 matching lines...) Expand all Loading... |
| 41 this._lastPaintRectByLayerId = {}; | 41 this._lastPaintRectByLayerId = {}; |
| 42 InspectorBackend.registerLayerTreeDispatcher(new WebInspector.LayerTreeDispa
tcher(this)); | 42 InspectorBackend.registerLayerTreeDispatcher(new WebInspector.LayerTreeDispa
tcher(this)); |
| 43 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document
Updated, this._onDocumentUpdated, this); | 43 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.Document
Updated, this._onDocumentUpdated, this); |
| 44 } | 44 } |
| 45 | 45 |
| 46 WebInspector.LayerTreeModel.Events = { | 46 WebInspector.LayerTreeModel.Events = { |
| 47 LayerTreeChanged: "LayerTreeChanged", | 47 LayerTreeChanged: "LayerTreeChanged", |
| 48 LayerPainted: "LayerPainted", | 48 LayerPainted: "LayerPainted", |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** |
| 52 * @param {!LayerTreeAgent.ScrollRect} first |
| 53 * @param {!LayerTreeAgent.ScrollRect} second |
| 54 */ |
| 55 WebInspector.LayerTreeModel._scrollRectsAreEqual = function(first, second) |
| 56 { |
| 57 return first.rect.x === second.rect.x && first.rect.y === second.rect.y && |
| 58 first.rect.width === second.rect.width && first.rect.height === second.r
ect.height && |
| 59 first.type === second.type; |
| 60 } |
| 61 |
| 51 WebInspector.LayerTreeModel.prototype = { | 62 WebInspector.LayerTreeModel.prototype = { |
| 52 disable: function() | 63 disable: function() |
| 53 { | 64 { |
| 54 if (!this._enabled) | 65 if (!this._enabled) |
| 55 return; | 66 return; |
| 56 this._enabled = false; | 67 this._enabled = false; |
| 57 LayerTreeAgent.disable(); | 68 LayerTreeAgent.disable(); |
| 58 }, | 69 }, |
| 59 | 70 |
| 60 /** | 71 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 90 /** | 101 /** |
| 91 * @return {?WebInspector.Layer} | 102 * @return {?WebInspector.Layer} |
| 92 */ | 103 */ |
| 93 contentRoot: function() | 104 contentRoot: function() |
| 94 { | 105 { |
| 95 return this._contentRoot; | 106 return this._contentRoot; |
| 96 }, | 107 }, |
| 97 | 108 |
| 98 /** | 109 /** |
| 99 * @param {function(!WebInspector.Layer)} callback | 110 * @param {function(!WebInspector.Layer)} callback |
| 100 * @param {?WebInspector.Layer} root | 111 * @param {?WebInspector.Layer=} root |
| 101 * @return {boolean} | 112 * @return {boolean} |
| 102 */ | 113 */ |
| 103 forEachLayer: function(callback, root) | 114 forEachLayer: function(callback, root) |
| 104 { | 115 { |
| 105 if (!root) { | 116 if (!root) { |
| 106 root = this.root(); | 117 root = this.root(); |
| 107 if (!root) | 118 if (!root) |
| 108 return false; | 119 return false; |
| 109 } | 120 } |
| 110 return callback(root) || root.children().some(this.forEachLayer.bind(thi
s, callback)); | 121 return callback(root) || root.children().some(this.forEachLayer.bind(thi
s, callback)); |
| 111 }, | 122 }, |
| 112 | 123 |
| 113 /** | 124 /** |
| 114 * @param {string} id | 125 * @param {string} id |
| 115 * @return {?WebInspector.Layer} | 126 * @return {?WebInspector.Layer} |
| 116 */ | 127 */ |
| 117 layerById: function(id) | 128 layerById: function(id) |
| 118 { | 129 { |
| 119 return this._layersById[id] || null; | 130 return this._layersById[id] || null; |
| 120 }, | 131 }, |
| 121 | 132 |
| 122 /** | 133 /** |
| 123 * @param {!Array.<!LayerTreeAgent.Layer>} payload | 134 * @param {!Array.<!LayerTreeAgent.Layer>} layers |
| 124 */ | 135 */ |
| 125 _repopulate: function(payload) | 136 _repopulate: function(layers) |
| 126 { | 137 { |
| 127 var oldLayersById = this._layersById; | 138 var oldLayersById = this._layersById; |
| 128 this._layersById = {}; | 139 this._layersById = {}; |
| 129 for (var i = 0; i < payload.length; ++i) { | 140 for (var i = 0; i < layers.length; ++i) { |
| 130 var layerId = payload[i].layerId; | 141 var layerId = layers[i].layerId; |
| 131 var layer = oldLayersById[layerId]; | 142 var layer = oldLayersById[layerId]; |
| 132 if (layer) | 143 if (layer) |
| 133 layer._reset(payload[i]); | 144 layer._reset(layers[i]); |
| 134 else | 145 else |
| 135 layer = new WebInspector.Layer(payload[i]); | 146 layer = new WebInspector.Layer(layers[i]); |
| 136 this._layersById[layerId] = layer; | 147 this._layersById[layerId] = layer; |
| 137 var parentId = layer.parentId(); | 148 var parentId = layer.parentId(); |
| 138 if (!this._contentRoot && layer.nodeId()) | 149 if (!this._contentRoot && layer.nodeId()) |
| 139 this._contentRoot = layer; | 150 this._contentRoot = layer; |
| 140 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; | 151 var lastPaintRect = this._lastPaintRectByLayerId[layerId]; |
| 141 if (lastPaintRect) | 152 if (lastPaintRect) |
| 142 layer._lastPaintRect = lastPaintRect; | 153 layer._lastPaintRect = lastPaintRect; |
| 143 if (parentId) { | 154 if (parentId) { |
| 144 var parent = this._layersById[parentId]; | 155 var parent = this._layersById[parentId]; |
| 145 if (!parent) | 156 if (!parent) |
| 146 console.assert(parent, "missing parent " + parentId + " for
layer " + layerId); | 157 console.assert(parent, "missing parent " + parentId + " for
layer " + layerId); |
| 147 parent.addChild(layer); | 158 parent.addChild(layer); |
| 148 } else { | 159 } else { |
| 149 if (this._root) | 160 if (this._root) |
| 150 console.assert(false, "Multiple root layers"); | 161 console.assert(false, "Multiple root layers"); |
| 151 this._root = layer; | 162 this._root = layer; |
| 152 } | 163 } |
| 153 } | 164 } |
| 154 this._lastPaintRectByLayerId = {}; | 165 this._lastPaintRectByLayerId = {}; |
| 155 }, | 166 }, |
| 156 | 167 |
| 157 /** | 168 /** |
| 158 * @param {!Array.<!LayerTreeAgent.Layer>=} payload | 169 * @param {!Array.<!LayerTreeAgent.Layer>=} layers |
| 159 */ | 170 */ |
| 160 _layerTreeChanged: function(payload) | 171 _layerTreeChanged: function(layers) |
| 161 { | 172 { |
| 162 this._root = null; | 173 this._root = null; |
| 163 this._contentRoot = null; | 174 this._contentRoot = null; |
| 164 // Payload will be null when not in the composited mode. | 175 // Payload will be null when not in the composited mode. |
| 165 if (payload) | 176 if (layers) |
| 166 this._repopulate(payload); | 177 this._repopulate(layers); |
| 167 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr
eeChanged); | 178 this.dispatchEventToListeners(WebInspector.LayerTreeModel.Events.LayerTr
eeChanged); |
| 168 }, | 179 }, |
| 169 | 180 |
| 170 /** | 181 /** |
| 171 * @param {!LayerTreeAgent.LayerId} layerId | 182 * @param {!LayerTreeAgent.LayerId} layerId |
| 172 * @param {!DOMAgent.Rect} clipRect | 183 * @param {!DOMAgent.Rect} clipRect |
| 173 */ | 184 */ |
| 174 _layerPainted: function(layerId, clipRect) | 185 _layerPainted: function(layerId, clipRect) |
| 175 { | 186 { |
| 176 var layer = this._layersById[layerId]; | 187 var layer = this._layersById[layerId]; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 190 | 201 |
| 191 __proto__: WebInspector.Object.prototype | 202 __proto__: WebInspector.Object.prototype |
| 192 } | 203 } |
| 193 | 204 |
| 194 /** | 205 /** |
| 195 * @constructor | 206 * @constructor |
| 196 * @param {!LayerTreeAgent.Layer} layerPayload | 207 * @param {!LayerTreeAgent.Layer} layerPayload |
| 197 */ | 208 */ |
| 198 WebInspector.Layer = function(layerPayload) | 209 WebInspector.Layer = function(layerPayload) |
| 199 { | 210 { |
| 211 this._scrollRects = []; |
| 200 this._reset(layerPayload); | 212 this._reset(layerPayload); |
| 201 } | 213 } |
| 202 | 214 |
| 203 WebInspector.Layer.prototype = { | 215 WebInspector.Layer.prototype = { |
| 204 /** | 216 /** |
| 205 * @return {string} | 217 * @return {string} |
| 206 */ | 218 */ |
| 207 id: function() | 219 id: function() |
| 208 { | 220 { |
| 209 return this._layerPayload.layerId; | 221 return this._layerPayload.layerId; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 355 |
| 344 /** | 356 /** |
| 345 * @return {?DOMAgent.Rect} | 357 * @return {?DOMAgent.Rect} |
| 346 */ | 358 */ |
| 347 lastPaintRect: function() | 359 lastPaintRect: function() |
| 348 { | 360 { |
| 349 return this._lastPaintRect; | 361 return this._lastPaintRect; |
| 350 }, | 362 }, |
| 351 | 363 |
| 352 /** | 364 /** |
| 365 * @return {!Array.<!LayerTreeAgent.ScrollRect>} |
| 366 */ |
| 367 scrollRects: function() |
| 368 { |
| 369 return this._scrollRects; |
| 370 }, |
| 371 |
| 372 /** |
| 353 * @param {function(!Array.<string>)} callback | 373 * @param {function(!Array.<string>)} callback |
| 354 */ | 374 */ |
| 355 requestCompositingReasons: function(callback) | 375 requestCompositingReasons: function(callback) |
| 356 { | 376 { |
| 357 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "Lay
erTreeAgent.reasonsForCompositingLayer(): ", undefined, []); | 377 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "Lay
erTreeAgent.reasonsForCompositingLayer(): ", undefined, []); |
| 358 LayerTreeAgent.compositingReasons(this.id(), wrappedCallback); | 378 LayerTreeAgent.compositingReasons(this.id(), wrappedCallback); |
| 359 }, | 379 }, |
| 360 | 380 |
| 361 /** | 381 /** |
| 362 * @param {function(!WebInspector.PaintProfilerSnapshot=)} callback | 382 * @param {function(!WebInspector.PaintProfilerSnapshot=)} callback |
| (...skipping 17 matching lines...) Expand all Loading... |
| 380 /** | 400 /** |
| 381 * @param {!LayerTreeAgent.Layer} layerPayload | 401 * @param {!LayerTreeAgent.Layer} layerPayload |
| 382 */ | 402 */ |
| 383 _reset: function(layerPayload) | 403 _reset: function(layerPayload) |
| 384 { | 404 { |
| 385 this._children = []; | 405 this._children = []; |
| 386 this._parent = null; | 406 this._parent = null; |
| 387 this._paintCount = 0; | 407 this._paintCount = 0; |
| 388 this._layerPayload = layerPayload; | 408 this._layerPayload = layerPayload; |
| 389 this._image = null; | 409 this._image = null; |
| 410 this._updateScrollRects(); |
| 411 }, |
| 412 |
| 413 _updateScrollRects: function() |
| 414 { |
| 415 var newRects = this._layerPayload.scrollRects || []; |
| 416 for (var i = 0; i < newRects.length; ++i) { |
| 417 if (i >= this._scrollRects.length || |
| 418 !WebInspector.LayerTreeModel._scrollRectsAreEqual(newRects[i], t
his._scrollRects[i])) { |
| 419 this._scrollRects[i] = newRects[i]; |
| 420 } |
| 421 } |
| 422 this._scrollRects.splice(newRects.length); |
| 390 } | 423 } |
| 391 } | 424 } |
| 392 | 425 |
| 393 /** | 426 /** |
| 394 * @constructor | 427 * @constructor |
| 395 * @implements {LayerTreeAgent.Dispatcher} | 428 * @implements {LayerTreeAgent.Dispatcher} |
| 396 * @param {!WebInspector.LayerTreeModel} layerTreeModel | 429 * @param {!WebInspector.LayerTreeModel} layerTreeModel |
| 397 */ | 430 */ |
| 398 WebInspector.LayerTreeDispatcher = function(layerTreeModel) | 431 WebInspector.LayerTreeDispatcher = function(layerTreeModel) |
| 399 { | 432 { |
| 400 this._layerTreeModel = layerTreeModel; | 433 this._layerTreeModel = layerTreeModel; |
| 401 } | 434 } |
| 402 | 435 |
| 403 WebInspector.LayerTreeDispatcher.prototype = { | 436 WebInspector.LayerTreeDispatcher.prototype = { |
| 404 /** | 437 /** |
| 405 * @param {!Array.<!LayerTreeAgent.Layer>=} payload | 438 * @param {!Array.<!LayerTreeAgent.Layer>=} layers |
| 406 */ | 439 */ |
| 407 layerTreeDidChange: function(payload) | 440 layerTreeDidChange: function(layers) |
| 408 { | 441 { |
| 409 this._layerTreeModel._layerTreeChanged(payload); | 442 this._layerTreeModel._layerTreeChanged(layers); |
| 410 }, | 443 }, |
| 411 | 444 |
| 412 /** | 445 /** |
| 413 * @param {!LayerTreeAgent.LayerId} layerId | 446 * @param {!LayerTreeAgent.LayerId} layerId |
| 414 * @param {!DOMAgent.Rect} clipRect | 447 * @param {!DOMAgent.Rect} clipRect |
| 415 */ | 448 */ |
| 416 layerPainted: function(layerId, clipRect) | 449 layerPainted: function(layerId, clipRect) |
| 417 { | 450 { |
| 418 this._layerTreeModel._layerPainted(layerId, clipRect); | 451 this._layerTreeModel._layerPainted(layerId, clipRect); |
| 419 } | 452 } |
| 420 } | 453 } |
| OLD | NEW |