OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 /** @typedef {!{ | 4 /** @typedef {!{ |
5 bounds: {height: number, width: number}, | 5 bounds: {height: number, width: number}, |
6 children: Array.<!TimelineModel.TracingLayerPayload>, | 6 children: Array.<!TimelineModel.TracingLayerPayload>, |
7 layer_id: number, | 7 layer_id: number, |
8 position: Array.<number>, | 8 position: Array.<number>, |
9 scroll_offset: Array.<number>, | 9 scroll_offset: Array.<number>, |
10 layer_quad: Array.<number>, | 10 layer_quad: Array.<number>, |
(...skipping 19 matching lines...) Expand all Loading... |
30 * @unrestricted | 30 * @unrestricted |
31 */ | 31 */ |
32 TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase { | 32 TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase { |
33 /** | 33 /** |
34 * @param {?SDK.Target} target | 34 * @param {?SDK.Target} target |
35 */ | 35 */ |
36 constructor(target) { | 36 constructor(target) { |
37 super(target); | 37 super(target); |
38 /** @type {!Map.<string, !TimelineModel.TracingLayerTile>} */ | 38 /** @type {!Map.<string, !TimelineModel.TracingLayerTile>} */ |
39 this._tileById = new Map(); | 39 this._tileById = new Map(); |
| 40 this._paintProfilerModel = target && target.model(SDK.PaintProfilerModel); |
40 } | 41 } |
41 | 42 |
42 /** | 43 /** |
43 * @param {?TimelineModel.TracingLayerPayload} root | 44 * @param {?TimelineModel.TracingLayerPayload} root |
44 * @param {?Array<!TimelineModel.TracingLayerPayload>} layers | 45 * @param {?Array<!TimelineModel.TracingLayerPayload>} layers |
45 * @param {!Array<!TimelineModel.LayerPaintEvent>} paints | 46 * @param {!Array<!TimelineModel.LayerPaintEvent>} paints |
46 * @param {function()} callback | 47 * @param {function()} callback |
47 */ | 48 */ |
48 setLayers(root, layers, paints, callback) { | 49 setLayers(root, layers, paints, callback) { |
49 var idsToResolve = new Set(); | 50 var idsToResolve = new Set(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 /** | 123 /** |
123 * @param {!Object<(string|number), !SDK.Layer>} oldLayersById | 124 * @param {!Object<(string|number), !SDK.Layer>} oldLayersById |
124 * @param {!TimelineModel.TracingLayerPayload} payload | 125 * @param {!TimelineModel.TracingLayerPayload} payload |
125 * @return {!TimelineModel.TracingLayer} | 126 * @return {!TimelineModel.TracingLayer} |
126 */ | 127 */ |
127 _innerSetLayers(oldLayersById, payload) { | 128 _innerSetLayers(oldLayersById, payload) { |
128 var layer = /** @type {?TimelineModel.TracingLayer} */ (oldLayersById[payloa
d.layer_id]); | 129 var layer = /** @type {?TimelineModel.TracingLayer} */ (oldLayersById[payloa
d.layer_id]); |
129 if (layer) | 130 if (layer) |
130 layer._reset(payload); | 131 layer._reset(payload); |
131 else | 132 else |
132 layer = new TimelineModel.TracingLayer(this.target(), payload); | 133 layer = new TimelineModel.TracingLayer(this._paintProfilerModel, payload); |
133 this._layersById[payload.layer_id] = layer; | 134 this._layersById[payload.layer_id] = layer; |
134 if (payload.owner_node) | 135 if (payload.owner_node) |
135 layer._setNode(this.backendNodeIdToNode().get(payload.owner_node) || null)
; | 136 layer._setNode(this.backendNodeIdToNode().get(payload.owner_node) || null)
; |
136 if (!this.contentRoot() && layer.drawsContent()) | 137 if (!this.contentRoot() && layer.drawsContent()) |
137 this.setContentRoot(layer); | 138 this.setContentRoot(layer); |
138 for (var i = 0; payload.children && i < payload.children.length; ++i) | 139 for (var i = 0; payload.children && i < payload.children.length; ++i) |
139 layer.addChild(this._innerSetLayers(oldLayersById, payload.children[i])); | 140 layer.addChild(this._innerSetLayers(oldLayersById, payload.children[i])); |
140 return layer; | 141 return layer; |
141 } | 142 } |
142 | 143 |
(...skipping 10 matching lines...) Expand all Loading... |
153 this._extractNodeIdsToResolve(nodeIdsToResolve, seenNodeIds, payload.child
ren[i]); | 154 this._extractNodeIdsToResolve(nodeIdsToResolve, seenNodeIds, payload.child
ren[i]); |
154 } | 155 } |
155 }; | 156 }; |
156 | 157 |
157 /** | 158 /** |
158 * @implements {SDK.Layer} | 159 * @implements {SDK.Layer} |
159 * @unrestricted | 160 * @unrestricted |
160 */ | 161 */ |
161 TimelineModel.TracingLayer = class { | 162 TimelineModel.TracingLayer = class { |
162 /** | 163 /** |
| 164 * @param {?SDK.PaintProfilerModel} paintProfilerModel |
163 * @param {!TimelineModel.TracingLayerPayload} payload | 165 * @param {!TimelineModel.TracingLayerPayload} payload |
164 * @param {?SDK.Target} target | |
165 */ | 166 */ |
166 constructor(target, payload) { | 167 constructor(paintProfilerModel, payload) { |
167 this._target = target; | 168 this._paintProfilerModel = paintProfilerModel; |
168 this._reset(payload); | 169 this._reset(payload); |
169 } | 170 } |
170 | 171 |
171 /** | 172 /** |
172 * @param {!TimelineModel.TracingLayerPayload} payload | 173 * @param {!TimelineModel.TracingLayerPayload} payload |
173 */ | 174 */ |
174 _reset(payload) { | 175 _reset(payload) { |
175 /** @type {?SDK.DOMNode} */ | 176 /** @type {?SDK.DOMNode} */ |
176 this._node = null; | 177 this._node = null; |
177 this._layerId = String(payload.layer_id); | 178 this._layerId = String(payload.layer_id); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 381 |
381 /** | 382 /** |
382 * @param {!Array<number>} targetRect | 383 * @param {!Array<number>} targetRect |
383 * @return {!Promise<?SDK.SnapshotWithRect>} | 384 * @return {!Promise<?SDK.SnapshotWithRect>} |
384 */ | 385 */ |
385 _pictureForRect(targetRect) { | 386 _pictureForRect(targetRect) { |
386 return Promise.all(this._paints.map(paint => paint.picturePromise())).then(p
ictures => { | 387 return Promise.all(this._paints.map(paint => paint.picturePromise())).then(p
ictures => { |
387 var fragments = | 388 var fragments = |
388 pictures.filter(picture => picture && rectsOverlap(picture.rect, targe
tRect)) | 389 pictures.filter(picture => picture && rectsOverlap(picture.rect, targe
tRect)) |
389 .map(picture => ({x: picture.rect[0], y: picture.rect[1], picture:
picture.serializedPicture})); | 390 .map(picture => ({x: picture.rect[0], y: picture.rect[1], picture:
picture.serializedPicture})); |
390 if (!fragments.length || !this._target) | 391 if (!fragments.length || !this._paintProfilerModel) |
391 return null; | 392 return null; |
392 var x0 = fragments.reduce((min, item) => Math.min(min, item.x), Infinity); | 393 var x0 = fragments.reduce((min, item) => Math.min(min, item.x), Infinity); |
393 var y0 = fragments.reduce((min, item) => Math.min(min, item.y), Infinity); | 394 var y0 = fragments.reduce((min, item) => Math.min(min, item.y), Infinity); |
394 // Rect is in layer content coordinates, make it relative to picture by of
fsetting to the top left corner. | 395 // Rect is in layer content coordinates, make it relative to picture by of
fsetting to the top left corner. |
395 var rect = {x: targetRect[0] - x0, y: targetRect[1] - y0, width: targetRec
t[2], height: targetRect[3]}; | 396 var rect = {x: targetRect[0] - x0, y: targetRect[1] - y0, width: targetRec
t[2], height: targetRect[3]}; |
396 return SDK.PaintProfilerSnapshot.loadFromFragments(this._target, fragments
) | 397 return this._paintProfilerModel.loadSnapshotFromFragments(fragments).then( |
397 .then(snapshot => snapshot ? {rect: rect, snapshot: snapshot} : null); | 398 snapshot => snapshot ? {rect: rect, snapshot: snapshot} : null); |
398 }); | 399 }); |
399 | 400 |
400 /** | 401 /** |
401 * @param {number} a1 | 402 * @param {number} a1 |
402 * @param {number} a2 | 403 * @param {number} a2 |
403 * @param {number} b1 | 404 * @param {number} b1 |
404 * @param {number} b2 | 405 * @param {number} b2 |
405 * @return {boolean} | 406 * @return {boolean} |
406 */ | 407 */ |
407 function segmentsOverlap(a1, a2, b1, b2) { | 408 function segmentsOverlap(a1, a2, b1, b2) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 469 } |
469 | 470 |
470 /** | 471 /** |
471 * @override | 472 * @override |
472 * @return {boolean} | 473 * @return {boolean} |
473 */ | 474 */ |
474 drawsContent() { | 475 drawsContent() { |
475 return this._drawsContent; | 476 return this._drawsContent; |
476 } | 477 } |
477 }; | 478 }; |
OLD | NEW |