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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline_model/TracingLayerTree.js

Issue 2434393002: Timeline: promisify paint profiler and Layers panel, part I (Closed)
Patch Set: Timeline: promisify paint profiler and Layers panel, part I Created 4 years, 1 month 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 // 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 4
5 /** @typedef {!{ 5 /** @typedef {!{
6 bounds: {height: number, width: number}, 6 bounds: {height: number, width: number},
7 children: Array.<!WebInspector.TracingLayerPayload>, 7 children: Array.<!WebInspector.TracingLayerPayload>,
8 layer_id: number, 8 layer_id: number,
9 position: Array.<number>, 9 position: Array.<number>,
10 scroll_offset: Array.<number>, 10 scroll_offset: Array.<number>,
11 layer_quad: Array.<number>, 11 layer_quad: Array.<number>,
12 draws_content: number, 12 draws_content: number,
13 gpu_memory_usage: number, 13 gpu_memory_usage: number,
14 transform: Array.<number>, 14 transform: Array.<number>,
15 owner_node: number, 15 owner_node: number,
16 compositing_reasons: Array.<string> 16 compositing_reasons: Array.<string>
17 }} 17 }}
18 */ 18 */
19 WebInspector.TracingLayerPayload; 19 WebInspector.TracingLayerPayload;
20 20
21 /** @typedef {!{ 21 /** @typedef {!{
22 id: string, 22 id: string,
23 layer_id: string, 23 layer_id: string,
24 gpu_memory_usage: number, 24 gpu_memory_usage: number,
25 content_rect: !Array.<number> 25 content_rect: !Array.<number>
26 }} 26 }}
27 */ 27 */
28 WebInspector.TracingLayerTile; 28 WebInspector.TracingLayerTile;
29 29
30 /** @typedef {!{
31 rect: !DOMAgent.Rect,
alph 2016/10/21 00:25:10 indent
32 snapshot: !WebInspector.PaintProfilerSnapshot
33 }}
34 */
35 WebInspector.SnapshotWithRect;
36
30 /** 37 /**
31 * @constructor 38 * @constructor
32 * @extends {WebInspector.LayerTreeBase} 39 * @extends {WebInspector.LayerTreeBase}
33 * @param {?WebInspector.Target} target 40 * @param {?WebInspector.Target} target
34 */ 41 */
35 WebInspector.TracingLayerTree = function(target) 42 WebInspector.TracingLayerTree = function(target)
36 { 43 {
37 WebInspector.LayerTreeBase.call(this, target); 44 WebInspector.LayerTreeBase.call(this, target);
38 /** @type {!Map.<string, !WebInspector.TracingLayerTile>} */ 45 /** @type {!Map.<string, !WebInspector.TracingLayerTile>} */
39 this._tileById = new Map(); 46 this._tileById = new Map();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 */ 96 */
90 setTiles: function(tiles) 97 setTiles: function(tiles)
91 { 98 {
92 this._tileById = new Map(); 99 this._tileById = new Map();
93 for (var tile of tiles) 100 for (var tile of tiles)
94 this._tileById.set(tile.id, tile); 101 this._tileById.set(tile.id, tile);
95 }, 102 },
96 103
97 /** 104 /**
98 * @param {string} tileId 105 * @param {string} tileId
99 * @param {function(?DOMAgent.Rect, ?WebInspector.PaintProfilerSnapshot)} ca llback 106 * @return {!Promise<?WebInspector.SnapshotWithRect>}
100 */ 107 */
101 pictureForRasterTile: function(tileId, callback) 108 pictureForRasterTile: function(tileId)
102 { 109 {
103 var tile = this._tileById.get("cc::Tile/" + tileId); 110 var tile = this._tileById.get("cc::Tile/" + tileId);
104 if (!tile) { 111 if (!tile) {
105 WebInspector.console.error(`Tile ${tileId} is missing`); 112 WebInspector.console.error(`Tile ${tileId} is missing`);
106 callback(null, null); 113 return /** @type {!Promise<?WebInspector.SnapshotWithRect>} */ (Prom ise.resolve(null));
107 return;
108 } 114 }
109 var layer = this.layerById(tile.layer_id); 115 var layer = this.layerById(tile.layer_id);
110 if (!layer) { 116 if (!layer) {
111 WebInspector.console.error(`Layer ${tile.layer_id} for tile ${tileId } is not found`); 117 WebInspector.console.error(`Layer ${tile.layer_id} for tile ${tileId } is not found`);
112 callback(null, null); 118 return /** @type {!Promise<?WebInspector.SnapshotWithRect>} */ (Prom ise.resolve(null));
113 return;
114 } 119 }
115 layer.pictureForRect(this.target(), tile.content_rect, callback); 120 return layer.pictureForRect(this.target(), tile.content_rect);
116 }, 121 },
117 122
118 /** 123 /**
119 * @param {!Array<!WebInspector.LayerPaintEvent>} paints 124 * @param {!Array<!WebInspector.LayerPaintEvent>} paints
120 */ 125 */
121 _setPaints: function(paints) 126 _setPaints: function(paints)
122 { 127 {
123 for (var i = 0; i < paints.length; ++i) { 128 for (var i = 0; i < paints.length; ++i) {
124 var layer = this._layersById[paints[i].layerId()]; 129 var layer = this._layersById[paints[i].layerId()];
125 if (layer) 130 if (layer)
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 * @return {number} 398 * @return {number}
394 */ 399 */
395 gpuMemoryUsage: function() 400 gpuMemoryUsage: function()
396 { 401 {
397 return this._gpuMemoryUsage; 402 return this._gpuMemoryUsage;
398 }, 403 },
399 404
400 /** 405 /**
401 * @param {!WebInspector.Target} target 406 * @param {!WebInspector.Target} target
402 * @param {!Array<number>} targetRect 407 * @param {!Array<number>} targetRect
403 * @param {function(?DOMAgent.Rect, ?WebInspector.PaintProfilerSnapshot)} ca llback 408 * @return {!Promise<?{rect: !DOMAgent.Rect, snapshot: !WebInspector.PaintPr ofilerSnapshot}>}
404 */ 409 */
405 pictureForRect: function(target, targetRect, callback) 410 pictureForRect: function(target, targetRect)
406 { 411 {
407 var fetchPictureFragmentsBarrier = new CallbackBarrier(); 412 return Promise.all(this._paints.map(paint => paint.picturePromise())).th en(pictures => {
408 this._paints.forEach(paint => paint.loadPicture(fetchPictureFragmentsBar rier.createCallback(pictureLoaded))); 413 var fragments = pictures.filter(picture => picture && rectsOverlap(p icture.rect, targetRect))
409 fetchPictureFragmentsBarrier.callWhenDone(allPicturesLoaded); 414 .map(picture => ({x: picture.rect[0], y: picture.rect[1], pictur e: picture.serializedPicture}));
415 if (!fragments.length)
416 return null;
417 var topLeft = fragments.reduce((acc, current) => ({x: Math.min(acc.x , current.x), y: Math.min(acc.y, current.y)}), {x: Infinity, y: Infinity});
alph 2016/10/21 00:25:10 For the sake of performance I'd do it with two red
418 // Rect is in layer content coordinates, make it relative to picture by offsetting to the top left corner.
419 var rect = {x: targetRect[0] - topLeft.x, y: targetRect[1] - topLeft .y, width: targetRect[2], height: targetRect[3]};
420 return WebInspector.PaintProfilerSnapshot.loadFromFragments(target, fragments).then(snapshot => snapshot ? {rect: rect, snapshot: snapshot} : null);
421 });
410 422
411 /** 423 /**
412 * @param {number} a1 424 * @param {number} a1
413 * @param {number} a2 425 * @param {number} a2
414 * @param {number} b1 426 * @param {number} b1
415 * @param {number} b2 427 * @param {number} b2
416 * @return {boolean} 428 * @return {boolean}
417 */ 429 */
418 function segmentsOverlap(a1, a2, b1, b2) 430 function segmentsOverlap(a1, a2, b1, b2)
419 { 431 {
420 console.assert(a1 <= a2 && b1 <= b2, "segments should be specified a s ordered pairs"); 432 console.assert(a1 <= a2 && b1 <= b2, "segments should be specified a s ordered pairs");
421 return a2 > b1 && a1 < b2; 433 return a2 > b1 && a1 < b2;
422 } 434 }
435
423 /** 436 /**
424 * @param {!Array.<number>} a 437 * @param {!Array.<number>} a
425 * @param {!Array.<number>} b 438 * @param {!Array.<number>} b
426 * @return {boolean} 439 * @return {boolean}
427 */ 440 */
428 function rectsOverlap(a, b) 441 function rectsOverlap(a, b)
429 { 442 {
430 return segmentsOverlap(a[0], a[0] + a[2], b[0], b[0] + b[2]) && segm entsOverlap(a[1], a[1] + a[3], b[1], b[1] + b[3]); 443 return segmentsOverlap(a[0], a[0] + a[2], b[0], b[0] + b[2]) && segm entsOverlap(a[1], a[1] + a[3], b[1], b[1] + b[3]);
431 } 444 }
432
433 var x0 = Infinity;
434 var y0 = Infinity;
435 var fragments = [];
436 /**
437 * @param {?Array.<number>} rect
438 * @param {?string} picture
439 */
440 function pictureLoaded(rect, picture)
441 {
442 if (!rect || !picture)
443 return;
444 if (!rectsOverlap(rect, targetRect))
445 return;
446 var x = rect[0];
447 var y = rect[1];
448 x0 = Math.min(x0, x);
449 y0 = Math.min(y0, y);
450 fragments.push({x: x, y: y, picture: picture});
451 }
452
453 function allPicturesLoaded()
454 {
455 if (!fragments.length) {
456 callback(null, null);
457 return;
458 }
459 // Rect is in layer content coordinates, make it relative to picture by offsetting to the top left corner.
460 var rect = {x: targetRect[0] - x0, y: targetRect[1] - y0, width: tar getRect[2], height: targetRect[3]};
461 WebInspector.PaintProfilerSnapshot.loadFromFragments(target, fragmen ts, callback.bind(null, rect));
462 }
463 }, 445 },
464 446
465 /** 447 /**
466 * @param {!Array.<number>} params 448 * @param {!Array.<number>} params
467 * @param {string} type 449 * @param {string} type
468 * @return {!Object} 450 * @return {!Object}
469 */ 451 */
470 _scrollRectsFromParams: function(params, type) 452 _scrollRectsFromParams: function(params, type)
471 { 453 {
472 return {rect: {x: params[0], y: params[1], width: params[2], height: par ams[3]}, type: type}; 454 return {rect: {x: params[0], y: params[1], width: params[2], height: par ams[3]}, type: type};
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 489
508 /** 490 /**
509 * @override 491 * @override
510 * @return {boolean} 492 * @return {boolean}
511 */ 493 */
512 drawsContent: function() 494 drawsContent: function()
513 { 495 {
514 return this._drawsContent; 496 return this._drawsContent;
515 } 497 }
516 } 498 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698