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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/layers/LayerTreeModel.js

Issue 2845813003: [DevTools] Host paint profiles in PaintProfilerModel (Closed)
Patch Set: addressed comments Created 3 years, 7 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 16 matching lines...) Expand all
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 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 Layers.LayerTreeModel = class extends SDK.SDKModel { 34 Layers.LayerTreeModel = class extends SDK.SDKModel {
35 constructor(target) { 35 constructor(target) {
36 super(target); 36 super(target);
37 this._layerTreeAgent = target.layerTreeAgent();
37 target.registerLayerTreeDispatcher(new Layers.LayerTreeDispatcher(this)); 38 target.registerLayerTreeDispatcher(new Layers.LayerTreeDispatcher(this));
39 this._paintProfilerModel = /** @type {!SDK.PaintProfilerModel} */ (target.mo del(SDK.PaintProfilerModel));
38 var resourceTreeModel = target.model(SDK.ResourceTreeModel); 40 var resourceTreeModel = target.model(SDK.ResourceTreeModel);
39 if (resourceTreeModel) { 41 if (resourceTreeModel) {
40 resourceTreeModel.addEventListener( 42 resourceTreeModel.addEventListener(
41 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._onMainFrameNavi gated, this); 43 SDK.ResourceTreeModel.Events.MainFrameNavigated, this._onMainFrameNavi gated, this);
42 } 44 }
43 /** @type {?SDK.LayerTreeBase} */ 45 /** @type {?SDK.LayerTreeBase} */
44 this._layerTree = null; 46 this._layerTree = null;
45 } 47 }
46 48
47 disable() { 49 disable() {
48 if (!this._enabled) 50 if (!this._enabled)
49 return; 51 return;
50 this._enabled = false; 52 this._enabled = false;
51 this.target().layerTreeAgent().disable(); 53 this._layerTreeAgent.disable();
52 } 54 }
53 55
54 enable() { 56 enable() {
55 if (this._enabled) 57 if (this._enabled)
56 return; 58 return;
57 this._enabled = true; 59 this._enabled = true;
58 this._forceEnable(); 60 this._forceEnable();
59 } 61 }
60 62
61 _forceEnable() { 63 _forceEnable() {
62 this._lastPaintRectByLayerId = {}; 64 this._lastPaintRectByLayerId = {};
63 if (!this._layerTree) 65 if (!this._layerTree)
64 this._layerTree = new Layers.AgentLayerTree(this.target()); 66 this._layerTree = new Layers.AgentLayerTree(this);
65 this.target().layerTreeAgent().enable(); 67 this._layerTreeAgent.enable();
66 } 68 }
67 69
68 /** 70 /**
69 * @return {?SDK.LayerTreeBase} 71 * @return {?SDK.LayerTreeBase}
70 */ 72 */
71 layerTree() { 73 layerTree() {
72 return this._layerTree; 74 return this._layerTree;
73 } 75 }
74 76
75 /** 77 /**
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 Layers.LayerTreeModel.Events = { 129 Layers.LayerTreeModel.Events = {
128 LayerTreeChanged: Symbol('LayerTreeChanged'), 130 LayerTreeChanged: Symbol('LayerTreeChanged'),
129 LayerPainted: Symbol('LayerPainted'), 131 LayerPainted: Symbol('LayerPainted'),
130 }; 132 };
131 133
132 /** 134 /**
133 * @unrestricted 135 * @unrestricted
134 */ 136 */
135 Layers.AgentLayerTree = class extends SDK.LayerTreeBase { 137 Layers.AgentLayerTree = class extends SDK.LayerTreeBase {
136 /** 138 /**
137 * @param {?SDK.Target} target 139 * @param {!Layers.LayerTreeModel} layerTreeModel
138 */ 140 */
139 constructor(target) { 141 constructor(layerTreeModel) {
140 super(target); 142 super(layerTreeModel.target());
143 this._layerTreeModel = layerTreeModel;
141 } 144 }
142 145
143 /** 146 /**
144 * @param {?Array.<!Protocol.LayerTree.Layer>} payload 147 * @param {?Array.<!Protocol.LayerTree.Layer>} payload
145 * @param {function()} callback 148 * @param {function()} callback
146 */ 149 */
147 setLayers(payload, callback) { 150 setLayers(payload, callback) {
148 if (!payload) { 151 if (!payload) {
149 onBackendNodeIdsResolved.call(this); 152 onBackendNodeIdsResolved.call(this);
150 return; 153 return;
(...skipping 28 matching lines...) Expand all
179 return; 182 return;
180 var root; 183 var root;
181 var oldLayersById = this._layersById; 184 var oldLayersById = this._layersById;
182 this._layersById = {}; 185 this._layersById = {};
183 for (var i = 0; i < layers.length; ++i) { 186 for (var i = 0; i < layers.length; ++i) {
184 var layerId = layers[i].layerId; 187 var layerId = layers[i].layerId;
185 var layer = oldLayersById[layerId]; 188 var layer = oldLayersById[layerId];
186 if (layer) 189 if (layer)
187 layer._reset(layers[i]); 190 layer._reset(layers[i]);
188 else 191 else
189 layer = new Layers.AgentLayer(this.target(), layers[i]); 192 layer = new Layers.AgentLayer(this._layerTreeModel, layers[i]);
190 this._layersById[layerId] = layer; 193 this._layersById[layerId] = layer;
191 var backendNodeId = layers[i].backendNodeId; 194 var backendNodeId = layers[i].backendNodeId;
192 if (backendNodeId) 195 if (backendNodeId)
193 layer._setNode(this.backendNodeIdToNode().get(backendNodeId)); 196 layer._setNode(this.backendNodeIdToNode().get(backendNodeId));
194 if (!this.contentRoot() && layer.drawsContent()) 197 if (!this.contentRoot() && layer.drawsContent())
195 this.setContentRoot(layer); 198 this.setContentRoot(layer);
196 var parentId = layer.parentId(); 199 var parentId = layer.parentId();
197 if (parentId) { 200 if (parentId) {
198 var parent = this._layersById[parentId]; 201 var parent = this._layersById[parentId];
199 if (!parent) 202 if (!parent)
(...skipping 11 matching lines...) Expand all
211 } 214 }
212 } 215 }
213 }; 216 };
214 217
215 /** 218 /**
216 * @implements {SDK.Layer} 219 * @implements {SDK.Layer}
217 * @unrestricted 220 * @unrestricted
218 */ 221 */
219 Layers.AgentLayer = class { 222 Layers.AgentLayer = class {
220 /** 223 /**
221 * @param {?SDK.Target} target 224 * @param {!Layers.LayerTreeModel} layerTreeModel
222 * @param {!Protocol.LayerTree.Layer} layerPayload 225 * @param {!Protocol.LayerTree.Layer} layerPayload
223 */ 226 */
224 constructor(target, layerPayload) { 227 constructor(layerTreeModel, layerPayload) {
225 this._target = target; 228 this._layerTreeModel = layerTreeModel;
226 this._reset(layerPayload); 229 this._reset(layerPayload);
227 } 230 }
228 231
229 /** 232 /**
230 * @override 233 * @override
231 * @return {string} 234 * @return {string}
232 */ 235 */
233 id() { 236 id() {
234 return this._layerPayload.layerId; 237 return this._layerPayload.layerId;
235 } 238 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 */ 397 */
395 scrollRects() { 398 scrollRects() {
396 return this._scrollRects; 399 return this._scrollRects;
397 } 400 }
398 401
399 /** 402 /**
400 * @override 403 * @override
401 * @param {function(!Array.<string>)} callback 404 * @param {function(!Array.<string>)} callback
402 */ 405 */
403 requestCompositingReasons(callback) { 406 requestCompositingReasons(callback) {
404 if (!this._target) {
405 callback([]);
406 return;
407 }
408
409 var wrappedCallback = Protocol.inspectorBackend.wrapClientCallback( 407 var wrappedCallback = Protocol.inspectorBackend.wrapClientCallback(
410 callback, 'Protocol.LayerTree.reasonsForCompositingLayer(): ', undefined , []); 408 callback, 'Protocol.LayerTree.reasonsForCompositingLayer(): ', undefined , []);
411 this._target.layerTreeAgent().compositingReasons(this.id(), wrappedCallback) ; 409 this._layerTreeModel._layerTreeAgent.compositingReasons(this.id(), wrappedCa llback);
412 } 410 }
413 411
414 /** 412 /**
415 * @override 413 * @override
416 * @return {boolean} 414 * @return {boolean}
417 */ 415 */
418 drawsContent() { 416 drawsContent() {
419 return this._layerPayload.drawsContent; 417 return this._layerPayload.drawsContent;
420 } 418 }
421 419
422 /** 420 /**
423 * @override 421 * @override
424 * @return {number} 422 * @return {number}
425 */ 423 */
426 gpuMemoryUsage() { 424 gpuMemoryUsage() {
427 /** 425 /**
428 * @const 426 * @const
429 */ 427 */
430 var bytesPerPixel = 4; 428 var bytesPerPixel = 4;
431 return this.drawsContent() ? this.width() * this.height() * bytesPerPixel : 0; 429 return this.drawsContent() ? this.width() * this.height() * bytesPerPixel : 0;
432 } 430 }
433 431
434 /** 432 /**
435 * @override 433 * @override
436 * @return {!Array<!Promise<?SDK.SnapshotWithRect>>} 434 * @return {!Array<!Promise<?SDK.SnapshotWithRect>>}
437 */ 435 */
438 snapshots() { 436 snapshots() {
439 var rect = {x: 0, y: 0, width: this.width(), height: this.height()}; 437 var promise = this._layerTreeModel._paintProfilerModel.makeSnapshot(this.id( )).then(snapshot => {
440 var promise = this._target.layerTreeAgent().makeSnapshot( 438 if (!snapshot)
441 this.id(), (error, snapshotId) => error || !this._target ? 439 return null;
442 null : 440 return {rect: {x: 0, y: 0, width: this.width(), height: this.height()}, sn apshot: snapshot};
443 {rect: rect, snapshot: new SDK.PaintProfilerSnapshot(this._target, s napshotId)}); 441 });
444 return [promise]; 442 return [promise];
445 } 443 }
446 444
447 /** 445 /**
448 * @param {!Protocol.DOM.Rect} rect 446 * @param {!Protocol.DOM.Rect} rect
449 */ 447 */
450 _didPaint(rect) { 448 _didPaint(rect) {
451 this._lastPaintRect = rect; 449 this._lastPaintRect = rect;
452 this._paintCount = this.paintCount() + 1; 450 this._paintCount = this.paintCount() + 1;
453 this._image = null; 451 this._image = null;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 550
553 /** 551 /**
554 * @override 552 * @override
555 * @param {!Protocol.LayerTree.LayerId} layerId 553 * @param {!Protocol.LayerTree.LayerId} layerId
556 * @param {!Protocol.DOM.Rect} clipRect 554 * @param {!Protocol.DOM.Rect} clipRect
557 */ 555 */
558 layerPainted(layerId, clipRect) { 556 layerPainted(layerId, clipRect) {
559 this._layerTreeModel._layerPainted(layerId, clipRect); 557 this._layerTreeModel._layerPainted(layerId, clipRect);
560 } 558 }
561 }; 559 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698