Commit 39206f00 authored by dgozman's avatar dgozman Committed by Commit bot

[DevTools] Host paint profiles in PaintProfilerModel

This ensures proper capability check.

BUG=none

Review-Url: https://codereview.chromium.org/2845813003
Cr-Commit-Position: refs/heads/master@{#468108}
parent fd1f401a
...@@ -370,11 +370,9 @@ LayerViewer.PaintProfilerCommandLogView = class extends UI.ThrottledWidget { ...@@ -370,11 +370,9 @@ LayerViewer.PaintProfilerCommandLogView = class extends UI.ThrottledWidget {
} }
/** /**
* @param {?SDK.Target} target
* @param {!Array.<!SDK.PaintProfilerLogItem>} log * @param {!Array.<!SDK.PaintProfilerLogItem>} log
*/ */
setCommandLog(target, log) { setCommandLog(log) {
this._target = target;
this._log = log; this._log = log;
/** @type {!Map<!SDK.PaintProfilerLogItem>} */ /** @type {!Map<!SDK.PaintProfilerLogItem>} */
this._treeItemCache = new Map(); this._treeItemCache = new Map();
......
...@@ -34,7 +34,7 @@ Layers.LayerPaintProfilerView = class extends UI.SplitWidget { ...@@ -34,7 +34,7 @@ Layers.LayerPaintProfilerView = class extends UI.SplitWidget {
* @this {Layers.LayerPaintProfilerView} * @this {Layers.LayerPaintProfilerView}
*/ */
function setSnapshotAndLog(snapshot, log) { function setSnapshotAndLog(snapshot, log) {
this._logTreeView.setCommandLog(snapshot && snapshot.target(), log || []); this._logTreeView.setCommandLog(log || []);
this._paintProfilerView.setSnapshotAndLog(snapshot, log || [], null); this._paintProfilerView.setSnapshotAndLog(snapshot, log || [], null);
if (snapshot) if (snapshot)
snapshot.release(); snapshot.release();
......
...@@ -34,7 +34,9 @@ ...@@ -34,7 +34,9 @@
Layers.LayerTreeModel = class extends SDK.SDKModel { Layers.LayerTreeModel = class extends SDK.SDKModel {
constructor(target) { constructor(target) {
super(target); super(target);
this._layerTreeAgent = target.layerTreeAgent();
target.registerLayerTreeDispatcher(new Layers.LayerTreeDispatcher(this)); target.registerLayerTreeDispatcher(new Layers.LayerTreeDispatcher(this));
this._paintProfilerModel = /** @type {!SDK.PaintProfilerModel} */ (target.model(SDK.PaintProfilerModel));
var resourceTreeModel = target.model(SDK.ResourceTreeModel); var resourceTreeModel = target.model(SDK.ResourceTreeModel);
if (resourceTreeModel) { if (resourceTreeModel) {
resourceTreeModel.addEventListener( resourceTreeModel.addEventListener(
...@@ -48,7 +50,7 @@ Layers.LayerTreeModel = class extends SDK.SDKModel { ...@@ -48,7 +50,7 @@ Layers.LayerTreeModel = class extends SDK.SDKModel {
if (!this._enabled) if (!this._enabled)
return; return;
this._enabled = false; this._enabled = false;
this.target().layerTreeAgent().disable(); this._layerTreeAgent.disable();
} }
enable() { enable() {
...@@ -61,8 +63,8 @@ Layers.LayerTreeModel = class extends SDK.SDKModel { ...@@ -61,8 +63,8 @@ Layers.LayerTreeModel = class extends SDK.SDKModel {
_forceEnable() { _forceEnable() {
this._lastPaintRectByLayerId = {}; this._lastPaintRectByLayerId = {};
if (!this._layerTree) if (!this._layerTree)
this._layerTree = new Layers.AgentLayerTree(this.target()); this._layerTree = new Layers.AgentLayerTree(this);
this.target().layerTreeAgent().enable(); this._layerTreeAgent.enable();
} }
/** /**
...@@ -134,10 +136,11 @@ Layers.LayerTreeModel.Events = { ...@@ -134,10 +136,11 @@ Layers.LayerTreeModel.Events = {
*/ */
Layers.AgentLayerTree = class extends SDK.LayerTreeBase { Layers.AgentLayerTree = class extends SDK.LayerTreeBase {
/** /**
* @param {?SDK.Target} target * @param {!Layers.LayerTreeModel} layerTreeModel
*/ */
constructor(target) { constructor(layerTreeModel) {
super(target); super(layerTreeModel.target());
this._layerTreeModel = layerTreeModel;
} }
/** /**
...@@ -186,7 +189,7 @@ Layers.AgentLayerTree = class extends SDK.LayerTreeBase { ...@@ -186,7 +189,7 @@ Layers.AgentLayerTree = class extends SDK.LayerTreeBase {
if (layer) if (layer)
layer._reset(layers[i]); layer._reset(layers[i]);
else else
layer = new Layers.AgentLayer(this.target(), layers[i]); layer = new Layers.AgentLayer(this._layerTreeModel, layers[i]);
this._layersById[layerId] = layer; this._layersById[layerId] = layer;
var backendNodeId = layers[i].backendNodeId; var backendNodeId = layers[i].backendNodeId;
if (backendNodeId) if (backendNodeId)
...@@ -218,11 +221,11 @@ Layers.AgentLayerTree = class extends SDK.LayerTreeBase { ...@@ -218,11 +221,11 @@ Layers.AgentLayerTree = class extends SDK.LayerTreeBase {
*/ */
Layers.AgentLayer = class { Layers.AgentLayer = class {
/** /**
* @param {?SDK.Target} target * @param {!Layers.LayerTreeModel} layerTreeModel
* @param {!Protocol.LayerTree.Layer} layerPayload * @param {!Protocol.LayerTree.Layer} layerPayload
*/ */
constructor(target, layerPayload) { constructor(layerTreeModel, layerPayload) {
this._target = target; this._layerTreeModel = layerTreeModel;
this._reset(layerPayload); this._reset(layerPayload);
} }
...@@ -401,14 +404,9 @@ Layers.AgentLayer = class { ...@@ -401,14 +404,9 @@ Layers.AgentLayer = class {
* @param {function(!Array.<string>)} callback * @param {function(!Array.<string>)} callback
*/ */
requestCompositingReasons(callback) { requestCompositingReasons(callback) {
if (!this._target) {
callback([]);
return;
}
var wrappedCallback = Protocol.inspectorBackend.wrapClientCallback( var wrappedCallback = Protocol.inspectorBackend.wrapClientCallback(
callback, 'Protocol.LayerTree.reasonsForCompositingLayer(): ', undefined, []); callback, 'Protocol.LayerTree.reasonsForCompositingLayer(): ', undefined, []);
this._target.layerTreeAgent().compositingReasons(this.id(), wrappedCallback); this._layerTreeModel._layerTreeAgent.compositingReasons(this.id(), wrappedCallback);
} }
/** /**
...@@ -436,11 +434,11 @@ Layers.AgentLayer = class { ...@@ -436,11 +434,11 @@ Layers.AgentLayer = class {
* @return {!Array<!Promise<?SDK.SnapshotWithRect>>} * @return {!Array<!Promise<?SDK.SnapshotWithRect>>}
*/ */
snapshots() { snapshots() {
var rect = {x: 0, y: 0, width: this.width(), height: this.height()}; var promise = this._layerTreeModel._paintProfilerModel.makeSnapshot(this.id()).then(snapshot => {
var promise = this._target.layerTreeAgent().makeSnapshot( if (!snapshot)
this.id(), (error, snapshotId) => error || !this._target ? return null;
null : return {rect: {x: 0, y: 0, width: this.width(), height: this.height()}, snapshot: snapshot};
{rect: rect, snapshot: new SDK.PaintProfilerSnapshot(this._target, snapshotId)}); });
return [promise]; return [promise];
} }
......
...@@ -27,49 +27,66 @@ ...@@ -27,49 +27,66 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/**
* @typedef {!{x: number, y: number, picture: string}}
*/
SDK.PictureFragment;
/** SDK.PaintProfilerModel = class extends SDK.SDKModel {
* @unrestricted
*/
SDK.PaintProfilerSnapshot = class {
/** /**
* @param {!SDK.Target} target * @param {!SDK.Target} target
* @param {string} snapshotId
*/ */
constructor(target, snapshotId) { constructor(target) {
this._target = target; super(target);
this._id = snapshotId; this._layerTreeAgent = target.layerTreeAgent();
this._refCount = 1;
} }
/** /**
* @param {!SDK.Target} target
* @param {!Array.<!SDK.PictureFragment>} fragments * @param {!Array.<!SDK.PictureFragment>} fragments
* @return {!Promise<?SDK.PaintProfilerSnapshot>} * @return {!Promise<?SDK.PaintProfilerSnapshot>}
*/ */
static loadFromFragments(target, fragments) { loadSnapshotFromFragments(fragments) {
return target.layerTreeAgent().loadSnapshot( return this._layerTreeAgent.loadSnapshot(
fragments, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnapshot(target, snapshotId)); fragments, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnapshot(this, snapshotId));
} }
/** /**
* @param {!SDK.Target} target
* @param {string} encodedPicture * @param {string} encodedPicture
* @return {!Promise<?SDK.PaintProfilerSnapshot>} * @return {!Promise<?SDK.PaintProfilerSnapshot>}
*/ */
static load(target, encodedPicture) { loadSnapshot(encodedPicture) {
var fragment = {x: 0, y: 0, picture: encodedPicture}; var fragment = {x: 0, y: 0, picture: encodedPicture};
return SDK.PaintProfilerSnapshot.loadFromFragments(target, [fragment]); return this.loadSnapshotFromFragments([fragment]);
}
/**
* @param {string} layerId
* @return {!Promise<?SDK.PaintProfilerSnapshot>}
*/
makeSnapshot(layerId) {
return this._layerTreeAgent.makeSnapshot(
layerId, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnapshot(this, snapshotId));
}
};
SDK.SDKModel.register(SDK.PaintProfilerModel, SDK.Target.Capability.DOM, false);
/**
* @typedef {!{x: number, y: number, picture: string}}
*/
SDK.PictureFragment;
SDK.PaintProfilerSnapshot = class {
/**
* @param {!SDK.PaintProfilerModel} paintProfilerModel
* @param {string} snapshotId
*/
constructor(paintProfilerModel, snapshotId) {
this._paintProfilerModel = paintProfilerModel;
this._id = snapshotId;
this._refCount = 1;
} }
release() { release() {
console.assert(this._refCount > 0, 'release is already called on the object'); console.assert(this._refCount > 0, 'release is already called on the object');
if (!--this._refCount) if (!--this._refCount)
this._target.layerTreeAgent().releaseSnapshot(this._id); this._paintProfilerModel._layerTreeAgent.releaseSnapshot(this._id);
} }
addReference() { addReference() {
...@@ -77,13 +94,6 @@ SDK.PaintProfilerSnapshot = class { ...@@ -77,13 +94,6 @@ SDK.PaintProfilerSnapshot = class {
console.assert(this._refCount > 0, 'Referencing a dead object'); console.assert(this._refCount > 0, 'Referencing a dead object');
} }
/**
* @return {!SDK.Target}
*/
target() {
return this._target;
}
/** /**
* @param {?number} firstStep * @param {?number} firstStep
* @param {?number} lastStep * @param {?number} lastStep
...@@ -91,7 +101,7 @@ SDK.PaintProfilerSnapshot = class { ...@@ -91,7 +101,7 @@ SDK.PaintProfilerSnapshot = class {
* @return {!Promise<?string>} * @return {!Promise<?string>}
*/ */
replay(firstStep, lastStep, scale) { replay(firstStep, lastStep, scale) {
return this._target.layerTreeAgent().replaySnapshot( return this._paintProfilerModel._layerTreeAgent.replaySnapshot(
this._id, firstStep || undefined, lastStep || undefined, scale || 1.0, (error, str) => error ? null : str); this._id, firstStep || undefined, lastStep || undefined, scale || 1.0, (error, str) => error ? null : str);
} }
...@@ -102,14 +112,14 @@ SDK.PaintProfilerSnapshot = class { ...@@ -102,14 +112,14 @@ SDK.PaintProfilerSnapshot = class {
profile(clipRect, callback) { profile(clipRect, callback) {
var wrappedCallback = var wrappedCallback =
Protocol.inspectorBackend.wrapClientCallback(callback, 'Protocol.LayerTree.profileSnapshot(): '); Protocol.inspectorBackend.wrapClientCallback(callback, 'Protocol.LayerTree.profileSnapshot(): ');
this._target.layerTreeAgent().profileSnapshot(this._id, 5, 1, clipRect || undefined, wrappedCallback); this._paintProfilerModel._layerTreeAgent.profileSnapshot(this._id, 5, 1, clipRect || undefined, wrappedCallback);
} }
/** /**
* @return {!Promise<?Array<!SDK.PaintProfilerLogItem>>} * @return {!Promise<?Array<!SDK.PaintProfilerLogItem>>}
*/ */
commandLog() { commandLog() {
return this._target.layerTreeAgent().snapshotCommandLog(this._id, processLog); return this._paintProfilerModel._layerTreeAgent.snapshotCommandLog(this._id, processLog);
/** /**
* @param {?string} error * @param {?string} error
...@@ -125,7 +135,6 @@ SDK.PaintProfilerSnapshot = class { ...@@ -125,7 +135,6 @@ SDK.PaintProfilerSnapshot = class {
} }
}; };
/** /**
* @typedef {!{method: string, params: ?Object<string, *>}} * @typedef {!{method: string, params: ?Object<string, *>}}
*/ */
......
...@@ -204,11 +204,11 @@ Timeline.TimelineDetailsView = class extends UI.VBox { ...@@ -204,11 +204,11 @@ Timeline.TimelineDetailsView = class extends UI.VBox {
* @param {!SDK.TracingModel.Event} event * @param {!SDK.TracingModel.Event} event
*/ */
_showEventInPaintProfiler(event) { _showEventInPaintProfiler(event) {
const target = SDK.targetManager.mainTarget(); const paintProfilerModel = SDK.targetManager.models(SDK.PaintProfilerModel)[0];
if (!target) if (!paintProfilerModel)
return; return;
const paintProfilerView = this._paintProfilerView(); const paintProfilerView = this._paintProfilerView();
const hasProfileData = paintProfilerView.setEvent(target, event); const hasProfileData = paintProfilerView.setEvent(paintProfilerModel, event);
if (!hasProfileData) if (!hasProfileData)
return; return;
if (this._tabbedPane.hasTab(Timeline.TimelineDetailsView.Tab.PaintProfiler)) if (this._tabbedPane.hasTab(Timeline.TimelineDetailsView.Tab.PaintProfiler))
......
...@@ -32,8 +32,8 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget { ...@@ -32,8 +32,8 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
this._pendingSnapshot = null; this._pendingSnapshot = null;
/** @type {?SDK.TracingModel.Event} */ /** @type {?SDK.TracingModel.Event} */
this._event = null; this._event = null;
/** @type {?SDK.Target} */ /** @type {?SDK.PaintProfilerModel} */
this._target = null; this._paintProfilerModel = null;
/** @type {?SDK.PaintProfilerSnapshot} */ /** @type {?SDK.PaintProfilerSnapshot} */
this._lastLoadedSnapshot = null; this._lastLoadedSnapshot = null;
} }
...@@ -59,13 +59,13 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget { ...@@ -59,13 +59,13 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
} }
/** /**
* @param {!SDK.Target} target * @param {!SDK.PaintProfilerModel} paintProfilerModel
* @param {!SDK.TracingModel.Event} event * @param {!SDK.TracingModel.Event} event
* @return {boolean} * @return {boolean}
*/ */
setEvent(target, event) { setEvent(paintProfilerModel, event) {
this._releaseSnapshot(); this._releaseSnapshot();
this._target = target; this._paintProfilerModel = paintProfilerModel;
this._pendingSnapshot = null; this._pendingSnapshot = null;
this._event = event; this._event = event;
...@@ -85,7 +85,7 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget { ...@@ -85,7 +85,7 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
} }
_update() { _update() {
this._logTreeView.setCommandLog(null, []); this._logTreeView.setCommandLog([]);
this._paintProfilerView.setSnapshotAndLog(null, [], null); this._paintProfilerView.setSnapshotAndLog(null, [], null);
var snapshotPromise; var snapshotPromise;
...@@ -93,9 +93,8 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget { ...@@ -93,9 +93,8 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
snapshotPromise = Promise.resolve({rect: null, snapshot: this._pendingSnapshot}); snapshotPromise = Promise.resolve({rect: null, snapshot: this._pendingSnapshot});
} else if (this._event.name === TimelineModel.TimelineModel.RecordType.Paint) { } else if (this._event.name === TimelineModel.TimelineModel.RecordType.Paint) {
var picture = TimelineModel.TimelineData.forEvent(this._event).picture; var picture = TimelineModel.TimelineData.forEvent(this._event).picture;
snapshotPromise = snapshotPromise = picture.objectPromise()
picture.objectPromise() .then(data => this._paintProfilerModel.loadSnapshot(data['skp64']))
.then(data => SDK.PaintProfilerSnapshot.load(/** @type {!SDK.Target} */ (this._target), data['skp64']))
.then(snapshot => snapshot && {rect: null, snapshot: snapshot}); .then(snapshot => snapshot && {rect: null, snapshot: snapshot});
} else if (this._event.name === TimelineModel.TimelineModel.RecordType.RasterTask) { } else if (this._event.name === TimelineModel.TimelineModel.RecordType.RasterTask) {
snapshotPromise = this._frameModel.rasterTilePromise(this._event); snapshotPromise = this._frameModel.rasterTilePromise(this._event);
...@@ -122,7 +121,7 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget { ...@@ -122,7 +121,7 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
* @this {Timeline.TimelinePaintProfilerView} * @this {Timeline.TimelinePaintProfilerView}
*/ */
function onCommandLogDone(snapshot, clipRect, log) { function onCommandLogDone(snapshot, clipRect, log) {
this._logTreeView.setCommandLog(snapshot.target(), log || []); this._logTreeView.setCommandLog(log || []);
this._paintProfilerView.setSnapshotAndLog(snapshot, log || [], clipRect); this._paintProfilerView.setSnapshotAndLog(snapshot, log || [], clipRect);
} }
} }
......
...@@ -505,10 +505,11 @@ TimelineModel.LayerPaintEvent = class { ...@@ -505,10 +505,11 @@ TimelineModel.LayerPaintEvent = class {
* @return !Promise<?{rect: !Array<number>, snapshot: !SDK.PaintProfilerSnapshot}>} * @return !Promise<?{rect: !Array<number>, snapshot: !SDK.PaintProfilerSnapshot}>}
*/ */
snapshotPromise() { snapshotPromise() {
var paintProfilerModel = this._target && this._target.model(SDK.PaintProfilerModel);
return this.picturePromise().then(picture => { return this.picturePromise().then(picture => {
if (!picture || !this._target) if (!picture || !paintProfilerModel)
return null; return null;
return SDK.PaintProfilerSnapshot.load(this._target, picture.serializedPicture) return paintProfilerModel.loadSnapshot(picture.serializedPicture)
.then(snapshot => snapshot ? {rect: picture.rect, snapshot: snapshot} : null); .then(snapshot => snapshot ? {rect: picture.rect, snapshot: snapshot} : null);
}); });
} }
......
...@@ -37,6 +37,7 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase { ...@@ -37,6 +37,7 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase {
super(target); super(target);
/** @type {!Map.<string, !TimelineModel.TracingLayerTile>} */ /** @type {!Map.<string, !TimelineModel.TracingLayerTile>} */
this._tileById = new Map(); this._tileById = new Map();
this._paintProfilerModel = target && target.model(SDK.PaintProfilerModel);
} }
/** /**
...@@ -129,7 +130,7 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase { ...@@ -129,7 +130,7 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase {
if (layer) if (layer)
layer._reset(payload); layer._reset(payload);
else else
layer = new TimelineModel.TracingLayer(this.target(), payload); layer = new TimelineModel.TracingLayer(this._paintProfilerModel, payload);
this._layersById[payload.layer_id] = layer; this._layersById[payload.layer_id] = layer;
if (payload.owner_node) if (payload.owner_node)
layer._setNode(this.backendNodeIdToNode().get(payload.owner_node) || null); layer._setNode(this.backendNodeIdToNode().get(payload.owner_node) || null);
...@@ -160,11 +161,11 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase { ...@@ -160,11 +161,11 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase {
*/ */
TimelineModel.TracingLayer = class { TimelineModel.TracingLayer = class {
/** /**
* @param {?SDK.PaintProfilerModel} paintProfilerModel
* @param {!TimelineModel.TracingLayerPayload} payload * @param {!TimelineModel.TracingLayerPayload} payload
* @param {?SDK.Target} target
*/ */
constructor(target, payload) { constructor(paintProfilerModel, payload) {
this._target = target; this._paintProfilerModel = paintProfilerModel;
this._reset(payload); this._reset(payload);
} }
...@@ -387,14 +388,14 @@ TimelineModel.TracingLayer = class { ...@@ -387,14 +388,14 @@ TimelineModel.TracingLayer = class {
var fragments = var fragments =
pictures.filter(picture => picture && rectsOverlap(picture.rect, targetRect)) pictures.filter(picture => picture && rectsOverlap(picture.rect, targetRect))
.map(picture => ({x: picture.rect[0], y: picture.rect[1], picture: picture.serializedPicture})); .map(picture => ({x: picture.rect[0], y: picture.rect[1], picture: picture.serializedPicture}));
if (!fragments.length || !this._target) if (!fragments.length || !this._paintProfilerModel)
return null; return null;
var x0 = fragments.reduce((min, item) => Math.min(min, item.x), Infinity); var x0 = fragments.reduce((min, item) => Math.min(min, item.x), Infinity);
var y0 = fragments.reduce((min, item) => Math.min(min, item.y), Infinity); var y0 = fragments.reduce((min, item) => Math.min(min, item.y), Infinity);
// Rect is in layer content coordinates, make it relative to picture by offsetting to the top left corner. // Rect is in layer content coordinates, make it relative to picture by offsetting to the top left corner.
var rect = {x: targetRect[0] - x0, y: targetRect[1] - y0, width: targetRect[2], height: targetRect[3]}; var rect = {x: targetRect[0] - x0, y: targetRect[1] - y0, width: targetRect[2], height: targetRect[3]};
return SDK.PaintProfilerSnapshot.loadFromFragments(this._target, fragments) return this._paintProfilerModel.loadSnapshotFromFragments(fragments).then(
.then(snapshot => snapshot ? {rect: rect, snapshot: snapshot} : null); snapshot => snapshot ? {rect: rect, snapshot: snapshot} : null);
}); });
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment